#include <m2mbase.h>
Data Structures | |
struct | lwm2m_parameters |
LwM2M parameters. More... | |
Public Types | |
enum | BaseType { Object = 0x0, Resource = 0x1, ObjectInstance = 0x2, ResourceInstance = 0x3 } |
Enum to define the type of object. | |
enum | Observation { None = 0x0, R_Attribute = 0x01, OI_Attribute = 0x02, OIR_Attribute = 0x03, O_Attribute = 0x04, OR_Attribute = 0x05, OOI_Attribute = 0x06, OOIR_Attribute = 0x07 } |
Enum to define observation level. | |
enum | Mode { Static, Dynamic, Directory } |
Enum defining a resource type. More... | |
enum | DataType { STRING, INTEGER, FLOAT, BOOLEAN, OPAQUE, TIME, OBJLINK } |
Enum defining a resource data type. | |
enum | Operation { NOT_ALLOWED = 0x00, GET_ALLOWED = 0x01, PUT_ALLOWED = 0x02, GET_PUT_ALLOWED = 0x03, POST_ALLOWED = 0x04, GET_POST_ALLOWED = 0x05, PUT_POST_ALLOWED = 0x06, GET_PUT_POST_ALLOWED = 0x07, DELETE_ALLOWED = 0x08, GET_DELETE_ALLOWED = 0x09, PUT_DELETE_ALLOWED = 0x0A, GET_PUT_DELETE_ALLOWED = 0x0B, POST_DELETE_ALLOWED = 0x0C, GET_POST_DELETE_ALLOWED = 0x0D, PUT_POST_DELETE_ALLOWED = 0x0E, GET_PUT_POST_DELETE_ALLOWED = 0x0F } |
Enum defining an operation that can be supported by a given resource. More... | |
enum | MessageDeliveryStatus { MESSAGE_STATUS_INIT = 0, MESSAGE_STATUS_BUILD_ERROR, MESSAGE_STATUS_RESEND_QUEUE_FULL, MESSAGE_STATUS_SENT, MESSAGE_STATUS_DELIVERED, MESSAGE_STATUS_SEND_FAILED, MESSAGE_STATUS_SUBSCRIBED, MESSAGE_STATUS_UNSUBSCRIBED, MESSAGE_STATUS_REJECTED } |
Enum defining an status codes that can happen when sending confirmable message. More... | |
enum | MessageType { NOTIFICATION = 0, DELAYED_POST_RESPONSE, BLOCK_SUBSCRIBE, PING, DELAYED_RESPONSE } |
enum | MaxPathSize { MAX_NAME_SIZE = 64, MAX_INSTANCE_SIZE = 5, MAX_PATH_SIZE = ((MAX_NAME_SIZE * 2) + (MAX_INSTANCE_SIZE * 2) + 3 + 1), MAX_PATH_SIZE_2 = ((MAX_NAME_SIZE * 2) + MAX_INSTANCE_SIZE + 2 + 1), MAX_PATH_SIZE_3 = (MAX_NAME_SIZE + (MAX_INSTANCE_SIZE * 2) + 2 + 1), MAX_PATH_SIZE_4 = (MAX_NAME_SIZE + MAX_INSTANCE_SIZE + 1 + 1) } |
typedef void(* | message_delivery_status_cb) (const M2MBase &base, const MessageDeliveryStatus status, const MessageType type, void *client_args) |
typedef struct M2MBase::lwm2m_parameters | lwm2m_parameters_s |
LwM2M parameters. More... | |
Public Member Functions | |
virtual | ~M2MBase () |
Destructor. | |
void | set_operation (M2MBase::Operation operation) |
Sets the operation type for an object. More... | |
void | set_interface_description (const String &description) |
Sets the interface description of the object. More... | |
void | set_interface_description (const char *description) |
Sets the interface description of the object. More... | |
const char * | interface_description () const |
Returns the interface description of the object. More... | |
virtual void | set_resource_type (const String &resource_type) |
Sets the resource type of the object. More... | |
virtual void | set_resource_type (const char *resource_type) |
Sets the resource type of the object. More... | |
const char * | resource_type () const |
Returns the resource type of the object. More... | |
void | set_coap_content_type (const uint16_t content_type) |
Sets the CoAP content type of the object. More... | |
void | set_observable (bool observable) |
Sets the observable mode for the object. More... | |
void | set_auto_observable (bool auto_observable) |
Sets the object to be auto-observable. More... | |
void | set_confirmable (bool confirmable) |
Sets how the notification is sent. By default confirmable CoAP message type is used. More... | |
virtual void | add_observation_level (M2MBase::Observation observation_level) |
Adds the observation level for the object. More... | |
virtual void | remove_observation_level (M2MBase::Observation observation_level) |
Removes the observation level for the object. More... | |
void | set_under_observation (bool observed, M2MObservationHandler *handler) |
Sets the object under observation. More... | |
virtual M2MObservationHandler * | observation_handler () const =0 |
Returns the Observation Handler object. More... | |
virtual void | set_observation_handler (M2MObservationHandler *handler)=0 |
Sets the observation handler. More... | |
void | set_instance_id (const uint16_t instance_id) |
Sets the instance ID of the object. More... | |
void | set_max_age (const uint32_t max_age) |
Sets the max age for the resource value to be cached. More... | |
M2MBase::BaseType | base_type () const |
Returns the object type. More... | |
M2MBase::Operation | operation () const |
Returns the operation type of the object. More... | |
const char * | name () const |
Returns the object name. More... | |
int32_t | name_id () const |
Returns the object name in integer. More... | |
uint16_t | instance_id () const |
Returns the object's instance ID. More... | |
const char * | uri_path () const |
Returns the path of the object. More... | |
uint16_t | coap_content_type () const |
Returns the CoAP content type of the object. More... | |
bool | is_readable () const |
Returns get operation allow state. More... | |
bool | is_auto_observable () const |
Returns the auto observation status of the object. More... | |
M2MBase::Observation | observation_level () const |
Returns the observation level of the object. More... | |
Mode | mode () const |
Returns the mode of the resource. More... | |
uint16_t | observation_number () const |
Returns the observation number. More... | |
uint32_t | max_age () const |
Returns the max age for the resource value to be cached. More... | |
virtual sn_coap_hdr_s * | handle_get_request (nsdl_s *nsdl, sn_coap_hdr_s *received_coap_header, M2MObservationHandler *observation_handler=NULL) |
Handles GET request for the registered objects. More... | |
virtual sn_coap_hdr_s * | handle_put_request (nsdl_s *nsdl, sn_coap_hdr_s *received_coap_header, M2MObservationHandler *observation_handler, bool &execute_value_updated) |
Handles PUT request for the registered objects. More... | |
virtual sn_coap_hdr_s * | handle_post_request (nsdl_s *nsdl, sn_coap_hdr_s *received_coap_header, M2MObservationHandler *observation_handler, bool &execute_value_updated, sn_nsdl_addr_s *address=NULL) |
Handles GET request for the registered objects. More... | |
void | send_message_delivery_status (const M2MBase &object, const MessageDeliveryStatus status, const MessageType type) |
Executes the function that is set in "set_message_delivery_status_cb". | |
void | set_register_uri (bool register_uri) |
Sets whether this resource is published to server or not. More... | |
bool | register_uri () |
Returns whether this resource is published to server or not. More... | |
bool | is_under_observation () const |
Returns whether this resource is under observation or not. More... | |
bool | set_value_updated_function (value_updated_callback callback) |
Sets the function that is executed when this object receives a PUT or POST command. More... | |
bool | set_value_updated_function (value_updated_callback2 callback) |
Sets the function that is executed when this object receives a PUT or POST command. More... | |
bool | is_value_updated_function_set () const |
Returns whether a callback function is set or not. More... | |
void | execute_value_updated (const String &name) |
Calls the function that is set in the "set_value_updated_function". More... | |
size_t | resource_name_length () const |
Returns length of the object name. More... | |
sn_nsdl_dynamic_resource_parameters_s * | get_nsdl_resource () const |
Returns the resource information. More... | |
M2MBase::lwm2m_parameters_s * | get_lwm2m_parameters () const |
Returns the resource structure. More... | |
uint16_t | get_notification_msgid () const m2m_deprecated |
Returns the notification message id. More... | |
void | set_notification_msgid (uint16_t msgid) m2m_deprecated |
Sets the notification message id. This is used to map RESET and EMPTY ACK messages. More... | |
bool | set_message_delivery_status_cb (message_delivery_status_cb callback, void *client_args) |
Sets the function that is executed when message state changes. Currently this is used to track notifications and delayed response delivery statuses. More... | |
M2MReportHandler * | report_handler () const |
Returns the Report Handler object. More... | |
Static Public Member Functions | |
static char * | create_path (const M2MObject &parent, const char *name) |
static char * | create_path (const M2MObject &parent, uint16_t object_instance) |
static char * | create_path (const M2MResource &parent, uint16_t resource_instance) |
static char * | create_path (const M2MResource &parent, const char *name) |
static char * | create_path (const M2MObjectInstance &parent, const char *name) |
Protected Member Functions | |
M2MBase & | operator= (const M2MBase &) |
M2MBase (const M2MBase &) | |
M2MBase (const String &name, M2MBase::Mode mode, const String &resource_type, char *path, bool external_blockwise_store, bool multiple_instance, M2MBase::DataType type=M2MBase::OBJLINK) | |
Constructor. More... | |
M2MBase (const lwm2m_parameters_s *s) | |
virtual bool | observation_to_be_sent (const m2m::Vector< uint16_t > &changed_instance_ids, uint16_t obs_number, bool send_object=false) |
An observation callback to be sent to the server due to a change in the observed parameter. More... | |
void | set_base_type (M2MBase::BaseType type) |
Sets the base type for an object. More... | |
M2MReportHandler * | create_report_handler () |
Create Report Handler object. More... | |
void | free_resources () |
Delete the resource structures owned by this object. Note: this needs to be called separately from each subclass' destructor as this method uses a virtual method and the call needs to be done at same class which has the implementation of the pure virtual method. | |
void | clear_notification_delivery_status () m2m_deprecated |
Clears the notification send status to initial state. | |
void | get_observation_token (uint8_t *token, uint8_t &token_length) const |
Provides the observation token of the object. More... | |
void | set_observation_token (const uint8_t *token, const uint8_t length) |
Sets the observation token value. More... | |
virtual void | set_changed () |
The data has changed and it needs to be updated into Device Management. Current implementation maintains the changed state only in M2MEndpoint. If any of the changes in an object changes the M2M registration structure, the information is propagated to M2MEndpoint using this interface. | |
virtual M2MBase * | get_parent () const |
Returns the owner object. Can return NULL if the object has no parent. | |
void | handle_observation (nsdl_s *nsdl, const sn_coap_hdr_s &received_coap_header, sn_coap_hdr_s &coap_response, M2MObservationHandler *observation_handler, sn_coap_msg_code_e &response_code) |
Handles subscription request. More... | |
void | cancel_observation (M2MBase::MessageDeliveryStatus status=M2MBase::MESSAGE_STATUS_UNSUBSCRIBED, bool notify=true) |
Cancels the ongoing observation. More... | |
void | start_observation (const sn_coap_hdr_s &received_coap_header, M2MObservationHandler *observation_handler) |
Start the observation. More... | |
Static Protected Member Functions | |
static void * | memory_alloc (uint32_t size) |
Memory allocation required for libCoap. More... | |
static void | memory_free (void *ptr) |
Memory free functions required for libCoap. More... | |
static char * | alloc_string_copy (const char *source) |
Allocate and make a copy of given zero terminated string. This is functionally equivalent with strdup(). More... | |
static uint8_t * | alloc_string_copy (const uint8_t *source, uint32_t size) |
Allocate (size + 1) amount of memory, copy size bytes into it and add zero termination. More... | |
static uint8_t * | alloc_copy (const uint8_t *source, uint32_t size) |
Allocate (size) amount of memory, copy size bytes into it. More... | |
static bool | validate_string_length (const String &string, size_t min_length, size_t max_length) |
static bool | validate_string_length (const char *string, size_t min_length, size_t max_length) |
static bool | build_path (StringBuffer< MAX_PATH_SIZE > &buffer, const char *s1, uint16_t i1, const char *s2, uint16_t i2) |
static bool | build_path (StringBuffer< MAX_PATH_SIZE_2 > &buffer, const char *s1, uint16_t i1, const char *s2) |
static bool | build_path (StringBuffer< MAX_PATH_SIZE_3 > &buffer, const char *s1, uint16_t i1, uint16_t i2) |
static bool | build_path (StringBuffer< MAX_PATH_SIZE_4 > &buffer, const char *s1, uint16_t i1) |
static char * | stringdup (const char *s) |
static bool | is_blockwise_needed (const nsdl_s *nsdl, uint32_t payload_len) |
Checks whether blockwise is needed to send resource value to server. More... | |
Friends | |
class | Test_M2MBase |
class | Test_M2MObject |
class | M2MNsdlInterface |
class | M2MInterfaceFactory |
class | M2MObject |
The base class based on which all LwM2M object models can be created.
It serves as the base class for Objects, ObjectInstances and Resources.
typedef struct M2MBase::lwm2m_parameters M2MBase::lwm2m_parameters_s |
LwM2M parameters.
Enum defining an status codes that can happen when sending confirmable message.
set_confirmable(false)
then only following MessageDeliveryStatuses are valid: MESSAGE_STATUS_BUILD_ERROR MESSAGE_STATUS_SENT MESSAGE_STATUS_SUBSCRIBED MESSAGE_STATUS_UNSUBSCRIBED enum M2MBase::Mode |
Enum defining a resource type.
Enumerator | |
---|---|
Static |
Static resource, value cannot change. |
Dynamic |
Dynamic resource. |
Directory |
Unsupported.
|
enum M2MBase::Operation |
Enum defining an operation that can be supported by a given resource.
Enumerator | |
---|---|
NOT_ALLOWED |
No operations allowed. |
GET_ALLOWED |
Only GET operation allowed. |
PUT_ALLOWED |
Only PUT operation allowed. |
GET_PUT_ALLOWED |
GET and PUT operations allowed. |
POST_ALLOWED |
Only POST operation allowed. |
GET_POST_ALLOWED |
|
PUT_POST_ALLOWED |
|
GET_PUT_POST_ALLOWED |
|
DELETE_ALLOWED |
Only DELETE operation allowed. |
GET_DELETE_ALLOWED |
GET and DELETE operations allowed. |
PUT_DELETE_ALLOWED |
PUT and DELETE operations allowed. |
GET_PUT_DELETE_ALLOWED |
GET, PUT and DELETE operations allowed. |
POST_DELETE_ALLOWED |
|
GET_POST_DELETE_ALLOWED |
|
PUT_POST_DELETE_ALLOWED |
|
GET_PUT_POST_DELETE_ALLOWED |
|
|
protected |
Constructor.
name | Name of the object created. |
mode | Type of the resource. |
resource_type | Textual information of resource. |
path | Path of the object like 3/0/1 |
external_blockwise_store | If true CoAP blocks are passed to application through callbacks otherwise handled in mbed-client-c. |
|
virtual |
Adds the observation level for the object.
observation_level | The level of observation. |
Reimplemented in M2MObjectInstance, M2MResource, and M2MObject.
|
staticprotected |
Allocate (size) amount of memory, copy size bytes into it.
source | The source buffer to copy, may not be NULL. |
size | The size of memory to be reserved. |
|
staticprotected |
Allocate and make a copy of given zero terminated string. This is functionally equivalent with strdup().
source | The source string to copy, may not be NULL. |
|
staticprotected |
Allocate (size + 1) amount of memory, copy size bytes into it and add zero termination.
source | The source string to copy, may not be NULL. |
size | The size of memory to be reserved. |
M2MBase::BaseType M2MBase::base_type | ( | ) | const |
Returns the object type.
|
protected |
Cancels the ongoing observation.
status | Delivery status to be sent to application |
notify | Whether application is notified or not |
uint16_t M2MBase::coap_content_type | ( | ) | const |
Returns the CoAP content type of the object.
|
protected |
Create Report Handler object.
void M2MBase::execute_value_updated | ( | const String & | name | ) |
Calls the function that is set in the "set_value_updated_function".
name | The name of the object. |
M2MBase::lwm2m_parameters_s* M2MBase::get_lwm2m_parameters | ( | ) | const |
Returns the resource structure.
uint16_t M2MBase::get_notification_msgid | ( | ) | const |
Returns the notification message id.
sn_nsdl_dynamic_resource_parameters_s* M2MBase::get_nsdl_resource | ( | ) | const |
Returns the resource information.
|
protected |
Provides the observation token of the object.
[out] | token | A pointer to the value of the token. |
[out] | token_length | The length of the token pointer. |
|
virtual |
Handles GET request for the registered objects.
nsdl | An NSDL handler for the CoAP library. |
received_coap_header | The received CoAP message from the server. |
observation_handler | A handler object for sending observation callbacks. |
Reimplemented in M2MResourceBase, M2MObjectInstance, M2MResource, and M2MObject.
|
protected |
Handles subscription request.
nsdl | An NSDL handler for the CoAP library. |
received_coap_header | The received CoAP message from the server. |
coap_response | The CoAP response to be sent to server. |
observation_handler | A handler object for sending observation callbacks. |
|
virtual |
Handles GET request for the registered objects.
nsdl | An NSDL handler for the CoAP library. |
received_coap_header | The received CoAP message from the server. |
observation_handler | A handler object for sending observation callbacks. |
execute_value_updated | True executes the "value_updated" callback. |
Reimplemented in M2MObjectInstance, M2MResource, and M2MObject.
|
virtual |
Handles PUT request for the registered objects.
nsdl | An NSDL handler for the CoAP library. |
received_coap_header | The received CoAP message from the server. |
observation_handler | A handler object for sending observation callbacks. |
execute_value_updated | True executes the "value_updated" callback. |
Reimplemented in M2MResourceBase, M2MObjectInstance, M2MResource, and M2MObject.
uint16_t M2MBase::instance_id | ( | ) | const |
Returns the object's instance ID.
const char* M2MBase::interface_description | ( | ) | const |
Returns the interface description of the object.
bool M2MBase::is_auto_observable | ( | ) | const |
Returns the auto observation status of the object.
|
staticprotected |
Checks whether blockwise is needed to send resource value to server.
nsdl | An NSDL handler for the CoAP library. |
payload_len | Length of the CoAP payload. |
bool M2MBase::is_readable | ( | ) | const |
Returns get operation allow state.
bool M2MBase::is_under_observation | ( | ) | const |
Returns whether this resource is under observation or not.
bool M2MBase::is_value_updated_function_set | ( | ) | const |
Returns whether a callback function is set or not.
uint32_t M2MBase::max_age | ( | ) | const |
Returns the max age for the resource value to be cached.
|
staticprotected |
Memory allocation required for libCoap.
size | The size of memory to be reserved. |
|
staticprotected |
Memory free functions required for libCoap.
ptr | The object whose memory needs to be freed. |
Mode M2MBase::mode | ( | ) | const |
Returns the mode of the resource.
const char* M2MBase::name | ( | ) | const |
Returns the object name.
int32_t M2MBase::name_id | ( | ) | const |
Returns the object name in integer.
|
pure virtual |
Returns the Observation Handler object.
Implemented in M2MObjectInstance, M2MResource, M2MObject, and M2MResourceInstance.
M2MBase::Observation M2MBase::observation_level | ( | ) | const |
Returns the observation level of the object.
uint16_t M2MBase::observation_number | ( | ) | const |
Returns the observation number.
|
protectedvirtual |
An observation callback to be sent to the server due to a change in the observed parameter.
changed_instance_ids | A list of changed object instance IDs. |
obs_number | The observation number. |
send_object | Indicates whether the whole object will be sent or not. |
Implements M2MReportObserver.
M2MBase::Operation M2MBase::operation | ( | ) | const |
Returns the operation type of the object.
bool M2MBase::register_uri | ( | ) |
Returns whether this resource is published to server or not.
|
virtual |
Removes the observation level for the object.
observation_level | The level of observation. |
Reimplemented in M2MObjectInstance, M2MResource, and M2MObject.
M2MReportHandler* M2MBase::report_handler | ( | ) | const |
Returns the Report Handler object.
size_t M2MBase::resource_name_length | ( | ) | const |
Returns length of the object name.
const char* M2MBase::resource_type | ( | ) | const |
Returns the resource type of the object.
void M2MBase::set_auto_observable | ( | bool | auto_observable | ) |
Sets the object to be auto-observable.
auto_observable | Is auto-obs feature enabled or not. |
|
protected |
Sets the base type for an object.
type | The base type of the object. |
void M2MBase::set_coap_content_type | ( | const uint16_t | content_type | ) |
Sets the CoAP content type of the object.
content_type | The content type to be set based on CoAP specifications. |
void M2MBase::set_confirmable | ( | bool | confirmable | ) |
Sets how the notification is sent. By default confirmable CoAP message type is used.
confirmable | True means confirmable message, False means non-confirmable message. |
void M2MBase::set_instance_id | ( | const uint16_t | instance_id | ) |
Sets the instance ID of the object.
instance_id | The instance ID of the object. |
void M2MBase::set_interface_description | ( | const String & | description | ) |
Sets the interface description of the object.
description | The description to be set. |
void M2MBase::set_interface_description | ( | const char * | description | ) |
Sets the interface description of the object.
description | The description to be set. |
void M2MBase::set_max_age | ( | const uint32_t | max_age | ) |
Sets the max age for the resource value to be cached.
max_age | The max age in seconds. |
bool M2MBase::set_message_delivery_status_cb | ( | message_delivery_status_cb | callback, |
void * | client_args | ||
) |
Sets the function that is executed when message state changes. Currently this is used to track notifications and delayed response delivery statuses.
callback | The function pointer that is called. |
client_args | The argument which is passed to the callback function. |
void M2MBase::set_notification_msgid | ( | uint16_t | msgid | ) |
Sets the notification message id. This is used to map RESET and EMPTY ACK messages.
msgid | The message id. |
void M2MBase::set_observable | ( | bool | observable | ) |
Sets the observable mode for the object.
observable | A value for the observation. |
|
pure virtual |
Sets the observation handler.
handler | Observation handler |
Implemented in M2MObjectInstance, M2MResource, M2MObject, and M2MResourceInstance.
|
protected |
Sets the observation token value.
token | A pointer to the token of the resource. |
length | The length of the token pointer. |
void M2MBase::set_operation | ( | M2MBase::Operation | operation | ) |
Sets the operation type for an object.
operation | The operation to be set. |
void M2MBase::set_register_uri | ( | bool | register_uri | ) |
Sets whether this resource is published to server or not.
register_uri | True sets the resource as part of registration message. |
|
virtual |
Sets the resource type of the object.
resource_type | The resource type to be set. |
|
virtual |
Sets the resource type of the object.
resource_type | The resource type to be set. |
void M2MBase::set_under_observation | ( | bool | observed, |
M2MObservationHandler * | handler | ||
) |
Sets the object under observation.
observed | The value for observation. When true, starts observing. When false, the ongoing observation is cancelled. |
handler | A handler object for sending observation callbacks. |
bool M2MBase::set_value_updated_function | ( | value_updated_callback | callback | ) |
Sets the function that is executed when this object receives a PUT or POST command.
callback | The function pointer that is called. |
bool M2MBase::set_value_updated_function | ( | value_updated_callback2 | callback | ) |
Sets the function that is executed when this object receives a PUT or POST command.
callback | The function pointer that is called. |
|
protected |
Start the observation.
received_coap_header | An NSDL handler for the CoAP library. |
observation_handler | A handler object for sending observation callbacks. |
const char* M2MBase::uri_path | ( | ) | const |
Returns the path of the object.