Mistake on this page? Email us
m2mobject.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_H
17 #define M2M_OBJECT_H
18 
19 #include "mbed-client/m2mvector.h"
20 #include "mbed-client/m2mbase.h"
22 
23 //FORWARD DECLARATION
24 typedef Vector<M2MObjectInstance *> M2MObjectInstanceList;
25 
26 class M2MEndpoint;
27 
35 class M2MObject : public M2MBase {
36 
37  friend class M2MInterfaceFactory;
38  friend class M2MEndpoint;
39  friend class TestFactory;
40 
41 protected :
42 
50  M2MObject(const String &object_name,
51  char *path,
52  bool external_blockwise_store = false);
53 
54  // Prevents the use of default constructor.
55  M2MObject();
56 
57  // Prevents the use of assignment operator.
58  M2MObject &operator=(const M2MObject & /*other*/);
59 
60  // Prevents the use of copy constructor.
61  M2MObject(const M2MObject & /*other*/);
62 
67  M2MObject(const M2MBase::lwm2m_parameters_s *static_res);
68 
69 public:
70 
74  virtual ~M2MObject();
75 
82 
91 
97  bool remove_object_instance(uint16_t instance_id = 0);
98 
104  M2MObjectInstance *object_instance(uint16_t instance_id = 0) const;
105 
110  const M2MObjectInstanceList &instances() const;
111 
116  uint16_t instance_count() const;
117 
122  uint16_t new_instance_id() const;
123 
130 
136  virtual void set_observation_handler(M2MObservationHandler *handler);
137 
144 
150  virtual void remove_observation_level(M2MBase::Observation observation_level);
151 
161  virtual sn_coap_hdr_s *handle_get_request(nsdl_s *nsdl,
162  sn_coap_hdr_s *received_coap_header,
163  M2MObservationHandler *observation_handler = NULL);
164 
175  virtual sn_coap_hdr_s *handle_put_request(nsdl_s *nsdl,
176  sn_coap_hdr_s *received_coap_header,
177  M2MObservationHandler *observation_handler,
178  bool &execute_value_updated);
179 
190  virtual sn_coap_hdr_s *handle_post_request(nsdl_s *nsdl,
191  sn_coap_hdr_s *received_coap_header,
192  M2MObservationHandler *observation_handler,
193  bool &execute_value_updated,
194  sn_nsdl_addr_s *address = NULL);
195 
199  void notification_update(uint16_t obj_instance_id);
200 
201 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
202  void set_endpoint(M2MEndpoint *endpoint);
203 
204  M2MEndpoint *get_endpoint() const;
205 #endif
206 
207 protected :
211  virtual M2MBase *get_parent() const;
212 
213 private:
214 
215  M2MObjectInstanceList _instance_list; // owned
216 
217  M2MObservationHandler *_observation_handler; // Not owned
218 
219 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
220  M2MEndpoint *_endpoint; // Parent endpoint
221 #endif
222 
223  friend class Test_M2MObject;
224  friend class Test_M2MEndpoint;
225  friend class Test_M2MInterfaceImpl;
226  friend class Test_M2MInterfaceFactory;
227  friend class Test_M2MNsdlInterface;
228  friend class Test_M2MTLVSerializer;
229  friend class Test_M2MTLVDeserializer;
230  friend class Test_M2MDevice;
231  friend class Test_M2MBase;
232  friend class Test_M2MObjectInstance;
233  friend class Test_M2MResource;
234  friend class Test_M2MSecurity;
235  friend class Test_M2MServer;
236  friend class Test_M2MReportHandler;
237  friend class Test_M2MResourceInstance;
238  friend class Test_M2MDiscover;
239  friend class Test_M2MDynLog;
240 };
241 
242 #endif // M2M_OBJECT_H
Definition: m2mobject.h:35
Definition: m2mobservationhandler.h:30
virtual M2MBase * get_parent() const
Returns the owner object. Can return NULL if the object has no parent.
Definition: m2mbase.h:54
virtual void set_observation_handler(M2MObservationHandler *handler)
Sets the observation handler.
virtual ~M2MObject()
Destructor.
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.
header for M2MObjectInstance
Definition: m2mobjectinstance.h:42
void notification_update(uint16_t obj_instance_id)
LwM2M parameters.
Definition: m2mbase.h:199
const M2MObjectInstanceList & instances() const
Returns a list of object instances.
Header for M2MBase class.
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.
header for m2m::Vector
virtual M2MObservationHandler * observation_handler() const
Returns the Observation Handler object.
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.
uint16_t new_instance_id() const
Returns instance id to be used for new instances.
M2MObjectInstance * create_object_instance(uint16_t instance_id=0)
Creates a new object instance for a given mbed Client Interface object. With this, the client can respond to server&#39;s GET methods with the provided value.
M2MBase::Observation observation_level() const
Returns the observation level of the object.
Definition: m2minterfacefactory.h:36
uint16_t instance_id() const
Returns the object&#39;s instance ID.
bool remove_object_instance(uint16_t instance_id=0)
Removes the object instance resource with the given instance id.
void execute_value_updated(const String &name)
Calls the function that is set in the "set_value_updated_function".
M2MObjectInstance * object_instance(uint16_t instance_id=0) const
Returns the object instance with the the given instance ID.
virtual void remove_observation_level(M2MBase::Observation observation_level)
Removes the observation level from the object.
uint16_t instance_count() const
Returns the total number of object instances-.
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.