Function anjay_send_batch_builder_new
Defined in File lwm2m_send.h
Function Documentation
-
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:
Create a batch builder.
Fill in the builder with data, by calling anjay_send_batch_add_* functions (possibly multiple times).
Convert the builder into the final, immutable batch by anjay_send_batch_builder_compile function call.
Pass the resulting batch to anjay_send .
IMPORTANT NOTE: LwM2M SEND API can be also used with LwM2M Gateway End Device objects lwm2m_gateway.h . In such case, use anjay_lwm2m_gateway_send_batch_add_* functions to add values from Gateway End Device objects to the batch. In one batch builder you can mix data from different End Devices and Gateway objects. Do not use anjay_lwm2m_gateway_deregister_device or anjay_lwm2m_gateway_register_device when building data batch because the records in batch may refer to the wrong End Device.
Example use (error checking omitted for brevity):
// Creates a builder for a batch. anjay_send_batch_builder_t *builder = anjay_send_batch_builder_new(); // Adds signed integer value to batch builder, without checking if such // resource (oid=1, iid=2, rid=3) exists in datamodel. anjay_send_batch_add_int( builder, 1, 2, 3, UINT16_MAX, avs_time_real_now(), 123); // Adds value from datamodel (oid=4, iid=5, rid=6) to batch builder if it // exists. anjay_send_batch_data_add_current(builder, anjay, 4, 5, 6); // Creates immutable data batch and releases builder. anjay_send_batch_t *batch = anjay_send_batch_builder_compile(builder); // Puts LwM2M Send request on the scheduler queue. During next call to // anjay_sched_run content of the batch will be sent to server with SSID=1 anjay_send(anjay, 1, batch, NULL, NULL); // Releases the batch if it's not used by some send operation. anjay_send_batch_release(&batch);
- Returns:
Pointer to dynamically allocated batch builder, which is freed implicitly in anjay_send_batch_builder_compile() or has to be freed manually by calling anjay_send_batch_builder_cleanup() . NULL in case of allocation failure.