Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/source/MbedCloudClient.cpp@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 2 | // Copyright 2016-2017 ARM Ltd. |
leothedragon | 0:8f0bb79ddd48 | 3 | // |
leothedragon | 0:8f0bb79ddd48 | 4 | // SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 5 | // |
leothedragon | 0:8f0bb79ddd48 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
leothedragon | 0:8f0bb79ddd48 | 7 | // you may not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 8 | // You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 9 | // |
leothedragon | 0:8f0bb79ddd48 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 11 | // |
leothedragon | 0:8f0bb79ddd48 | 12 | // Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
leothedragon | 0:8f0bb79ddd48 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 15 | // See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 16 | // limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 17 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 18 | |
leothedragon | 0:8f0bb79ddd48 | 19 | #include "mbed-cloud-client/MbedCloudClientConfig.h" |
leothedragon | 0:8f0bb79ddd48 | 20 | #include "mbed-cloud-client/MbedCloudClient.h" |
leothedragon | 0:8f0bb79ddd48 | 21 | #include "mbed-cloud-client/SimpleM2MResource.h" |
leothedragon | 0:8f0bb79ddd48 | 22 | |
leothedragon | 0:8f0bb79ddd48 | 23 | #include "mbed-trace/mbed_trace.h" |
leothedragon | 0:8f0bb79ddd48 | 24 | #ifndef MBED_CONF_MBED_CLOUD_CLIENT_DISABLE_CERTIFICATE_ENROLLMENT |
leothedragon | 0:8f0bb79ddd48 | 25 | #include "CertificateEnrollmentClient.h" |
leothedragon | 0:8f0bb79ddd48 | 26 | #endif // MBED_CONF_MBED_CLOUD_CLIENT_DISABLE_CERTIFICATE_ENROLLMENT |
leothedragon | 0:8f0bb79ddd48 | 27 | |
leothedragon | 0:8f0bb79ddd48 | 28 | #include <assert.h> |
leothedragon | 0:8f0bb79ddd48 | 29 | |
leothedragon | 0:8f0bb79ddd48 | 30 | #define xstr(s) str(s) |
leothedragon | 0:8f0bb79ddd48 | 31 | #define str(s) #s |
leothedragon | 0:8f0bb79ddd48 | 32 | |
leothedragon | 0:8f0bb79ddd48 | 33 | #define TRACE_GROUP "mClt" |
leothedragon | 0:8f0bb79ddd48 | 34 | |
leothedragon | 0:8f0bb79ddd48 | 35 | MbedCloudClient::MbedCloudClient() |
leothedragon | 0:8f0bb79ddd48 | 36 | :_client(*this), |
leothedragon | 0:8f0bb79ddd48 | 37 | _value_callback(NULL), |
leothedragon | 0:8f0bb79ddd48 | 38 | _error_description(NULL) |
leothedragon | 0:8f0bb79ddd48 | 39 | { |
leothedragon | 0:8f0bb79ddd48 | 40 | } |
leothedragon | 0:8f0bb79ddd48 | 41 | |
leothedragon | 0:8f0bb79ddd48 | 42 | MbedCloudClient::~MbedCloudClient() |
leothedragon | 0:8f0bb79ddd48 | 43 | { |
leothedragon | 0:8f0bb79ddd48 | 44 | _object_list.clear(); |
leothedragon | 0:8f0bb79ddd48 | 45 | } |
leothedragon | 0:8f0bb79ddd48 | 46 | |
leothedragon | 0:8f0bb79ddd48 | 47 | void MbedCloudClient::add_objects(const M2MObjectList& object_list) |
leothedragon | 0:8f0bb79ddd48 | 48 | { |
leothedragon | 0:8f0bb79ddd48 | 49 | if(!object_list.empty()) { |
leothedragon | 0:8f0bb79ddd48 | 50 | M2MObjectList::const_iterator it; |
leothedragon | 0:8f0bb79ddd48 | 51 | it = object_list.begin(); |
leothedragon | 0:8f0bb79ddd48 | 52 | for (; it!= object_list.end(); it++) { |
leothedragon | 0:8f0bb79ddd48 | 53 | _object_list.push_back((M2MBase*)*it); |
leothedragon | 0:8f0bb79ddd48 | 54 | } |
leothedragon | 0:8f0bb79ddd48 | 55 | } |
leothedragon | 0:8f0bb79ddd48 | 56 | } |
leothedragon | 0:8f0bb79ddd48 | 57 | |
leothedragon | 0:8f0bb79ddd48 | 58 | void MbedCloudClient::add_objects(const M2MBaseList& base_list) |
leothedragon | 0:8f0bb79ddd48 | 59 | { |
leothedragon | 0:8f0bb79ddd48 | 60 | if(!base_list.empty()) { |
leothedragon | 0:8f0bb79ddd48 | 61 | M2MBaseList::const_iterator it; |
leothedragon | 0:8f0bb79ddd48 | 62 | it = base_list.begin(); |
leothedragon | 0:8f0bb79ddd48 | 63 | for (; it!= base_list.end(); it++) { |
leothedragon | 0:8f0bb79ddd48 | 64 | _object_list.push_back(*it); |
leothedragon | 0:8f0bb79ddd48 | 65 | } |
leothedragon | 0:8f0bb79ddd48 | 66 | } |
leothedragon | 0:8f0bb79ddd48 | 67 | } |
leothedragon | 0:8f0bb79ddd48 | 68 | |
leothedragon | 0:8f0bb79ddd48 | 69 | void MbedCloudClient::remove_object(M2MBase *object) |
leothedragon | 0:8f0bb79ddd48 | 70 | { |
leothedragon | 0:8f0bb79ddd48 | 71 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 72 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 73 | |
leothedragon | 0:8f0bb79ddd48 | 74 | M2MBaseList::const_iterator it; |
leothedragon | 0:8f0bb79ddd48 | 75 | int found_index = -1; |
leothedragon | 0:8f0bb79ddd48 | 76 | int index; |
leothedragon | 0:8f0bb79ddd48 | 77 | tr_debug("MbedCloudClient::remove_object %p", object); |
leothedragon | 0:8f0bb79ddd48 | 78 | for (it = _object_list.begin(), index = 0; it != _object_list.end(); it++, index++) { |
leothedragon | 0:8f0bb79ddd48 | 79 | if(*it == object) { |
leothedragon | 0:8f0bb79ddd48 | 80 | found_index = index; |
leothedragon | 0:8f0bb79ddd48 | 81 | break; |
leothedragon | 0:8f0bb79ddd48 | 82 | } |
leothedragon | 0:8f0bb79ddd48 | 83 | } |
leothedragon | 0:8f0bb79ddd48 | 84 | if (found_index != -1) { |
leothedragon | 0:8f0bb79ddd48 | 85 | tr_debug(" object found at index %d", found_index); |
leothedragon | 0:8f0bb79ddd48 | 86 | _object_list.erase(found_index); |
leothedragon | 0:8f0bb79ddd48 | 87 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 88 | _client.connector_client().m2m_interface()->remove_object(object); |
leothedragon | 0:8f0bb79ddd48 | 89 | } |
leothedragon | 0:8f0bb79ddd48 | 90 | } |
leothedragon | 0:8f0bb79ddd48 | 91 | } |
leothedragon | 0:8f0bb79ddd48 | 92 | |
leothedragon | 0:8f0bb79ddd48 | 93 | void MbedCloudClient::set_update_callback(MbedCloudClientCallback *callback) |
leothedragon | 0:8f0bb79ddd48 | 94 | { |
leothedragon | 0:8f0bb79ddd48 | 95 | _value_callback = callback; |
leothedragon | 0:8f0bb79ddd48 | 96 | } |
leothedragon | 0:8f0bb79ddd48 | 97 | |
leothedragon | 0:8f0bb79ddd48 | 98 | bool MbedCloudClient::setup(void* iface) |
leothedragon | 0:8f0bb79ddd48 | 99 | { |
leothedragon | 0:8f0bb79ddd48 | 100 | tr_debug("MbedCloudClient setup()"); |
leothedragon | 0:8f0bb79ddd48 | 101 | |
leothedragon | 0:8f0bb79ddd48 | 102 | // Add objects to list |
leothedragon | 0:8f0bb79ddd48 | 103 | #if MBED_CLOUD_CLIENT_STL_API |
leothedragon | 0:8f0bb79ddd48 | 104 | map<string, M2MObject*>::iterator it; |
leothedragon | 0:8f0bb79ddd48 | 105 | for (it = _objects.begin(); it != _objects.end(); it++) |
leothedragon | 0:8f0bb79ddd48 | 106 | { |
leothedragon | 0:8f0bb79ddd48 | 107 | _object_list.push_back((M2MBase*)it->second); |
leothedragon | 0:8f0bb79ddd48 | 108 | } |
leothedragon | 0:8f0bb79ddd48 | 109 | #endif |
leothedragon | 0:8f0bb79ddd48 | 110 | |
leothedragon | 0:8f0bb79ddd48 | 111 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 112 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 113 | |
leothedragon | 0:8f0bb79ddd48 | 114 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 115 | // set the network interface to M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 116 | _client.connector_client().m2m_interface()->set_platform_network_handler(iface); |
leothedragon | 0:8f0bb79ddd48 | 117 | _client.initialize_and_register(_object_list); |
leothedragon | 0:8f0bb79ddd48 | 118 | } |
leothedragon | 0:8f0bb79ddd48 | 119 | return success; |
leothedragon | 0:8f0bb79ddd48 | 120 | } |
leothedragon | 0:8f0bb79ddd48 | 121 | |
leothedragon | 0:8f0bb79ddd48 | 122 | void MbedCloudClient::on_registered(void(*fn)(void)) |
leothedragon | 0:8f0bb79ddd48 | 123 | { |
leothedragon | 0:8f0bb79ddd48 | 124 | FP0<void> fp(fn); |
leothedragon | 0:8f0bb79ddd48 | 125 | _on_registered = fp; |
leothedragon | 0:8f0bb79ddd48 | 126 | } |
leothedragon | 0:8f0bb79ddd48 | 127 | |
leothedragon | 0:8f0bb79ddd48 | 128 | |
leothedragon | 0:8f0bb79ddd48 | 129 | void MbedCloudClient::on_error(void(*fn)(int)) |
leothedragon | 0:8f0bb79ddd48 | 130 | { |
leothedragon | 0:8f0bb79ddd48 | 131 | _on_error = fn; |
leothedragon | 0:8f0bb79ddd48 | 132 | } |
leothedragon | 0:8f0bb79ddd48 | 133 | |
leothedragon | 0:8f0bb79ddd48 | 134 | |
leothedragon | 0:8f0bb79ddd48 | 135 | void MbedCloudClient::on_unregistered(void(*fn)(void)) |
leothedragon | 0:8f0bb79ddd48 | 136 | { |
leothedragon | 0:8f0bb79ddd48 | 137 | FP0<void> fp(fn); |
leothedragon | 0:8f0bb79ddd48 | 138 | _on_unregistered = fp; |
leothedragon | 0:8f0bb79ddd48 | 139 | } |
leothedragon | 0:8f0bb79ddd48 | 140 | |
leothedragon | 0:8f0bb79ddd48 | 141 | void MbedCloudClient::on_registration_updated(void(*fn)(void)) |
leothedragon | 0:8f0bb79ddd48 | 142 | { |
leothedragon | 0:8f0bb79ddd48 | 143 | FP0<void> fp(fn); |
leothedragon | 0:8f0bb79ddd48 | 144 | _on_registration_updated = fp; |
leothedragon | 0:8f0bb79ddd48 | 145 | } |
leothedragon | 0:8f0bb79ddd48 | 146 | |
leothedragon | 0:8f0bb79ddd48 | 147 | void MbedCloudClient::keep_alive() |
leothedragon | 0:8f0bb79ddd48 | 148 | { |
leothedragon | 0:8f0bb79ddd48 | 149 | _client.connector_client().update_registration(); |
leothedragon | 0:8f0bb79ddd48 | 150 | } |
leothedragon | 0:8f0bb79ddd48 | 151 | |
leothedragon | 0:8f0bb79ddd48 | 152 | void MbedCloudClient::register_update() |
leothedragon | 0:8f0bb79ddd48 | 153 | { |
leothedragon | 0:8f0bb79ddd48 | 154 | _client.connector_client().update_registration(); |
leothedragon | 0:8f0bb79ddd48 | 155 | } |
leothedragon | 0:8f0bb79ddd48 | 156 | |
leothedragon | 0:8f0bb79ddd48 | 157 | void MbedCloudClient::close() |
leothedragon | 0:8f0bb79ddd48 | 158 | { |
leothedragon | 0:8f0bb79ddd48 | 159 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 160 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 161 | |
leothedragon | 0:8f0bb79ddd48 | 162 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 163 | _client.connector_client().m2m_interface()->unregister_object(NULL); |
leothedragon | 0:8f0bb79ddd48 | 164 | } |
leothedragon | 0:8f0bb79ddd48 | 165 | } |
leothedragon | 0:8f0bb79ddd48 | 166 | |
leothedragon | 0:8f0bb79ddd48 | 167 | const ConnectorClientEndpointInfo *MbedCloudClient::endpoint_info() const |
leothedragon | 0:8f0bb79ddd48 | 168 | { |
leothedragon | 0:8f0bb79ddd48 | 169 | return _client.connector_client().endpoint_info(); |
leothedragon | 0:8f0bb79ddd48 | 170 | } |
leothedragon | 0:8f0bb79ddd48 | 171 | |
leothedragon | 0:8f0bb79ddd48 | 172 | void MbedCloudClient::set_queue_sleep_handler(callback_handler handler) |
leothedragon | 0:8f0bb79ddd48 | 173 | { |
leothedragon | 0:8f0bb79ddd48 | 174 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 175 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 176 | |
leothedragon | 0:8f0bb79ddd48 | 177 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 178 | _client.connector_client().m2m_interface()->set_queue_sleep_handler(handler); |
leothedragon | 0:8f0bb79ddd48 | 179 | } |
leothedragon | 0:8f0bb79ddd48 | 180 | } |
leothedragon | 0:8f0bb79ddd48 | 181 | |
leothedragon | 0:8f0bb79ddd48 | 182 | void MbedCloudClient::set_random_number_callback(random_number_cb callback) |
leothedragon | 0:8f0bb79ddd48 | 183 | { |
leothedragon | 0:8f0bb79ddd48 | 184 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 185 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 186 | |
leothedragon | 0:8f0bb79ddd48 | 187 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 188 | _client.connector_client().m2m_interface()->set_random_number_callback(callback); |
leothedragon | 0:8f0bb79ddd48 | 189 | } |
leothedragon | 0:8f0bb79ddd48 | 190 | } |
leothedragon | 0:8f0bb79ddd48 | 191 | |
leothedragon | 0:8f0bb79ddd48 | 192 | void MbedCloudClient::set_entropy_callback(entropy_cb callback) |
leothedragon | 0:8f0bb79ddd48 | 193 | { |
leothedragon | 0:8f0bb79ddd48 | 194 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 195 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 196 | |
leothedragon | 0:8f0bb79ddd48 | 197 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 198 | _client.connector_client().m2m_interface()->set_entropy_callback(callback); |
leothedragon | 0:8f0bb79ddd48 | 199 | } |
leothedragon | 0:8f0bb79ddd48 | 200 | } |
leothedragon | 0:8f0bb79ddd48 | 201 | |
leothedragon | 0:8f0bb79ddd48 | 202 | #if MBED_CLOUD_CLIENT_STL_API |
leothedragon | 0:8f0bb79ddd48 | 203 | bool MbedCloudClient::set_device_resource_value(M2MDevice::DeviceResource resource, |
leothedragon | 0:8f0bb79ddd48 | 204 | const std::string &value) |
leothedragon | 0:8f0bb79ddd48 | 205 | { |
leothedragon | 0:8f0bb79ddd48 | 206 | return _client.set_device_resource_value(resource, value); |
leothedragon | 0:8f0bb79ddd48 | 207 | } |
leothedragon | 0:8f0bb79ddd48 | 208 | |
leothedragon | 0:8f0bb79ddd48 | 209 | void MbedCloudClient::register_update_callback(string route, |
leothedragon | 0:8f0bb79ddd48 | 210 | SimpleM2MResourceBase* resource) |
leothedragon | 0:8f0bb79ddd48 | 211 | { |
leothedragon | 0:8f0bb79ddd48 | 212 | _update_values[route] = resource; |
leothedragon | 0:8f0bb79ddd48 | 213 | } |
leothedragon | 0:8f0bb79ddd48 | 214 | #endif // MBED_CLOUD_CLIENT_STL_API |
leothedragon | 0:8f0bb79ddd48 | 215 | |
leothedragon | 0:8f0bb79ddd48 | 216 | #ifdef MBED_CLOUD_CLIENT_SUPPORT_UPDATE |
leothedragon | 0:8f0bb79ddd48 | 217 | void MbedCloudClient::set_update_authorize_handler(void (*handler)(int32_t request)) |
leothedragon | 0:8f0bb79ddd48 | 218 | { |
leothedragon | 0:8f0bb79ddd48 | 219 | _client.set_update_authorize_handler(handler); |
leothedragon | 0:8f0bb79ddd48 | 220 | } |
leothedragon | 0:8f0bb79ddd48 | 221 | |
leothedragon | 0:8f0bb79ddd48 | 222 | void MbedCloudClient::set_update_progress_handler(void (*handler)(uint32_t progress, uint32_t total)) |
leothedragon | 0:8f0bb79ddd48 | 223 | { |
leothedragon | 0:8f0bb79ddd48 | 224 | _client.set_update_progress_handler(handler); |
leothedragon | 0:8f0bb79ddd48 | 225 | } |
leothedragon | 0:8f0bb79ddd48 | 226 | |
leothedragon | 0:8f0bb79ddd48 | 227 | void MbedCloudClient::update_authorize(int32_t request) |
leothedragon | 0:8f0bb79ddd48 | 228 | { |
leothedragon | 0:8f0bb79ddd48 | 229 | _client.update_authorize(request); |
leothedragon | 0:8f0bb79ddd48 | 230 | } |
leothedragon | 0:8f0bb79ddd48 | 231 | #endif |
leothedragon | 0:8f0bb79ddd48 | 232 | |
leothedragon | 0:8f0bb79ddd48 | 233 | const char *MbedCloudClient::error_description() const |
leothedragon | 0:8f0bb79ddd48 | 234 | { |
leothedragon | 0:8f0bb79ddd48 | 235 | return _error_description; |
leothedragon | 0:8f0bb79ddd48 | 236 | } |
leothedragon | 0:8f0bb79ddd48 | 237 | |
leothedragon | 0:8f0bb79ddd48 | 238 | |
leothedragon | 0:8f0bb79ddd48 | 239 | void MbedCloudClient::complete(ServiceClientCallbackStatus status) |
leothedragon | 0:8f0bb79ddd48 | 240 | { |
leothedragon | 0:8f0bb79ddd48 | 241 | tr_info("MbedCloudClient::complete status (%d)", status); |
leothedragon | 0:8f0bb79ddd48 | 242 | if (status == Service_Client_Status_Registered) { |
leothedragon | 0:8f0bb79ddd48 | 243 | _on_registered.call(); |
leothedragon | 0:8f0bb79ddd48 | 244 | } else if (status == Service_Client_Status_Unregistered) { |
leothedragon | 0:8f0bb79ddd48 | 245 | _object_list.clear(); |
leothedragon | 0:8f0bb79ddd48 | 246 | _on_unregistered.call(); |
leothedragon | 0:8f0bb79ddd48 | 247 | } else if (status == Service_Client_Status_Register_Updated) { |
leothedragon | 0:8f0bb79ddd48 | 248 | _on_registration_updated.call(); |
leothedragon | 0:8f0bb79ddd48 | 249 | } |
leothedragon | 0:8f0bb79ddd48 | 250 | } |
leothedragon | 0:8f0bb79ddd48 | 251 | |
leothedragon | 0:8f0bb79ddd48 | 252 | void MbedCloudClient::error(int error, const char *reason) |
leothedragon | 0:8f0bb79ddd48 | 253 | { |
leothedragon | 0:8f0bb79ddd48 | 254 | tr_error("MbedCloudClient::error code (%d)", error); |
leothedragon | 0:8f0bb79ddd48 | 255 | _error_description = reason; |
leothedragon | 0:8f0bb79ddd48 | 256 | _on_error(error); |
leothedragon | 0:8f0bb79ddd48 | 257 | } |
leothedragon | 0:8f0bb79ddd48 | 258 | |
leothedragon | 0:8f0bb79ddd48 | 259 | void MbedCloudClient::value_updated(M2MBase *base, M2MBase::BaseType type) |
leothedragon | 0:8f0bb79ddd48 | 260 | { |
leothedragon | 0:8f0bb79ddd48 | 261 | if (base) { |
leothedragon | 0:8f0bb79ddd48 | 262 | tr_info("MbedCloudClient::value_updated path %s", base->uri_path()); |
leothedragon | 0:8f0bb79ddd48 | 263 | if (base->uri_path()) { |
leothedragon | 0:8f0bb79ddd48 | 264 | #if MBED_CLOUD_CLIENT_STL_API |
leothedragon | 0:8f0bb79ddd48 | 265 | if (_update_values.count(base->uri_path()) != 0) { |
leothedragon | 0:8f0bb79ddd48 | 266 | tr_debug("MbedCloudClient::value_updated calling update() for %s", base->uri_path()); |
leothedragon | 0:8f0bb79ddd48 | 267 | _update_values[base->uri_path()]->update(); |
leothedragon | 0:8f0bb79ddd48 | 268 | } else |
leothedragon | 0:8f0bb79ddd48 | 269 | #endif |
leothedragon | 0:8f0bb79ddd48 | 270 | { |
leothedragon | 0:8f0bb79ddd48 | 271 | // way to tell application that there is a value update |
leothedragon | 0:8f0bb79ddd48 | 272 | if (_value_callback) { |
leothedragon | 0:8f0bb79ddd48 | 273 | _value_callback->value_updated(base, type); |
leothedragon | 0:8f0bb79ddd48 | 274 | } |
leothedragon | 0:8f0bb79ddd48 | 275 | } |
leothedragon | 0:8f0bb79ddd48 | 276 | } |
leothedragon | 0:8f0bb79ddd48 | 277 | } |
leothedragon | 0:8f0bb79ddd48 | 278 | } |
leothedragon | 0:8f0bb79ddd48 | 279 | |
leothedragon | 0:8f0bb79ddd48 | 280 | void MbedCloudClient::send_get_request(DownloadType type, |
leothedragon | 0:8f0bb79ddd48 | 281 | const char *uri, |
leothedragon | 0:8f0bb79ddd48 | 282 | const size_t offset, |
leothedragon | 0:8f0bb79ddd48 | 283 | get_data_cb data_cb, |
leothedragon | 0:8f0bb79ddd48 | 284 | get_data_error_cb error_cb, |
leothedragon | 0:8f0bb79ddd48 | 285 | void *context) |
leothedragon | 0:8f0bb79ddd48 | 286 | { |
leothedragon | 0:8f0bb79ddd48 | 287 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 288 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 289 | |
leothedragon | 0:8f0bb79ddd48 | 290 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 291 | _client.connector_client().m2m_interface()->get_data_request(type, |
leothedragon | 0:8f0bb79ddd48 | 292 | uri, |
leothedragon | 0:8f0bb79ddd48 | 293 | offset, |
leothedragon | 0:8f0bb79ddd48 | 294 | true, |
leothedragon | 0:8f0bb79ddd48 | 295 | data_cb, |
leothedragon | 0:8f0bb79ddd48 | 296 | error_cb, |
leothedragon | 0:8f0bb79ddd48 | 297 | context); |
leothedragon | 0:8f0bb79ddd48 | 298 | } |
leothedragon | 0:8f0bb79ddd48 | 299 | } |
leothedragon | 0:8f0bb79ddd48 | 300 | |
leothedragon | 0:8f0bb79ddd48 | 301 | #ifndef MBED_CONF_MBED_CLOUD_CLIENT_DISABLE_CERTIFICATE_ENROLLMENT |
leothedragon | 0:8f0bb79ddd48 | 302 | ce_status_e MbedCloudClient::certificate_renew(const char *cert_name) |
leothedragon | 0:8f0bb79ddd48 | 303 | { |
leothedragon | 0:8f0bb79ddd48 | 304 | return CertificateEnrollmentClient::certificate_renew(cert_name); |
leothedragon | 0:8f0bb79ddd48 | 305 | } |
leothedragon | 0:8f0bb79ddd48 | 306 | |
leothedragon | 0:8f0bb79ddd48 | 307 | void MbedCloudClient::on_certificate_renewal(cert_renewal_cb_f user_cb) |
leothedragon | 0:8f0bb79ddd48 | 308 | { |
leothedragon | 0:8f0bb79ddd48 | 309 | CertificateEnrollmentClient::on_certificate_renewal(user_cb); |
leothedragon | 0:8f0bb79ddd48 | 310 | } |
leothedragon | 0:8f0bb79ddd48 | 311 | #endif // MBED_CONF_MBED_CLOUD_CLIENT_DISABLE_CERTIFICATE_ENROLLMENT |
leothedragon | 0:8f0bb79ddd48 | 312 | |
leothedragon | 0:8f0bb79ddd48 | 313 | #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION |
leothedragon | 0:8f0bb79ddd48 | 314 | const M2MBaseList* MbedCloudClient::get_object_list() const |
leothedragon | 0:8f0bb79ddd48 | 315 | { |
leothedragon | 0:8f0bb79ddd48 | 316 | return &_object_list; |
leothedragon | 0:8f0bb79ddd48 | 317 | } |
leothedragon | 0:8f0bb79ddd48 | 318 | #endif // MBED_CLOUD_CLIENT_EDGE_EXTENSION |
leothedragon | 0:8f0bb79ddd48 | 319 | |
leothedragon | 0:8f0bb79ddd48 | 320 | void MbedCloudClient::pause() |
leothedragon | 0:8f0bb79ddd48 | 321 | { |
leothedragon | 0:8f0bb79ddd48 | 322 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 323 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 324 | |
leothedragon | 0:8f0bb79ddd48 | 325 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 326 | _client.connector_client().m2m_interface()->pause(); |
leothedragon | 0:8f0bb79ddd48 | 327 | } |
leothedragon | 0:8f0bb79ddd48 | 328 | } |
leothedragon | 0:8f0bb79ddd48 | 329 | |
leothedragon | 0:8f0bb79ddd48 | 330 | void MbedCloudClient::resume(void *iface) |
leothedragon | 0:8f0bb79ddd48 | 331 | { |
leothedragon | 0:8f0bb79ddd48 | 332 | // finish the ServiceClient's initialization and M2MInterface |
leothedragon | 0:8f0bb79ddd48 | 333 | bool success = _client.connector_client().setup(); |
leothedragon | 0:8f0bb79ddd48 | 334 | |
leothedragon | 0:8f0bb79ddd48 | 335 | if (success) { |
leothedragon | 0:8f0bb79ddd48 | 336 | _client.connector_client().m2m_interface()->resume(iface, _object_list); |
leothedragon | 0:8f0bb79ddd48 | 337 | } |
leothedragon | 0:8f0bb79ddd48 | 338 | } |