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