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.
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of 6_songs-from-the-cloud by
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 private: // Constructor and destructor are private 00043 // which means that these objects can be created or 00044 // deleted only through a function provided by the M2MObjectInstance. 00045 00046 /** 00047 * @brief Constructor 00048 * @param resource_name, Resource name of the object. 00049 * @param resource_type, Resource type of the object. 00050 * @param type, Resource Data Type of the object. 00051 * @param value, Value pointer of the object. 00052 * @param value_length, Length of the value pointer 00053 * @param multiple_instance, True if resource supports instances. 00054 */ 00055 M2MResource(M2MObjectInstanceCallback &object_instance_callback, 00056 const String &resource_name, 00057 const String &resource_type, 00058 M2MResourceInstance::ResourceType type, 00059 const uint8_t *value, 00060 const uint8_t value_length, 00061 bool multiple_instance = false); 00062 00063 /** 00064 * @brief Constructor 00065 * @param name, Name of the object 00066 */ 00067 M2MResource(M2MObjectInstanceCallback &object_instance_callback, 00068 const String &resource_name, 00069 const String &resource_type, 00070 M2MResourceInstance::ResourceType type, 00071 bool observable, 00072 bool multiple_instance = false); 00073 00074 // Prevents the use of default constructor. 00075 M2MResource(); 00076 00077 // Prevents the use of assignment operator. 00078 M2MResource& operator=( const M2MResource& /*other*/ ); 00079 00080 // Prevents the use of copy constructor 00081 M2MResource( const M2MResource& /*other*/ ); 00082 00083 /** 00084 * Destructor 00085 */ 00086 virtual ~M2MResource(); 00087 00088 public: 00089 00090 /** 00091 * @brief Adds resource instances to the M2MResource. 00092 * @param resource_instance, Resource Instance to be added. 00093 */ 00094 void add_resource_instance(M2MResourceInstance *resource_instance); 00095 00096 /** 00097 * @brief Returns whether the resource has multiple 00098 * resource instances or not. 00099 * @return True if resource base has multiple instances, 00100 * else false. 00101 */ 00102 bool supports_multiple_instances() const; 00103 00104 /** 00105 * @brief Removes the resource with the given name. 00106 * @param name, Name of the resource to be removed. 00107 * @param instance_id, Instance ID of resource to be removed, default is 0. 00108 * @return True if removed, else false. 00109 */ 00110 virtual bool remove_resource_instance(uint16_t instance_id = 0); 00111 00112 /** 00113 * @brief Returns resource instance with the given name. 00114 * @param instance_id, Instance ID of the requested resource, default is 0 00115 * @return M2MResourceInstance object if found, else NULL. 00116 */ 00117 virtual M2MResourceInstance* resource_instance(uint16_t instance_id = 0) const; 00118 00119 /** 00120 * @brief Returns a list of resources. 00121 * @return List of resources with the object. 00122 */ 00123 virtual const M2MResourceInstanceList& resource_instances() const; 00124 00125 /** 00126 * @brief Returns the total number of resources with the object. 00127 * @return Total number of resources. 00128 */ 00129 virtual uint16_t resource_instance_count() const; 00130 00131 /** 00132 * @brief Parses the received query for a notification 00133 * attribute. 00134 * @return True if required attributes are present, else false. 00135 */ 00136 virtual bool handle_observation_attribute(char *&query); 00137 00138 /** 00139 * @brief Adds the observation level for the object. 00140 * @param observation_level, Level of observation. 00141 */ 00142 virtual void add_observation_level(M2MBase::Observation observation_level); 00143 00144 /** 00145 * @brief Removes the observation level from the object. 00146 * @param observation_level, Level of observation. 00147 */ 00148 virtual void remove_observation_level(M2MBase::Observation observation_level); 00149 00150 /** 00151 * @brief Handles GET request for the registered objects. 00152 * @param nsdl, NSDL handler for the CoAP library. 00153 * @param received_coap_header, CoAP message received from the server. 00154 * @param observation_handler, Handler object for sending 00155 * observation callbacks. 00156 * @return sn_coap_hdr_s, Message that needs to be sent to the server. 00157 */ 00158 virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl, 00159 sn_coap_hdr_s *received_coap_header, 00160 M2MObservationHandler *observation_handler = NULL); 00161 /** 00162 * @brief Handles PUT request for the registered objects. 00163 * @param nsdl, NSDL handler for the CoAP library. 00164 * @param received_coap_header, CoAP message received from the server. 00165 * @param observation_handler, Handler object for sending 00166 * observation callbacks. 00167 * @return sn_coap_hdr_s, Message that needs to be sent to the server. 00168 */ 00169 virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl, 00170 sn_coap_hdr_s *received_coap_header, 00171 M2MObservationHandler *observation_handler = NULL); 00172 /** 00173 * @brief Handles POST request for the registered objects. 00174 * @param nsdl, NSDL handler for the CoAP library. 00175 * @param received_coap_header, CoAP message received from the server. 00176 * @param observation_handler, Handler object for sending 00177 * observation callbacks. 00178 * @return sn_coap_hdr_s, Message that needs to be sent to the 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 = NULL); 00183 00184 protected: 00185 virtual void notification_update(); 00186 00187 private: 00188 00189 M2MResourceInstanceList _resource_instance_list; // owned 00190 bool _has_multiple_instances; 00191 00192 friend class Test_M2MResource; 00193 friend class Test_M2MObjectInstance; 00194 friend class Test_M2MObject; 00195 friend class Test_M2MDevice; 00196 friend class Test_M2MSecurity; 00197 friend class Test_M2MServer; 00198 friend class Test_M2MNsdlInterface; 00199 friend class Test_M2MFirmware; 00200 friend class Test_M2MTLVSerializer; 00201 friend class Test_M2MTLVDeserializer; 00202 00203 }; 00204 00205 #endif // M2M_RESOURCE_H
Generated on Tue Jul 12 2022 12:47:48 by
