Ram Gandikota / Mbed OS ABCD
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mresourceinstance_stub.cpp Source File

m2mresourceinstance_stub.cpp

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 #include "m2mresourceinstance_stub.h"
00017 
00018 uint32_t m2mresourceinstance_stub::int_value;
00019 bool m2mresourceinstance_stub::bool_value;
00020 String *m2mresourceinstance_stub::string_value;
00021 M2MResourceInstance::ResourceType m2mresourceinstance_stub::resource_type;
00022 sn_coap_hdr_s *m2mresourceinstance_stub::header;
00023 uint8_t* m2mresourceinstance_stub::value;
00024 M2MBase::BaseType m2mresourceinstance_stub::base_type;
00025 
00026 
00027 void m2mresourceinstance_stub::clear()
00028 {
00029     int_value = 0;
00030     bool_value = false;
00031     resource_type = M2MResourceInstance::STRING;
00032     header = NULL;
00033     value = NULL;
00034     base_type = M2MBase::ResourceInstance;
00035     string_value = NULL;
00036 }
00037 
00038 M2MResourceInstance::M2MResourceInstance(M2MResource &parent,
00039                                          const String &res_name,
00040                                          const String &resource_type,
00041                                          M2MResourceInstance::ResourceType type,
00042                                          const uint16_t object_instance_id,
00043                                          char* path,
00044                                          bool external_blockwise_store)
00045 : M2MBase(res_name,
00046           M2MBase::Dynamic,
00047           resource_type,
00048           path,
00049           external_blockwise_store),
00050  _parent_resource(parent),
00051  _value(NULL),
00052  _value_length(0),
00053  _block_message_data(NULL),
00054  _execute_callback(NULL),
00055  _resource_callback(NULL),
00056  _execute_function_pointer(NULL),
00057  _notification_sent_function_pointer(NULL),
00058  _notification_sent_callback(NULL),
00059  _object_instance_id(object_instance_id),
00060  _resource_type(type)
00061 {
00062 
00063 }
00064 
00065 M2MResourceInstance::M2MResourceInstance(M2MResource &parent,
00066                                          const String &res_name,
00067                                          const String &resource_type,
00068                                          M2MResourceInstance::ResourceType type,
00069                                          const uint8_t *value,
00070                                          const uint8_t value_length,
00071                                          const uint16_t object_instance_id,
00072                                          char* path,
00073                                          bool external_blockwise_store)
00074 : M2MBase(res_name,
00075           M2MBase::Static,
00076           resource_type,
00077           path,
00078           external_blockwise_store),
00079  _parent_resource(parent),
00080  _value(NULL),
00081  _value_length(0),
00082  _block_message_data(NULL),
00083  _execute_callback(NULL),
00084  _resource_callback(NULL),
00085  _execute_function_pointer(NULL),
00086  _notification_sent_function_pointer(NULL),
00087  _notification_sent_callback(NULL),
00088  _object_instance_id(object_instance_id),
00089   _resource_type(type)
00090 {
00091 }
00092 
00093 M2MResourceInstance::M2MResourceInstance(M2MResource &parent,
00094                                          const lwm2m_parameters_s* s,
00095                                          M2MResourceInstance::ResourceType type,
00096                                          const uint16_t object_instance_id)
00097 : M2MBase(s),
00098   _parent_resource(parent),
00099   _value(NULL),
00100   _value_length(0),
00101   _block_message_data(NULL),
00102   _execute_callback(NULL),
00103   _resource_callback(NULL),
00104   _execute_function_pointer(NULL),
00105   _notification_sent_function_pointer(NULL),
00106   _object_instance_id(object_instance_id),
00107   _resource_type(type)
00108 {
00109 }
00110 
00111 M2MResourceInstance::~M2MResourceInstance()
00112 {
00113 }
00114 
00115 M2MBase::BaseType M2MResourceInstance::base_type() const
00116 {
00117     return m2mresourceinstance_stub::base_type;
00118 }
00119 
00120 M2MResourceInstance::ResourceType M2MResourceInstance::resource_instance_type() const
00121 {
00122     return m2mresourceinstance_stub::resource_type;
00123 }
00124 
00125 bool M2MResourceInstance::handle_observation_attribute(const char *)
00126 {
00127     return m2mresourceinstance_stub::bool_value;
00128 }
00129 
00130 void M2MResourceInstance::set_execute_function(execute_callback )
00131 {
00132 }
00133 
00134 bool M2MResourceInstance::set_value(const uint8_t *,
00135                                     const uint32_t )
00136 {
00137     return m2mresourceinstance_stub::bool_value;
00138 }
00139 
00140 bool M2MResourceInstance::set_value(int64_t value)
00141 {
00142     return m2mresourceinstance_stub::bool_value;
00143 }
00144 
00145 
00146 void M2MResourceInstance::clear_value()
00147 {
00148     if (m2mresourceinstance_stub::value) {
00149         free(m2mresourceinstance_stub::value);
00150         m2mresourceinstance_stub::value = NULL;
00151         m2mresourceinstance_stub::int_value = 0;
00152     }
00153 }
00154 
00155 void M2MResourceInstance::execute(void *)
00156 {
00157 }
00158 
00159 void M2MResourceInstance::get_value(uint8_t *&value, uint32_t &value_length)
00160 {
00161     value_length = 0;
00162     if(value) {
00163         free(value);
00164         value = NULL;
00165     }
00166     value = (uint8_t *)malloc(m2mresourceinstance_stub::int_value);
00167     if(value) {
00168         value_length = m2mresourceinstance_stub::int_value;
00169         memcpy((uint8_t *)value, (uint8_t *)m2mresourceinstance_stub::value, value_length);
00170     }
00171 }
00172 
00173 int M2MResourceInstance::get_value_int()
00174 {
00175     // Note: this is a copy-paste from the original version, as the tests
00176     // set only m2mresourceinstance_stub::value.
00177 
00178     int value_int = 0;
00179     // Get the value and convert it into integer. This is not the most
00180     // efficient way, as it takes pointless heap copy to get the zero termination.
00181     uint8_t* buffer = NULL;
00182     uint32_t length;
00183     get_value(buffer,length);
00184     if(buffer) {
00185         value_int = atoi((const char*)buffer);
00186         free(buffer);
00187     }
00188     return value_int;
00189 }
00190 
00191 String M2MResourceInstance::get_value_string() const
00192 {
00193     // XXX: do a better constructor to avoid pointless malloc
00194     String value;
00195     if (m2mresourceinstance_stub::value) {
00196         value.append_raw((char*)m2mresourceinstance_stub::value, m2mresourceinstance_stub::int_value);
00197     }
00198 
00199     return value;
00200 }
00201 
00202 uint8_t* M2MResourceInstance::value() const
00203 {
00204     return m2mresourceinstance_stub::value;
00205 }
00206 
00207 uint32_t M2MResourceInstance::value_length() const
00208 {
00209     return m2mresourceinstance_stub::int_value;
00210 }
00211 
00212 sn_coap_hdr_s* M2MResourceInstance::handle_get_request(nsdl_s *,
00213                                                sn_coap_hdr_s *,
00214                                                M2MObservationHandler *)
00215 {
00216     return m2mresourceinstance_stub::header;
00217 }
00218 
00219 sn_coap_hdr_s* M2MResourceInstance::handle_put_request(nsdl_s *,
00220                                                sn_coap_hdr_s *,
00221                                                M2MObservationHandler *,
00222                                                bool &)
00223 {
00224     return m2mresourceinstance_stub::header;
00225 }
00226 
00227 void M2MResourceInstance::set_resource_observer(M2MResourceCallback *callback)
00228 {
00229 
00230 }
00231 
00232 uint16_t M2MResourceInstance::object_instance_id() const
00233 {
00234     return m2mresourceinstance_stub::int_value;
00235 }
00236 
00237 void M2MResourceInstance::set_execute_function(execute_callback_2 callback)
00238 {
00239 }
00240 
00241 M2MBlockMessage* M2MResourceInstance::block_message() const
00242 {
00243 
00244 }
00245 
00246 void M2MResourceInstance::set_incoming_block_message_callback(incoming_block_message_callback callback)
00247 {
00248 }
00249 
00250 void M2MResourceInstance::set_outgoing_block_message_callback(outgoing_block_message_callback callback)
00251 {
00252 
00253 }
00254 
00255 void M2MResourceInstance::set_notification_sent_callback(notification_sent_callback callback)
00256 {
00257 }
00258 
00259 void M2MResourceInstance::set_notification_sent_callback(notification_sent_callback_2 callback)
00260 {
00261 }
00262 
00263 void M2MResourceInstance::notification_sent()
00264 {
00265 }
00266 
00267 const char* M2MResourceInstance::object_name() const
00268 {
00269 
00270 }