anjay
|
#include <anjay/anjay.h>
Go to the source code of this file.
Data Structures | |
struct | anjay_send_resource_path_t |
Macros | |
#define | ANJAY_SEND_DEFERRED_ERROR (-3) |
#define | ANJAY_SEND_ABORT (-2) |
#define | ANJAY_SEND_TIMEOUT (-1) |
#define | ANJAY_SEND_SUCCESS 0 |
Typedefs | |
typedef struct anjay_send_batch_builder_struct | anjay_send_batch_builder_t |
typedef struct anjay_send_batch_struct | anjay_send_batch_t |
typedef void | anjay_send_finished_handler_t(anjay_t *anjay, anjay_ssid_t ssid, const anjay_send_batch_t *batch, int result, void *data) |
Enumerations | |
enum | anjay_send_result_t { ANJAY_SEND_OK = 0 , ANJAY_SEND_ERR_UNSUPPORTED , ANJAY_SEND_ERR_MUTED , ANJAY_SEND_ERR_OFFLINE , ANJAY_SEND_ERR_BOOTSTRAP , ANJAY_SEND_ERR_SSID , ANJAY_SEND_ERR_PROTOCOL , ANJAY_SEND_ERR_INTERNAL } |
#define ANJAY_SEND_ABORT (-2) |
Result passed to anjay_send_finished_handler_t: No response from Server was received and further retransmissions are aborted due to library cleanup or because the socket used to communicate with the server is being disconnected (e.g. when entering offline mode).
#define ANJAY_SEND_DEFERRED_ERROR (-3) |
Send request has previously been deferred, the factors that caused it to be deferred are no longer valid, but it could not be initiated for other reasons.
EXAMPLE: anjay_send_deferrable may have been called when the server was offline. The server is now online, but the Send request have been rejected due to the registration having been performed with the LwM2M TS 1.0 protocol version.
NOTE: Any of the errors defined in anjay_send_result_t may be mapped onto this error code. There is currently no way to determine more detailed reason.
#define ANJAY_SEND_SUCCESS 0 |
Result passed to anjay_send_finished_handler_t: Server confirmed successful message delivery.
#define ANJAY_SEND_TIMEOUT (-1) |
Result passed to anjay_send_finished_handler_t: No response from Server was received in expected time, or connection with the server has been lost. Retransmissions will not continue - you may try to send the same batch again using anjay_send .
typedef struct anjay_send_batch_builder_struct anjay_send_batch_builder_t |
typedef struct anjay_send_batch_struct anjay_send_batch_t |
typedef void anjay_send_finished_handler_t(anjay_t *anjay, anjay_ssid_t ssid, const anjay_send_batch_t *batch, int result, void *data) |
A handler called if acknowledgement for LwM2M Send operation is received from the Server or all retransmissions of LwM2M Send have failed.
anjay | Anjay object for which the Send operation was attempted. |
ssid | Short Server ID of the server to which the batch was being sent. |
batch | Pointer to a batch that was being sent. This pointer may be passed to anjay_send for sending again; if you wish to store it for later usage, anjay_send_batch_acquire MUST be used. |
result | Result of the Send message delivery attempt. May be one of:
|
data | Data defined by user passed into the handler. |
enum anjay_send_result_t |
All possible error codes that will be returned by the anjay_send()
Enumerator | |
---|---|
ANJAY_SEND_OK | |
ANJAY_SEND_ERR_UNSUPPORTED | This version of Anjay does not support LwM2M Send operation. |
ANJAY_SEND_ERR_MUTED | LwM2M Send cannot be performed because of "Mute Send" Resource is set to true. NOTE: The value of "Mute Send" Resource is controlled by the LwM2M Server itself. |
ANJAY_SEND_ERR_OFFLINE | Passed Short Server ID refers to a server, connection to which is currently offline. The LwM2M Send operation may be retried after making the connection back online. |
ANJAY_SEND_ERR_BOOTSTRAP | Anjay is in process of a Bootstrap. The LwM2M Send operation may be retried after finishing the Bootstrap stage. |
ANJAY_SEND_ERR_SSID | Passed Short Server ID does not correspond to any existing / connected, non-Bootstrap Server. Especially passing ANJAY_SSID_ANY or ANJAY_SSID_BOOTSTRAP causes this error to be returned. |
ANJAY_SEND_ERR_PROTOCOL | The LwM2M protocol version used to connect to an LwM2M Server does not support the LwM2M Send operation. |
ANJAY_SEND_ERR_INTERNAL | Internal error. Very likely caused by the out-of-memory condition. The LwM2M Send operation may be retried after freeing some memory. |
anjay_send_result_t anjay_send | ( | anjay_t * | anjay, |
anjay_ssid_t | ssid, | ||
const anjay_send_batch_t * | data, | ||
anjay_send_finished_handler_t * | finished_handler, | ||
void * | finished_handler_data | ||
) |
Sends data to the LwM2M Server without explicit request by that Server.
During the next call to anjay_sched_run data
will be sent asynchronously to the Server with specified ssid
but only if Mute Send resource of the server instance associated with ssid
is set to false. Otherwise nothing is sent and ANJAY_SEND_ERR_MUTED is returned.
data
must not be NULL but it can be everything successfully returned from anjay_send_batch_builder_compile . Even empty batch is acceptable:
Before sending content of data
is filtered according to Access Control permissions of a particular server. The server will get only those entries of data
which paths were configured by anjay_access_control_set_acl with enabled ANJAY_ACCESS_MASK_READ
.
If finished_handler
is not NULL it will always be called at some point - after receiving acknowledgement from the Server or if no response was received in expected time.
Success of this function means only that the data has been sent, not necessarily delivered. Data is delivered if and only if finished_handler
with status ANJAY_SEND_SUCCESS
is called.
anjay | Anjay object to operate on. |
ssid | Short Server ID of target LwM2M Server. Cannot be ANJAY_SSID_ANY or ANJAY_SSID_BOOTSTRAP. |
data | Content of the message compiled previously with anjay_send_batch_builder_compile . |
finished_handler | Handler called if the server confirmed message delivery or if no response was received in expected time (handler can be NULL). |
finished_handler_data | Data for the handler. |
anjay_send_batch_t * anjay_send_batch_acquire | ( | const anjay_send_batch_t * | batch | ) |
Increments the refcount for a *batch. Must always be used if batch would be referenced out of current scope, especially when the pointer would be saved to an object that is dynamically allocated. Each call of this function must have complementary anjay_send_batch_release call at some point.
batch | Non-null batch which refcount will be incremented |
batch
int anjay_send_batch_add_bool | ( | anjay_send_batch_builder_t * | builder, |
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid, | ||
anjay_riid_t | riid, | ||
avs_time_real_t | timestamp, | ||
bool | value | ||
) |
Adds a value to batch builder.
IMPORTANT NOTE: If timestamp
is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"
builder | Pointer to batch builder |
oid | Object ID, MUST NOT be UINT16_MAX |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
riid | Resource Instance ID, UINT16_MAX for no RIID |
timestamp | Time related to value being sent (e.g. when the measurement corresponding to the passed value was made) |
value | Value to add to the batch. |
builder
is left unchanged. int anjay_send_batch_add_bytes | ( | anjay_send_batch_builder_t * | builder, |
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid, | ||
anjay_riid_t | riid, | ||
avs_time_real_t | timestamp, | ||
const void * | data, | ||
size_t | length | ||
) |
Adds bytes to batch builder.
IMPORTANT NOTE: If timestamp
is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"
builder | Pointer to batch builder |
oid | Object ID, MUST NOT be UINT16_MAX |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
riid | Resource Instance ID, UINT16_MAX for no RIID |
timestamp | Time related to bytes being send (e.g. when the measurement corresponding to the passed bytes was made) |
data | Pointer to data. No longer required by batch builder after call to this function, because internal copy is made. Can be NULL only if length is 0. |
length | Length of data in bytes. |
builder
is left unchanged. int anjay_send_batch_add_double | ( | anjay_send_batch_builder_t * | builder, |
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid, | ||
anjay_riid_t | riid, | ||
avs_time_real_t | timestamp, | ||
double | value | ||
) |
Adds a value to batch builder.
IMPORTANT NOTE: If timestamp
is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"
builder | Pointer to batch builder |
oid | Object ID, MUST NOT be UINT16_MAX |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
riid | Resource Instance ID, UINT16_MAX for no RIID |
timestamp | Time related to value being sent (e.g. when the measurement corresponding to the passed value was made) |
value | Value to add to the batch. |
builder
is left unchanged. int anjay_send_batch_add_int | ( | anjay_send_batch_builder_t * | builder, |
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid, | ||
anjay_riid_t | riid, | ||
avs_time_real_t | timestamp, | ||
int64_t | value | ||
) |
Adds a value to batch builder.
IMPORTANT NOTE: If timestamp
is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"
builder | Pointer to batch builder |
oid | Object ID, MUST NOT be UINT16_MAX |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
riid | Resource Instance ID, UINT16_MAX for no RIID |
timestamp | Time related to value being sent (e.g. when the measurement corresponding to the passed value was made) |
value | Value to add to the batch. |
builder
is left unchanged. int anjay_send_batch_add_objlnk | ( | anjay_send_batch_builder_t * | builder, |
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid, | ||
anjay_riid_t | riid, | ||
avs_time_real_t | timestamp, | ||
anjay_oid_t | objlnk_oid, | ||
anjay_iid_t | objlnk_iid | ||
) |
Adds an Object Link to batch builder.
IMPORTANT NOTE: If timestamp
is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"
builder | Pointer to batch builder |
oid | Object ID, MUST NOT be UINT16_MAX |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
riid | Resource Instance ID, UINT16_MAX for no RIID |
timestamp | Time related to Object Link being send (e.g. when the measurement corresponding to the passed Object Link was made) |
objlnk_oid | OID of Object Link |
objlnk_iid | IID of Object Link |
builder
is left unchanged. int anjay_send_batch_add_string | ( | anjay_send_batch_builder_t * | builder, |
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid, | ||
anjay_riid_t | riid, | ||
avs_time_real_t | timestamp, | ||
const char * | str | ||
) |
Adds a string to batch builder.
IMPORTANT NOTE: If timestamp
is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"
builder | Pointer to batch builder |
oid | Object ID, MUST NOT be UINT16_MAX |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
riid | Resource Instance ID, UINT16_MAX for no RIID |
timestamp | Time related to string being send (e.g. when the measurement corresponding to the passed string was made) |
str | Pointer to a NULL-terminated string. Must not be NULL. No longer required by batch builder after call to this function, because internal copy is made. |
builder
is left unchanged. int anjay_send_batch_add_uint | ( | anjay_send_batch_builder_t * | builder, |
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid, | ||
anjay_riid_t | riid, | ||
avs_time_real_t | timestamp, | ||
uint64_t | value | ||
) |
Adds a value to batch builder.
IMPORTANT NOTE: If timestamp
is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"
builder | Pointer to batch builder |
oid | Object ID, MUST NOT be UINT16_MAX |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
riid | Resource Instance ID, UINT16_MAX for no RIID |
timestamp | Time related to value being sent (e.g. when the measurement corresponding to the passed value was made) |
value | Value to add to the batch. |
builder
is left unchanged. void anjay_send_batch_builder_cleanup | ( | anjay_send_batch_builder_t ** | builder | ) |
Releases batch builder and discards all data. It has no effect if builder was previously compiled.
builder | Pointer to pointer to data builder. Set to NULL after cleanup. |
anjay_send_batch_t * anjay_send_batch_builder_compile | ( | anjay_send_batch_builder_t ** | builder | ) |
Makes a dynamically-allocated, reference-counted immutable data batch using data from batch builder. Created batch can be used for multiple calls of anjay_send()
.
builder | Pointer to pointer to batch builder. Set to NULL after successful return. |
anjay_send_batch_builder_t * anjay_send_batch_builder_new | ( | void | ) |
Creates a batch builder that may be used to build a payload with the data to be sent to the LwM2M Server by means of LwM2M Send operation.
Intended use of the batch builder may be divided into four steps, as follows:
Example use (error checking omitted for brevity):
int anjay_send_batch_data_add_current | ( | anjay_send_batch_builder_t * | builder, |
anjay_t * | anjay, | ||
anjay_oid_t | oid, | ||
anjay_iid_t | iid, | ||
anjay_rid_t | rid | ||
) |
Reads value from data model of object anjay
(without checking access privileges) and adds it to the builder with timestamp set to avs_time_real_now()
.
May possibly add multiple entries if /oid/iid/rid is a Multiple Resource.
builder | Pointer to batch builder, MUST NOT be NULL |
anjay | Pointer to Anjay object, MUST NOT be NULL |
oid | Object ID, MUST NOT be UINT16_MAX , 0 (Security object ID) or 21 (OSCORE object ID). |
iid | Instance ID, MUST NOT be UINT16_MAX |
rid | Resource ID, MUST NOT be UINT16_MAX |
builder
is left unchanged. int anjay_send_batch_data_add_current_multiple | ( | anjay_send_batch_builder_t * | builder, |
anjay_t * | anjay, | ||
const anjay_send_resource_path_t * | paths, | ||
size_t | paths_length | ||
) |
Reads values from data model of object anjay
(without checking access privileges) and adds them to the builder with the same timestamp for every value. Timestamp is set to avs_time_real_now()
.
builder | Pointer to batch builder, MUST NOT be NULL |
anjay | Pointer to Anjay object, MUST NOT be NULL |
paths | Pointer to array of anjay_send_resource_path_t . |
paths_length | Length of paths array. |
builder
is left unchanged. int anjay_send_batch_data_add_current_multiple_ignore_not_found | ( | anjay_send_batch_builder_t * | builder, |
anjay_t * | anjay, | ||
const anjay_send_resource_path_t * | paths, | ||
size_t | paths_length | ||
) |
Reads values from data model of object anjay
(without checking access privileges) and adds them to the builder with the same timestamp for every value. Timestamp is set to avs_time_real_now()
.
If a resource is not found, it's ignored, the error isn't returned and the function adds next resources from the paths
.
builder | Pointer to batch builder, MUST NOT be NULL |
anjay | Pointer to Anjay object, MUST NOT be NULL |
paths | Pointer to array of anjay_send_resource_path_t . |
paths_length | Length of paths array. |
builder
is left unchanged. void anjay_send_batch_release | ( | anjay_send_batch_t ** | batch | ) |
Decreases the refcount for a *batch, sets it to NULL, and frees it if the refcount has reached zero.
*batch | Pointer to compiled data batch. |
anjay_send_result_t anjay_send_deferrable | ( | anjay_t * | anjay, |
anjay_ssid_t | ssid, | ||
const anjay_send_batch_t * | data, | ||
anjay_send_finished_handler_t * | finished_handler, | ||
void * | finished_handler_data | ||
) |
Sends data to the LwM2M server, either immediately, or deferring it until such operation will be possible.
This function is equivalent to anjay_send, but in cases when the former would return ANJAY_SEND_ERR_OFFLINE or ANJAY_SEND_ERR_BOOTSTRAP, this variant returns success and postpones the actual Send operation until the server connection identified by ssid
is online.
If at that time, the server in question will be removed from the data model, registered using a LwM2M version that does not support the Send operation (i.e., LwM2M 1.0), or the Mute Send resource changes while the Send is deferred, the operation is cancelled and finished_handler
is called with the result
argument set to ANJAY_SEND_DEFERRED_ERROR.
anjay | Anjay object to operate on. |
ssid | Short Server ID of target LwM2M Server. Cannot be ANJAY_SSID_ANY or ANJAY_SSID_BOOTSTRAP. |
data | Content of the message compiled previously with anjay_send_batch_builder_compile . |
finished_handler | Handler called if the server confirmed message delivery or if no response was received in expected time (handler can be NULL). |
finished_handler_data | Data for the handler. |