26 #include "nsdl-c/sn_nsdl.h" 27 #include "sn_coap_header.h" 28 #include "nsdl-c/sn_nsdl_lib.h" 32 typedef sn_coap_hdr_ sn_coap_hdr_s;
35 typedef sn_nsdl_addr_ sn_nsdl_addr_s;
38 typedef void(*value_updated_callback2) (
const char* object_name);
40 class M2MReportHandler;
65 ResourceInstance = 0x3
66 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION 67 ,ObjectDirectory = 0x4
116 GET_PUT_ALLOWED = 0x03,
118 GET_POST_ALLOWED = 0x05,
119 PUT_POST_ALLOWED = 0x06,
120 GET_PUT_POST_ALLOWED = 0x07,
121 DELETE_ALLOWED = 0x08,
122 GET_DELETE_ALLOWED = 0x09,
123 PUT_DELETE_ALLOWED = 0x0A,
124 GET_PUT_DELETE_ALLOWED = 0x0B,
125 POST_DELETE_ALLOWED = 0x0C,
126 GET_POST_DELETE_ALLOWED = 0x0D,
127 PUT_POST_DELETE_ALLOWED = 0x0E,
128 GET_PUT_POST_DELETE_ALLOWED = 0x0F
136 MESSAGE_STATUS_INIT = 0,
137 MESSAGE_STATUS_BUILD_ERROR,
138 MESSAGE_STATUS_RESEND_QUEUE_FULL,
140 MESSAGE_STATUS_DELIVERED,
141 MESSAGE_STATUS_SEND_FAILED,
142 MESSAGE_STATUS_SUBSCRIBED,
143 MESSAGE_STATUS_UNSUBSCRIBED,
144 MESSAGE_STATUS_REJECTED
149 DELAYED_POST_RESPONSE,
157 MAX_INSTANCE_SIZE = 5,
159 MAX_PATH_SIZE = ((MAX_NAME_SIZE * 2) + (MAX_INSTANCE_SIZE * 2) + 3 + 1),
160 MAX_PATH_SIZE_2 = ((MAX_NAME_SIZE * 2) + MAX_INSTANCE_SIZE + 2 + 1),
161 MAX_PATH_SIZE_3 = (MAX_NAME_SIZE + (MAX_INSTANCE_SIZE * 2) + 2 + 1),
162 MAX_PATH_SIZE_4 = (MAX_NAME_SIZE + MAX_INSTANCE_SIZE + 1 + 1)
168 typedef void(*notification_delivery_status_cb) (
const M2MBase& base,
169 const NotificationDeliveryStatus status,
172 typedef void(*message_delivery_status_cb) (
const M2MBase& base,
173 const MessageDeliveryStatus status,
174 const MessageType type,
177 #ifdef ENABLE_ASYNC_REST_RESPONSE 188 typedef void (*handle_async_coap_request_cb)(
const M2MBase &base,
190 const uint8_t *token,
191 const uint8_t token_len,
192 const uint8_t *buffer,
195 #endif // ENABLE_ASYNC_REST_RESPONSE 207 uint16_t instance_id;
209 sn_nsdl_dynamic_resource_parameters_s *dynamic_resource_params;
212 bool multiple_instance;
219 bool identifier_int_type;
246 #ifndef DISABLE_RESOURCE_TYPE
250 bool external_blockwise_store,
251 bool multiple_instance,
269 #if !defined(MEMORY_OPTIMIZED_API) || defined(RESOURCE_ATTRIBUTES_LIST) 274 #if !defined(DISABLE_INTERFACE_DESCRIPTION) || defined(RESOURCE_ATTRIBUTES_LIST) 289 #if !defined(DISABLE_RESOURCE_TYPE) || defined(RESOURCE_ATTRIBUTES_LIST) 394 const char* name()
const;
406 uint16_t instance_id()
const;
454 uint32_t max_age()
const;
456 #if defined (MBED_CONF_MBED_CLIENT_ENABLE_OBSERVATION_PARAMETERS) && (MBED_CONF_MBED_CLIENT_ENABLE_OBSERVATION_PARAMETERS == 1) 463 virtual bool handle_observation_attribute(
const char *query);
475 sn_coap_hdr_s *received_coap_header,
487 sn_coap_hdr_s *received_coap_header,
501 sn_coap_hdr_s *received_coap_header,
504 sn_nsdl_addr_s *address = NULL);
583 #ifdef ENABLE_ASYNC_REST_RESPONSE 593 bool send_async_response_with_code(
const uint8_t *payload,
595 const uint8_t* token,
596 const uint8_t token_len,
606 bool set_async_coap_request_cb(handle_async_coap_request_cb callback,
void *client_args);
608 #endif //ENABLE_ASYNC_REST_RESPONSE 638 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION 639 static char* create_path(
const M2MEndpoint &parent,
const char *name);
641 static char* create_path(
const M2MObject &parent,
const char *name);
642 static char* create_path(
const M2MObject &parent, uint16_t object_instance);
643 static char* create_path(
const M2MResource &parent, uint16_t resource_instance);
644 static char* create_path(
const M2MResource &parent,
const char *name);
647 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION 654 virtual void set_deleted();
661 virtual bool is_deleted();
663 #endif // MBED_CLOUD_CLIENT_EDGE_EXTENSION 669 bool send_object =
false);
709 static uint8_t*
alloc_copy(
const uint8_t* source, uint32_t size);
712 static bool validate_string_length(
const String &
string,
size_t min_length,
size_t max_length);
713 static bool validate_string_length(
const char*
string,
size_t min_length,
size_t max_length);
735 static char* stringdup(
const char* s);
769 const uint8_t length);
801 const sn_coap_hdr_s &received_coap_header,
802 sn_coap_hdr_s &coap_response,
804 sn_coap_msg_code_e &response_code);
819 #ifdef ENABLE_ASYNC_REST_RESPONSE 827 void call_async_coap_request_callback(sn_coap_hdr_s *coap_request,
835 bool is_async_coap_request_callback_set();
837 #endif //ENABLE_ASYNC_REST_RESPONSE 841 static bool is_integer(
const String &value);
843 static bool is_integer(
const char *value);
845 static char* create_path_base(
const M2MBase &parent,
const char *name);
848 M2MReportHandler *_report_handler;
850 friend class Test_M2MBase;
851 friend class Test_M2MObject;
852 friend class M2MNsdlInterface;
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 notifi...
sn_nsdl_dynamic_resource_parameters_s * get_nsdl_resource() const
Returns the resource information.
Mode
Enum defining a resource type.
Definition: m2mbase.h:89
Definition: m2mobject.h:35
Definition: m2mobservationhandler.h:30
virtual void set_changed()
The data has changed and it needs to be updated into Device Management. Current implementation mainta...
const char * interface_description() const
Returns the interface description of the object.
size_t resource_name_length() const
Returns length of the object name.
int32_t name_id() const
Returns the object name in integer.
void set_observable(bool observable)
Sets the observable mode for the object.
void free_resources()
Delete the resource structures owned by this object. Note: this needs to be called separately from ea...
void get_observation_token(uint8_t *token, uint8_t &token_length) const
Provides the observation token of the object.
bool is_value_updated_function_set() const
Returns whether a callback function is set or not.
void set_register_uri(bool register_uri)
Sets whether this resource is published to server or not.
void set_base_type(M2MBase::BaseType type)
Sets the base type for an object.
void set_under_observation(bool observed, M2MObservationHandler *handler)
Sets the object under observation.
static uint8_t * alloc_copy(const uint8_t *source, uint32_t size)
Allocate (size) amount of memory, copy size bytes into it.
M2MBase::Operation operation() const
Returns the operation type of the object.
void send_notification_delivery_status(const M2MBase &object, const NotificationDeliveryStatus status)
Executes the function that is set in "set_notification_delivery_status_cb". Note: the setter for this...
Observation
Enum to define observation level.
Definition: m2mbase.h:74
Definition: m2mobjectinstance.h:42
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.
BaseType
Enum to define the type of object.
Definition: m2mbase.h:61
M2MBase::lwm2m_parameters_s * get_lwm2m_parameters() const
Returns the resource structure.
uint16_t observation_number() const
Returns the observation number.
bool register_uri()
Returns whether this resource is published to server or not.
Definition: m2mstringbuffer.h:30
bool is_under_observation() const
Returns whether this resource is under observation or not.
virtual ~M2MBase()
Destructor.
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.
LwM2M parameters.
Definition: m2mbase.h:199
header for M2MReportObserver
virtual void set_observation_handler(M2MObservationHandler *handler)=0
Sets the observation handler.
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.
CoAP response code values.
static void memory_free(void *ptr)
Memory free functions required for libCoap.
M2MReportHandler * create_report_handler()
Create Report Handler object.
static bool is_blockwise_needed(const nsdl_s *nsdl, uint32_t payload_len)
Checks whether blockwise is needed to send resource value to server.
void cancel_observation()
Cancels the ongoing observation.
bool is_auto_observable() const
Returns the auto observation status of the object.
void set_notification_msgid(uint16_t msgid) m2m_deprecated
Sets the notification message id. This is used to map RESET and EMPTY ACK messages.
DataType
Enum defining a resource data type.
Definition: m2mbase.h:98
bool set_value_updated_function(value_updated_callback callback)
Sets the function that is executed when this object receives a PUT or POST command.
Header for function pointer classes.
Definition: m2mreportobserver.h:27
const char * uri_path() const
Returns the path of the object.
Mode mode() const
Returns the mode of the resource.
bool set_notification_delivery_status_cb(notification_delivery_status_cb callback, void *client_args) m2m_deprecated
Sets the function that is executed when notification message state changes.
void set_interface_description(const String &description)
Sets the interface description of the object.
NotificationDeliveryStatus get_notification_delivery_status() const m2m_deprecated
Returns notification send status.
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.
File defining all system build time configuration used by mbed-client.
A simple C++ Vector class, used as replacement for std::vector.
Definition: m2mvector.h:29
coap_response_code_e
Definition: coap_response.h:26
uint16_t coap_content_type() const
Returns the CoAP content type of the object.
bool read_write_callback_set
If set, all the read and write operations are handled in callbacks and the resource value is not stor...
Definition: m2mbase.h:220
void set_instance_id(const uint16_t instance_id)
Sets the instance ID of the object.
virtual M2MBase * get_parent() const
Returns the owner object. Can return NULL if the object has no parent.
void set_auto_observable(bool auto_observable)
Sets the object to be auto-observable.
uint16_t get_notification_msgid() const m2m_deprecated
Returns the notification message id.
M2MReportHandler * report_handler() const
Returns the Report Handler object.
Definition: m2mresource.h:38
struct M2MBase::lwm2m_parameters lwm2m_parameters_s
LwM2M parameters.
void set_operation(M2MBase::Operation operation)
Sets the operation type for an object.
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_observation_token(const uint8_t *token, const uint8_t length)
Sets the observation token value.
virtual void remove_observation_level(M2MBase::Observation observation_level)
Removes the observation level for the object.
virtual void add_observation_level(M2MBase::Observation observation_level)
Adds the observation level for the object.
const char * resource_type() const
Returns the resource type of the object.
M2MBase::Observation observation_level() const
Returns the observation level of the object.
Definition: m2minterfacefactory.h:35
bool is_observable() const
Returns the observation status of the object.
bool free_on_delete
true if struct is dynamically allocated and it and its members (name) are to be freed on destructor...
Definition: m2mbase.h:213
static void * memory_alloc(uint32_t size)
Memory allocation required for libCoap.
Operation
Enum defining an operation that can be supported by a given resource.
Definition: m2mbase.h:112
void execute_value_updated(const String &name)
Calls the function that is set in the "set_value_updated_function".
void set_coap_content_type(const uint16_t content_type)
Sets the CoAP content type of the object.
Definition: coap_response.h:30
virtual M2MObservationHandler * observation_handler() const =0
Returns the Observation Handler object.
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.
MessageDeliveryStatus
Enum defining an status codes that can happen when sending confirmable message.
Definition: m2mbase.h:135
virtual void set_resource_type(const String &resource_type)
Sets the resource type of the object.
void clear_notification_delivery_status() m2m_deprecated
Clears the notification send status to initial state.
Definition: functionpointer.h:113
void set_max_age(const uint32_t max_age)
Sets the max age for the resource value to be cached.
void start_observation(const sn_coap_hdr_s &received_coap_header, M2MObservationHandler *observation_handler)
Start the observation.
static char * alloc_string_copy(const char *source)
Allocate and make a copy of given zero terminated string. This is functionally equivalent with strdup...