Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
m2mendpoint.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_ENDPOINT_H 00017 #define M2M_ENDPOINT_H 00018 00019 #include "mbed-client/m2mvector.h" 00020 #include "mbed-client/m2mbase.h" 00021 #include "mbed-client/m2mobject.h" 00022 #include "mbed-client/m2mstring.h" 00023 00024 #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION 00025 00026 //FORWARD DECLARATION 00027 typedef Vector<M2MObject *> M2MObjectList; 00028 00029 /*! \file M2MEndpoint.h 00030 * \brief M2MEndpoint. 00031 * This class can be used to represent an LwM2M Device endpoint, it contains a list of LwM2M objects. 00032 * It implements the M2MBase interface so it can be passed to the m2minterface for registering to server. 00033 */ 00034 00035 class M2MEndpoint : public M2MBase 00036 { 00037 00038 friend class M2MInterfaceFactory; 00039 friend class M2MNsdlInterface; 00040 friend class TestFactory; 00041 friend class Test_M2MObject; 00042 00043 protected : 00044 00045 /** 00046 * \brief Constructor 00047 * \param name The name of the object. 00048 * \param path Path of the object like 3/0/1 00049 * \param external_blockwise_store If true CoAP blocks are passed to application through callbacks 00050 * otherwise handled in mbed-client-c. 00051 */ 00052 M2MEndpoint(const String &object_name, 00053 char *path); 00054 00055 // Prevents the use of default constructor. 00056 M2MEndpoint(); 00057 00058 // Prevents the use of assignment operator. 00059 M2MEndpoint& operator=( const M2MEndpoint& /*other*/ ); 00060 00061 // Prevents the use of copy constructor. 00062 M2MEndpoint( const M2MEndpoint& /*other*/ ); 00063 00064 /* 00065 * \brief Data has been changed and it needs to be updated to Mbed Cloud. 00066 */ 00067 virtual void set_changed(); 00068 00069 /* 00070 * \brief Clears the changed flag. This can be done when the data has been updated into Mbed Cloud. 00071 */ 00072 void clear_changed(); 00073 00074 /* 00075 * \brief Returns current changed status. 00076 */ 00077 bool get_changed() const; 00078 00079 00080 public: 00081 00082 /** 00083 * \brief Destructor 00084 */ 00085 virtual ~M2MEndpoint(); 00086 00087 /** 00088 * \brief Creates a new object for a given mbed Client endpoint instance. With this, 00089 * the client can respond to server's GET methods with the provided value. 00090 * \return M2MObject. An object for managing object instances and resources. 00091 */ 00092 M2MObject* create_object(const String &name); 00093 00094 /** 00095 * \brief Removes the object with the given id. 00096 * \param object_id The ID of the object to be removed, default is 0. 00097 * \return True if removed, else false. 00098 */ 00099 bool remove_object(const String &name); 00100 00101 /** 00102 * \brief Returns the object with the the given ID. 00103 * \param instance_id The ID of the requested object ID, default is 0. 00104 * \return Object reference if found, else NULL. 00105 */ 00106 M2MObject* object(const String &name) const; 00107 00108 /** 00109 * \brief Returns a list of objects. 00110 * \return A list of objects. 00111 */ 00112 const M2MObjectList& objects() const; 00113 00114 /** 00115 * \brief Returns the total number of objects- 00116 * \return The total number of the objects. 00117 */ 00118 uint16_t object_count() const; 00119 00120 /** 00121 * \brief Returns the Observation Handler object. 00122 * \return M2MObservationHandler object. 00123 */ 00124 virtual M2MObservationHandler* observation_handler() const; 00125 00126 /** 00127 * \brief Sets the observation handler 00128 * \param handler Observation handler 00129 */ 00130 virtual void set_observation_handler(M2MObservationHandler *handler); 00131 00132 /** 00133 * \brief Adds the observation level for the object. 00134 * \param observation_level The level of observation. 00135 */ 00136 virtual void add_observation_level(M2MBase::Observation observation_level); 00137 00138 /** 00139 * \brief Removes the observation level from the object. 00140 * \param observation_level The level of observation. 00141 */ 00142 virtual void remove_observation_level(M2MBase::Observation observation_level); 00143 00144 /** 00145 * \brief Handles GET request for the registered objects. 00146 * \param nsdl The NSDL handler for the CoAP library. 00147 * \param received_coap_header The CoAP message received from the server. 00148 * \param observation_handler The handler object for sending 00149 * observation callbacks. 00150 * \return sn_coap_hdr_s The message that needs to be sent to server. 00151 */ 00152 virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl, 00153 sn_coap_hdr_s *received_coap_header, 00154 M2MObservationHandler *observation_handler = NULL); 00155 00156 /** 00157 * \brief Handles PUT request for the registered objects. 00158 * \param nsdl The NSDL handler for the CoAP library. 00159 * \param received_coap_header The received CoAP message from the server. 00160 * \param observation_handler The handler object for sending 00161 * observation callbacks. 00162 * \param execute_value_updated True will execute the "value_updated" callback. 00163 * \return sn_coap_hdr_s The message that needs to be sent to server. 00164 */ 00165 virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl, 00166 sn_coap_hdr_s *received_coap_header, 00167 M2MObservationHandler *observation_handler, 00168 bool &execute_value_updated); 00169 00170 /** 00171 * \brief Handles GET request for the registered objects. 00172 * \param nsdl The NSDL handler for the CoAP library. 00173 * \param received_coap_header The received CoAP message from the server. 00174 * \param observation_handler The handler object for sending 00175 * observation callbacks. 00176 * \param execute_value_updated True will execute the "value_updated" callback. 00177 * \return sn_coap_hdr_s The message that needs to be sent to server. 00178 */ 00179 virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl, 00180 sn_coap_hdr_s *received_coap_header, 00181 M2MObservationHandler *observation_handler, 00182 bool &execute_value_updated, 00183 sn_nsdl_addr_s *address = NULL); 00184 00185 /** 00186 * \brief Set the user defined context for this M2MEndpoint. 00187 * \param ctx pointer to allocated context, lifecycle must be handled outside of M2MEndpoint. 00188 */ 00189 void set_context(void *ctx); 00190 00191 /** 00192 * \brief Get the user defined context set for this M2MEndpoint. 00193 * \return The user defined context or NULL if not set. The lifecycle of the user defined context 00194 * is handled outside of M2MEndpoint. 00195 */ 00196 void* get_context() const; 00197 00198 protected : 00199 00200 00201 private: 00202 00203 M2MObjectList _object_list; // owned 00204 M2MObservationHandler *_observation_handler; // Not owned 00205 void *_ctx; // user defined context 00206 bool _changed; // True if modifications have been done to this endpoint since last registration update. 00207 // False otherwise. 00208 00209 friend class Test_M2MEndpoint; 00210 friend class Test_M2MInterfaceImpl; 00211 friend class Test_M2MNsdlInterface; 00212 friend class Test_M2MTLVSerializer; 00213 friend class Test_M2MTLVDeserializer; 00214 friend class Test_M2MDevice; 00215 friend class Test_M2MFirmware; 00216 friend class Test_M2MBase; 00217 friend class Test_M2MResource; 00218 friend class Test_M2MSecurity; 00219 friend class Test_M2MServer; 00220 friend class Test_M2MResourceInstance; 00221 }; 00222 00223 #endif // MBED_CLOUD_CLIENT_EDGE_EXTENSION 00224 00225 #endif // M2M_ENDPOINT_H
Generated on Tue Jul 12 2022 16:24:14 by
1.7.2