Mistake on this page? Email us
m2mobjectinstance.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_OBJECT_INSTANCE_H
17 #define M2M_OBJECT_INSTANCE_H
18 
19 #include "mbed-client/m2mvector.h"
21 
22 //FORWARD DECLARATION
25 
26 
27 class M2MObject;
28 
36 class M2MObjectInstance : public M2MBase
37 {
38 
39 friend class M2MObject;
40 
41 private: // Constructor and destructor are private which means
42  // that these objects can be created or
43  // deleted only through function provided by M2MObject.
44 
50  const String &resource_type,
51  char *path,
52  bool external_blockwise_store = false);
53 
54  M2MObjectInstance(M2MObject& parent, const lwm2m_parameters_s* static_res);
55 
56  // Prevents the use of default constructor.
58 
59  // Prevents the use of assignment operator.
60  M2MObjectInstance& operator=( const M2MObjectInstance& /*other*/ );
61 
62  // Prevents the use of copy constructor.
63  M2MObjectInstance( const M2MObjectInstance& /*other*/ );
64 
68  virtual ~M2MObjectInstance();
69 
70 public:
71 
78 
92  M2MResource* create_static_resource(const String &resource_name,
93  const String &resource_type,
95  const uint8_t *value,
96  const uint8_t value_length,
97  bool multiple_instance = false,
98  bool external_blockwise_store = false);
99 
113  M2MResource* create_dynamic_resource(const String &resource_name,
114  const String &resource_type,
116  bool observable,
117  bool multiple_instance = false,
118  bool external_blockwise_store = false);
119 
133  M2MResource* create_dynamic_resource(const uint16_t resource_name,
134  const char *resource_type,
136  bool observable,
137  bool multiple_instance = false,
138  bool external_blockwise_store = false);
139 
146  bool observable);
147 
161  const String &resource_type,
163  const uint8_t *value,
164  const uint8_t value_length,
165  uint16_t instance_id,
166  bool external_blockwise_store = false);
167 
181  const String &resource_type,
183  bool observable,
184  uint16_t instance_id,
185  bool external_blockwise_store = false);
186 
194  bool remove_resource(const String &name);
195 
201  bool remove_resource(const char *name);
202 
209  bool remove_resource_instance(const String &resource_name,
210  uint16_t instance_id);
211 
217  M2MResource* resource(const uint16_t resource_id) const;
218 
219  M2MResource* resource(const String &name) const;
220 
221  M2MResource* resource(const char *resource) const;
222 
227  const M2MResourceList& resources() const;
228 
233  uint16_t resource_count() const;
234 
242  uint16_t resource_count(const String& resource) const;
243 
249  uint16_t resource_count(const char *resource) const;
250 
256 
261  virtual void remove_observation_level(M2MBase::Observation observation_level);
262 
268 
273  virtual void set_observation_handler(M2MObservationHandler *handler);
274 
283  virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl,
284  sn_coap_hdr_s *received_coap_header,
285  M2MObservationHandler *observation_handler = NULL);
295  virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl,
296  sn_coap_hdr_s *received_coap_header,
297  M2MObservationHandler *observation_handler,
298  bool &execute_value_updated);
299 
309  virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl,
310  sn_coap_hdr_s *received_coap_header,
311  M2MObservationHandler *observation_handler,
312  bool &execute_value_updated,
313  sn_nsdl_addr_s *address = NULL);
314 
315  inline M2MObject& get_parent_object() const;
316 
317  // callback used from M2MResource/M2MResourceInstance
318  void notification_update(M2MBase::Observation observation_level);
319 
320 protected:
321  virtual M2MBase *get_parent() const;
322 
323 private:
324 
332 
333 private:
334 
335  M2MObject &_parent;
336 
337  M2MResourceList _resource_list; // owned
338 
339  friend class Test_M2MObjectInstance;
340  friend class Test_M2MObject;
341  friend class Test_M2MDevice;
342  friend class Test_M2MSecurity;
343  friend class Test_M2MServer;
344  friend class Test_M2MInterfaceFactory;
345  friend class Test_M2MNsdlInterface;
346  friend class Test_M2MFirmware;
347  friend class Test_M2MTLVSerializer;
348  friend class Test_M2MTLVDeserializer;
349  friend class Test_M2MBase;
350  friend class Test_M2MResource;
351  friend class Test_M2MResourceInstance;
352  friend class TestFactory;
353 };
354 
355 inline M2MObject& M2MObjectInstance::get_parent_object() const
356 {
357  return _parent;
358 }
359 
360 #endif // M2M_OBJECT_INSTANCE_H
The base class for Client Objects.
Definition: m2mobject.h:39
Definition: m2mobservationhandler.h:31
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.
The base class based on which all LwM2M object models can be created.
Definition: m2mbase.h:63
M2MResource * create_static_resource(const lwm2m_parameters_s *static_res, M2MResourceInstance::ResourceType type)
TODO!
Observation
Enum to define observation level.
Definition: m2mbase.h:83
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:36
ResourceType
Definition: m2mresourcebase.h:66
uint16_t resource_count() const
Returns the total number of resources with the object.
LwM2M parameters.
Definition: m2mbase.h:210
virtual M2MObservationHandler * observation_handler() const
Returns the Observation Handler object.
bool remove_resource(const String &name)
Removes the resource with the given name.
Definition: m2mstring.h:33
M2MResource. This class is the base class for mbed Client Resources.
DataType
Enum defining a resource data type.
Definition: m2mbase.h:107
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'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.
Definition: m2mresourceinstance.h:32
A simple C++ Vector class, used as replacement for std::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...
The base class for Client Resources.
Definition: m2mresource.h:40
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'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".