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.
m2mresource.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_RESOURCE_H 00017 #define M2M_RESOURCE_H 00018 00019 #include "mbed-client/m2mvector.h" 00020 #include "mbed-client/m2mresourceinstance.h" 00021 00022 //FORWARD DECLARATION 00023 class M2MObjectInstance; 00024 typedef Vector<M2MResourceInstance *> M2MResourceInstanceList; 00025 00026 class M2MResourceCallback { 00027 public: 00028 virtual void notification_update() = 0; 00029 }; 00030 00031 /** 00032 * \brief M2MResource. 00033 * This class is the base class for mbed Client Resources. All defined 00034 * LWM2M object models can be created using it. This class will also hold all resources 00035 * instances associated with the given object. 00036 */ 00037 00038 class M2MResource : public M2MResourceInstance, M2MResourceCallback { 00039 00040 friend class M2MObjectInstance; 00041 00042 public: 00043 class M2MExecuteParameter; 00044 00045 private: // Constructor and destructor are private 00046 // which means that these objects can be created or 00047 // deleted only through a function provided by the M2MObjectInstance. 00048 00049 /** 00050 * \brief Constructor 00051 * \param resource_name The resource name of the object. 00052 * \param resource_type The resource type of the object. 00053 * \param type The resource data type of the object. 00054 * \param value The value pointer of the object. 00055 * \param value_length The length of the value pointer. 00056 * \param object_instance_id Object instance id where resource exists. 00057 * \param object_name Object name where resource exists. 00058 * \param multiple_instance True if the resource supports instances. 00059 */ 00060 M2MResource(M2MObjectInstanceCallback &object_instance_callback, 00061 const String &resource_name, 00062 const String &resource_type, 00063 M2MResourceInstance::ResourceType type, 00064 const uint8_t *value, 00065 const uint8_t value_length, 00066 const uint16_t object_instance_id = 0, 00067 const String &object_name = "", 00068 bool multiple_instance = false); 00069 00070 /** 00071 * \brief Constructor 00072 * \param resource_name The resource name of the object. 00073 * \param resource_type The resource type of the object. 00074 * \param type The resource data type of the object. 00075 * \param observable Indicates whether the resource is observable or not. 00076 * \param object_instance_id Object instance id where resource exists. 00077 * \param object_name Object name where resource exists. 00078 * \param multiple_instance True if the resource supports instances. 00079 */ 00080 M2MResource(M2MObjectInstanceCallback &object_instance_callback, 00081 const String &resource_name, 00082 const String &resource_type, 00083 M2MResourceInstance::ResourceType type, 00084 bool observable, 00085 const uint16_t object_instance_id = 0, 00086 const String &object_name = "", 00087 bool multiple_instance = false); 00088 00089 // Prevents the use of default constructor. 00090 M2MResource(); 00091 00092 // Prevents the use of assignment operator. 00093 M2MResource& operator=( const M2MResource& /*other*/ ); 00094 00095 // Prevents the use of copy constructor 00096 M2MResource( const M2MResource& /*other*/ ); 00097 00098 /** 00099 * Destructor 00100 */ 00101 virtual ~M2MResource(); 00102 00103 public: 00104 00105 /** 00106 * \brief Adds resource instances to the M2MResource. 00107 * \param resource_instance The resource instance to be added. 00108 */ 00109 void add_resource_instance(M2MResourceInstance *resource_instance); 00110 00111 /** 00112 * \brief Returns whether the resource has multiple 00113 * resource instances or not. 00114 * \return True if the resource base has multiple instances, 00115 * else false. 00116 */ 00117 bool supports_multiple_instances() const; 00118 00119 /** 00120 * \brief Sets whether the resource should send a delayed response for POST request. 00121 * \param delayed_response A boolean value to set the delayed response. 00122 */ 00123 void set_delayed_response(bool delayed_response); 00124 00125 /** 00126 * \brief A trigger to send the delayed response for the POST request. 00127 * The delayed_response flag must be set before receiving the POST request 00128 * and the value of the resource must be updated before calling this function. 00129 * \return True if response is sent, else false. 00130 */ 00131 bool send_delayed_post_response(); 00132 00133 /** 00134 * \brief Provides the value of the given token. 00135 * \param value[OUT] A pointer to the token value. 00136 * \param value_length[OUT] The length of the token pointer. 00137 */ 00138 void get_delayed_token(uint8_t *&token, uint8_t &token_length); 00139 00140 /** 00141 * \brief Removes the resource with the given name. 00142 * \param name The name of the resource to be removed. 00143 * \param instance_id The instance ID of the resource to be removed, default is 0. 00144 * \return True if removed, else false. 00145 */ 00146 virtual bool remove_resource_instance(uint16_t instance_id = 0); 00147 00148 /** 00149 * \brief Returns the resource instance with the given name. 00150 * \param instance_id The instance ID of the requested resource, default is 0 00151 * \return M2MResourceInstance object if found, else NULL. 00152 */ 00153 virtual M2MResourceInstance* resource_instance(uint16_t instance_id = 0) const; 00154 00155 /** 00156 * \brief Returns a list of resources. 00157 * \return A list of resources. 00158 */ 00159 virtual const M2MResourceInstanceList& resource_instances() const; 00160 00161 /** 00162 * \brief Returns the total number of resources. 00163 * \return The total number of resources. 00164 */ 00165 virtual uint16_t resource_instance_count() const; 00166 00167 /** 00168 * \brief Returns the value set for delayed response. 00169 * \return The value for delayed response. 00170 */ 00171 bool delayed_response() const; 00172 00173 /** 00174 * \brief Parses the received query for a notification 00175 * attribute. 00176 * \return True if required attributes are present, else false. 00177 */ 00178 virtual bool handle_observation_attribute(char *&query); 00179 00180 /** 00181 * \brief Adds the observation level for the object. 00182 * \param observation_level The öevel of observation. 00183 */ 00184 virtual void add_observation_level(M2MBase::Observation observation_level); 00185 00186 /** 00187 * \brief Removes the observation level from the object. 00188 * \param observation_level The level of observation. 00189 */ 00190 virtual void remove_observation_level(M2MBase::Observation observation_level); 00191 00192 /** 00193 * \brief Handles the GET request for the registered objects. 00194 * \param nsdl The NSDL handler for the CoAP library. 00195 * \param received_coap_header The CoAP message received from the server. 00196 * \param observation_handler The handler object for sending 00197 * observation callbacks. 00198 * \return sn_coap_hdr_s The message that needs to be sent to the server. 00199 */ 00200 virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl, 00201 sn_coap_hdr_s *received_coap_header, 00202 M2MObservationHandler *observation_handler = NULL); 00203 /** 00204 * \brief Handles the PUT request for the registered objects. 00205 * \param nsdl The NSDL handler for the CoAP library. 00206 * \param received_coap_header The CoAP message received from the server. 00207 * \param observation_handler The handler object for sending 00208 * observation callbacks. 00209 * \param execute_value_updated True will execute the "value_updated" callback. 00210 * \return sn_coap_hdr_s The message that needs to be sent to the server. 00211 */ 00212 virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl, 00213 sn_coap_hdr_s *received_coap_header, 00214 M2MObservationHandler *observation_handler, 00215 bool &execute_value_updated); 00216 /** 00217 * \brief Handles the POST request for the registered objects. 00218 * \param nsdl The NSDL handler for the CoAP library. 00219 * \param received_coap_header The CoAP message received from the server. 00220 * \param observation_handler The handler object for sending 00221 * observation callbacks. 00222 * \param execute_value_updated True will execute the "value_updated" callback. 00223 * \return sn_coap_hdr_s The message that needs to be sent to the server. 00224 */ 00225 virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl, 00226 sn_coap_hdr_s *received_coap_header, 00227 M2MObservationHandler *observation_handler, 00228 bool &execute_value_updated); 00229 00230 protected: 00231 virtual void notification_update(); 00232 00233 private: 00234 00235 M2MResourceInstanceList _resource_instance_list; // owned 00236 uint8_t *_delayed_token; 00237 uint8_t _delayed_token_len; 00238 bool _has_multiple_instances; 00239 bool _delayed_response; 00240 00241 friend class Test_M2MResource; 00242 friend class Test_M2MObjectInstance; 00243 friend class Test_M2MObject; 00244 friend class Test_M2MDevice; 00245 friend class Test_M2MSecurity; 00246 friend class Test_M2MServer; 00247 friend class Test_M2MNsdlInterface; 00248 friend class Test_M2MFirmware; 00249 friend class Test_M2MTLVSerializer; 00250 friend class Test_M2MTLVDeserializer; 00251 00252 }; 00253 00254 /** 00255 * \brief M2MResource::M2MExecuteParameter. 00256 * This class handles the "Execute" operation arguments. 00257 */ 00258 class M2MResource::M2MExecuteParameter { 00259 00260 private: 00261 00262 /** 00263 * \brief Constructor 00264 */ 00265 M2MExecuteParameter(); 00266 00267 /** 00268 * Destructor 00269 */ 00270 ~M2MExecuteParameter(); 00271 00272 public: 00273 00274 /** 00275 * \brief Returns the value of the argument. 00276 * \return uint8_t * The argument value. 00277 */ 00278 uint8_t *get_argument_value() const; 00279 00280 /** 00281 * \brief Returns the length of the value argument. 00282 * \return uint8_t The argument value length. 00283 */ 00284 uint16_t get_argument_value_length() const; 00285 00286 /** 00287 * \brief Returns the object name where resource exists. 00288 * \return Object name. 00289 */ 00290 const String& get_argument_object_name() const; 00291 00292 /** 00293 * \brief Returns the resource name. 00294 * \return Resource name. 00295 */ 00296 const String& get_argument_resource_name() const; 00297 00298 /** 00299 * \brief Returns the object instance id where resource exists. 00300 * \return Object instance id. 00301 */ 00302 uint16_t get_argument_object_instance_id() const; 00303 00304 private: 00305 00306 String _object_name; 00307 String _resource_name; 00308 uint8_t * _value; 00309 uint16_t _value_length; 00310 uint16_t _object_instance_id; 00311 00312 00313 friend class Test_M2MResource; 00314 friend class M2MResource; 00315 }; 00316 00317 #endif // M2M_RESOURCE_H
Generated on Tue Jul 12 2022 13:05:11 by
 1.7.2
 1.7.2