Ram Gandikota
/
metronome
FRDM K64F Metronome
mbed-client/test/mbedclient/utest/stub/m2mresource_stub.cpp@0:a2cb7295a1f7, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:35:07 2017 +0000
- Revision:
- 0:a2cb7295a1f7
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a2cb7295a1f7 | 1 | /* |
ram54288 | 0:a2cb7295a1f7 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
ram54288 | 0:a2cb7295a1f7 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a2cb7295a1f7 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a2cb7295a1f7 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a2cb7295a1f7 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a2cb7295a1f7 | 7 | * |
ram54288 | 0:a2cb7295a1f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a2cb7295a1f7 | 9 | * |
ram54288 | 0:a2cb7295a1f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a2cb7295a1f7 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a2cb7295a1f7 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a2cb7295a1f7 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a2cb7295a1f7 | 14 | * limitations under the License. |
ram54288 | 0:a2cb7295a1f7 | 15 | */ |
ram54288 | 0:a2cb7295a1f7 | 16 | #include "m2mresource_stub.h" |
ram54288 | 0:a2cb7295a1f7 | 17 | |
ram54288 | 0:a2cb7295a1f7 | 18 | uint32_t m2mresource_stub::int_value; |
ram54288 | 0:a2cb7295a1f7 | 19 | uint8_t* m2mresource_stub::delayed_token; |
ram54288 | 0:a2cb7295a1f7 | 20 | uint8_t m2mresource_stub::delayed_token_len; |
ram54288 | 0:a2cb7295a1f7 | 21 | bool m2mresource_stub::bool_value; |
ram54288 | 0:a2cb7295a1f7 | 22 | // The statically initialized list must be bigh enough to cater |
ram54288 | 0:a2cb7295a1f7 | 23 | // for all the tests, or the utest framework will complain for memory leak. |
ram54288 | 0:a2cb7295a1f7 | 24 | M2MResourceInstanceList m2mresource_stub::list(12); |
ram54288 | 0:a2cb7295a1f7 | 25 | |
ram54288 | 0:a2cb7295a1f7 | 26 | M2MResourceInstance *m2mresource_stub::instance; |
ram54288 | 0:a2cb7295a1f7 | 27 | M2MObjectInstance *m2mresource_stub::object_instance; |
ram54288 | 0:a2cb7295a1f7 | 28 | sn_coap_hdr_s *m2mresource_stub::header; |
ram54288 | 0:a2cb7295a1f7 | 29 | void m2mresource_stub::clear() |
ram54288 | 0:a2cb7295a1f7 | 30 | { |
ram54288 | 0:a2cb7295a1f7 | 31 | int_value = 0; |
ram54288 | 0:a2cb7295a1f7 | 32 | delayed_token = NULL; |
ram54288 | 0:a2cb7295a1f7 | 33 | delayed_token_len = 0; |
ram54288 | 0:a2cb7295a1f7 | 34 | bool_value = false; |
ram54288 | 0:a2cb7295a1f7 | 35 | list.clear(); |
ram54288 | 0:a2cb7295a1f7 | 36 | instance = NULL; |
ram54288 | 0:a2cb7295a1f7 | 37 | object_instance = NULL; |
ram54288 | 0:a2cb7295a1f7 | 38 | } |
ram54288 | 0:a2cb7295a1f7 | 39 | |
ram54288 | 0:a2cb7295a1f7 | 40 | M2MResource::M2MResource(M2MObjectInstance &parent, |
ram54288 | 0:a2cb7295a1f7 | 41 | const String &resource_name, |
ram54288 | 0:a2cb7295a1f7 | 42 | const String &resource_type, |
ram54288 | 0:a2cb7295a1f7 | 43 | M2MResourceInstance::ResourceType type, |
ram54288 | 0:a2cb7295a1f7 | 44 | const uint8_t *value, |
ram54288 | 0:a2cb7295a1f7 | 45 | const uint8_t value_length, |
ram54288 | 0:a2cb7295a1f7 | 46 | char* path, |
ram54288 | 0:a2cb7295a1f7 | 47 | const uint16_t object_instance_id, |
ram54288 | 0:a2cb7295a1f7 | 48 | bool multiple_instance, |
ram54288 | 0:a2cb7295a1f7 | 49 | bool external_blockwise_store) |
ram54288 | 0:a2cb7295a1f7 | 50 | : M2MResourceInstance(*this, resource_name, resource_type, type, value, value_length, object_instance_id, |
ram54288 | 0:a2cb7295a1f7 | 51 | path, external_blockwise_store), |
ram54288 | 0:a2cb7295a1f7 | 52 | _parent(parent), |
ram54288 | 0:a2cb7295a1f7 | 53 | _delayed_token(NULL), |
ram54288 | 0:a2cb7295a1f7 | 54 | _delayed_token_len(0), |
ram54288 | 0:a2cb7295a1f7 | 55 | _has_multiple_instances(multiple_instance), |
ram54288 | 0:a2cb7295a1f7 | 56 | _delayed_response(false) |
ram54288 | 0:a2cb7295a1f7 | 57 | { |
ram54288 | 0:a2cb7295a1f7 | 58 | |
ram54288 | 0:a2cb7295a1f7 | 59 | } |
ram54288 | 0:a2cb7295a1f7 | 60 | |
ram54288 | 0:a2cb7295a1f7 | 61 | M2MResource::M2MResource(M2MObjectInstance &parent, |
ram54288 | 0:a2cb7295a1f7 | 62 | const lwm2m_parameters_s* s, |
ram54288 | 0:a2cb7295a1f7 | 63 | M2MResourceInstance::ResourceType type, |
ram54288 | 0:a2cb7295a1f7 | 64 | const uint16_t object_instance_id) |
ram54288 | 0:a2cb7295a1f7 | 65 | : M2MResourceInstance(*this, s, type, object_instance_id), |
ram54288 | 0:a2cb7295a1f7 | 66 | _parent(parent), |
ram54288 | 0:a2cb7295a1f7 | 67 | _delayed_token(NULL), |
ram54288 | 0:a2cb7295a1f7 | 68 | _delayed_token_len(0), |
ram54288 | 0:a2cb7295a1f7 | 69 | _has_multiple_instances(false), |
ram54288 | 0:a2cb7295a1f7 | 70 | _delayed_response(false) |
ram54288 | 0:a2cb7295a1f7 | 71 | { |
ram54288 | 0:a2cb7295a1f7 | 72 | // tbd: _has_multiple_instances could be in flash, but no real benefit, because of current alignment. |
ram54288 | 0:a2cb7295a1f7 | 73 | } |
ram54288 | 0:a2cb7295a1f7 | 74 | |
ram54288 | 0:a2cb7295a1f7 | 75 | M2MResource::M2MResource(M2MObjectInstance &parent, |
ram54288 | 0:a2cb7295a1f7 | 76 | const String &resource_name, |
ram54288 | 0:a2cb7295a1f7 | 77 | const String &resource_type, |
ram54288 | 0:a2cb7295a1f7 | 78 | M2MResourceInstance::ResourceType type, |
ram54288 | 0:a2cb7295a1f7 | 79 | bool observable, |
ram54288 | 0:a2cb7295a1f7 | 80 | char *path, |
ram54288 | 0:a2cb7295a1f7 | 81 | const uint16_t object_instance_id, |
ram54288 | 0:a2cb7295a1f7 | 82 | bool multiple_instance, |
ram54288 | 0:a2cb7295a1f7 | 83 | bool external_blockwise_store) |
ram54288 | 0:a2cb7295a1f7 | 84 | : M2MResourceInstance(*this, resource_name, resource_type, type, |
ram54288 | 0:a2cb7295a1f7 | 85 | object_instance_id, path, external_blockwise_store), |
ram54288 | 0:a2cb7295a1f7 | 86 | _parent(parent), |
ram54288 | 0:a2cb7295a1f7 | 87 | _delayed_token(NULL), |
ram54288 | 0:a2cb7295a1f7 | 88 | _delayed_token_len(0), |
ram54288 | 0:a2cb7295a1f7 | 89 | _has_multiple_instances(multiple_instance), |
ram54288 | 0:a2cb7295a1f7 | 90 | _delayed_response(false) |
ram54288 | 0:a2cb7295a1f7 | 91 | { |
ram54288 | 0:a2cb7295a1f7 | 92 | |
ram54288 | 0:a2cb7295a1f7 | 93 | } |
ram54288 | 0:a2cb7295a1f7 | 94 | |
ram54288 | 0:a2cb7295a1f7 | 95 | M2MResource::~M2MResource() |
ram54288 | 0:a2cb7295a1f7 | 96 | { |
ram54288 | 0:a2cb7295a1f7 | 97 | } |
ram54288 | 0:a2cb7295a1f7 | 98 | |
ram54288 | 0:a2cb7295a1f7 | 99 | bool M2MResource::supports_multiple_instances() const |
ram54288 | 0:a2cb7295a1f7 | 100 | { |
ram54288 | 0:a2cb7295a1f7 | 101 | return m2mresource_stub::bool_value; |
ram54288 | 0:a2cb7295a1f7 | 102 | } |
ram54288 | 0:a2cb7295a1f7 | 103 | |
ram54288 | 0:a2cb7295a1f7 | 104 | void M2MResource::get_delayed_token(unsigned char *&token, unsigned char &token_len) |
ram54288 | 0:a2cb7295a1f7 | 105 | { |
ram54288 | 0:a2cb7295a1f7 | 106 | token_len = 0; |
ram54288 | 0:a2cb7295a1f7 | 107 | if(token) { |
ram54288 | 0:a2cb7295a1f7 | 108 | free(token); |
ram54288 | 0:a2cb7295a1f7 | 109 | token = NULL; |
ram54288 | 0:a2cb7295a1f7 | 110 | } |
ram54288 | 0:a2cb7295a1f7 | 111 | token = (uint8_t *)malloc(m2mresource_stub::delayed_token_len); |
ram54288 | 0:a2cb7295a1f7 | 112 | if(token) { |
ram54288 | 0:a2cb7295a1f7 | 113 | token_len = m2mresource_stub::delayed_token_len; |
ram54288 | 0:a2cb7295a1f7 | 114 | memcpy((uint8_t *)token, (uint8_t *)m2mresource_stub::delayed_token, token_len); |
ram54288 | 0:a2cb7295a1f7 | 115 | } |
ram54288 | 0:a2cb7295a1f7 | 116 | } |
ram54288 | 0:a2cb7295a1f7 | 117 | |
ram54288 | 0:a2cb7295a1f7 | 118 | bool M2MResource::remove_resource_instance(uint16_t inst_id) |
ram54288 | 0:a2cb7295a1f7 | 119 | { |
ram54288 | 0:a2cb7295a1f7 | 120 | return m2mresource_stub::bool_value; |
ram54288 | 0:a2cb7295a1f7 | 121 | } |
ram54288 | 0:a2cb7295a1f7 | 122 | |
ram54288 | 0:a2cb7295a1f7 | 123 | M2MResourceInstance* M2MResource::resource_instance(uint16_t inst_id) const |
ram54288 | 0:a2cb7295a1f7 | 124 | { |
ram54288 | 0:a2cb7295a1f7 | 125 | return m2mresource_stub::instance; |
ram54288 | 0:a2cb7295a1f7 | 126 | } |
ram54288 | 0:a2cb7295a1f7 | 127 | |
ram54288 | 0:a2cb7295a1f7 | 128 | const M2MResourceInstanceList& M2MResource::resource_instances() const |
ram54288 | 0:a2cb7295a1f7 | 129 | { |
ram54288 | 0:a2cb7295a1f7 | 130 | return m2mresource_stub::list; |
ram54288 | 0:a2cb7295a1f7 | 131 | } |
ram54288 | 0:a2cb7295a1f7 | 132 | |
ram54288 | 0:a2cb7295a1f7 | 133 | uint16_t M2MResource::resource_instance_count() const |
ram54288 | 0:a2cb7295a1f7 | 134 | { |
ram54288 | 0:a2cb7295a1f7 | 135 | return m2mresource_stub::int_value; |
ram54288 | 0:a2cb7295a1f7 | 136 | } |
ram54288 | 0:a2cb7295a1f7 | 137 | |
ram54288 | 0:a2cb7295a1f7 | 138 | bool M2MResource::handle_observation_attribute(const char *query) |
ram54288 | 0:a2cb7295a1f7 | 139 | { |
ram54288 | 0:a2cb7295a1f7 | 140 | return m2mresource_stub::bool_value; |
ram54288 | 0:a2cb7295a1f7 | 141 | } |
ram54288 | 0:a2cb7295a1f7 | 142 | |
ram54288 | 0:a2cb7295a1f7 | 143 | void M2MResource::add_resource_instance(M2MResourceInstance *) |
ram54288 | 0:a2cb7295a1f7 | 144 | { |
ram54288 | 0:a2cb7295a1f7 | 145 | } |
ram54288 | 0:a2cb7295a1f7 | 146 | |
ram54288 | 0:a2cb7295a1f7 | 147 | void M2MResource::add_observation_level(M2MBase::Observation) |
ram54288 | 0:a2cb7295a1f7 | 148 | { |
ram54288 | 0:a2cb7295a1f7 | 149 | } |
ram54288 | 0:a2cb7295a1f7 | 150 | |
ram54288 | 0:a2cb7295a1f7 | 151 | void M2MResource::remove_observation_level(M2MBase::Observation) |
ram54288 | 0:a2cb7295a1f7 | 152 | { |
ram54288 | 0:a2cb7295a1f7 | 153 | } |
ram54288 | 0:a2cb7295a1f7 | 154 | |
ram54288 | 0:a2cb7295a1f7 | 155 | void M2MResource::notification_update() |
ram54288 | 0:a2cb7295a1f7 | 156 | { |
ram54288 | 0:a2cb7295a1f7 | 157 | } |
ram54288 | 0:a2cb7295a1f7 | 158 | |
ram54288 | 0:a2cb7295a1f7 | 159 | sn_coap_hdr_s* M2MResource::handle_get_request(nsdl_s *, |
ram54288 | 0:a2cb7295a1f7 | 160 | sn_coap_hdr_s *, |
ram54288 | 0:a2cb7295a1f7 | 161 | M2MObservationHandler *) |
ram54288 | 0:a2cb7295a1f7 | 162 | { |
ram54288 | 0:a2cb7295a1f7 | 163 | return m2mresource_stub::header; |
ram54288 | 0:a2cb7295a1f7 | 164 | } |
ram54288 | 0:a2cb7295a1f7 | 165 | |
ram54288 | 0:a2cb7295a1f7 | 166 | sn_coap_hdr_s* M2MResource::handle_put_request(nsdl_s *, |
ram54288 | 0:a2cb7295a1f7 | 167 | sn_coap_hdr_s *, |
ram54288 | 0:a2cb7295a1f7 | 168 | M2MObservationHandler *, |
ram54288 | 0:a2cb7295a1f7 | 169 | bool &) |
ram54288 | 0:a2cb7295a1f7 | 170 | { |
ram54288 | 0:a2cb7295a1f7 | 171 | return m2mresource_stub::header; |
ram54288 | 0:a2cb7295a1f7 | 172 | } |
ram54288 | 0:a2cb7295a1f7 | 173 | |
ram54288 | 0:a2cb7295a1f7 | 174 | sn_coap_hdr_s* M2MResource::handle_post_request(nsdl_s *, |
ram54288 | 0:a2cb7295a1f7 | 175 | sn_coap_hdr_s *, |
ram54288 | 0:a2cb7295a1f7 | 176 | M2MObservationHandler *, |
ram54288 | 0:a2cb7295a1f7 | 177 | bool &, sn_nsdl_addr_s *) |
ram54288 | 0:a2cb7295a1f7 | 178 | { |
ram54288 | 0:a2cb7295a1f7 | 179 | return m2mresource_stub::header; |
ram54288 | 0:a2cb7295a1f7 | 180 | } |
ram54288 | 0:a2cb7295a1f7 | 181 | |
ram54288 | 0:a2cb7295a1f7 | 182 | M2MObjectInstance& M2MResource::get_parent_object_instance() const |
ram54288 | 0:a2cb7295a1f7 | 183 | { |
ram54288 | 0:a2cb7295a1f7 | 184 | return *m2mresource_stub::object_instance; |
ram54288 | 0:a2cb7295a1f7 | 185 | } |
ram54288 | 0:a2cb7295a1f7 | 186 | |
ram54288 | 0:a2cb7295a1f7 | 187 | const char* M2MResource::object_name() const |
ram54288 | 0:a2cb7295a1f7 | 188 | { |
ram54288 | 0:a2cb7295a1f7 | 189 | |
ram54288 | 0:a2cb7295a1f7 | 190 | } |