Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
mbed-client/test/mbedclient/utest/stub/m2mresourceinstance_stub.cpp@0:a7a43371b306, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:40:18 2017 +0000
- Revision:
- 0:a7a43371b306
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a7a43371b306 | 1 | /* |
ram54288 | 0:a7a43371b306 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
ram54288 | 0:a7a43371b306 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a7a43371b306 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a7a43371b306 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a7a43371b306 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a7a43371b306 | 7 | * |
ram54288 | 0:a7a43371b306 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a7a43371b306 | 9 | * |
ram54288 | 0:a7a43371b306 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a7a43371b306 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a7a43371b306 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a7a43371b306 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a7a43371b306 | 14 | * limitations under the License. |
ram54288 | 0:a7a43371b306 | 15 | */ |
ram54288 | 0:a7a43371b306 | 16 | #include "m2mresourceinstance_stub.h" |
ram54288 | 0:a7a43371b306 | 17 | |
ram54288 | 0:a7a43371b306 | 18 | uint32_t m2mresourceinstance_stub::int_value; |
ram54288 | 0:a7a43371b306 | 19 | bool m2mresourceinstance_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 20 | String *m2mresourceinstance_stub::string_value; |
ram54288 | 0:a7a43371b306 | 21 | M2MResourceInstance::ResourceType m2mresourceinstance_stub::resource_type; |
ram54288 | 0:a7a43371b306 | 22 | sn_coap_hdr_s *m2mresourceinstance_stub::header; |
ram54288 | 0:a7a43371b306 | 23 | uint8_t* m2mresourceinstance_stub::value; |
ram54288 | 0:a7a43371b306 | 24 | M2MBase::BaseType m2mresourceinstance_stub::base_type; |
ram54288 | 0:a7a43371b306 | 25 | |
ram54288 | 0:a7a43371b306 | 26 | |
ram54288 | 0:a7a43371b306 | 27 | void m2mresourceinstance_stub::clear() |
ram54288 | 0:a7a43371b306 | 28 | { |
ram54288 | 0:a7a43371b306 | 29 | int_value = 0; |
ram54288 | 0:a7a43371b306 | 30 | bool_value = false; |
ram54288 | 0:a7a43371b306 | 31 | resource_type = M2MResourceInstance::STRING; |
ram54288 | 0:a7a43371b306 | 32 | header = NULL; |
ram54288 | 0:a7a43371b306 | 33 | value = NULL; |
ram54288 | 0:a7a43371b306 | 34 | base_type = M2MBase::ResourceInstance; |
ram54288 | 0:a7a43371b306 | 35 | string_value = NULL; |
ram54288 | 0:a7a43371b306 | 36 | } |
ram54288 | 0:a7a43371b306 | 37 | |
ram54288 | 0:a7a43371b306 | 38 | M2MResourceInstance::M2MResourceInstance(M2MResource &parent, |
ram54288 | 0:a7a43371b306 | 39 | const String &res_name, |
ram54288 | 0:a7a43371b306 | 40 | const String &resource_type, |
ram54288 | 0:a7a43371b306 | 41 | M2MResourceInstance::ResourceType type, |
ram54288 | 0:a7a43371b306 | 42 | const uint16_t object_instance_id, |
ram54288 | 0:a7a43371b306 | 43 | char* path, |
ram54288 | 0:a7a43371b306 | 44 | bool external_blockwise_store) |
ram54288 | 0:a7a43371b306 | 45 | : M2MBase(res_name, |
ram54288 | 0:a7a43371b306 | 46 | M2MBase::Dynamic, |
ram54288 | 0:a7a43371b306 | 47 | resource_type, |
ram54288 | 0:a7a43371b306 | 48 | path, |
ram54288 | 0:a7a43371b306 | 49 | external_blockwise_store), |
ram54288 | 0:a7a43371b306 | 50 | _parent_resource(parent), |
ram54288 | 0:a7a43371b306 | 51 | _value(NULL), |
ram54288 | 0:a7a43371b306 | 52 | _value_length(0), |
ram54288 | 0:a7a43371b306 | 53 | _block_message_data(NULL), |
ram54288 | 0:a7a43371b306 | 54 | _execute_callback(NULL), |
ram54288 | 0:a7a43371b306 | 55 | _resource_callback(NULL), |
ram54288 | 0:a7a43371b306 | 56 | _execute_function_pointer(NULL), |
ram54288 | 0:a7a43371b306 | 57 | _notification_sent_function_pointer(NULL), |
ram54288 | 0:a7a43371b306 | 58 | _notification_sent_callback(NULL), |
ram54288 | 0:a7a43371b306 | 59 | _object_instance_id(object_instance_id), |
ram54288 | 0:a7a43371b306 | 60 | _resource_type(type) |
ram54288 | 0:a7a43371b306 | 61 | { |
ram54288 | 0:a7a43371b306 | 62 | |
ram54288 | 0:a7a43371b306 | 63 | } |
ram54288 | 0:a7a43371b306 | 64 | |
ram54288 | 0:a7a43371b306 | 65 | M2MResourceInstance::M2MResourceInstance(M2MResource &parent, |
ram54288 | 0:a7a43371b306 | 66 | const String &res_name, |
ram54288 | 0:a7a43371b306 | 67 | const String &resource_type, |
ram54288 | 0:a7a43371b306 | 68 | M2MResourceInstance::ResourceType type, |
ram54288 | 0:a7a43371b306 | 69 | const uint8_t *value, |
ram54288 | 0:a7a43371b306 | 70 | const uint8_t value_length, |
ram54288 | 0:a7a43371b306 | 71 | const uint16_t object_instance_id, |
ram54288 | 0:a7a43371b306 | 72 | char* path, |
ram54288 | 0:a7a43371b306 | 73 | bool external_blockwise_store) |
ram54288 | 0:a7a43371b306 | 74 | : M2MBase(res_name, |
ram54288 | 0:a7a43371b306 | 75 | M2MBase::Static, |
ram54288 | 0:a7a43371b306 | 76 | resource_type, |
ram54288 | 0:a7a43371b306 | 77 | path, |
ram54288 | 0:a7a43371b306 | 78 | external_blockwise_store), |
ram54288 | 0:a7a43371b306 | 79 | _parent_resource(parent), |
ram54288 | 0:a7a43371b306 | 80 | _value(NULL), |
ram54288 | 0:a7a43371b306 | 81 | _value_length(0), |
ram54288 | 0:a7a43371b306 | 82 | _block_message_data(NULL), |
ram54288 | 0:a7a43371b306 | 83 | _execute_callback(NULL), |
ram54288 | 0:a7a43371b306 | 84 | _resource_callback(NULL), |
ram54288 | 0:a7a43371b306 | 85 | _execute_function_pointer(NULL), |
ram54288 | 0:a7a43371b306 | 86 | _notification_sent_function_pointer(NULL), |
ram54288 | 0:a7a43371b306 | 87 | _notification_sent_callback(NULL), |
ram54288 | 0:a7a43371b306 | 88 | _object_instance_id(object_instance_id), |
ram54288 | 0:a7a43371b306 | 89 | _resource_type(type) |
ram54288 | 0:a7a43371b306 | 90 | { |
ram54288 | 0:a7a43371b306 | 91 | } |
ram54288 | 0:a7a43371b306 | 92 | |
ram54288 | 0:a7a43371b306 | 93 | M2MResourceInstance::M2MResourceInstance(M2MResource &parent, |
ram54288 | 0:a7a43371b306 | 94 | const lwm2m_parameters_s* s, |
ram54288 | 0:a7a43371b306 | 95 | M2MResourceInstance::ResourceType type, |
ram54288 | 0:a7a43371b306 | 96 | const uint16_t object_instance_id) |
ram54288 | 0:a7a43371b306 | 97 | : M2MBase(s), |
ram54288 | 0:a7a43371b306 | 98 | _parent_resource(parent), |
ram54288 | 0:a7a43371b306 | 99 | _value(NULL), |
ram54288 | 0:a7a43371b306 | 100 | _value_length(0), |
ram54288 | 0:a7a43371b306 | 101 | _block_message_data(NULL), |
ram54288 | 0:a7a43371b306 | 102 | _execute_callback(NULL), |
ram54288 | 0:a7a43371b306 | 103 | _resource_callback(NULL), |
ram54288 | 0:a7a43371b306 | 104 | _execute_function_pointer(NULL), |
ram54288 | 0:a7a43371b306 | 105 | _notification_sent_function_pointer(NULL), |
ram54288 | 0:a7a43371b306 | 106 | _object_instance_id(object_instance_id), |
ram54288 | 0:a7a43371b306 | 107 | _resource_type(type) |
ram54288 | 0:a7a43371b306 | 108 | { |
ram54288 | 0:a7a43371b306 | 109 | } |
ram54288 | 0:a7a43371b306 | 110 | |
ram54288 | 0:a7a43371b306 | 111 | M2MResourceInstance::~M2MResourceInstance() |
ram54288 | 0:a7a43371b306 | 112 | { |
ram54288 | 0:a7a43371b306 | 113 | } |
ram54288 | 0:a7a43371b306 | 114 | |
ram54288 | 0:a7a43371b306 | 115 | M2MBase::BaseType M2MResourceInstance::base_type() const |
ram54288 | 0:a7a43371b306 | 116 | { |
ram54288 | 0:a7a43371b306 | 117 | return m2mresourceinstance_stub::base_type; |
ram54288 | 0:a7a43371b306 | 118 | } |
ram54288 | 0:a7a43371b306 | 119 | |
ram54288 | 0:a7a43371b306 | 120 | M2MResourceInstance::ResourceType M2MResourceInstance::resource_instance_type() const |
ram54288 | 0:a7a43371b306 | 121 | { |
ram54288 | 0:a7a43371b306 | 122 | return m2mresourceinstance_stub::resource_type; |
ram54288 | 0:a7a43371b306 | 123 | } |
ram54288 | 0:a7a43371b306 | 124 | |
ram54288 | 0:a7a43371b306 | 125 | bool M2MResourceInstance::handle_observation_attribute(const char *) |
ram54288 | 0:a7a43371b306 | 126 | { |
ram54288 | 0:a7a43371b306 | 127 | return m2mresourceinstance_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 128 | } |
ram54288 | 0:a7a43371b306 | 129 | |
ram54288 | 0:a7a43371b306 | 130 | void M2MResourceInstance::set_execute_function(execute_callback) |
ram54288 | 0:a7a43371b306 | 131 | { |
ram54288 | 0:a7a43371b306 | 132 | } |
ram54288 | 0:a7a43371b306 | 133 | |
ram54288 | 0:a7a43371b306 | 134 | bool M2MResourceInstance::set_value(const uint8_t *, |
ram54288 | 0:a7a43371b306 | 135 | const uint32_t ) |
ram54288 | 0:a7a43371b306 | 136 | { |
ram54288 | 0:a7a43371b306 | 137 | return m2mresourceinstance_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 138 | } |
ram54288 | 0:a7a43371b306 | 139 | |
ram54288 | 0:a7a43371b306 | 140 | bool M2MResourceInstance::set_value(int64_t value) |
ram54288 | 0:a7a43371b306 | 141 | { |
ram54288 | 0:a7a43371b306 | 142 | return m2mresourceinstance_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 143 | } |
ram54288 | 0:a7a43371b306 | 144 | |
ram54288 | 0:a7a43371b306 | 145 | |
ram54288 | 0:a7a43371b306 | 146 | void M2MResourceInstance::clear_value() |
ram54288 | 0:a7a43371b306 | 147 | { |
ram54288 | 0:a7a43371b306 | 148 | if (m2mresourceinstance_stub::value) { |
ram54288 | 0:a7a43371b306 | 149 | free(m2mresourceinstance_stub::value); |
ram54288 | 0:a7a43371b306 | 150 | m2mresourceinstance_stub::value = NULL; |
ram54288 | 0:a7a43371b306 | 151 | m2mresourceinstance_stub::int_value = 0; |
ram54288 | 0:a7a43371b306 | 152 | } |
ram54288 | 0:a7a43371b306 | 153 | } |
ram54288 | 0:a7a43371b306 | 154 | |
ram54288 | 0:a7a43371b306 | 155 | void M2MResourceInstance::execute(void *) |
ram54288 | 0:a7a43371b306 | 156 | { |
ram54288 | 0:a7a43371b306 | 157 | } |
ram54288 | 0:a7a43371b306 | 158 | |
ram54288 | 0:a7a43371b306 | 159 | void M2MResourceInstance::get_value(uint8_t *&value, uint32_t &value_length) |
ram54288 | 0:a7a43371b306 | 160 | { |
ram54288 | 0:a7a43371b306 | 161 | value_length = 0; |
ram54288 | 0:a7a43371b306 | 162 | if(value) { |
ram54288 | 0:a7a43371b306 | 163 | free(value); |
ram54288 | 0:a7a43371b306 | 164 | value = NULL; |
ram54288 | 0:a7a43371b306 | 165 | } |
ram54288 | 0:a7a43371b306 | 166 | value = (uint8_t *)malloc(m2mresourceinstance_stub::int_value); |
ram54288 | 0:a7a43371b306 | 167 | if(value) { |
ram54288 | 0:a7a43371b306 | 168 | value_length = m2mresourceinstance_stub::int_value; |
ram54288 | 0:a7a43371b306 | 169 | memcpy((uint8_t *)value, (uint8_t *)m2mresourceinstance_stub::value, value_length); |
ram54288 | 0:a7a43371b306 | 170 | } |
ram54288 | 0:a7a43371b306 | 171 | } |
ram54288 | 0:a7a43371b306 | 172 | |
ram54288 | 0:a7a43371b306 | 173 | int M2MResourceInstance::get_value_int() |
ram54288 | 0:a7a43371b306 | 174 | { |
ram54288 | 0:a7a43371b306 | 175 | // Note: this is a copy-paste from the original version, as the tests |
ram54288 | 0:a7a43371b306 | 176 | // set only m2mresourceinstance_stub::value. |
ram54288 | 0:a7a43371b306 | 177 | |
ram54288 | 0:a7a43371b306 | 178 | int value_int = 0; |
ram54288 | 0:a7a43371b306 | 179 | // Get the value and convert it into integer. This is not the most |
ram54288 | 0:a7a43371b306 | 180 | // efficient way, as it takes pointless heap copy to get the zero termination. |
ram54288 | 0:a7a43371b306 | 181 | uint8_t* buffer = NULL; |
ram54288 | 0:a7a43371b306 | 182 | uint32_t length; |
ram54288 | 0:a7a43371b306 | 183 | get_value(buffer,length); |
ram54288 | 0:a7a43371b306 | 184 | if(buffer) { |
ram54288 | 0:a7a43371b306 | 185 | value_int = atoi((const char*)buffer); |
ram54288 | 0:a7a43371b306 | 186 | free(buffer); |
ram54288 | 0:a7a43371b306 | 187 | } |
ram54288 | 0:a7a43371b306 | 188 | return value_int; |
ram54288 | 0:a7a43371b306 | 189 | } |
ram54288 | 0:a7a43371b306 | 190 | |
ram54288 | 0:a7a43371b306 | 191 | String M2MResourceInstance::get_value_string() const |
ram54288 | 0:a7a43371b306 | 192 | { |
ram54288 | 0:a7a43371b306 | 193 | // XXX: do a better constructor to avoid pointless malloc |
ram54288 | 0:a7a43371b306 | 194 | String value; |
ram54288 | 0:a7a43371b306 | 195 | if (m2mresourceinstance_stub::value) { |
ram54288 | 0:a7a43371b306 | 196 | value.append_raw((char*)m2mresourceinstance_stub::value, m2mresourceinstance_stub::int_value); |
ram54288 | 0:a7a43371b306 | 197 | } |
ram54288 | 0:a7a43371b306 | 198 | |
ram54288 | 0:a7a43371b306 | 199 | return value; |
ram54288 | 0:a7a43371b306 | 200 | } |
ram54288 | 0:a7a43371b306 | 201 | |
ram54288 | 0:a7a43371b306 | 202 | uint8_t* M2MResourceInstance::value() const |
ram54288 | 0:a7a43371b306 | 203 | { |
ram54288 | 0:a7a43371b306 | 204 | return m2mresourceinstance_stub::value; |
ram54288 | 0:a7a43371b306 | 205 | } |
ram54288 | 0:a7a43371b306 | 206 | |
ram54288 | 0:a7a43371b306 | 207 | uint32_t M2MResourceInstance::value_length() const |
ram54288 | 0:a7a43371b306 | 208 | { |
ram54288 | 0:a7a43371b306 | 209 | return m2mresourceinstance_stub::int_value; |
ram54288 | 0:a7a43371b306 | 210 | } |
ram54288 | 0:a7a43371b306 | 211 | |
ram54288 | 0:a7a43371b306 | 212 | sn_coap_hdr_s* M2MResourceInstance::handle_get_request(nsdl_s *, |
ram54288 | 0:a7a43371b306 | 213 | sn_coap_hdr_s *, |
ram54288 | 0:a7a43371b306 | 214 | M2MObservationHandler *) |
ram54288 | 0:a7a43371b306 | 215 | { |
ram54288 | 0:a7a43371b306 | 216 | return m2mresourceinstance_stub::header; |
ram54288 | 0:a7a43371b306 | 217 | } |
ram54288 | 0:a7a43371b306 | 218 | |
ram54288 | 0:a7a43371b306 | 219 | sn_coap_hdr_s* M2MResourceInstance::handle_put_request(nsdl_s *, |
ram54288 | 0:a7a43371b306 | 220 | sn_coap_hdr_s *, |
ram54288 | 0:a7a43371b306 | 221 | M2MObservationHandler *, |
ram54288 | 0:a7a43371b306 | 222 | bool &) |
ram54288 | 0:a7a43371b306 | 223 | { |
ram54288 | 0:a7a43371b306 | 224 | return m2mresourceinstance_stub::header; |
ram54288 | 0:a7a43371b306 | 225 | } |
ram54288 | 0:a7a43371b306 | 226 | |
ram54288 | 0:a7a43371b306 | 227 | void M2MResourceInstance::set_resource_observer(M2MResourceCallback *callback) |
ram54288 | 0:a7a43371b306 | 228 | { |
ram54288 | 0:a7a43371b306 | 229 | |
ram54288 | 0:a7a43371b306 | 230 | } |
ram54288 | 0:a7a43371b306 | 231 | |
ram54288 | 0:a7a43371b306 | 232 | uint16_t M2MResourceInstance::object_instance_id() const |
ram54288 | 0:a7a43371b306 | 233 | { |
ram54288 | 0:a7a43371b306 | 234 | return m2mresourceinstance_stub::int_value; |
ram54288 | 0:a7a43371b306 | 235 | } |
ram54288 | 0:a7a43371b306 | 236 | |
ram54288 | 0:a7a43371b306 | 237 | void M2MResourceInstance::set_execute_function(execute_callback_2 callback) |
ram54288 | 0:a7a43371b306 | 238 | { |
ram54288 | 0:a7a43371b306 | 239 | } |
ram54288 | 0:a7a43371b306 | 240 | |
ram54288 | 0:a7a43371b306 | 241 | M2MBlockMessage* M2MResourceInstance::block_message() const |
ram54288 | 0:a7a43371b306 | 242 | { |
ram54288 | 0:a7a43371b306 | 243 | |
ram54288 | 0:a7a43371b306 | 244 | } |
ram54288 | 0:a7a43371b306 | 245 | |
ram54288 | 0:a7a43371b306 | 246 | void M2MResourceInstance::set_incoming_block_message_callback(incoming_block_message_callback callback) |
ram54288 | 0:a7a43371b306 | 247 | { |
ram54288 | 0:a7a43371b306 | 248 | } |
ram54288 | 0:a7a43371b306 | 249 | |
ram54288 | 0:a7a43371b306 | 250 | void M2MResourceInstance::set_outgoing_block_message_callback(outgoing_block_message_callback callback) |
ram54288 | 0:a7a43371b306 | 251 | { |
ram54288 | 0:a7a43371b306 | 252 | |
ram54288 | 0:a7a43371b306 | 253 | } |
ram54288 | 0:a7a43371b306 | 254 | |
ram54288 | 0:a7a43371b306 | 255 | void M2MResourceInstance::set_notification_sent_callback(notification_sent_callback callback) |
ram54288 | 0:a7a43371b306 | 256 | { |
ram54288 | 0:a7a43371b306 | 257 | } |
ram54288 | 0:a7a43371b306 | 258 | |
ram54288 | 0:a7a43371b306 | 259 | void M2MResourceInstance::set_notification_sent_callback(notification_sent_callback_2 callback) |
ram54288 | 0:a7a43371b306 | 260 | { |
ram54288 | 0:a7a43371b306 | 261 | } |
ram54288 | 0:a7a43371b306 | 262 | |
ram54288 | 0:a7a43371b306 | 263 | void M2MResourceInstance::notification_sent() |
ram54288 | 0:a7a43371b306 | 264 | { |
ram54288 | 0:a7a43371b306 | 265 | } |
ram54288 | 0:a7a43371b306 | 266 | |
ram54288 | 0:a7a43371b306 | 267 | const char* M2MResourceInstance::object_name() const |
ram54288 | 0:a7a43371b306 | 268 | { |
ram54288 | 0:a7a43371b306 | 269 | |
ram54288 | 0:a7a43371b306 | 270 | } |