leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mobject.h Source File

m2mobject.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef M2M_OBJECT_H
00017 #define M2M_OBJECT_H
00018 
00019 #include "mbed-client/m2mvector.h"
00020 #include "mbed-client/m2mbase.h"
00021 #include "mbed-client/m2mobjectinstance.h"
00022 
00023 //FORWARD DECLARATION
00024 typedef Vector<M2MObjectInstance *> M2MObjectInstanceList;
00025 
00026 class M2MEndpoint;
00027 
00028 /*! \file m2mobject.h
00029  *  \brief M2MObject.
00030  *  This class is the base class for the mbed Client Objects.
00031  *
00032  *  All defined LwM2M object models can be created based on it.
00033  *  This class also holds all object instances associated with the given object.
00034  */
00035 
00036 /*! \class M2MObject
00037  *  \brief The base class for Client Objects.
00038  */
00039 class M2MObject : public M2MBase
00040 {
00041 
00042 friend class M2MInterfaceFactory;
00043 friend class M2MEndpoint;
00044 friend class TestFactory;
00045 
00046 protected :
00047 
00048     /**
00049      * \brief Constructor
00050      * \param object_name The name of the object.
00051      * \param path Path of the object, such as 3/0/1
00052      * \param external_blockwise_store If true, CoAP blocks are passed to application through callbacks,
00053      *        otherwise handled in mbed-client-c.
00054      */
00055     M2MObject(const String &object_name,
00056               char *path,
00057               bool external_blockwise_store = false);
00058 
00059     // Prevents the use of default constructor.
00060     M2MObject();
00061 
00062     // Prevents the use of assignment operator.
00063     M2MObject& operator=( const M2MObject& /*other*/ );
00064 
00065     // Prevents the use of copy constructor.
00066     M2MObject( const M2MObject& /*other*/ );
00067 
00068     /**
00069      * \brief Constructor
00070      * \param name The name of the object.
00071      */
00072     M2MObject(const M2MBase::lwm2m_parameters_s* static_res);
00073 
00074 public:
00075 
00076     /**
00077      * \brief Destructor
00078      */
00079     virtual ~M2MObject();
00080 
00081     /**
00082      * \brief Creates a new object instance for a given mbed Client Interface object. With this,
00083      * the client can respond to server's GET methods with the provided value.
00084      * \return M2MObjectInstance. An object instance for managing other client operations.
00085      */
00086     M2MObjectInstance* create_object_instance(uint16_t instance_id = 0);
00087 
00088     /**
00089      * \brief Creates a new object instance for a given mbed Client Interface object. With this,
00090      * the client can respond to server's GET methods with the provided value.
00091      * \return M2MObjectInstance. An object instance for managing other client operations.
00092      */
00093     M2MObjectInstance* create_object_instance(const lwm2m_parameters_s* s);
00094 
00095     /**
00096      * \brief Removes the object instance resource with the given instance id.
00097      * \param instance_id The instance ID of the object instance to be removed, default is 0.
00098      * \return True if removed, else false.
00099      */
00100     bool remove_object_instance(uint16_t instance_id = 0);
00101 
00102     /**
00103      * \brief Returns the object instance with the the given instance ID.
00104      * \param instance_id The instance ID of the requested object instance ID, default is 0.
00105      * \return Object instance reference if found, else NULL.
00106      */
00107     M2MObjectInstance* object_instance(uint16_t instance_id = 0) const;
00108 
00109     /**
00110      * \brief Returns a list of object instances.
00111      * \return A list of object instances.
00112      */
00113     const M2MObjectInstanceList& instances() const;
00114 
00115     /**
00116      * \brief Returns the total number of object instances-
00117      * \return The total number of the object instances.
00118      */
00119     uint16_t instance_count() const;
00120 
00121     /**
00122      * \brief Returns the Observation Handler object.
00123      * \return M2MObservationHandler object.
00124     */
00125     virtual M2MObservationHandler* observation_handler() const;
00126 
00127     /**
00128      * \brief Sets the observation handler
00129      * \param handler Observation handler
00130     */
00131     virtual void set_observation_handler(M2MObservationHandler *handler);
00132 
00133     /**
00134      * \brief Adds the observation level for the object.
00135      * \param observation_level The level of observation.
00136      */
00137     virtual void add_observation_level(M2MBase::Observation observation_level);
00138 
00139     /**
00140      * \brief Removes the observation level from the object.
00141      * \param observation_level The level of observation.
00142      */
00143     virtual void remove_observation_level(M2MBase::Observation observation_level);
00144 
00145     /**
00146      * \brief Handles GET request for the registered objects.
00147      * \param nsdl The NSDL handler for the CoAP library.
00148      * \param received_coap_header The CoAP message received from the server.
00149      * \param observation_handler The handler object for sending
00150      * observation callbacks.
00151      * \return sn_coap_hdr_s  The message that needs to be sent to server.
00152      */
00153     virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl,
00154                                               sn_coap_hdr_s *received_coap_header,
00155                                               M2MObservationHandler *observation_handler = NULL);
00156 
00157     /**
00158      * \brief Handles PUT request for the registered objects.
00159      * \param nsdl The NSDL handler for the CoAP library.
00160      * \param received_coap_header The received CoAP message from the server.
00161      * \param observation_handler The handler object for sending
00162      * observation callbacks.
00163      * \param execute_value_updated True will execute the "value_updated" callback.
00164      * \return sn_coap_hdr_s The message that needs to be sent to server.
00165      */
00166     virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl,
00167                                               sn_coap_hdr_s *received_coap_header,
00168                                               M2MObservationHandler *observation_handler,
00169                                               bool &execute_value_updated);
00170 
00171     /**
00172      * \brief Handles GET request for the registered objects.
00173      * \param nsdl The NSDL handler for the CoAP library.
00174      * \param received_coap_header The received CoAP message from the server.
00175      * \param observation_handler The handler object for sending
00176      * observation callbacks.
00177      * \param execute_value_updated True will execute the "value_updated" callback.
00178      * \return sn_coap_hdr_s The message that needs to be sent to server.
00179      */
00180     virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl,
00181                                                sn_coap_hdr_s *received_coap_header,
00182                                                M2MObservationHandler *observation_handler,
00183                                                bool &execute_value_updated,
00184                                                sn_nsdl_addr_s *address = NULL);
00185 
00186     void notification_update(uint16_t obj_instance_id);
00187 
00188 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
00189     void set_endpoint(M2MEndpoint *endpoint);
00190 
00191     M2MEndpoint* get_endpoint() const;
00192 #endif
00193 
00194 protected :
00195     /**
00196      * \brief Returns the owner object. Can return NULL if the object has no parent.
00197      */
00198     virtual M2MBase *get_parent() const;
00199 
00200 private:
00201 
00202     M2MObjectInstanceList     _instance_list; // owned
00203 
00204     M2MObservationHandler    *_observation_handler; // Not owned
00205 
00206 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION
00207     M2MEndpoint              *_endpoint; // Parent endpoint
00208 #endif
00209 
00210 friend class Test_M2MObject;
00211 friend class Test_M2MEndpoint;
00212 friend class Test_M2MInterfaceImpl;
00213 friend class Test_M2MNsdlInterface;
00214 friend class Test_M2MTLVSerializer;
00215 friend class Test_M2MTLVDeserializer;
00216 friend class Test_M2MDevice;
00217 friend class Test_M2MFirmware;
00218 friend class Test_M2MBase;
00219 friend class Test_M2MObjectInstance;
00220 friend class Test_M2MResource;
00221 friend class Test_M2MSecurity;
00222 friend class Test_M2MServer;
00223 friend class Test_M2MResourceInstance;
00224 };
00225 
00226 #endif // M2M_OBJECT_H