A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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 #ifndef M2M_INTERFACE_IMPL_H
ram54288 0:a7a43371b306 17 #define M2M_INTERFACE_IMPL_H
ram54288 0:a7a43371b306 18
ram54288 0:a7a43371b306 19 #include "mbed-client/m2minterface.h"
ram54288 0:a7a43371b306 20 #include "mbed-client/m2mserver.h"
ram54288 0:a7a43371b306 21 #include "mbed-client/m2mconnectionobserver.h"
ram54288 0:a7a43371b306 22 #include "mbed-client/m2mconnectionsecurity.h"
ram54288 0:a7a43371b306 23 #include "include/m2mnsdlobserver.h"
ram54288 0:a7a43371b306 24 #include "include/m2mnsdlinterface.h"
ram54288 0:a7a43371b306 25 #include "mbed-client/m2mtimerobserver.h"
ram54288 0:a7a43371b306 26 #include "mbed-client/m2mtimer.h"
ram54288 0:a7a43371b306 27 #include "mbed-client/m2mconnectionhandler.h"
ram54288 0:a7a43371b306 28
ram54288 0:a7a43371b306 29 //FORWARD DECLARATION
ram54288 0:a7a43371b306 30 class M2MConnectionSecurity;
ram54288 0:a7a43371b306 31 class EventData;
ram54288 0:a7a43371b306 32 class M2MUpdateRegisterData;
ram54288 0:a7a43371b306 33 /**
ram54288 0:a7a43371b306 34 * @brief M2MInterfaceImpl.
ram54288 0:a7a43371b306 35 * This class implements handling of all mbed Client Interface operations
ram54288 0:a7a43371b306 36 * defined in OMA LWM2M specifications.
ram54288 0:a7a43371b306 37 * This includes Bootstrapping, Client Registration, Device Management &
ram54288 0:a7a43371b306 38 * Service Enablement and Information Reporting.
ram54288 0:a7a43371b306 39 */
ram54288 0:a7a43371b306 40
ram54288 0:a7a43371b306 41 class M2MInterfaceImpl : public M2MInterface,
ram54288 0:a7a43371b306 42 public M2MNsdlObserver,
ram54288 0:a7a43371b306 43 public M2MConnectionObserver,
ram54288 0:a7a43371b306 44 public M2MTimerObserver
ram54288 0:a7a43371b306 45 {
ram54288 0:a7a43371b306 46 private:
ram54288 0:a7a43371b306 47 // Prevents the use of assignment operator by accident.
ram54288 0:a7a43371b306 48 M2MInterfaceImpl& operator=( const M2MInterfaceImpl& /*other*/ );
ram54288 0:a7a43371b306 49
ram54288 0:a7a43371b306 50 // Prevents the use of copy constructor by accident
ram54288 0:a7a43371b306 51 M2MInterfaceImpl( const M2MInterfaceImpl& /*other*/ );
ram54288 0:a7a43371b306 52
ram54288 0:a7a43371b306 53 friend class M2MInterfaceFactory;
ram54288 0:a7a43371b306 54
ram54288 0:a7a43371b306 55 private:
ram54288 0:a7a43371b306 56
ram54288 0:a7a43371b306 57 /**
ram54288 0:a7a43371b306 58 * @brief Constructor
ram54288 0:a7a43371b306 59 * @param observer, Observer to pass the event callbacks for various
ram54288 0:a7a43371b306 60 * interface operations.
ram54288 0:a7a43371b306 61 * @param endpoint_name Endpoint name of the client.
ram54288 0:a7a43371b306 62 * @param endpoint_type Endpoint type of the client.
ram54288 0:a7a43371b306 63 * @param life_time Life time of the client in seconds
ram54288 0:a7a43371b306 64 * @param listen_port Listening port for the endpoint, default is 8000.
ram54288 0:a7a43371b306 65 * @param domain Domain of the client.
ram54288 0:a7a43371b306 66 * @param mode Binding mode of the client, default is UDP
ram54288 0:a7a43371b306 67 * @param stack Network stack to be used for connection, default is LwIP_IPv4.
ram54288 0:a7a43371b306 68 * @param context_address Context address, default is empty.
ram54288 0:a7a43371b306 69 */
ram54288 0:a7a43371b306 70 M2MInterfaceImpl(M2MInterfaceObserver& observer,
ram54288 0:a7a43371b306 71 const String &endpoint_name,
ram54288 0:a7a43371b306 72 const String &endpoint_type,
ram54288 0:a7a43371b306 73 const int32_t life_time,
ram54288 0:a7a43371b306 74 const uint16_t listen_port,
ram54288 0:a7a43371b306 75 const String &domain = "",
ram54288 0:a7a43371b306 76 BindingMode mode = M2MInterface::NOT_SET,
ram54288 0:a7a43371b306 77 M2MInterface::NetworkStack stack = M2MInterface::LwIP_IPv4,
ram54288 0:a7a43371b306 78 const String &context_address = "");
ram54288 0:a7a43371b306 79
ram54288 0:a7a43371b306 80 public:
ram54288 0:a7a43371b306 81
ram54288 0:a7a43371b306 82 /**
ram54288 0:a7a43371b306 83 * @brief Destructor
ram54288 0:a7a43371b306 84 */
ram54288 0:a7a43371b306 85 virtual ~M2MInterfaceImpl();
ram54288 0:a7a43371b306 86
ram54288 0:a7a43371b306 87 /**
ram54288 0:a7a43371b306 88 * @brief Initiates bootstrapping of the client with the provided Bootstrap
ram54288 0:a7a43371b306 89 * server information.
ram54288 0:a7a43371b306 90 * @param security_object Security object which contains information
ram54288 0:a7a43371b306 91 * required for successful bootstrapping of the client.
ram54288 0:a7a43371b306 92 */
ram54288 0:a7a43371b306 93 virtual void bootstrap(M2MSecurity *security);
ram54288 0:a7a43371b306 94
ram54288 0:a7a43371b306 95 /**
ram54288 0:a7a43371b306 96 * @brief Cancels on going bootstrapping operation of the client. If the client has
ram54288 0:a7a43371b306 97 * already successfully bootstrapped then this function deletes existing
ram54288 0:a7a43371b306 98 * bootstrap information from the client.
ram54288 0:a7a43371b306 99 */
ram54288 0:a7a43371b306 100 virtual void cancel_bootstrap();
ram54288 0:a7a43371b306 101
ram54288 0:a7a43371b306 102 /**
ram54288 0:a7a43371b306 103 * @brief Initiates registration of the provided Security object to the
ram54288 0:a7a43371b306 104 * corresponding LWM2M server.
ram54288 0:a7a43371b306 105 * @param security_object Security object which contains information
ram54288 0:a7a43371b306 106 * required for registering to the LWM2M server.
ram54288 0:a7a43371b306 107 * If client wants to register to multiple LWM2M servers then it has call
ram54288 0:a7a43371b306 108 * this function once for each of LWM2M server object separately.
ram54288 0:a7a43371b306 109 * @param object_list Objects which contains information
ram54288 0:a7a43371b306 110 * which the client want to register to the LWM2M server.
ram54288 0:a7a43371b306 111 */
ram54288 0:a7a43371b306 112 virtual void register_object(M2MSecurity *security_object, const M2MObjectList &object_list);
ram54288 0:a7a43371b306 113
ram54288 0:a7a43371b306 114 /**
ram54288 0:a7a43371b306 115 * @brief Updates or refreshes the client's registration on the LWM2M
ram54288 0:a7a43371b306 116 * server.
ram54288 0:a7a43371b306 117 * @param security_object Security object from which the device object
ram54288 0:a7a43371b306 118 * needs to update registration, if there is only one LWM2M server registered
ram54288 0:a7a43371b306 119 * then this parameter can be NULL.
ram54288 0:a7a43371b306 120 * @param lifetime Lifetime for the endpoint client in seconds.
ram54288 0:a7a43371b306 121 */
ram54288 0:a7a43371b306 122 virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime = 0);
ram54288 0:a7a43371b306 123
ram54288 0:a7a43371b306 124 /**
ram54288 0:a7a43371b306 125 * @brief Updates or refreshes the client's registration on the LWM2M
ram54288 0:a7a43371b306 126 * server. Use this function to publish new objects to LWM2M server.
ram54288 0:a7a43371b306 127 * @param security_object The security object from which the device object
ram54288 0:a7a43371b306 128 * needs to update the registration. If there is only one LWM2M server registered,
ram54288 0:a7a43371b306 129 * this parameter can be NULL.
ram54288 0:a7a43371b306 130 * @param object_list Objects that contain information about the
ram54288 0:a7a43371b306 131 * client attempting to register to the LWM2M server.
ram54288 0:a7a43371b306 132 * @param lifetime The lifetime of the endpoint client in seconds. If the same value
ram54288 0:a7a43371b306 133 * has to be passed, set the default value to 0.
ram54288 0:a7a43371b306 134 */
ram54288 0:a7a43371b306 135 virtual void update_registration(M2MSecurity *security_object, const M2MObjectList &object_list,
ram54288 0:a7a43371b306 136 const uint32_t lifetime = 0);
ram54288 0:a7a43371b306 137
ram54288 0:a7a43371b306 138 /**
ram54288 0:a7a43371b306 139 * @brief Unregisters the registered object from the LWM2M server
ram54288 0:a7a43371b306 140 * @param security_object Security object from which the device object
ram54288 0:a7a43371b306 141 * needs to be unregistered. If there is only one LWM2M server registered
ram54288 0:a7a43371b306 142 * this parameter can be NULL.
ram54288 0:a7a43371b306 143 */
ram54288 0:a7a43371b306 144 virtual void unregister_object(M2MSecurity* security = NULL);
ram54288 0:a7a43371b306 145
ram54288 0:a7a43371b306 146 /**
ram54288 0:a7a43371b306 147 * @brief Sets the function which will be called indicating client
ram54288 0:a7a43371b306 148 * is going to sleep when the Binding mode is selected with Queue mode.
ram54288 0:a7a43371b306 149 * @param callback A function pointer that will be called when client
ram54288 0:a7a43371b306 150 * goes to sleep.
ram54288 0:a7a43371b306 151 */
ram54288 0:a7a43371b306 152 virtual void set_queue_sleep_handler(callback_handler handler);
ram54288 0:a7a43371b306 153
ram54288 0:a7a43371b306 154 /**
ram54288 0:a7a43371b306 155 * @brief Sets the network interface handler that is used by client to connect
ram54288 0:a7a43371b306 156 * to a network over IP.
ram54288 0:a7a43371b306 157 * @param handler A network interface handler that is used by client to connect.
ram54288 0:a7a43371b306 158 * This API is optional but provides a mechanism for different platforms to
ram54288 0:a7a43371b306 159 * manage usage of underlying network interface by client.
ram54288 0:a7a43371b306 160 */
ram54288 0:a7a43371b306 161 virtual void set_platform_network_handler(void *handler = NULL);
ram54288 0:a7a43371b306 162
ram54288 0:a7a43371b306 163 /**
ram54288 0:a7a43371b306 164 * \brief Sets the function callback that will be called by mbed-client for
ram54288 0:a7a43371b306 165 * fetching random number from application for ensuring strong entropy.
ram54288 0:a7a43371b306 166 * \param random_callback A function pointer that will be called by mbed-client
ram54288 0:a7a43371b306 167 * while performing secure handshake.
ram54288 0:a7a43371b306 168 * Function signature should be uint32_t (*random_number_callback)(void);
ram54288 0:a7a43371b306 169 */
ram54288 0:a7a43371b306 170 virtual void set_random_number_callback(random_number_cb callback);
ram54288 0:a7a43371b306 171
ram54288 0:a7a43371b306 172 /**
ram54288 0:a7a43371b306 173 * \brief Sets the function callback that will be called by mbed-client for
ram54288 0:a7a43371b306 174 * providing entropy source from application for ensuring strong entropy.
ram54288 0:a7a43371b306 175 * \param entropy_callback A function pointer that will be called by mbed-client
ram54288 0:a7a43371b306 176 * while performing secure handshake.
ram54288 0:a7a43371b306 177 * Function signature , if using mbed-client-mbedtls should be
ram54288 0:a7a43371b306 178 * int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output,
ram54288 0:a7a43371b306 179 * size_t len, size_t *olen);
ram54288 0:a7a43371b306 180 */
ram54288 0:a7a43371b306 181 virtual void set_entropy_callback(entropy_cb callback);
ram54288 0:a7a43371b306 182
ram54288 0:a7a43371b306 183
ram54288 0:a7a43371b306 184 protected: // From M2MNsdlObserver
ram54288 0:a7a43371b306 185
ram54288 0:a7a43371b306 186 virtual void coap_message_ready(uint8_t *data_ptr,
ram54288 0:a7a43371b306 187 uint16_t data_len,
ram54288 0:a7a43371b306 188 sn_nsdl_addr_s *address_ptr);
ram54288 0:a7a43371b306 189
ram54288 0:a7a43371b306 190 virtual void client_registered(M2MServer *server_object);
ram54288 0:a7a43371b306 191
ram54288 0:a7a43371b306 192 virtual void registration_updated(const M2MServer &server_object);
ram54288 0:a7a43371b306 193
ram54288 0:a7a43371b306 194 virtual void registration_error(uint8_t error_code, bool retry = false);
ram54288 0:a7a43371b306 195
ram54288 0:a7a43371b306 196 virtual void client_unregistered();
ram54288 0:a7a43371b306 197
ram54288 0:a7a43371b306 198 virtual void bootstrap_done(M2MSecurity *security_object);
ram54288 0:a7a43371b306 199
ram54288 0:a7a43371b306 200 virtual void bootstrap_wait(M2MSecurity *security_object);
ram54288 0:a7a43371b306 201
ram54288 0:a7a43371b306 202 virtual void bootstrap_error();
ram54288 0:a7a43371b306 203
ram54288 0:a7a43371b306 204 virtual void coap_data_processed();
ram54288 0:a7a43371b306 205
ram54288 0:a7a43371b306 206 virtual void value_updated(M2MBase *base);
ram54288 0:a7a43371b306 207
ram54288 0:a7a43371b306 208 protected: // From M2MConnectionObserver
ram54288 0:a7a43371b306 209
ram54288 0:a7a43371b306 210 virtual void data_available(uint8_t* data,
ram54288 0:a7a43371b306 211 uint16_t data_size,
ram54288 0:a7a43371b306 212 const M2MConnectionObserver::SocketAddress &address);
ram54288 0:a7a43371b306 213
ram54288 0:a7a43371b306 214 virtual void socket_error(uint8_t error_code, bool retry = true);
ram54288 0:a7a43371b306 215
ram54288 0:a7a43371b306 216 virtual void address_ready(const M2MConnectionObserver::SocketAddress &address,
ram54288 0:a7a43371b306 217 M2MConnectionObserver::ServerType server_type,
ram54288 0:a7a43371b306 218 const uint16_t server_port);
ram54288 0:a7a43371b306 219
ram54288 0:a7a43371b306 220 virtual void data_sent();
ram54288 0:a7a43371b306 221
ram54288 0:a7a43371b306 222 protected: // from M2MTimerObserver
ram54288 0:a7a43371b306 223
ram54288 0:a7a43371b306 224 virtual void timer_expired(M2MTimerObserver::Type type);
ram54288 0:a7a43371b306 225
ram54288 0:a7a43371b306 226
ram54288 0:a7a43371b306 227 private: // state machine state functions
ram54288 0:a7a43371b306 228
ram54288 0:a7a43371b306 229 /**
ram54288 0:a7a43371b306 230 * When the state is Idle.
ram54288 0:a7a43371b306 231 */
ram54288 0:a7a43371b306 232 void state_idle(EventData* data);
ram54288 0:a7a43371b306 233
ram54288 0:a7a43371b306 234 /**
ram54288 0:a7a43371b306 235 * When the client starts bootstrap.
ram54288 0:a7a43371b306 236 */
ram54288 0:a7a43371b306 237 void state_bootstrap( EventData *data);
ram54288 0:a7a43371b306 238
ram54288 0:a7a43371b306 239 /**
ram54288 0:a7a43371b306 240 * When the bootstrap server address is resolved.
ram54288 0:a7a43371b306 241 */
ram54288 0:a7a43371b306 242 void state_bootstrap_address_resolved( EventData *data);
ram54288 0:a7a43371b306 243
ram54288 0:a7a43371b306 244 /**
ram54288 0:a7a43371b306 245 * When the bootstrap resource is created.
ram54288 0:a7a43371b306 246 */
ram54288 0:a7a43371b306 247 void state_bootstrap_resource_created( EventData *data);
ram54288 0:a7a43371b306 248
ram54288 0:a7a43371b306 249 /**
ram54288 0:a7a43371b306 250 * When the server has sent response and bootstrapping is done.
ram54288 0:a7a43371b306 251 */
ram54288 0:a7a43371b306 252 void state_bootstrapped( EventData *data);
ram54288 0:a7a43371b306 253
ram54288 0:a7a43371b306 254 /**
ram54288 0:a7a43371b306 255 * When the client starts register.
ram54288 0:a7a43371b306 256 */
ram54288 0:a7a43371b306 257 void state_register( EventData *data);
ram54288 0:a7a43371b306 258
ram54288 0:a7a43371b306 259 /**
ram54288 0:a7a43371b306 260 * When the server address for register is resolved.
ram54288 0:a7a43371b306 261 */
ram54288 0:a7a43371b306 262 void state_register_address_resolved( EventData *data);
ram54288 0:a7a43371b306 263
ram54288 0:a7a43371b306 264 /**
ram54288 0:a7a43371b306 265 * When the client is registered.
ram54288 0:a7a43371b306 266 */
ram54288 0:a7a43371b306 267 void state_registered( EventData *data);
ram54288 0:a7a43371b306 268
ram54288 0:a7a43371b306 269 /**
ram54288 0:a7a43371b306 270 * When the client is updating registration.
ram54288 0:a7a43371b306 271 */
ram54288 0:a7a43371b306 272 void state_update_registration( EventData *data);
ram54288 0:a7a43371b306 273
ram54288 0:a7a43371b306 274 /**
ram54288 0:a7a43371b306 275 * When the client starts unregister.
ram54288 0:a7a43371b306 276 */
ram54288 0:a7a43371b306 277 void state_unregister( EventData *data);
ram54288 0:a7a43371b306 278
ram54288 0:a7a43371b306 279 /**
ram54288 0:a7a43371b306 280 * When the client has been unregistered.
ram54288 0:a7a43371b306 281 */
ram54288 0:a7a43371b306 282 void state_unregistered( EventData *data);
ram54288 0:a7a43371b306 283
ram54288 0:a7a43371b306 284 /**
ram54288 0:a7a43371b306 285 * When the coap data is been sent through socket.
ram54288 0:a7a43371b306 286 */
ram54288 0:a7a43371b306 287 void state_sending_coap_data( EventData *data);
ram54288 0:a7a43371b306 288
ram54288 0:a7a43371b306 289 /**
ram54288 0:a7a43371b306 290 * When the coap data is sent successfully.
ram54288 0:a7a43371b306 291 */
ram54288 0:a7a43371b306 292 void state_coap_data_sent( EventData *data);
ram54288 0:a7a43371b306 293
ram54288 0:a7a43371b306 294 /**
ram54288 0:a7a43371b306 295 * When the socket is receiving coap data.
ram54288 0:a7a43371b306 296 */
ram54288 0:a7a43371b306 297 void state_receiving_coap_data( EventData *data);
ram54288 0:a7a43371b306 298
ram54288 0:a7a43371b306 299 /**
ram54288 0:a7a43371b306 300 * When the socket has received coap data.
ram54288 0:a7a43371b306 301 */
ram54288 0:a7a43371b306 302 void state_coap_data_received( EventData *data);
ram54288 0:a7a43371b306 303
ram54288 0:a7a43371b306 304 /**
ram54288 0:a7a43371b306 305 * When the coap message is being processed.
ram54288 0:a7a43371b306 306 */
ram54288 0:a7a43371b306 307 void state_processing_coap_data( EventData *data);
ram54288 0:a7a43371b306 308
ram54288 0:a7a43371b306 309 /**
ram54288 0:a7a43371b306 310 * When the coap message has been processed.
ram54288 0:a7a43371b306 311 */
ram54288 0:a7a43371b306 312 void state_coap_data_processed( EventData *data);
ram54288 0:a7a43371b306 313
ram54288 0:a7a43371b306 314 /**
ram54288 0:a7a43371b306 315 * When the client is waiting to receive or send data.
ram54288 0:a7a43371b306 316 */
ram54288 0:a7a43371b306 317 void state_waiting( EventData *data);
ram54288 0:a7a43371b306 318
ram54288 0:a7a43371b306 319 /**
ram54288 0:a7a43371b306 320 * Start registration update.
ram54288 0:a7a43371b306 321 */
ram54288 0:a7a43371b306 322 void start_register_update(M2MUpdateRegisterData *data);
ram54288 0:a7a43371b306 323
ram54288 0:a7a43371b306 324 /**
ram54288 0:a7a43371b306 325 * State enumeration order must match the order of state
ram54288 0:a7a43371b306 326 * method entries in the state map
ram54288 0:a7a43371b306 327 */
ram54288 0:a7a43371b306 328 enum E_States {
ram54288 0:a7a43371b306 329 STATE_IDLE = 0,
ram54288 0:a7a43371b306 330 STATE_BOOTSTRAP,
ram54288 0:a7a43371b306 331 STATE_BOOTSTRAP_ADDRESS_RESOLVED,
ram54288 0:a7a43371b306 332 STATE_BOOTSTRAP_RESOURCE_CREATED,
ram54288 0:a7a43371b306 333 STATE_BOOTSTRAP_WAIT,
ram54288 0:a7a43371b306 334 STATE_BOOTSTRAPPED, //5
ram54288 0:a7a43371b306 335 STATE_REGISTER,
ram54288 0:a7a43371b306 336 STATE_REGISTER_ADDRESS_RESOLVED,
ram54288 0:a7a43371b306 337 STATE_REGISTERED,
ram54288 0:a7a43371b306 338 STATE_UPDATE_REGISTRATION,
ram54288 0:a7a43371b306 339 STATE_UNREGISTER, //10
ram54288 0:a7a43371b306 340 STATE_UNREGISTERED,
ram54288 0:a7a43371b306 341 STATE_SENDING_COAP_DATA,
ram54288 0:a7a43371b306 342 STATE_COAP_DATA_SENT,
ram54288 0:a7a43371b306 343 STATE_COAP_DATA_RECEIVED,
ram54288 0:a7a43371b306 344 STATE_PROCESSING_COAP_DATA, //15
ram54288 0:a7a43371b306 345 STATE_COAP_DATA_PROCESSED,
ram54288 0:a7a43371b306 346 STATE_WAITING,
ram54288 0:a7a43371b306 347 STATE_MAX_STATES
ram54288 0:a7a43371b306 348 };
ram54288 0:a7a43371b306 349
ram54288 0:a7a43371b306 350 /**
ram54288 0:a7a43371b306 351 * @brief Redirects the state machine to right function.
ram54288 0:a7a43371b306 352 * @param current_state Current state to be set.
ram54288 0:a7a43371b306 353 * @param data Data to be passed to the state function.
ram54288 0:a7a43371b306 354 */
ram54288 0:a7a43371b306 355 void state_function( uint8_t current_state, EventData* data );
ram54288 0:a7a43371b306 356
ram54288 0:a7a43371b306 357 /**
ram54288 0:a7a43371b306 358 * @brief State Engine maintaining state machine logic.
ram54288 0:a7a43371b306 359 */
ram54288 0:a7a43371b306 360 void state_engine(void);
ram54288 0:a7a43371b306 361
ram54288 0:a7a43371b306 362 /**
ram54288 0:a7a43371b306 363 * External event which can trigger the state machine.
ram54288 0:a7a43371b306 364 * @param New The state to which the state machine should go.
ram54288 0:a7a43371b306 365 * @param data The data to be passed to the state machine.
ram54288 0:a7a43371b306 366 */
ram54288 0:a7a43371b306 367 void external_event(uint8_t, EventData* = NULL);
ram54288 0:a7a43371b306 368
ram54288 0:a7a43371b306 369 /**
ram54288 0:a7a43371b306 370 * Internal event generated by state machine.
ram54288 0:a7a43371b306 371 * @param New State which the state machine should go to.
ram54288 0:a7a43371b306 372 * @param data The data to be passed to the state machine.
ram54288 0:a7a43371b306 373 */
ram54288 0:a7a43371b306 374 void internal_event(uint8_t, EventData* = NULL);
ram54288 0:a7a43371b306 375
ram54288 0:a7a43371b306 376 enum
ram54288 0:a7a43371b306 377 {
ram54288 0:a7a43371b306 378 EVENT_IGNORED = 0xFE,
ram54288 0:a7a43371b306 379 CANNOT_HAPPEN
ram54288 0:a7a43371b306 380 };
ram54288 0:a7a43371b306 381
ram54288 0:a7a43371b306 382 /**
ram54288 0:a7a43371b306 383 * Helper method for extracting the IP address part and port from the
ram54288 0:a7a43371b306 384 * given server address.
ram54288 0:a7a43371b306 385 * @param server_address Source URL (without "coap" or "coaps" prefix).
ram54288 0:a7a43371b306 386 * @param ip_address The extracted IP.
ram54288 0:a7a43371b306 387 * @param port The extracted port.
ram54288 0:a7a43371b306 388 */
ram54288 0:a7a43371b306 389 static void process_address(const String& server_address, String& ip_address, uint16_t& port);
ram54288 0:a7a43371b306 390
ram54288 0:a7a43371b306 391 private:
ram54288 0:a7a43371b306 392
ram54288 0:a7a43371b306 393 EventData *_event_data;
ram54288 0:a7a43371b306 394 M2MTimer *_bootstrap_timer;
ram54288 0:a7a43371b306 395 uint16_t _server_port;
ram54288 0:a7a43371b306 396 uint16_t _listen_port;
ram54288 0:a7a43371b306 397 String _endpoint_type;
ram54288 0:a7a43371b306 398 String _domain;
ram54288 0:a7a43371b306 399 int32_t _life_time;
ram54288 0:a7a43371b306 400 String _context_address;
ram54288 0:a7a43371b306 401 String _server_ip_address;
ram54288 0:a7a43371b306 402 M2MSecurity *_register_server; //TODO: to be the list not owned
ram54288 0:a7a43371b306 403 M2MTimer _queue_sleep_timer;
ram54288 0:a7a43371b306 404 M2MTimer _retry_timer;
ram54288 0:a7a43371b306 405 callback_handler _callback_handler;
ram54288 0:a7a43371b306 406 const uint8_t _max_states;
ram54288 0:a7a43371b306 407 bool _event_ignored;
ram54288 0:a7a43371b306 408 bool _event_generated;
ram54288 0:a7a43371b306 409 bool _reconnecting;
ram54288 0:a7a43371b306 410 bool _retry_timer_expired;
ram54288 0:a7a43371b306 411 bool _bootstrapped;
ram54288 0:a7a43371b306 412 uint8_t _current_state;
ram54288 0:a7a43371b306 413 uint8_t _retry_count;
ram54288 0:a7a43371b306 414 BindingMode _binding_mode;
ram54288 0:a7a43371b306 415 M2MInterfaceObserver &_observer;
ram54288 0:a7a43371b306 416 M2MConnectionSecurity *_security_connection; // Doesn't own
ram54288 0:a7a43371b306 417 M2MConnectionHandler _connection_handler;
ram54288 0:a7a43371b306 418 M2MNsdlInterface _nsdl_interface;
ram54288 0:a7a43371b306 419 M2MSecurity *_security;
ram54288 0:a7a43371b306 420
ram54288 0:a7a43371b306 421 friend class Test_M2MInterfaceImpl;
ram54288 0:a7a43371b306 422
ram54288 0:a7a43371b306 423 };
ram54288 0:a7a43371b306 424
ram54288 0:a7a43371b306 425 #define BEGIN_TRANSITION_MAP \
ram54288 0:a7a43371b306 426 static const uint8_t TRANSITIONS[] = {\
ram54288 0:a7a43371b306 427
ram54288 0:a7a43371b306 428 #define TRANSITION_MAP_ENTRY(entry)\
ram54288 0:a7a43371b306 429 entry,
ram54288 0:a7a43371b306 430
ram54288 0:a7a43371b306 431 #define END_TRANSITION_MAP(data) \
ram54288 0:a7a43371b306 432 0 };\
ram54288 0:a7a43371b306 433 external_event(TRANSITIONS[_current_state], data);
ram54288 0:a7a43371b306 434
ram54288 0:a7a43371b306 435 #endif //M2M_INTERFACE_IMPL_H
ram54288 0:a7a43371b306 436
ram54288 0:a7a43371b306 437