mbed Connector Interface simplification API on top of mbed-client
Fork of mbedConnectorInterfaceV3 by
NOTE:
This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!
source/OptionsBuilder.cpp@33:1d0b855df5a5, 2016-06-14 (annotated)
- Committer:
- ansond
- Date:
- Tue Jun 14 19:29:30 2016 +0000
- Revision:
- 33:1d0b855df5a5
- Parent:
- 27:b8aaf7dc7023
- Child:
- 34:a10d65907549
updated and unified headers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:1f1f55e73248 | 1 | /** |
ansond | 0:1f1f55e73248 | 2 | * @file OptionsBuilder.cpp |
ansond | 0:1f1f55e73248 | 3 | * @brief mbed CoAP OptionsBuilder class implementation |
ansond | 0:1f1f55e73248 | 4 | * @author Doug Anson/Chris Paola |
ansond | 0:1f1f55e73248 | 5 | * @version 1.0 |
ansond | 0:1f1f55e73248 | 6 | * @see |
ansond | 0:1f1f55e73248 | 7 | * |
ansond | 0:1f1f55e73248 | 8 | * Copyright (c) 2014 |
ansond | 0:1f1f55e73248 | 9 | * |
ansond | 0:1f1f55e73248 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 0:1f1f55e73248 | 11 | * you may not use this file except in compliance with the License. |
ansond | 0:1f1f55e73248 | 12 | * You may obtain a copy of the License at |
ansond | 0:1f1f55e73248 | 13 | * |
ansond | 0:1f1f55e73248 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 0:1f1f55e73248 | 15 | * |
ansond | 0:1f1f55e73248 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 0:1f1f55e73248 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 0:1f1f55e73248 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 0:1f1f55e73248 | 19 | * See the License for the specific language governing permissions and |
ansond | 0:1f1f55e73248 | 20 | * limitations under the License. |
ansond | 0:1f1f55e73248 | 21 | */ |
ansond | 0:1f1f55e73248 | 22 | |
ansond | 33:1d0b855df5a5 | 23 | // Class support |
ansond | 0:1f1f55e73248 | 24 | #include "mbed-connector-interface/OptionsBuilder.h" |
ansond | 0:1f1f55e73248 | 25 | |
ansond | 0:1f1f55e73248 | 26 | // external included configuration file for the endpoint... |
ansond | 0:1f1f55e73248 | 27 | #include "mbed-connector-interface/configuration.h" |
ansond | 0:1f1f55e73248 | 28 | |
ansond | 33:1d0b855df5a5 | 29 | // ResourceObserver support (enabled in configuration.h) |
ansond | 0:1f1f55e73248 | 30 | #include "mbed-connector-interface/ThreadedResourceObserver.h" |
ansond | 0:1f1f55e73248 | 31 | #include "mbed-connector-interface/TickerResourceObserver.h" |
ansond | 27:b8aaf7dc7023 | 32 | #include "mbed-connector-interface/MinarResourceObserver.h" |
ansond | 0:1f1f55e73248 | 33 | |
ansond | 0:1f1f55e73248 | 34 | // DEBUG |
ansond | 0:1f1f55e73248 | 35 | #ifndef NDEBUG |
ansond | 0:1f1f55e73248 | 36 | #define DEBUG_OUT(...) { printf(__VA_ARGS__); } |
ansond | 0:1f1f55e73248 | 37 | #else |
ansond | 0:1f1f55e73248 | 38 | #define DEBUG_OUT(...) /* nothing */ |
ansond | 0:1f1f55e73248 | 39 | #endif |
ansond | 0:1f1f55e73248 | 40 | |
ansond | 0:1f1f55e73248 | 41 | // Connector namespace |
ansond | 0:1f1f55e73248 | 42 | namespace Connector { |
ansond | 0:1f1f55e73248 | 43 | |
ansond | 0:1f1f55e73248 | 44 | // Constructor |
ansond | 0:1f1f55e73248 | 45 | OptionsBuilder::OptionsBuilder() |
ansond | 0:1f1f55e73248 | 46 | { |
ansond | 27:b8aaf7dc7023 | 47 | this->m_domain = NSP_DOMAIN; |
ansond | 27:b8aaf7dc7023 | 48 | this->m_endpoint_type = NSP_ENDPOINT_TYPE; |
ansond | 27:b8aaf7dc7023 | 49 | this->m_node_name = NODE_NAME; |
ansond | 27:b8aaf7dc7023 | 50 | this->m_reg_update_period = REG_UPDATE_PERIOD_MS; |
ansond | 27:b8aaf7dc7023 | 51 | this->m_lifetime = REG_LIFETIME_SEC; |
ansond | 27:b8aaf7dc7023 | 52 | this->m_connector_url = string(CONNECTOR_URL); |
ansond | 27:b8aaf7dc7023 | 53 | this->m_device_resources_object = NULL; |
ansond | 27:b8aaf7dc7023 | 54 | this->m_firmware_resources_object = NULL; |
ansond | 0:1f1f55e73248 | 55 | this->m_static_resources.clear(); |
ansond | 0:1f1f55e73248 | 56 | this->m_dynamic_resources.clear(); |
ansond | 0:1f1f55e73248 | 57 | this->m_resource_observers.clear(); |
ansond | 0:1f1f55e73248 | 58 | } |
ansond | 0:1f1f55e73248 | 59 | |
ansond | 0:1f1f55e73248 | 60 | // Copy Constructor |
ansond | 0:1f1f55e73248 | 61 | OptionsBuilder::OptionsBuilder(const OptionsBuilder &ob) : Options(ob) |
ansond | 0:1f1f55e73248 | 62 | { |
ansond | 8:f950fb1b78c0 | 63 | this->m_domain = ob.m_domain; |
ansond | 0:1f1f55e73248 | 64 | this->m_endpoint_type = ob.m_endpoint_type; |
ansond | 8:f950fb1b78c0 | 65 | this->m_node_name = ob.m_node_name; |
ansond | 8:f950fb1b78c0 | 66 | this->m_reg_update_period = ob.m_reg_update_period; |
ansond | 8:f950fb1b78c0 | 67 | this->m_lifetime = ob.m_lifetime; |
ansond | 8:f950fb1b78c0 | 68 | this->m_connector_url = ob.m_connector_url; |
ansond | 27:b8aaf7dc7023 | 69 | this->m_device_resources_object = ob.m_device_resources_object; |
ansond | 27:b8aaf7dc7023 | 70 | this->m_firmware_resources_object = ob.m_firmware_resources_object; |
ansond | 0:1f1f55e73248 | 71 | this->m_static_resources = ob.m_static_resources; |
ansond | 0:1f1f55e73248 | 72 | this->m_dynamic_resources = ob.m_dynamic_resources; |
ansond | 0:1f1f55e73248 | 73 | this->m_resource_observers = ob.m_resource_observers; |
ansond | 0:1f1f55e73248 | 74 | } |
ansond | 0:1f1f55e73248 | 75 | |
ansond | 0:1f1f55e73248 | 76 | // Destructor |
ansond | 0:1f1f55e73248 | 77 | OptionsBuilder::~OptionsBuilder() |
ansond | 0:1f1f55e73248 | 78 | { |
ansond | 27:b8aaf7dc7023 | 79 | if (this->m_device_resources_object != NULL) { |
ansond | 27:b8aaf7dc7023 | 80 | delete this->m_device_resources_object; |
ansond | 27:b8aaf7dc7023 | 81 | } |
ansond | 27:b8aaf7dc7023 | 82 | if (this->m_firmware_resources_object != NULL) { |
ansond | 27:b8aaf7dc7023 | 83 | delete this->m_firmware_resources_object; |
ansond | 27:b8aaf7dc7023 | 84 | } |
ansond | 0:1f1f55e73248 | 85 | this->m_static_resources.clear(); |
ansond | 0:1f1f55e73248 | 86 | this->m_dynamic_resources.clear(); |
ansond | 0:1f1f55e73248 | 87 | this->m_resource_observers.clear(); |
ansond | 0:1f1f55e73248 | 88 | } |
ansond | 0:1f1f55e73248 | 89 | |
ansond | 0:1f1f55e73248 | 90 | // set lifetime |
ansond | 0:1f1f55e73248 | 91 | OptionsBuilder &OptionsBuilder::setLifetime(int lifetime) |
ansond | 0:1f1f55e73248 | 92 | { |
ansond | 0:1f1f55e73248 | 93 | this->m_lifetime = lifetime; |
ansond | 0:1f1f55e73248 | 94 | return *this; |
ansond | 0:1f1f55e73248 | 95 | } |
ansond | 0:1f1f55e73248 | 96 | |
ansond | 0:1f1f55e73248 | 97 | // set domain |
ansond | 0:1f1f55e73248 | 98 | OptionsBuilder &OptionsBuilder::setDomain(const char *domain) |
ansond | 0:1f1f55e73248 | 99 | { |
ansond | 0:1f1f55e73248 | 100 | this->m_domain = string(domain); |
ansond | 0:1f1f55e73248 | 101 | return *this; |
ansond | 0:1f1f55e73248 | 102 | } |
ansond | 0:1f1f55e73248 | 103 | |
ansond | 0:1f1f55e73248 | 104 | // set endpoint nodename |
ansond | 0:1f1f55e73248 | 105 | OptionsBuilder &OptionsBuilder::setEndpointNodename(const char *node_name) |
ansond | 0:1f1f55e73248 | 106 | { |
ansond | 0:1f1f55e73248 | 107 | this->m_node_name = string(node_name); |
ansond | 0:1f1f55e73248 | 108 | return *this; |
ansond | 0:1f1f55e73248 | 109 | } |
ansond | 0:1f1f55e73248 | 110 | |
ansond | 0:1f1f55e73248 | 111 | // set lifetime |
ansond | 0:1f1f55e73248 | 112 | OptionsBuilder &OptionsBuilder::setEndpointType(const char *endpoint_type) |
ansond | 0:1f1f55e73248 | 113 | { |
ansond | 0:1f1f55e73248 | 114 | this->m_endpoint_type = string(endpoint_type); |
ansond | 0:1f1f55e73248 | 115 | return *this; |
ansond | 0:1f1f55e73248 | 116 | } |
ansond | 0:1f1f55e73248 | 117 | |
ansond | 0:1f1f55e73248 | 118 | // set mbed registration update period |
ansond | 0:1f1f55e73248 | 119 | OptionsBuilder &OptionsBuilder::setRegUpdatePeriod(const int reg_update_period) |
ansond | 0:1f1f55e73248 | 120 | { |
ansond | 0:1f1f55e73248 | 121 | this->m_reg_update_period = reg_update_period; |
ansond | 0:1f1f55e73248 | 122 | return *this; |
ansond | 0:1f1f55e73248 | 123 | } |
ansond | 0:1f1f55e73248 | 124 | |
ansond | 0:1f1f55e73248 | 125 | // set Connector URL |
ansond | 0:1f1f55e73248 | 126 | OptionsBuilder &OptionsBuilder::setConnectorURL(const char *connector_url) |
ansond | 0:1f1f55e73248 | 127 | { |
ansond | 0:1f1f55e73248 | 128 | if (connector_url != NULL) { |
ansond | 0:1f1f55e73248 | 129 | this->m_connector_url = string(connector_url); |
ansond | 0:1f1f55e73248 | 130 | } |
ansond | 0:1f1f55e73248 | 131 | return *this; |
ansond | 0:1f1f55e73248 | 132 | } |
ansond | 0:1f1f55e73248 | 133 | |
ansond | 27:b8aaf7dc7023 | 134 | // add the device resources object |
ansond | 27:b8aaf7dc7023 | 135 | OptionsBuilder &OptionsBuilder::setDeviceResourcesObject(const void *device_resources_object) |
ansond | 27:b8aaf7dc7023 | 136 | { |
ansond | 27:b8aaf7dc7023 | 137 | if (device_resources_object != NULL) { |
ansond | 27:b8aaf7dc7023 | 138 | this->m_device_resources_object = (void *)device_resources_object; |
ansond | 27:b8aaf7dc7023 | 139 | } |
ansond | 27:b8aaf7dc7023 | 140 | return *this; |
ansond | 27:b8aaf7dc7023 | 141 | } |
ansond | 27:b8aaf7dc7023 | 142 | |
ansond | 27:b8aaf7dc7023 | 143 | // add the firmware resources object |
ansond | 27:b8aaf7dc7023 | 144 | OptionsBuilder &OptionsBuilder::setFirmwareResourcesObject(const void *firmware_resources_object) |
ansond | 27:b8aaf7dc7023 | 145 | { |
ansond | 27:b8aaf7dc7023 | 146 | if (firmware_resources_object != NULL) { |
ansond | 27:b8aaf7dc7023 | 147 | this->m_firmware_resources_object = (void *)firmware_resources_object; |
ansond | 0:1f1f55e73248 | 148 | } |
ansond | 0:1f1f55e73248 | 149 | return *this; |
ansond | 0:1f1f55e73248 | 150 | } |
ansond | 0:1f1f55e73248 | 151 | |
ansond | 0:1f1f55e73248 | 152 | // add static resource |
ansond | 0:1f1f55e73248 | 153 | OptionsBuilder &OptionsBuilder::addResource(const StaticResource *resource) |
ansond | 0:1f1f55e73248 | 154 | { |
ansond | 0:1f1f55e73248 | 155 | if (resource != NULL) { |
ansond | 0:1f1f55e73248 | 156 | ((StaticResource *)resource)->setOptions(this); |
ansond | 0:1f1f55e73248 | 157 | this->m_static_resources.push_back((StaticResource *)resource); |
ansond | 0:1f1f55e73248 | 158 | } |
ansond | 0:1f1f55e73248 | 159 | return *this; |
ansond | 0:1f1f55e73248 | 160 | } |
ansond | 0:1f1f55e73248 | 161 | |
ansond | 0:1f1f55e73248 | 162 | // add dynamic resource |
ansond | 0:1f1f55e73248 | 163 | OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource) |
ansond | 0:1f1f55e73248 | 164 | { |
ansond | 0:1f1f55e73248 | 165 | // ensure that the boolean isn't mistaken by the compiler for the obs period... |
ansond | 0:1f1f55e73248 | 166 | return this->addResource(resource,OBS_PERIOD_MS,!(((DynamicResource *)resource)->implementsObservation())); |
ansond | 0:1f1f55e73248 | 167 | } |
ansond | 0:1f1f55e73248 | 168 | |
ansond | 0:1f1f55e73248 | 169 | // add dynamic resource |
ansond | 0:1f1f55e73248 | 170 | OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource,const int sleep_time) |
ansond | 0:1f1f55e73248 | 171 | { |
ansond | 0:1f1f55e73248 | 172 | // ensure that the boolean isn't mistaken by the compiler for the obs period... |
ansond | 0:1f1f55e73248 | 173 | return this->addResource(resource,sleep_time,!(((DynamicResource *)resource)->implementsObservation())); |
ansond | 0:1f1f55e73248 | 174 | } |
ansond | 0:1f1f55e73248 | 175 | |
ansond | 0:1f1f55e73248 | 176 | // add dynamic resource |
ansond | 0:1f1f55e73248 | 177 | OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource,const bool use_observer) |
ansond | 0:1f1f55e73248 | 178 | { |
ansond | 0:1f1f55e73248 | 179 | // ensure that the boolean isn't mistaken by the compiler for the obs period... |
ansond | 0:1f1f55e73248 | 180 | return this->addResource(resource,OBS_PERIOD_MS,use_observer); |
ansond | 0:1f1f55e73248 | 181 | } |
ansond | 0:1f1f55e73248 | 182 | |
ansond | 0:1f1f55e73248 | 183 | // add dynamic resource |
ansond | 0:1f1f55e73248 | 184 | OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource,const int sleep_time,const bool use_observer) |
ansond | 0:1f1f55e73248 | 185 | { |
ansond | 0:1f1f55e73248 | 186 | if (resource != NULL) { |
ansond | 0:1f1f55e73248 | 187 | this->m_dynamic_resources.push_back((DynamicResource *)resource); |
ansond | 0:1f1f55e73248 | 188 | ((DynamicResource *)resource)->setOptions(this); |
ansond | 17:defb680f8fce | 189 | ((DynamicResource *)resource)->setEndpoint((const void *)this->getEndpoint()); |
ansond | 0:1f1f55e73248 | 190 | if (((DynamicResource *)resource)->isObservable() == true && use_observer == true) { |
ansond | 27:b8aaf7dc7023 | 191 | #if defined (MCI_MINAR_SCHEDULER) |
ansond | 27:b8aaf7dc7023 | 192 | MinarResourceObserver *observer = new MinarResourceObserver((DynamicResource *)resource,(int)sleep_time); |
ansond | 27:b8aaf7dc7023 | 193 | #else |
ansond | 27:b8aaf7dc7023 | 194 | #ifdef CONNECTOR_USING_THREADS |
ansond | 0:1f1f55e73248 | 195 | ThreadedResourceObserver *observer = new ThreadedResourceObserver((DynamicResource *)resource,(int)sleep_time); |
ansond | 27:b8aaf7dc7023 | 196 | #else |
ansond | 0:1f1f55e73248 | 197 | TickerResourceObserver *observer = new TickerResourceObserver((DynamicResource *)resource,(int)sleep_time); |
ansond | 27:b8aaf7dc7023 | 198 | #endif |
ansond | 0:1f1f55e73248 | 199 | #endif |
ansond | 0:1f1f55e73248 | 200 | this->m_resource_observers.push_back(observer); |
ansond | 0:1f1f55e73248 | 201 | |
ansond | 0:1f1f55e73248 | 202 | // immedate observation enablement option |
ansond | 0:1f1f55e73248 | 203 | if (this->immedateObservationEnabled()) { |
ansond | 0:1f1f55e73248 | 204 | observer->beginObservation(); |
ansond | 0:1f1f55e73248 | 205 | } |
ansond | 0:1f1f55e73248 | 206 | } |
ansond | 0:1f1f55e73248 | 207 | } |
ansond | 0:1f1f55e73248 | 208 | return *this; |
ansond | 0:1f1f55e73248 | 209 | } |
ansond | 0:1f1f55e73248 | 210 | |
ansond | 0:1f1f55e73248 | 211 | // set WiFi SSID |
ansond | 0:1f1f55e73248 | 212 | OptionsBuilder &OptionsBuilder::setWiFiSSID(char *ssid) |
ansond | 0:1f1f55e73248 | 213 | { |
ansond | 0:1f1f55e73248 | 214 | this->m_wifi_ssid = string(ssid); |
ansond | 0:1f1f55e73248 | 215 | return *this; |
ansond | 0:1f1f55e73248 | 216 | } |
ansond | 0:1f1f55e73248 | 217 | |
ansond | 0:1f1f55e73248 | 218 | // set WiFi AuthType |
ansond | 0:1f1f55e73248 | 219 | OptionsBuilder &OptionsBuilder::setWiFiAuthType(WiFiAuthTypes auth_type) |
ansond | 0:1f1f55e73248 | 220 | { |
ansond | 0:1f1f55e73248 | 221 | this->m_wifi_auth_type = auth_type; |
ansond | 0:1f1f55e73248 | 222 | return *this; |
ansond | 0:1f1f55e73248 | 223 | } |
ansond | 0:1f1f55e73248 | 224 | |
ansond | 0:1f1f55e73248 | 225 | // set WiFi AuthKey |
ansond | 0:1f1f55e73248 | 226 | OptionsBuilder &OptionsBuilder::setWiFiAuthKey(char *auth_key) |
ansond | 0:1f1f55e73248 | 227 | { |
ansond | 0:1f1f55e73248 | 228 | this->m_wifi_auth_key = string(auth_key); |
ansond | 0:1f1f55e73248 | 229 | return *this; |
ansond | 0:1f1f55e73248 | 230 | } |
ansond | 0:1f1f55e73248 | 231 | |
ansond | 8:f950fb1b78c0 | 232 | // set 802.15.4 Pre Shared Key |
ansond | 8:f950fb1b78c0 | 233 | OptionsBuilder &OptionsBuilder::setPreSharedKey(unsigned char psk[16]) |
ansond | 0:1f1f55e73248 | 234 | { |
ansond | 8:f950fb1b78c0 | 235 | memset(this->m_psk,0,16); |
ansond | 8:f950fb1b78c0 | 236 | for(int i=0;i<16;++i) { |
ansond | 8:f950fb1b78c0 | 237 | this->m_psk[i] = psk[i]; |
ansond | 8:f950fb1b78c0 | 238 | } |
ansond | 0:1f1f55e73248 | 239 | return *this; |
ansond | 0:1f1f55e73248 | 240 | } |
ansond | 0:1f1f55e73248 | 241 | |
ansond | 8:f950fb1b78c0 | 242 | // set 802.15.4 Pre Shared Key Identity |
ansond | 8:f950fb1b78c0 | 243 | OptionsBuilder &OptionsBuilder::setPreSharedKeyIdentity(unsigned char psk_identity[2]) |
ansond | 0:1f1f55e73248 | 244 | { |
ansond | 8:f950fb1b78c0 | 245 | memset(this->m_psk_identity,0,2); |
ansond | 8:f950fb1b78c0 | 246 | for(int i=0;i<2;++i) { |
ansond | 8:f950fb1b78c0 | 247 | this->m_psk_identity[i] = psk_identity[i]; |
ansond | 8:f950fb1b78c0 | 248 | } |
ansond | 0:1f1f55e73248 | 249 | return *this; |
ansond | 0:1f1f55e73248 | 250 | } |
ansond | 0:1f1f55e73248 | 251 | |
ansond | 9:faa43faea4ca | 252 | // set 802.15.4 Mesh Type |
ansond | 9:faa43faea4ca | 253 | OptionsBuilder &OptionsBuilder::setMeshType(MeshTypes mesh_type) |
ansond | 9:faa43faea4ca | 254 | { |
ansond | 9:faa43faea4ca | 255 | this->m_mesh_type = mesh_type; |
ansond | 9:faa43faea4ca | 256 | return *this; |
ansond | 9:faa43faea4ca | 257 | } |
ansond | 9:faa43faea4ca | 258 | |
ansond | 10:3f79b5e67c22 | 259 | // set the CoAP Connection Type |
ansond | 10:3f79b5e67c22 | 260 | OptionsBuilder &OptionsBuilder::setCoAPConnectionType(CoAPConnectionTypes coap_connection_type) |
ansond | 10:3f79b5e67c22 | 261 | { |
ansond | 10:3f79b5e67c22 | 262 | this->m_coap_connection_type = coap_connection_type; |
ansond | 10:3f79b5e67c22 | 263 | return *this; |
ansond | 10:3f79b5e67c22 | 264 | } |
ansond | 10:3f79b5e67c22 | 265 | |
ansond | 10:3f79b5e67c22 | 266 | // set the IP Address Type |
ansond | 10:3f79b5e67c22 | 267 | OptionsBuilder &OptionsBuilder::setIPAddressType(IPAddressTypes ip_address_type) |
ansond | 10:3f79b5e67c22 | 268 | { |
ansond | 10:3f79b5e67c22 | 269 | this->m_ip_address_type = ip_address_type; |
ansond | 10:3f79b5e67c22 | 270 | return *this; |
ansond | 10:3f79b5e67c22 | 271 | } |
ansond | 10:3f79b5e67c22 | 272 | |
ansond | 0:1f1f55e73248 | 273 | // build out our immutable self |
ansond | 0:1f1f55e73248 | 274 | Options *OptionsBuilder::build() |
ansond | 0:1f1f55e73248 | 275 | { |
ansond | 0:1f1f55e73248 | 276 | return (Options *)this; |
ansond | 0:1f1f55e73248 | 277 | } |
ansond | 0:1f1f55e73248 | 278 | |
ansond | 0:1f1f55e73248 | 279 | // Enable/Disable immediate observationing |
ansond | 0:1f1f55e73248 | 280 | OptionsBuilder &OptionsBuilder::setImmedateObservationEnabled(bool enable) { |
ansond | 0:1f1f55e73248 | 281 | this->m_enable_immediate_observation = enable; |
ansond | 0:1f1f55e73248 | 282 | return *this; |
ansond | 0:1f1f55e73248 | 283 | } |
ansond | 0:1f1f55e73248 | 284 | |
ansond | 0:1f1f55e73248 | 285 | // Enable/Disable GET-based control of observations |
ansond | 0:1f1f55e73248 | 286 | OptionsBuilder &OptionsBuilder::setEnableGETObservationControl(bool enable) { |
ansond | 0:1f1f55e73248 | 287 | this->m_enable_get_obs_control = enable; |
ansond | 0:1f1f55e73248 | 288 | return *this; |
ansond | 0:1f1f55e73248 | 289 | } |
ansond | 0:1f1f55e73248 | 290 | |
ansond | 0:1f1f55e73248 | 291 | // set the server certificate |
ansond | 0:1f1f55e73248 | 292 | OptionsBuilder &OptionsBuilder::setServerCertificate(uint8_t cert[],int cert_size) { |
ansond | 0:1f1f55e73248 | 293 | memset(this->m_server_cert,0,MAX_SERVER_CERT_LENGTH); |
ansond | 0:1f1f55e73248 | 294 | int length = cert_size; |
ansond | 0:1f1f55e73248 | 295 | if (length > MAX_SERVER_CERT_LENGTH) { |
ansond | 0:1f1f55e73248 | 296 | length = MAX_SERVER_CERT_LENGTH; |
ansond | 0:1f1f55e73248 | 297 | DEBUG_OUT("WARNING: Truncated Server Certificate: orig: %d bytes (trunc: %d bytes)\r\n",cert_size,length); |
ansond | 0:1f1f55e73248 | 298 | } |
ansond | 0:1f1f55e73248 | 299 | memcpy(this->m_server_cert,cert,length); |
ansond | 0:1f1f55e73248 | 300 | this->m_server_cert_length = length; |
ansond | 0:1f1f55e73248 | 301 | return *this; |
ansond | 0:1f1f55e73248 | 302 | } |
ansond | 0:1f1f55e73248 | 303 | |
ansond | 0:1f1f55e73248 | 304 | // set the client certificate |
ansond | 0:1f1f55e73248 | 305 | OptionsBuilder &OptionsBuilder::setClientCertificate(uint8_t cert[],int cert_size) { |
ansond | 0:1f1f55e73248 | 306 | memset(this->m_client_cert,0,MAX_CLIENT_CERT_LENGTH); |
ansond | 0:1f1f55e73248 | 307 | int length = cert_size; |
ansond | 0:1f1f55e73248 | 308 | if (length > MAX_CLIENT_CERT_LENGTH) { |
ansond | 0:1f1f55e73248 | 309 | length = MAX_CLIENT_CERT_LENGTH; |
ansond | 0:1f1f55e73248 | 310 | DEBUG_OUT("WARNING: Truncated Client Certificate: orig: %d bytes (trunc: %d bytes)\r\n",cert_size,length); |
ansond | 0:1f1f55e73248 | 311 | } |
ansond | 0:1f1f55e73248 | 312 | memcpy(this->m_client_cert,cert,length); |
ansond | 0:1f1f55e73248 | 313 | this->m_client_cert_length = length; |
ansond | 0:1f1f55e73248 | 314 | return *this; |
ansond | 0:1f1f55e73248 | 315 | } |
ansond | 0:1f1f55e73248 | 316 | |
ansond | 0:1f1f55e73248 | 317 | // set the client key |
ansond | 0:1f1f55e73248 | 318 | OptionsBuilder &OptionsBuilder::setClientKey(uint8_t key[],int key_size) { |
ansond | 0:1f1f55e73248 | 319 | memset(this->m_client_key,0,MAX_CLIENT_KEY_LENGTH); |
ansond | 0:1f1f55e73248 | 320 | int length = key_size; |
ansond | 0:1f1f55e73248 | 321 | if (length > MAX_CLIENT_KEY_LENGTH) { |
ansond | 0:1f1f55e73248 | 322 | length = MAX_CLIENT_KEY_LENGTH; |
ansond | 0:1f1f55e73248 | 323 | DEBUG_OUT("WARNING: Truncated Client Key: orig: %d bytes (trunc: %d bytes)\r\n",key_size,length); |
ansond | 0:1f1f55e73248 | 324 | } |
ansond | 0:1f1f55e73248 | 325 | memcpy(this->m_client_key,key,length); |
ansond | 0:1f1f55e73248 | 326 | this->m_client_key_length = length; |
ansond | 0:1f1f55e73248 | 327 | return *this; |
ansond | 0:1f1f55e73248 | 328 | } |
ansond | 0:1f1f55e73248 | 329 | |
ansond | 22:68fcdc40b397 | 330 | // set our endpoint |
ansond | 22:68fcdc40b397 | 331 | void OptionsBuilder::setEndpoint(void *endpoint) { |
ansond | 22:68fcdc40b397 | 332 | this->m_endpoint = endpoint; |
ansond | 22:68fcdc40b397 | 333 | } |
ansond | 22:68fcdc40b397 | 334 | |
ansond | 0:1f1f55e73248 | 335 | } // namespace Connector |