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 
27 //FORWARD DECLARATION
28 class M2MObjectInstance;
29 typedef Vector<M2MResourceInstance *> M2MResourceInstanceList;
30 
31 
39 {
40 
41  friend class M2MObjectInstance;
42 
43 public:
44  class M2MExecuteParameter;
45 
46 private: // Constructor and destructor are private,
47  // which means that these objects can be created or
48  // deleted only through a function provided by the M2MObjectInstance.
49 
51  const lwm2m_parameters_s* s,
52  M2MBase::DataType type);
67  const String &resource_name,
69  const String &resource_type,
70  M2MBase::DataType type,
71  const uint8_t *value,
72  const uint8_t value_length,
73  char *path,
74  bool multiple_instance = false,
75  bool external_blockwise_store = false);
76 
90  const String &resource_name,
91  M2MBase::Mode mode,
92  const String &resource_type,
93  M2MBase::DataType type,
94  bool observable,
95  char *path,
96  bool multiple_instance = false,
97  bool external_blockwise_store = false);
98 
99  // Prevents the use of a default constructor.
100  M2MResource();
101 
102  // Prevents the use of an assignment operator.
103  M2MResource& operator=( const M2MResource& /*other*/ );
104 
105  // Prevents the use of a copy constructor
106  M2MResource( const M2MResource& /*other*/ );
107 
111  virtual M2MBase *get_parent() const;
112 
116  virtual ~M2MResource();
117 
118 public:
119 
125 
132  bool supports_multiple_instances() const;
133 
134 #ifndef DISABLE_DELAYED_RESPONSE
135 
142 #ifdef ENABLE_ASYNC_REST_RESPONSE
143  void set_delayed_response(bool delayed_response) m2m_deprecated;
144 #else
145  void set_delayed_response(bool delayed_response);
146 #endif
147 
157  bool send_delayed_post_response(sn_coap_msg_code_e code = COAP_MSG_CODE_RESPONSE_CHANGED);
158 
164  void get_delayed_token(uint8_t *&token, uint8_t &token_length);
165 
170  bool delayed_response() const;
171 #endif //DISABLE_DELAYED_RESPONSE
172 
178  bool remove_resource_instance(uint16_t instance_id = 0);
179 
186 
191  const M2MResourceInstanceList& resource_instances() const;
192 
197  uint16_t resource_instance_count() const;
198 
204 
209  virtual void set_observation_handler(M2MObservationHandler *handler);
210 
211 #if defined (MBED_CONF_MBED_CLIENT_ENABLE_OBSERVATION_PARAMETERS) && (MBED_CONF_MBED_CLIENT_ENABLE_OBSERVATION_PARAMETERS == 1)
212 
217  virtual bool handle_observation_attribute(const char *query);
218 #endif
219 
225 
230  virtual void remove_observation_level(M2MBase::Observation observation_level);
231 
240  virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl,
241  sn_coap_hdr_s *received_coap_header,
242  M2MObservationHandler *observation_handler = NULL);
252  virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl,
253  sn_coap_hdr_s *received_coap_header,
254  M2MObservationHandler *observation_handler,
255  bool &execute_value_updated);
265  virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl,
266  sn_coap_hdr_s *received_coap_header,
267  M2MObservationHandler *observation_handler,
268  bool &execute_value_updated,
269  sn_nsdl_addr_s *address = NULL);
270 
271  M2MObjectInstance& get_parent_object_instance() const;
272 
277  virtual uint16_t object_instance_id() const;
278 
283  virtual const char* object_name() const;
284 
285  virtual M2MResource& get_parent_resource() const;
286 
287 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
288 
291  void set_manifest_check_status(bool status);
292 
297  bool get_manifest_check_status();
298 #endif
299 
300 private:
301  M2MObjectInstance &_parent;
302 
303  M2MResourceInstanceList _resource_instance_list; // owned
304 
305 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
306  bool _status;
307 #endif
308 
309 #ifndef DISABLE_DELAYED_RESPONSE
310  uint8_t *_delayed_token;
311  uint8_t _delayed_token_len;
312  bool _delayed_response;
313 #endif
314 
315 friend class Test_M2MResource;
316 friend class Test_M2MObjectInstance;
317 friend class Test_M2MObject;
318 friend class Test_M2MDevice;
319 friend class Test_M2MSecurity;
320 friend class Test_M2MServer;
321 friend class Test_M2MReportHandler;
322 friend class Test_M2MNsdlInterface;
323 friend class Test_M2MInterfaceFactory;
324 friend class Test_M2MTLVSerializer;
325 friend class Test_M2MTLVDeserializer;
326 friend class Test_M2MBase;
327 friend class Test_M2MResourceInstance;
328 friend class TestFactory;
329 };
330 
336 
337 private:
338 
343 
344 #ifdef MEMORY_OPTIMIZED_API
345  M2MExecuteParameter(const char *object_name, const char *resource_name, uint16_t object_instance_id);
346 #else
347  // This is a deprecated constructor, to be removed on next release.
348  M2MExecuteParameter(const String &object_name, const String &resource_name, uint16_t object_instance_id);
349 #endif
350 public:
351 
356  const uint8_t *get_argument_value() const;
357 
362  uint16_t get_argument_value_length() const;
363 
368 #ifdef MEMORY_OPTIMIZED_API
369  const char* get_argument_object_name() const;
370 #else
371  const String& get_argument_object_name() const;
372 #endif
373 
378 #ifdef MEMORY_OPTIMIZED_API
379  const char* get_argument_resource_name() const;
380 #else
381  const String& get_argument_resource_name() const;
382 #endif
383 
388  uint16_t get_argument_object_instance_id() const;
389 
390 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
391 
394  void set_resource(M2MResource* res);
395 
400  M2MResource * get_resource();
401 
402 #endif
403 
404 private:
405  // pointers to const data, not owned by this instance
406 
407 #ifdef MEMORY_OPTIMIZED_API
408  const char *_object_name;
409  const char *_resource_name;
410 #else
411  const String &_object_name;
412  const String &_resource_name;
413 #endif
414  const uint8_t *_value;
415  uint16_t _value_length;
416  uint16_t _object_instance_id;
417 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
418  M2MResource *_resource;
419 #endif
420 
421 friend class Test_M2MResource;
422 friend class M2MResource;
423 };
424 
425 #endif // M2M_RESOURCE_H
Mode
Enum defining a resource type.
Definition: m2mbase.h:89
Definition: m2mobservationhandler.h:30
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.
Definition: m2mbase.h:54
header for M2MResourceBase.
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:74
header for M2MResourceInstance.
bool remove_resource_instance(uint16_t instance_id=0)
Removes a resource with a given name.
Definition: m2mobjectinstance.h:42
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:199
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.
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:98
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:38
virtual void set_observation_handler(M2MObservationHandler *handler)
Sets the observation handler.
header for m2m::Vector
bool delayed_response() const
Returns the value set for delayed response for POST requests.
Definition: m2mresourcebase.h:47
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.
Definition: m2mresource.h:38
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:335
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".
bool send_delayed_post_response(sn_coap_msg_code_e code=COAP_MSG_CODE_RESPONSE_CHANGED)
A trigger to send the delayed response for the POST request. The delayed_response flag must be set be...
uint8_t * value() const
Returns the value pointer of the object.