Mistake on this page? Email us
m2mresource.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 ARM Limited. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef M2M_RESOURCE_H
17 #define M2M_RESOURCE_H
18 
19 #include "mbed-client/m2mvector.h"
23 #include <stdlib.h>
24 
25 //FORWARD DECLARATION
26 class M2MObjectInstance;
28 
41 {
42 
43  friend class M2MObjectInstance;
44 
45 public:
46  class M2MExecuteParameter;
47 
48 private: // Constructor and destructor are private,
49  // which means that these objects can be created or
50  // deleted only through a function provided by the M2MObjectInstance.
51 
53  const lwm2m_parameters_s* s,
54  M2MBase::DataType type);
69  const String &resource_name,
71  const String &resource_type,
72  M2MBase::DataType type,
73  const uint8_t *value,
74  const uint8_t value_length,
75  char *path,
76  bool multiple_instance = false,
77  bool external_blockwise_store = false);
78 
92  const String &resource_name,
93  M2MBase::Mode mode,
94  const String &resource_type,
95  M2MBase::DataType type,
96  bool observable,
97  char *path,
98  bool multiple_instance = false,
99  bool external_blockwise_store = false);
100 
101  // Prevents the use of a default constructor.
102  M2MResource();
103 
104  // Prevents the use of an assignment operator.
105  M2MResource& operator=( const M2MResource& /*other*/ );
106 
107  // Prevents the use of a copy constructor
108  M2MResource( const M2MResource& /*other*/ );
109 
113  virtual M2MBase *get_parent() const;
114 
118  virtual ~M2MResource();
119 
120 public:
121 
127 
134  bool supports_multiple_instances() const;
135 
136 #ifndef DISABLE_DELAYED_RESPONSE
137 
144 #ifdef ENABLE_ASYNC_REST_RESPONSE
145  void set_delayed_response(bool delayed_response) m2m_deprecated;
146 #else
147  void set_delayed_response(bool delayed_response);
148 #endif
149 
159 
165  void get_delayed_token(uint8_t *&token, uint8_t &token_length);
166 
171  bool delayed_response() const;
172 #endif //DISABLE_DELAYED_RESPONSE
173 
179  bool remove_resource_instance(uint16_t instance_id = 0);
180 
187 
193 
198  uint16_t resource_instance_count() const;
199 
205 
210  virtual void set_observation_handler(M2MObservationHandler *handler);
211 
212 #if defined (MBED_CONF_MBED_CLIENT_ENABLE_OBSERVATION_PARAMETERS) && (MBED_CONF_MBED_CLIENT_ENABLE_OBSERVATION_PARAMETERS == 1)
213 
218  virtual bool handle_observation_attribute(const char *query);
219 #endif
220 
226 
231  virtual void remove_observation_level(M2MBase::Observation observation_level);
232 
241  virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl,
242  sn_coap_hdr_s *received_coap_header,
243  M2MObservationHandler *observation_handler = NULL);
253  virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl,
254  sn_coap_hdr_s *received_coap_header,
255  M2MObservationHandler *observation_handler,
256  bool &execute_value_updated);
266  virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl,
267  sn_coap_hdr_s *received_coap_header,
268  M2MObservationHandler *observation_handler,
269  bool &execute_value_updated,
270  sn_nsdl_addr_s *address = NULL);
271 
272  M2MObjectInstance& get_parent_object_instance() const;
273 
278  virtual uint16_t object_instance_id() const;
279 
284  virtual const char* object_name() const;
285 
286  virtual M2MResource& get_parent_resource() const;
287 private:
288  M2MObjectInstance &_parent;
289 
290  M2MResourceInstanceList _resource_instance_list; // owned
291 #ifndef DISABLE_DELAYED_RESPONSE
292  uint8_t *_delayed_token;
293  uint8_t _delayed_token_len;
294  bool _delayed_response;
295 #endif
296 
297 friend class Test_M2MResource;
298 friend class Test_M2MObjectInstance;
299 friend class Test_M2MObject;
300 friend class Test_M2MDevice;
301 friend class Test_M2MSecurity;
302 friend class Test_M2MServer;
303 friend class Test_M2MNsdlInterface;
304 friend class Test_M2MInterfaceFactory;
305 friend class Test_M2MFirmware;
306 friend class Test_M2MTLVSerializer;
307 friend class Test_M2MTLVDeserializer;
308 friend class Test_M2MBase;
309 friend class Test_M2MResourceInstance;
310 friend class TestFactory;
311 };
312 
318 
319 private:
320 
325 
326 #ifdef MEMORY_OPTIMIZED_API
327  M2MExecuteParameter(const char *object_name, const char *resource_name, uint16_t object_instance_id);
328 #else
329  // This is a deprecated constructor, to be removed on next release.
330  M2MExecuteParameter(const String &object_name, const String &resource_name, uint16_t object_instance_id);
331 #endif
332 
333 public:
334 
339  const uint8_t *get_argument_value() const;
340 
345  uint16_t get_argument_value_length() const;
346 
351 #ifdef MEMORY_OPTIMIZED_API
352  const char* get_argument_object_name() const;
353 #else
354  const String& get_argument_object_name() const;
355 #endif
356 
361 #ifdef MEMORY_OPTIMIZED_API
362  const char* get_argument_resource_name() const;
363 #else
364  const String& get_argument_resource_name() const;
365 #endif
366 
371  uint16_t get_argument_object_instance_id() const;
372 
373 private:
374  // pointers to const data, not owned by this instance
375 
376 #ifdef MEMORY_OPTIMIZED_API
377  const char *_object_name;
378  const char *_resource_name;
379 #else
380  const String &_object_name;
381  const String &_resource_name;
382 #endif
383 
384  const uint8_t *_value;
385  uint16_t _value_length;
386  uint16_t _object_instance_id;
387 
388 friend class Test_M2MResource;
389 friend class M2MResource;
390 };
391 
392 #endif // M2M_RESOURCE_H
Mode
Enum defining a resource type.
Definition: m2mbase.h:98
Definition: m2mobservationhandler.h:31
void add_resource_instance(M2MResourceInstance *resource_instance)
Adds resource instances to a M2MResource.
virtual void remove_observation_level(M2MBase::Observation observation_level)
Removes the observation level from an object.
The base class based on which all LwM2M object models can be created.
Definition: m2mbase.h:63
M2MResourceBase. This class is the base class for mbed Client Resources. All defined LWM2M resource m...
virtual const char * object_name() const
Returns the name of the object where the resource exists.
Observation
Enum to define observation level.
Definition: m2mbase.h:83
M2MResourceInstance. This class is the base class for mbed Client Resources. All defined LWM2M resour...
bool remove_resource_instance(uint16_t instance_id=0)
Removes a resource with a given name.
Definition: m2mobjectinstance.h:36
uint32_t value_length() const
Returns the length of the value pointer.
virtual sn_coap_hdr_s * handle_get_request(nsdl_s *nsdl, sn_coap_hdr_s *received_coap_header, M2MObservationHandler *observation_handler=NULL)
Handles the GET request for registered objects.
uint16_t resource_instance_count() const
Returns the total number of resources.
LwM2M parameters.
Definition: m2mbase.h:210
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 the PUT request for registered objects.
const uint8_t * get_argument_value() const
Returns the value of an argument.
Definition: m2mstring.h:33
CoAP response code values.
void set_delayed_response(bool delayed_response)
Sets whether the resource should send a delayed response for a POST request. This only works for reso...
virtual uint16_t object_instance_id() const
Returns the instance ID of the object where the resource exists.
M2MResourceInstance * resource_instance(uint16_t instance_id=0) const
Returns a resource instance with a given name.
virtual void add_observation_level(M2MBase::Observation observation_level)
Adds the observation level for the object.
DataType
Enum defining a resource data type.
Definition: m2mbase.h:107
const String & get_argument_object_name() const
Returns the name of the object where the resource exists.
Mode mode() const
Returns the mode of the resource.
Definition: m2mresourceinstance.h:32
virtual void set_observation_handler(M2MObservationHandler *handler)
Sets the observation handler.
A simple C++ Vector class, used as replacement for std::vector.
bool send_delayed_post_response()
A trigger to send the delayed response for the POST request. The delayed_response flag must be set be...
bool delayed_response() const
Returns the value set for delayed response for POST requests.
Definition: m2mresourcebase.h:43
const String & get_argument_resource_name() const
Returns the resource name.
const M2MResourceInstanceList & resource_instances() const
Returns a list of resources.
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 the POST request for registered objects.
The base class for Client Resources.
Definition: m2mresource.h:40
virtual M2MObservationHandler * observation_handler() const
Returns the Observation Handler object.
uint16_t get_argument_value_length() const
Returns the length of the value argument.
M2MResource::M2MExecuteParameter. This class handles the "Execute" operation arguments.
Definition: m2mresource.h:317
const char * resource_type() const
Returns the resource type of the object.
void get_delayed_token(uint8_t *&token, uint8_t &token_length)
Provides the value of the token of the delayed post response.
M2MBase::Observation observation_level() const
Returns the observation level of the object.
bool supports_multiple_instances() const
Returns whether the resource has multiple resource instances or not.
uint16_t instance_id() const
Returns the object&#39;s instance ID.
uint16_t get_argument_object_instance_id() const
Returns the instance ID of the object where the resource exists.
void execute_value_updated(const String &name)
Calls the function that is set in the "set_value_updated_function".
uint8_t * value() const
Returns the value pointer of the object.