joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mobjectinstance.h Source File

m2mobjectinstance.h

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_INSTANCE_H
00017 #define M2M_OBJECT_INSTANCE_H
00018 
00019 #include "mbed-client/m2mvector.h"
00020 #include "mbed-client/m2mresource.h"
00021 
00022 //FORWARD DECLARATION
00023 typedef Vector<M2MResource *> M2MResourceList;
00024 typedef Vector<M2MResourceInstance *> M2MResourceInstanceList;
00025 
00026 class M2MObjectCallback {
00027 public:
00028     virtual void notification_update(uint16_t obj_instance_id) = 0;
00029 };
00030 
00031 /**
00032  *  \brief M2MObjectInstance.
00033  *  This class is the instance class for mbed Client Objects. All defined
00034  *  LWM2M object models can be created based on it. This class also holds all resource
00035  *  instances associated with the given object.
00036  */
00037 
00038 class M2MObjectInstance : public M2MBase,
00039                           public M2MObjectInstanceCallback
00040 {
00041 
00042 friend class M2MObject;
00043 
00044 private: // Constructor and destructor are private which means
00045          // that these objects can be created or
00046          // deleted only through function provided by M2MObject.
00047 
00048     /**
00049      * \brief Constructor
00050      * \param name Name of the object
00051      */
00052     M2MObjectInstance(const String &object_name,
00053                       M2MObjectCallback &object_callback);
00054 
00055 
00056     // Prevents the use of default constructor.
00057     M2MObjectInstance();
00058 
00059     // Prevents the use of assignment operator.
00060     M2MObjectInstance& operator=( const M2MObjectInstance& /*other*/ );
00061 
00062     // Prevents the use of copy constructor.
00063     M2MObjectInstance( const M2MObjectInstance& /*other*/ );
00064 
00065     /**
00066      * Destructor
00067      */
00068     virtual ~M2MObjectInstance();
00069 
00070 public:
00071 
00072     /**
00073      * \brief Creates a static resource for a given mbed Client Inteface object. With this, the
00074      * client can respond to server's GET methods with the provided value.
00075      * \param resource_name The name of the resource.
00076      * \param resource_type The type of the resource.
00077      * \param value A pointer to the value of the resource.
00078      * \param value_length The length of the value in the pointer.
00079      * \param multiple_instance A resource can have
00080      *        multiple instances, default is false.
00081      * \return M2MResource The resource for managing other client operations.
00082      */
00083     M2MResource* create_static_resource(const String &resource_name,
00084                                         const String &resource_type,
00085                                         M2MResourceInstance::ResourceType type,
00086                                         const uint8_t *value,
00087                                         const uint8_t value_length,
00088                                         bool multiple_instance = false);
00089 
00090     /**
00091      * \brief Creates a dynamic resource for a given mbed Client Inteface object. With this,
00092      * the client can respond to different queries from the server (GET,PUT etc).
00093      * This type of resource is also observable and carries callbacks.
00094      * \param resource_name The name of the resource.
00095      * \param resource_type The type of the resource.
00096      * \param observable Indicates whether the resource is observable or not.
00097      * \param multiple_instance The resource can have
00098      *        multiple instances, default is false.
00099      * \return M2MResource The resource for managing other client operations.
00100      */
00101     M2MResource* create_dynamic_resource(const String &resource_name,
00102                                          const String &resource_type,
00103                                          M2MResourceInstance::ResourceType type,
00104                                          bool observable,
00105                                          bool multiple_instance = false);
00106 
00107 
00108     /**
00109      * \brief Creates a static resource instance for a given mbed Client Inteface object. With this,
00110      * the client can respond to server's GET methods with the provided value.
00111      * \param resource_name The name of the resource.
00112      * \param resource_type The type of the resource.
00113      * \param value A pointer to the value of the resource.
00114      * \param value_length The length of the value in pointer.
00115      * \param instance_id The instance ID of the resource.
00116      * \return M2MResourceInstance The resource instance for managing other client operations.
00117      */
00118     M2MResourceInstance* create_static_resource_instance(const String &resource_name,
00119                                                          const String &resource_type,
00120                                                          M2MResourceInstance::ResourceType type,
00121                                                          const uint8_t *value,
00122                                                          const uint8_t value_length,
00123                                                          uint16_t instance_id);
00124 
00125     /**
00126      * \brief Creates a dynamic resource instance for a given mbed Client Inteface object. With this,
00127      * the client can respond to different queries from the server (GET,PUT etc).
00128      * This type of resource is also observable and carries callbacks.
00129      * \param resource_name The name of the resource.
00130      * \param resource_type The type of the resource.
00131      * \param observable Indicates whether the resource is observable or not.
00132      * \param instance_id The instance ID of the resource.
00133      * \return M2MResourceInstance The resource instance for managing other client operations.
00134      */
00135     M2MResourceInstance* create_dynamic_resource_instance(const String &resource_name,
00136                                                           const String &resource_type,
00137                                                           M2MResourceInstance::ResourceType type,
00138                                                           bool observable,
00139                                                           uint16_t instance_id);
00140 
00141     /**
00142      * \brief Removes the resource with the given name.
00143      * \param name The name of the resource to be removed.
00144      * \return True if removed, else false.
00145      */
00146     virtual bool remove_resource(const String &name);
00147 
00148     /**
00149      * \brief Removes the resource instance with the given name.
00150      * \param resource_name The name of the resource instance to be removed.
00151      * \param instance_id The instance ID of the instance.
00152      * \return True if removed, else false.
00153      */
00154     virtual bool remove_resource_instance(const String &resource_name,
00155                                           uint16_t instance_id);
00156 
00157     /**
00158      * \brief Returns the resource with the given name.
00159      * \param name The name of the requested resource.
00160      * \return Resource reference if found, else NULL.
00161      */
00162     virtual M2MResource* resource(const String &name) const;
00163 
00164     /**
00165      * \brief Returns a list of M2MResourceBase objects.
00166      * \return A list of M2MResourceBase objects.
00167      */
00168     virtual const M2MResourceList& resources() const;
00169 
00170     /**
00171      * \brief Returns the total number of resources with the object.
00172      * \return Total number of the resources.
00173      */
00174     virtual uint16_t resource_count() const;
00175 
00176     /**
00177      * \brief Returns the total number of single resource instances.
00178      * \param resource The name of the resource.
00179      * \return Total number of the resources.
00180      */
00181     virtual uint16_t resource_count(const String& resource) const;
00182 
00183     /**
00184      * \brief Returns the object type.
00185      * \return BaseType.
00186      */
00187     virtual M2MBase::BaseType base_type() const;
00188 
00189     /**
00190      * \brief Adds the observation level for the object.
00191      * \param observation_level The level of observation.
00192      */
00193     virtual void add_observation_level(M2MBase::Observation observation_level);
00194 
00195     /**
00196      * \brief Removes the observation level from the object.
00197      * \param observation_level The level of observation.
00198      */
00199     virtual void remove_observation_level(M2MBase::Observation observation_level);
00200 
00201     /**
00202      * \brief Handles GET request for the registered objects.
00203      * \param nsdl The NSDL handler for the CoAP library.
00204      * \param received_coap_header The CoAP message received from the server.
00205      * \param observation_handler The handler object for sending
00206      * observation callbacks.
00207      * return sn_coap_hdr_s The message that needs to be sent to the server.
00208      */
00209     virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl,
00210                                               sn_coap_hdr_s *received_coap_header,
00211                                               M2MObservationHandler *observation_handler = NULL);
00212     /**
00213      * \brief Handles PUT request for the registered objects.
00214      * \param nsdl The NSDL handler for the CoAP library.
00215      * \param received_coap_header The CoAP message received from the server.
00216      * \param observation_handler The handler object for sending
00217      * observation callbacks.
00218      * \param execute_value_updated True will execute the "value_updated" callback.
00219      * \return sn_coap_hdr_s The message that needs to be sent to server.
00220      */
00221     virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl,
00222                                               sn_coap_hdr_s *received_coap_header,
00223                                               M2MObservationHandler *observation_handler,
00224                                               bool &execute_value_updated);
00225 
00226     /**
00227      * \brief Handles POST request for the registered objects.
00228      * \param nsdl The NSDL handler for the CoAP library.
00229      * \param received_coap_header The CoAP message received from the server.
00230      * \param observation_handler The handler object for sending
00231      * observation callbacks.
00232      * \param execute_value_updated True will execute the "value_updated" callback.
00233      * \return sn_coap_hdr_s The message that needs to be sent to server.
00234      */
00235     virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl,
00236                                                sn_coap_hdr_s *received_coap_header,
00237                                                M2MObservationHandler *observation_handler,
00238                                                bool &execute_value_updated);
00239 
00240 
00241 protected :
00242 
00243     virtual void notification_update(M2MBase::Observation observation_level);
00244 
00245 private:
00246 
00247     M2MObjectCallback   &_object_callback;
00248     M2MResourceList     _resource_list; // owned
00249 
00250     friend class Test_M2MObjectInstance;
00251     friend class Test_M2MObject;
00252     friend class Test_M2MDevice;
00253     friend class Test_M2MSecurity;
00254     friend class Test_M2MServer;
00255     friend class Test_M2MNsdlInterface;
00256     friend class Test_M2MFirmware;
00257     friend class Test_M2MTLVSerializer;
00258     friend class Test_M2MTLVDeserializer;
00259 };
00260 
00261 #endif // M2M_OBJECT_INSTANCE_H