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

« Back to documentation index

Show/hide line numbers m2mresource_stub.cpp Source File

m2mresource_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 "m2mresource_stub.h"
00017 
00018 uint32_t m2mresource_stub::int_value;
00019 uint8_t* m2mresource_stub::delayed_token;
00020 uint8_t m2mresource_stub::delayed_token_len;
00021 bool m2mresource_stub::bool_value;
00022 // The statically initialized list must be bigh enough to cater
00023 // for all the tests, or the utest framework will complain for memory leak.
00024 M2MResourceInstanceList m2mresource_stub::list(12);
00025 
00026 M2MResourceInstance *m2mresource_stub::instance;
00027 M2MObjectInstance *m2mresource_stub::object_instance;
00028 sn_coap_hdr_s *m2mresource_stub::header;
00029 void m2mresource_stub::clear()
00030 {
00031     int_value = 0;
00032     delayed_token = NULL;
00033     delayed_token_len = 0;
00034     bool_value = false;
00035     list.clear();
00036     instance = NULL;
00037     object_instance = NULL;
00038 }
00039 
00040 M2MResource::M2MResource(M2MObjectInstance &parent,
00041                          const String &resource_name,
00042                          const String &resource_type,
00043                          M2MResourceInstance::ResourceType type,
00044                          const uint8_t *value,
00045                          const uint8_t value_length,
00046                          char* path,
00047                          const uint16_t object_instance_id,
00048                          bool multiple_instance,
00049                          bool external_blockwise_store)
00050 : M2MResourceInstance(*this, resource_name, resource_type, type, value, value_length, object_instance_id,
00051                       path, external_blockwise_store),
00052   _parent(parent),
00053   _delayed_token(NULL),
00054   _delayed_token_len(0),
00055   _has_multiple_instances(multiple_instance),
00056   _delayed_response(false)
00057 {
00058 
00059 }
00060 
00061 M2MResource::M2MResource(M2MObjectInstance &parent,
00062                          const lwm2m_parameters_s* s,
00063                           M2MResourceInstance::ResourceType type,
00064                          const uint16_t object_instance_id)
00065 : M2MResourceInstance(*this, s, type, object_instance_id),
00066   _parent(parent),
00067   _delayed_token(NULL),
00068   _delayed_token_len(0),
00069   _has_multiple_instances(false),
00070   _delayed_response(false)
00071 {
00072     // tbd: _has_multiple_instances could be in flash, but no real benefit, because of current alignment.
00073 }
00074 
00075 M2MResource::M2MResource(M2MObjectInstance &parent,
00076                          const String &resource_name,
00077                          const String &resource_type,
00078                          M2MResourceInstance::ResourceType type,
00079                          bool observable,
00080                          char *path,
00081                          const uint16_t object_instance_id,
00082                          bool multiple_instance,
00083                          bool external_blockwise_store)
00084 : M2MResourceInstance(*this, resource_name, resource_type, type,
00085                       object_instance_id, path, external_blockwise_store),
00086   _parent(parent),
00087   _delayed_token(NULL),
00088   _delayed_token_len(0),
00089   _has_multiple_instances(multiple_instance),
00090   _delayed_response(false)
00091 {
00092 
00093 }
00094 
00095 M2MResource::~M2MResource()
00096 {
00097 }
00098 
00099 bool M2MResource::supports_multiple_instances() const
00100 {
00101     return m2mresource_stub::bool_value;
00102 }
00103 
00104 void M2MResource::get_delayed_token(unsigned char *&token, unsigned char &token_len)
00105 {
00106     token_len = 0;
00107     if(token) {
00108         free(token);
00109         token = NULL;
00110     }
00111     token = (uint8_t *)malloc(m2mresource_stub::delayed_token_len);
00112     if(token) {
00113         token_len = m2mresource_stub::delayed_token_len;
00114         memcpy((uint8_t *)token, (uint8_t *)m2mresource_stub::delayed_token, token_len);
00115     }
00116 }
00117 
00118 bool M2MResource::remove_resource_instance(uint16_t inst_id)
00119 {
00120     return m2mresource_stub::bool_value;
00121 }
00122 
00123 M2MResourceInstance* M2MResource::resource_instance(uint16_t inst_id) const
00124 {
00125     return m2mresource_stub::instance;
00126 }
00127 
00128 const M2MResourceInstanceList& M2MResource::resource_instances() const
00129 {
00130     return m2mresource_stub::list;
00131 }
00132 
00133 uint16_t M2MResource::resource_instance_count() const
00134 {
00135     return m2mresource_stub::int_value;
00136 }
00137 
00138 bool M2MResource::handle_observation_attribute(const char *query)
00139 {
00140     return m2mresource_stub::bool_value;
00141 }
00142 
00143 void M2MResource::add_resource_instance(M2MResourceInstance *)
00144 {
00145 }
00146 
00147 void M2MResource::add_observation_level(M2MBase::Observation)
00148 {
00149 }
00150 
00151 void M2MResource::remove_observation_level(M2MBase::Observation)
00152 {
00153 }
00154 
00155 void M2MResource::notification_update()
00156 {
00157 }
00158 
00159 sn_coap_hdr_s* M2MResource::handle_get_request(nsdl_s *,
00160                                                sn_coap_hdr_s *,
00161                                                M2MObservationHandler *)
00162 {
00163     return m2mresource_stub::header;
00164 }
00165 
00166 sn_coap_hdr_s* M2MResource::handle_put_request(nsdl_s *,
00167                                                sn_coap_hdr_s *,
00168                                                M2MObservationHandler *,
00169                                                bool &)
00170 {
00171     return m2mresource_stub::header;
00172 }
00173 
00174 sn_coap_hdr_s* M2MResource::handle_post_request(nsdl_s *,
00175                                                sn_coap_hdr_s *,
00176                                                M2MObservationHandler *,
00177                                                bool &, sn_nsdl_addr_s *)
00178 {
00179     return m2mresource_stub::header;
00180 }
00181 
00182 M2MObjectInstance& M2MResource::get_parent_object_instance() const
00183 {
00184     return *m2mresource_stub::object_instance;
00185 }
00186 
00187 const char* M2MResource::object_name() const
00188 {
00189 
00190 }