Mistake on this page? Email us
m2mobjectinstance.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2021 Pelion. 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_OBJECT_INSTANCE_H
17 #define M2M_OBJECT_INSTANCE_H
18 
19 #include "mbed-client/m2mvector.h"
21 
22 //FORWARD DECLARATION
23 typedef Vector<M2MResource *> M2MResourceList;
24 typedef Vector<M2MResourceInstance *> M2MResourceInstanceList;
25 
26 
27 class M2MObject;
28 
42 class M2MObjectInstance : public M2MBase {
43 
44  friend class M2MObject;
45 
46 private:
52  const String &resource_type,
53  char *path,
54  bool external_blockwise_store = false);
55 
56  M2MObjectInstance(M2MObject &parent, const lwm2m_parameters_s *static_res);
57 
58  // Prevents the use of default constructor.
60 
61  // Prevents the use of assignment operator.
62  M2MObjectInstance &operator=(const M2MObjectInstance & /*other*/);
63 
64  // Prevents the use of copy constructor.
65  M2MObjectInstance(const M2MObjectInstance & /*other*/);
66 
70  virtual ~M2MObjectInstance();
71 
72 public:
73 
81 
96  M2MResource *create_static_resource(const String &resource_name,
97  const String &resource_type,
99  const uint8_t *value,
100  const uint8_t value_length,
101  bool multiple_instance = false,
102  bool external_blockwise_store = false);
103 
118  M2MResource *create_dynamic_resource(const String &resource_name,
119  const String &resource_type,
121  bool observable,
122  bool multiple_instance = false,
123  bool external_blockwise_store = false);
124 
139  M2MResource *create_dynamic_resource(const uint16_t resource_name,
140  const char *resource_type,
142  bool observable,
143  bool multiple_instance = false,
144  bool external_blockwise_store = false);
145 
153  bool observable);
154 
168  M2MResourceInstance *create_static_resource_instance(const String &resource_name,
169  const String &resource_type,
171  const uint8_t *value,
172  const uint8_t value_length,
173  uint16_t instance_id,
174  bool external_blockwise_store = false);
175 
189  M2MResourceInstance *create_dynamic_resource_instance(const String &resource_name,
190  const String &resource_type,
192  bool observable,
193  uint16_t instance_id,
194  bool external_blockwise_store = false);
195 
204  bool remove_resource(const String &name);
205 
211  bool remove_resource(const char *name);
212 
219  bool remove_resource_instance(const String &resource_name,
220  uint16_t instance_id);
221 
227  M2MResource *resource(const uint16_t resource_id) const;
228 
232  M2MResource *resource(const String &name) const;
233 
234  M2MResource *resource(const char *resource) const;
235 
240  const M2MResourceList &resources() const;
241 
246  uint16_t resource_count() const;
247 
256  uint16_t resource_count(const String &resource) const;
257 
263  uint16_t resource_count(const char *resource) const;
264 
271 
277  virtual void remove_observation_level(M2MBase::Observation observation_level);
278 
285 
291  virtual void set_observation_handler(M2MObservationHandler *handler);
292 
302  virtual sn_coap_hdr_s *handle_get_request(nsdl_s *nsdl,
303  sn_coap_hdr_s *received_coap_header,
304  M2MObservationHandler *observation_handler = NULL);
315  virtual sn_coap_hdr_s *handle_put_request(nsdl_s *nsdl,
316  sn_coap_hdr_s *received_coap_header,
317  M2MObservationHandler *observation_handler,
318  bool &execute_value_updated);
319 
330  virtual sn_coap_hdr_s *handle_post_request(nsdl_s *nsdl,
331  sn_coap_hdr_s *received_coap_header,
332  M2MObservationHandler *observation_handler,
333  bool &execute_value_updated,
334  sn_nsdl_addr_s *address = NULL);
335 
336  inline M2MObject &get_parent_object() const;
337 
341  void notification_update(M2MBase::Observation observation_level);
342 
343 protected:
344  virtual M2MBase *get_parent() const;
345 
346 private:
347 
355 
356 private:
357 
358  M2MObject &_parent;
359 
360  M2MResourceList _resource_list; // owned
361 
362  friend class Test_M2MObjectInstance;
363  friend class Test_M2MObject;
364  friend class Test_M2MDevice;
365  friend class Test_M2MSecurity;
366  friend class Test_M2MServer;
367  friend class Test_M2MInterfaceFactory;
368  friend class Test_M2MNsdlInterface;
369  friend class Test_M2MTLVSerializer;
370  friend class Test_M2MTLVDeserializer;
371  friend class Test_M2MBase;
372  friend class Test_M2MResource;
373  friend class Test_M2MResourceInstance;
374  friend class Test_M2MReportHandler;
375  friend class TestFactory;
376  friend class Test_M2MInterfaceImpl;
377  friend class Test_M2MDiscover;
378  friend class Test_M2MDynLog;
379 };
380 
381 inline M2MObject &M2MObjectInstance::get_parent_object() const
382 {
383  return _parent;
384 }
385 
386 #endif // M2M_OBJECT_INSTANCE_H
Definition: m2mobject.h:35
Definition: m2mobservationhandler.h:30
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.
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 POST request for the registered objects.
Definition: m2mbase.h:54
M2MResource * create_static_resource(const lwm2m_parameters_s *static_res, M2MResourceInstance::ResourceType type)
TODO!
Observation
Enum to define observation level.
Definition: m2mbase.h:74
virtual void add_observation_level(M2MBase::Observation observation_level)
Adds the observation level for the object.
const char * name() const
Returns the object name.
Definition: m2mobjectinstance.h:42
ResourceType
Definition: m2mresourcebase.h:61
uint16_t resource_count() const
Returns the total number of resources with the object.
LwM2M parameters.
Definition: m2mbase.h:199
virtual M2MObservationHandler * observation_handler() const
Returns the Observation Handler object.
bool remove_resource(const String &name)
Removes the resource with the given name.
header for M2MResource.
DataType
Enum defining a resource data type.
Definition: m2mbase.h:98
M2MResourceInstance * create_static_resource_instance(const String &resource_name, const String &resource_type, M2MResourceInstance::ResourceType type, const uint8_t *value, const uint8_t value_length, uint16_t instance_id, bool external_blockwise_store=false)
Creates a static resource instance for a given mbed Client Inteface object. With this, the client can respond to server&#39;s GET methods with the provided value.
bool remove_resource_instance(const String &resource_name, uint16_t instance_id)
Removes the resource instance with the given name.
void notification_update(M2MBase::Observation observation_level)
Definition: m2mresourceinstance.h:38
header for m2m::Vector
M2MResource * resource(const uint16_t resource_id) const
Returns the resource with the given name.
virtual void set_observation_handler(M2MObservationHandler *handler)
Sets the observation handler.
virtual M2MBase * get_parent() const
Returns the owner object. Can return NULL if the object has no parent.
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.
M2MResourceInstance * create_dynamic_resource_instance(const String &resource_name, const String &resource_type, M2MResourceInstance::ResourceType type, bool observable, uint16_t instance_id, bool external_blockwise_store=false)
Creates a dynamic resource instance for a given mbed Client Inteface object. With this...
Definition: m2mresource.h:38
const M2MResourceList & resources() const
Returns a list of M2MResourceBase objects.
const char * resource_type() const
Returns the resource type of the object.
M2MBase::Observation observation_level() const
Returns the observation level of the object.
M2MResource * create_dynamic_resource(const String &resource_name, const String &resource_type, M2MResourceInstance::ResourceType type, bool observable, bool multiple_instance=false, bool external_blockwise_store=false)
Creates a dynamic resource for a given mbed Client Inteface object. With this, the client can respond...
uint16_t instance_id() const
Returns the object&#39;s instance ID.
virtual void remove_observation_level(M2MBase::Observation observation_level)
Removes the observation level from the object.
void execute_value_updated(const String &name)
Calls the function that is set in the "set_value_updated_function".