![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Example
Dependencies: FXAS21002 FXOS8700Q
simple-mbed-cloud-client/mbed-cloud-client/mbed-client/mbed-client/m2mobject.h@0:11cc2b7889af, 2019-11-19 (annotated)
- Committer:
- maygup01
- Date:
- Tue Nov 19 09:49:38 2019 +0000
- Revision:
- 0:11cc2b7889af
Example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maygup01 | 0:11cc2b7889af | 1 | /* |
maygup01 | 0:11cc2b7889af | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
maygup01 | 0:11cc2b7889af | 3 | * SPDX-License-Identifier: Apache-2.0 |
maygup01 | 0:11cc2b7889af | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
maygup01 | 0:11cc2b7889af | 5 | * not use this file except in compliance with the License. |
maygup01 | 0:11cc2b7889af | 6 | * You may obtain a copy of the License at |
maygup01 | 0:11cc2b7889af | 7 | * |
maygup01 | 0:11cc2b7889af | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
maygup01 | 0:11cc2b7889af | 9 | * |
maygup01 | 0:11cc2b7889af | 10 | * Unless required by applicable law or agreed to in writing, software |
maygup01 | 0:11cc2b7889af | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
maygup01 | 0:11cc2b7889af | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
maygup01 | 0:11cc2b7889af | 13 | * See the License for the specific language governing permissions and |
maygup01 | 0:11cc2b7889af | 14 | * limitations under the License. |
maygup01 | 0:11cc2b7889af | 15 | */ |
maygup01 | 0:11cc2b7889af | 16 | #ifndef M2M_OBJECT_H |
maygup01 | 0:11cc2b7889af | 17 | #define M2M_OBJECT_H |
maygup01 | 0:11cc2b7889af | 18 | |
maygup01 | 0:11cc2b7889af | 19 | #include "mbed-client/m2mvector.h" |
maygup01 | 0:11cc2b7889af | 20 | #include "mbed-client/m2mbase.h" |
maygup01 | 0:11cc2b7889af | 21 | #include "mbed-client/m2mobjectinstance.h" |
maygup01 | 0:11cc2b7889af | 22 | |
maygup01 | 0:11cc2b7889af | 23 | //FORWARD DECLARATION |
maygup01 | 0:11cc2b7889af | 24 | typedef Vector<M2MObjectInstance *> M2MObjectInstanceList; |
maygup01 | 0:11cc2b7889af | 25 | |
maygup01 | 0:11cc2b7889af | 26 | class M2MEndpoint; |
maygup01 | 0:11cc2b7889af | 27 | |
maygup01 | 0:11cc2b7889af | 28 | /*! \file m2mobject.h |
maygup01 | 0:11cc2b7889af | 29 | * \brief M2MObject. |
maygup01 | 0:11cc2b7889af | 30 | * This class is the base class for the mbed Client Objects. |
maygup01 | 0:11cc2b7889af | 31 | * |
maygup01 | 0:11cc2b7889af | 32 | * All defined LwM2M object models can be created based on it. |
maygup01 | 0:11cc2b7889af | 33 | * This class also holds all object instances associated with the given object. |
maygup01 | 0:11cc2b7889af | 34 | */ |
maygup01 | 0:11cc2b7889af | 35 | |
maygup01 | 0:11cc2b7889af | 36 | /*! \class M2MObject |
maygup01 | 0:11cc2b7889af | 37 | * \brief The base class for Client Objects. |
maygup01 | 0:11cc2b7889af | 38 | */ |
maygup01 | 0:11cc2b7889af | 39 | class M2MObject : public M2MBase |
maygup01 | 0:11cc2b7889af | 40 | { |
maygup01 | 0:11cc2b7889af | 41 | |
maygup01 | 0:11cc2b7889af | 42 | friend class M2MInterfaceFactory; |
maygup01 | 0:11cc2b7889af | 43 | friend class M2MEndpoint; |
maygup01 | 0:11cc2b7889af | 44 | friend class TestFactory; |
maygup01 | 0:11cc2b7889af | 45 | |
maygup01 | 0:11cc2b7889af | 46 | protected : |
maygup01 | 0:11cc2b7889af | 47 | |
maygup01 | 0:11cc2b7889af | 48 | /** |
maygup01 | 0:11cc2b7889af | 49 | * \brief Constructor |
maygup01 | 0:11cc2b7889af | 50 | * \param object_name The name of the object. |
maygup01 | 0:11cc2b7889af | 51 | * \param path Path of the object, such as 3/0/1 |
maygup01 | 0:11cc2b7889af | 52 | * \param external_blockwise_store If true, CoAP blocks are passed to application through callbacks, |
maygup01 | 0:11cc2b7889af | 53 | * otherwise handled in mbed-client-c. |
maygup01 | 0:11cc2b7889af | 54 | */ |
maygup01 | 0:11cc2b7889af | 55 | M2MObject(const String &object_name, |
maygup01 | 0:11cc2b7889af | 56 | char *path, |
maygup01 | 0:11cc2b7889af | 57 | bool external_blockwise_store = false); |
maygup01 | 0:11cc2b7889af | 58 | |
maygup01 | 0:11cc2b7889af | 59 | // Prevents the use of default constructor. |
maygup01 | 0:11cc2b7889af | 60 | M2MObject(); |
maygup01 | 0:11cc2b7889af | 61 | |
maygup01 | 0:11cc2b7889af | 62 | // Prevents the use of assignment operator. |
maygup01 | 0:11cc2b7889af | 63 | M2MObject& operator=( const M2MObject& /*other*/ ); |
maygup01 | 0:11cc2b7889af | 64 | |
maygup01 | 0:11cc2b7889af | 65 | // Prevents the use of copy constructor. |
maygup01 | 0:11cc2b7889af | 66 | M2MObject( const M2MObject& /*other*/ ); |
maygup01 | 0:11cc2b7889af | 67 | |
maygup01 | 0:11cc2b7889af | 68 | /** |
maygup01 | 0:11cc2b7889af | 69 | * \brief Constructor |
maygup01 | 0:11cc2b7889af | 70 | * \param name The name of the object. |
maygup01 | 0:11cc2b7889af | 71 | */ |
maygup01 | 0:11cc2b7889af | 72 | M2MObject(const M2MBase::lwm2m_parameters_s* static_res); |
maygup01 | 0:11cc2b7889af | 73 | |
maygup01 | 0:11cc2b7889af | 74 | public: |
maygup01 | 0:11cc2b7889af | 75 | |
maygup01 | 0:11cc2b7889af | 76 | /** |
maygup01 | 0:11cc2b7889af | 77 | * \brief Destructor |
maygup01 | 0:11cc2b7889af | 78 | */ |
maygup01 | 0:11cc2b7889af | 79 | virtual ~M2MObject(); |
maygup01 | 0:11cc2b7889af | 80 | |
maygup01 | 0:11cc2b7889af | 81 | /** |
maygup01 | 0:11cc2b7889af | 82 | * \brief Creates a new object instance for a given mbed Client Interface object. With this, |
maygup01 | 0:11cc2b7889af | 83 | * the client can respond to server's GET methods with the provided value. |
maygup01 | 0:11cc2b7889af | 84 | * \return M2MObjectInstance. An object instance for managing other client operations. |
maygup01 | 0:11cc2b7889af | 85 | */ |
maygup01 | 0:11cc2b7889af | 86 | M2MObjectInstance* create_object_instance(uint16_t instance_id = 0); |
maygup01 | 0:11cc2b7889af | 87 | |
maygup01 | 0:11cc2b7889af | 88 | /** |
maygup01 | 0:11cc2b7889af | 89 | * \brief Creates a new object instance for a given mbed Client Interface object. With this, |
maygup01 | 0:11cc2b7889af | 90 | * the client can respond to server's GET methods with the provided value. |
maygup01 | 0:11cc2b7889af | 91 | * \return M2MObjectInstance. An object instance for managing other client operations. |
maygup01 | 0:11cc2b7889af | 92 | */ |
maygup01 | 0:11cc2b7889af | 93 | M2MObjectInstance* create_object_instance(const lwm2m_parameters_s* s); |
maygup01 | 0:11cc2b7889af | 94 | |
maygup01 | 0:11cc2b7889af | 95 | /** |
maygup01 | 0:11cc2b7889af | 96 | * \brief Removes the object instance resource with the given instance id. |
maygup01 | 0:11cc2b7889af | 97 | * \param instance_id The instance ID of the object instance to be removed, default is 0. |
maygup01 | 0:11cc2b7889af | 98 | * \return True if removed, else false. |
maygup01 | 0:11cc2b7889af | 99 | */ |
maygup01 | 0:11cc2b7889af | 100 | bool remove_object_instance(uint16_t instance_id = 0); |
maygup01 | 0:11cc2b7889af | 101 | |
maygup01 | 0:11cc2b7889af | 102 | /** |
maygup01 | 0:11cc2b7889af | 103 | * \brief Returns the object instance with the the given instance ID. |
maygup01 | 0:11cc2b7889af | 104 | * \param instance_id The instance ID of the requested object instance ID, default is 0. |
maygup01 | 0:11cc2b7889af | 105 | * \return Object instance reference if found, else NULL. |
maygup01 | 0:11cc2b7889af | 106 | */ |
maygup01 | 0:11cc2b7889af | 107 | M2MObjectInstance* object_instance(uint16_t instance_id = 0) const; |
maygup01 | 0:11cc2b7889af | 108 | |
maygup01 | 0:11cc2b7889af | 109 | /** |
maygup01 | 0:11cc2b7889af | 110 | * \brief Returns a list of object instances. |
maygup01 | 0:11cc2b7889af | 111 | * \return A list of object instances. |
maygup01 | 0:11cc2b7889af | 112 | */ |
maygup01 | 0:11cc2b7889af | 113 | const M2MObjectInstanceList& instances() const; |
maygup01 | 0:11cc2b7889af | 114 | |
maygup01 | 0:11cc2b7889af | 115 | /** |
maygup01 | 0:11cc2b7889af | 116 | * \brief Returns the total number of object instances- |
maygup01 | 0:11cc2b7889af | 117 | * \return The total number of the object instances. |
maygup01 | 0:11cc2b7889af | 118 | */ |
maygup01 | 0:11cc2b7889af | 119 | uint16_t instance_count() const; |
maygup01 | 0:11cc2b7889af | 120 | |
maygup01 | 0:11cc2b7889af | 121 | /** |
maygup01 | 0:11cc2b7889af | 122 | * \brief Returns the Observation Handler object. |
maygup01 | 0:11cc2b7889af | 123 | * \return M2MObservationHandler object. |
maygup01 | 0:11cc2b7889af | 124 | */ |
maygup01 | 0:11cc2b7889af | 125 | virtual M2MObservationHandler* observation_handler() const; |
maygup01 | 0:11cc2b7889af | 126 | |
maygup01 | 0:11cc2b7889af | 127 | /** |
maygup01 | 0:11cc2b7889af | 128 | * \brief Sets the observation handler |
maygup01 | 0:11cc2b7889af | 129 | * \param handler Observation handler |
maygup01 | 0:11cc2b7889af | 130 | */ |
maygup01 | 0:11cc2b7889af | 131 | virtual void set_observation_handler(M2MObservationHandler *handler); |
maygup01 | 0:11cc2b7889af | 132 | |
maygup01 | 0:11cc2b7889af | 133 | /** |
maygup01 | 0:11cc2b7889af | 134 | * \brief Adds the observation level for the object. |
maygup01 | 0:11cc2b7889af | 135 | * \param observation_level The level of observation. |
maygup01 | 0:11cc2b7889af | 136 | */ |
maygup01 | 0:11cc2b7889af | 137 | virtual void add_observation_level(M2MBase::Observation observation_level); |
maygup01 | 0:11cc2b7889af | 138 | |
maygup01 | 0:11cc2b7889af | 139 | /** |
maygup01 | 0:11cc2b7889af | 140 | * \brief Removes the observation level from the object. |
maygup01 | 0:11cc2b7889af | 141 | * \param observation_level The level of observation. |
maygup01 | 0:11cc2b7889af | 142 | */ |
maygup01 | 0:11cc2b7889af | 143 | virtual void remove_observation_level(M2MBase::Observation observation_level); |
maygup01 | 0:11cc2b7889af | 144 | |
maygup01 | 0:11cc2b7889af | 145 | /** |
maygup01 | 0:11cc2b7889af | 146 | * \brief Handles GET request for the registered objects. |
maygup01 | 0:11cc2b7889af | 147 | * \param nsdl The NSDL handler for the CoAP library. |
maygup01 | 0:11cc2b7889af | 148 | * \param received_coap_header The CoAP message received from the server. |
maygup01 | 0:11cc2b7889af | 149 | * \param observation_handler The handler object for sending |
maygup01 | 0:11cc2b7889af | 150 | * observation callbacks. |
maygup01 | 0:11cc2b7889af | 151 | * \return sn_coap_hdr_s The message that needs to be sent to server. |
maygup01 | 0:11cc2b7889af | 152 | */ |
maygup01 | 0:11cc2b7889af | 153 | virtual sn_coap_hdr_s* handle_get_request(nsdl_s *nsdl, |
maygup01 | 0:11cc2b7889af | 154 | sn_coap_hdr_s *received_coap_header, |
maygup01 | 0:11cc2b7889af | 155 | M2MObservationHandler *observation_handler = NULL); |
maygup01 | 0:11cc2b7889af | 156 | |
maygup01 | 0:11cc2b7889af | 157 | /** |
maygup01 | 0:11cc2b7889af | 158 | * \brief Handles PUT request for the registered objects. |
maygup01 | 0:11cc2b7889af | 159 | * \param nsdl The NSDL handler for the CoAP library. |
maygup01 | 0:11cc2b7889af | 160 | * \param received_coap_header The received CoAP message from the server. |
maygup01 | 0:11cc2b7889af | 161 | * \param observation_handler The handler object for sending |
maygup01 | 0:11cc2b7889af | 162 | * observation callbacks. |
maygup01 | 0:11cc2b7889af | 163 | * \param execute_value_updated True will execute the "value_updated" callback. |
maygup01 | 0:11cc2b7889af | 164 | * \return sn_coap_hdr_s The message that needs to be sent to server. |
maygup01 | 0:11cc2b7889af | 165 | */ |
maygup01 | 0:11cc2b7889af | 166 | virtual sn_coap_hdr_s* handle_put_request(nsdl_s *nsdl, |
maygup01 | 0:11cc2b7889af | 167 | sn_coap_hdr_s *received_coap_header, |
maygup01 | 0:11cc2b7889af | 168 | M2MObservationHandler *observation_handler, |
maygup01 | 0:11cc2b7889af | 169 | bool &execute_value_updated); |
maygup01 | 0:11cc2b7889af | 170 | |
maygup01 | 0:11cc2b7889af | 171 | /** |
maygup01 | 0:11cc2b7889af | 172 | * \brief Handles GET request for the registered objects. |
maygup01 | 0:11cc2b7889af | 173 | * \param nsdl The NSDL handler for the CoAP library. |
maygup01 | 0:11cc2b7889af | 174 | * \param received_coap_header The received CoAP message from the server. |
maygup01 | 0:11cc2b7889af | 175 | * \param observation_handler The handler object for sending |
maygup01 | 0:11cc2b7889af | 176 | * observation callbacks. |
maygup01 | 0:11cc2b7889af | 177 | * \param execute_value_updated True will execute the "value_updated" callback. |
maygup01 | 0:11cc2b7889af | 178 | * \return sn_coap_hdr_s The message that needs to be sent to server. |
maygup01 | 0:11cc2b7889af | 179 | */ |
maygup01 | 0:11cc2b7889af | 180 | virtual sn_coap_hdr_s* handle_post_request(nsdl_s *nsdl, |
maygup01 | 0:11cc2b7889af | 181 | sn_coap_hdr_s *received_coap_header, |
maygup01 | 0:11cc2b7889af | 182 | M2MObservationHandler *observation_handler, |
maygup01 | 0:11cc2b7889af | 183 | bool &execute_value_updated, |
maygup01 | 0:11cc2b7889af | 184 | sn_nsdl_addr_s *address = NULL); |
maygup01 | 0:11cc2b7889af | 185 | |
maygup01 | 0:11cc2b7889af | 186 | void notification_update(uint16_t obj_instance_id); |
maygup01 | 0:11cc2b7889af | 187 | |
maygup01 | 0:11cc2b7889af | 188 | #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION |
maygup01 | 0:11cc2b7889af | 189 | void set_endpoint(M2MEndpoint *endpoint); |
maygup01 | 0:11cc2b7889af | 190 | |
maygup01 | 0:11cc2b7889af | 191 | M2MEndpoint* get_endpoint() const; |
maygup01 | 0:11cc2b7889af | 192 | #endif |
maygup01 | 0:11cc2b7889af | 193 | |
maygup01 | 0:11cc2b7889af | 194 | protected : |
maygup01 | 0:11cc2b7889af | 195 | /** |
maygup01 | 0:11cc2b7889af | 196 | * \brief Returns the owner object. Can return NULL if the object has no parent. |
maygup01 | 0:11cc2b7889af | 197 | */ |
maygup01 | 0:11cc2b7889af | 198 | virtual M2MBase *get_parent() const; |
maygup01 | 0:11cc2b7889af | 199 | |
maygup01 | 0:11cc2b7889af | 200 | private: |
maygup01 | 0:11cc2b7889af | 201 | |
maygup01 | 0:11cc2b7889af | 202 | M2MObjectInstanceList _instance_list; // owned |
maygup01 | 0:11cc2b7889af | 203 | |
maygup01 | 0:11cc2b7889af | 204 | M2MObservationHandler *_observation_handler; // Not owned |
maygup01 | 0:11cc2b7889af | 205 | |
maygup01 | 0:11cc2b7889af | 206 | #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION |
maygup01 | 0:11cc2b7889af | 207 | M2MEndpoint *_endpoint; // Parent endpoint |
maygup01 | 0:11cc2b7889af | 208 | #endif |
maygup01 | 0:11cc2b7889af | 209 | |
maygup01 | 0:11cc2b7889af | 210 | friend class Test_M2MObject; |
maygup01 | 0:11cc2b7889af | 211 | friend class Test_M2MEndpoint; |
maygup01 | 0:11cc2b7889af | 212 | friend class Test_M2MInterfaceImpl; |
maygup01 | 0:11cc2b7889af | 213 | friend class Test_M2MNsdlInterface; |
maygup01 | 0:11cc2b7889af | 214 | friend class Test_M2MTLVSerializer; |
maygup01 | 0:11cc2b7889af | 215 | friend class Test_M2MTLVDeserializer; |
maygup01 | 0:11cc2b7889af | 216 | friend class Test_M2MDevice; |
maygup01 | 0:11cc2b7889af | 217 | friend class Test_M2MFirmware; |
maygup01 | 0:11cc2b7889af | 218 | friend class Test_M2MBase; |
maygup01 | 0:11cc2b7889af | 219 | friend class Test_M2MObjectInstance; |
maygup01 | 0:11cc2b7889af | 220 | friend class Test_M2MResource; |
maygup01 | 0:11cc2b7889af | 221 | friend class Test_M2MSecurity; |
maygup01 | 0:11cc2b7889af | 222 | friend class Test_M2MServer; |
maygup01 | 0:11cc2b7889af | 223 | friend class Test_M2MResourceInstance; |
maygup01 | 0:11cc2b7889af | 224 | }; |
maygup01 | 0:11cc2b7889af | 225 | |
maygup01 | 0:11cc2b7889af | 226 | #endif // M2M_OBJECT_H |