joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

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::operator=(const M2MResourceInstance&)
00039 {
00040     return *this;
00041 }
00042 
00043 M2MResourceInstance::M2MResourceInstance(const M2MResourceInstance& other)
00044 : M2MBase(other),
00045   _object_instance_callback(other._object_instance_callback)/*,
00046   _object_instance_id(other._object_instance_id),
00047   _object_name(other._object_name)*/
00048 {
00049     this->operator=(other);
00050 }
00051 
00052 M2MResourceInstance::M2MResourceInstance(const String &res_name,
00053                                          const String &,
00054                                          M2MResourceInstance::ResourceType,
00055                                          M2MObjectInstanceCallback &object_instance_callback,
00056                                          const uint16_t /*object_instance_id*/,
00057                                          const String &/*object_name*/)
00058 : M2MBase(res_name,
00059           M2MBase::Dynamic),
00060   _object_instance_callback(object_instance_callback)/*,
00061 _object_instance_id(object_instance_id),
00062 _object_name(object_name)*/
00063 {
00064     m2mresourceinstance_stub::base_type = M2MBase::ResourceInstance;
00065 }
00066 
00067 M2MResourceInstance::M2MResourceInstance(const String &res_name,
00068                                          const String &,
00069                                          M2MResourceInstance::ResourceType,
00070                                          const uint8_t *,
00071                                          const uint8_t,
00072                                          M2MObjectInstanceCallback &object_instance_callback,
00073                                          const uint16_t/* object_instance_id*/,
00074                                          const String &/*object_name*/)
00075 : M2MBase(res_name,
00076           M2MBase::Static),
00077 _object_instance_callback(object_instance_callback)/*,
00078   _object_instance_id(object_instance_id),
00079   _object_name(object_name)*/
00080 {
00081 }
00082 
00083 M2MResourceInstance::~M2MResourceInstance()
00084 {
00085 }
00086 
00087 M2MBase::BaseType M2MResourceInstance::base_type() const
00088 {
00089     return m2mresourceinstance_stub::base_type;
00090 }
00091 
00092 M2MResourceInstance::ResourceType M2MResourceInstance::resource_instance_type() const
00093 {
00094     return m2mresourceinstance_stub::resource_type;
00095 }
00096 
00097 bool M2MResourceInstance::handle_observation_attribute(char *&)
00098 {
00099     return m2mresourceinstance_stub::bool_value;
00100 }
00101 
00102 void M2MResourceInstance::set_execute_function(execute_callback )
00103 {
00104 }
00105 
00106 bool M2MResourceInstance::set_value(const uint8_t *,
00107                                     const uint32_t )
00108 {
00109     return m2mresourceinstance_stub::bool_value;
00110 }
00111 
00112 bool M2MResourceInstance::set_value(int64_t value)
00113 {
00114     return m2mresourceinstance_stub::bool_value;
00115 }
00116 
00117 
00118 void M2MResourceInstance::clear_value()
00119 {
00120     if (m2mresourceinstance_stub::value) {
00121         free(m2mresourceinstance_stub::value);
00122         m2mresourceinstance_stub::value = NULL;
00123         m2mresourceinstance_stub::int_value = 0;
00124     }
00125 }
00126 
00127 void M2MResourceInstance::execute(void *)
00128 {
00129 }
00130 
00131 void M2MResourceInstance::get_value(uint8_t *&value, uint32_t &value_length)
00132 {
00133     value_length = 0;
00134     if(value) {
00135         free(value);
00136         value = NULL;
00137     }
00138     value = (uint8_t *)malloc(m2mresourceinstance_stub::int_value);
00139     if(value) {
00140         value_length = m2mresourceinstance_stub::int_value;
00141         memcpy((uint8_t *)value, (uint8_t *)m2mresourceinstance_stub::value, value_length);
00142     }
00143 }
00144 
00145 int M2MResourceInstance::get_value_int()
00146 {
00147     // Note: this is a copy-paste from the original version, as the tests
00148     // set only m2mresourceinstance_stub::value.
00149 
00150     int value_int = 0;
00151     // Get the value and convert it into integer. This is not the most
00152     // efficient way, as it takes pointless heap copy to get the zero termination.
00153     uint8_t* buffer = NULL;
00154     uint32_t length;
00155     get_value(buffer,length);
00156     if(buffer) {
00157         value_int = atoi((const char*)buffer);
00158         free(buffer);
00159     }
00160     return value_int;
00161 }
00162 
00163 String M2MResourceInstance::get_value_string() const
00164 {
00165     // XXX: do a better constructor to avoid pointless malloc
00166     String value;
00167     if (m2mresourceinstance_stub::value) {
00168         value.append_raw((char*)m2mresourceinstance_stub::value, m2mresourceinstance_stub::int_value);
00169     }
00170 
00171     return value;
00172 }
00173 
00174 uint8_t* M2MResourceInstance::value() const
00175 {
00176     return m2mresourceinstance_stub::value;
00177 }
00178 
00179 uint32_t M2MResourceInstance::value_length() const
00180 {
00181     return m2mresourceinstance_stub::int_value;
00182 }
00183 
00184 sn_coap_hdr_s* M2MResourceInstance::handle_get_request(nsdl_s *,
00185                                                sn_coap_hdr_s *,
00186                                                M2MObservationHandler *)
00187 {
00188     return m2mresourceinstance_stub::header;
00189 }
00190 
00191 sn_coap_hdr_s* M2MResourceInstance::handle_put_request(nsdl_s *,
00192                                                sn_coap_hdr_s *,
00193                                                M2MObservationHandler *,
00194                                                bool &)
00195 {
00196     return m2mresourceinstance_stub::header;
00197 }
00198 
00199 void M2MResourceInstance::set_resource_observer(M2MResourceCallback *callback)
00200 {
00201 
00202 }
00203 const String& M2MResourceInstance::object_name() const
00204 {
00205     return *m2mresourceinstance_stub::string_value;
00206 }
00207 
00208 uint16_t M2MResourceInstance::object_instance_id() const
00209 {
00210     return m2mresourceinstance_stub::int_value;
00211 }
00212 
00213 void M2MResourceInstance::set_execute_function(execute_callback_2 callback)
00214 {
00215 }