sandbox / mbed-client

Fork of mbed-client by Christopher Haster

Committer:
Yogesh Pande
Date:
Thu Apr 07 01:54:45 2016 +0300
Revision:
5:e36098b177a4
Parent:
1:79b6cc67d8b4
Adding support for passing NetworkInterface to setup sockets.
Modifying ConnectionHandler API to handle blocking socket calls with timeouts.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 1:79b6cc67d8b4 1 /*
Christopher Haster 1:79b6cc67d8b4 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
Christopher Haster 1:79b6cc67d8b4 3 * SPDX-License-Identifier: Apache-2.0
Christopher Haster 1:79b6cc67d8b4 4 * Licensed under the Apache License, Version 2.0 (the License); you may
Christopher Haster 1:79b6cc67d8b4 5 * not use this file except in compliance with the License.
Christopher Haster 1:79b6cc67d8b4 6 * You may obtain a copy of the License at
Christopher Haster 1:79b6cc67d8b4 7 *
Christopher Haster 1:79b6cc67d8b4 8 * http://www.apache.org/licenses/LICENSE-2.0
Christopher Haster 1:79b6cc67d8b4 9 *
Christopher Haster 1:79b6cc67d8b4 10 * Unless required by applicable law or agreed to in writing, software
Christopher Haster 1:79b6cc67d8b4 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
Christopher Haster 1:79b6cc67d8b4 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Christopher Haster 1:79b6cc67d8b4 13 * See the License for the specific language governing permissions and
Christopher Haster 1:79b6cc67d8b4 14 * limitations under the License.
Christopher Haster 1:79b6cc67d8b4 15 */
Christopher Haster 1:79b6cc67d8b4 16 #ifndef M2M_INTERFACE_IMPL_H
Christopher Haster 1:79b6cc67d8b4 17 #define M2M_INTERFACE_IMPL_H
Christopher Haster 1:79b6cc67d8b4 18
Christopher Haster 1:79b6cc67d8b4 19 #include "mbed-client/m2minterface.h"
Christopher Haster 1:79b6cc67d8b4 20 #include "mbed-client/m2mserver.h"
Christopher Haster 1:79b6cc67d8b4 21 #include "mbed-client/m2mconnectionobserver.h"
Christopher Haster 1:79b6cc67d8b4 22 #include "include/m2mnsdlobserver.h"
Christopher Haster 1:79b6cc67d8b4 23 #include "mbed-client/m2mtimerobserver.h"
Christopher Haster 1:79b6cc67d8b4 24
Christopher Haster 1:79b6cc67d8b4 25 //FORWARD DECLARATION
Christopher Haster 1:79b6cc67d8b4 26 class M2MNsdlInterface;
Christopher Haster 1:79b6cc67d8b4 27 class M2MConnectionHandler;
Christopher Haster 1:79b6cc67d8b4 28 class EventData;
Christopher Haster 1:79b6cc67d8b4 29 class M2MTimer;
Christopher Haster 1:79b6cc67d8b4 30
Christopher Haster 1:79b6cc67d8b4 31 /**
Christopher Haster 1:79b6cc67d8b4 32 * @brief M2MInterfaceImpl.
Christopher Haster 1:79b6cc67d8b4 33 * This class implements handling of all mbed Client Interface operations
Christopher Haster 1:79b6cc67d8b4 34 * defined in OMA LWM2M specifications.
Christopher Haster 1:79b6cc67d8b4 35 * This includes Bootstrapping, Client Registration, Device Management &
Christopher Haster 1:79b6cc67d8b4 36 * Service Enablement and Information Reporting.
Christopher Haster 1:79b6cc67d8b4 37 */
Christopher Haster 1:79b6cc67d8b4 38
Christopher Haster 1:79b6cc67d8b4 39 class M2MInterfaceImpl : public M2MInterface,
Christopher Haster 1:79b6cc67d8b4 40 public M2MNsdlObserver,
Christopher Haster 1:79b6cc67d8b4 41 public M2MConnectionObserver,
Christopher Haster 1:79b6cc67d8b4 42 public M2MTimerObserver
Christopher Haster 1:79b6cc67d8b4 43 {
Christopher Haster 1:79b6cc67d8b4 44 private:
Christopher Haster 1:79b6cc67d8b4 45 // Prevents the use of assignment operator by accident.
Christopher Haster 1:79b6cc67d8b4 46 M2MInterfaceImpl& operator=( const M2MInterfaceImpl& /*other*/ );
Christopher Haster 1:79b6cc67d8b4 47
Christopher Haster 1:79b6cc67d8b4 48 // Prevents the use of copy constructor by accident
Christopher Haster 1:79b6cc67d8b4 49 M2MInterfaceImpl( const M2MInterfaceImpl& /*other*/ );
Christopher Haster 1:79b6cc67d8b4 50
Christopher Haster 1:79b6cc67d8b4 51 friend class M2MInterfaceFactory;
Christopher Haster 1:79b6cc67d8b4 52
Christopher Haster 1:79b6cc67d8b4 53 private:
Christopher Haster 1:79b6cc67d8b4 54
Christopher Haster 1:79b6cc67d8b4 55 /**
Christopher Haster 1:79b6cc67d8b4 56 * @brief Constructor
Christopher Haster 1:79b6cc67d8b4 57 * @param observer, Observer to pass the event callbacks for various
Christopher Haster 1:79b6cc67d8b4 58 * interface operations.
Christopher Haster 1:79b6cc67d8b4 59 * @param endpoint_name, Endpoint name of the client.
Christopher Haster 1:79b6cc67d8b4 60 * @param endpoint_type, Endpoint type of the client.
Christopher Haster 1:79b6cc67d8b4 61 * @param life_time, Life time of the client in seconds
Christopher Haster 1:79b6cc67d8b4 62 * @param listen_port, Listening port for the endpoint, default is 8000.
Christopher Haster 1:79b6cc67d8b4 63 * @param domain, Domain of the client.
Christopher Haster 1:79b6cc67d8b4 64 * @param mode, Binding mode of the client, default is UDP
Christopher Haster 1:79b6cc67d8b4 65 * @param stack, Network Stack to be used for connection, default is LwIP_IPv4
Christopher Haster 1:79b6cc67d8b4 66 * @param context_address, Context address default is empty.
Christopher Haster 1:79b6cc67d8b4 67 */
Christopher Haster 1:79b6cc67d8b4 68 M2MInterfaceImpl(M2MInterfaceObserver& observer,
Christopher Haster 1:79b6cc67d8b4 69 const String &endpoint_name,
Christopher Haster 1:79b6cc67d8b4 70 const String &endpoint_type,
Christopher Haster 1:79b6cc67d8b4 71 const int32_t life_time,
Christopher Haster 1:79b6cc67d8b4 72 const uint16_t listen_port,
Christopher Haster 1:79b6cc67d8b4 73 const String &domain = "",
Christopher Haster 1:79b6cc67d8b4 74 BindingMode mode = M2MInterface::NOT_SET,
Christopher Haster 1:79b6cc67d8b4 75 M2MInterface::NetworkStack stack = M2MInterface::LwIP_IPv4,
Christopher Haster 1:79b6cc67d8b4 76 const String &context_address = "");
Christopher Haster 1:79b6cc67d8b4 77
Christopher Haster 1:79b6cc67d8b4 78 public:
Christopher Haster 1:79b6cc67d8b4 79
Christopher Haster 1:79b6cc67d8b4 80 /**
Christopher Haster 1:79b6cc67d8b4 81 * @brief Destructor
Christopher Haster 1:79b6cc67d8b4 82 */
Christopher Haster 1:79b6cc67d8b4 83 virtual ~M2MInterfaceImpl();
Christopher Haster 1:79b6cc67d8b4 84
Christopher Haster 1:79b6cc67d8b4 85 /**
Christopher Haster 1:79b6cc67d8b4 86 * @brief Initiates bootstrapping of the client with the provided Bootstrap
Christopher Haster 1:79b6cc67d8b4 87 * server information.
Christopher Haster 1:79b6cc67d8b4 88 * @param security_object, Security object which contains information
Christopher Haster 1:79b6cc67d8b4 89 * required for successful bootstrapping of the client.
Christopher Haster 1:79b6cc67d8b4 90 */
Christopher Haster 1:79b6cc67d8b4 91 virtual void bootstrap(M2MSecurity *security);
Christopher Haster 1:79b6cc67d8b4 92
Christopher Haster 1:79b6cc67d8b4 93 /**
Christopher Haster 1:79b6cc67d8b4 94 * @brief Cancels on going bootstrapping operation of the client. If the client has
Christopher Haster 1:79b6cc67d8b4 95 * already successfully bootstrapped then this function deletes existing
Christopher Haster 1:79b6cc67d8b4 96 * bootstrap information from the client.
Christopher Haster 1:79b6cc67d8b4 97 */
Christopher Haster 1:79b6cc67d8b4 98 virtual void cancel_bootstrap();
Christopher Haster 1:79b6cc67d8b4 99
Christopher Haster 1:79b6cc67d8b4 100 /**
Christopher Haster 1:79b6cc67d8b4 101 * @brief Initiates registration of the provided Security object to the
Christopher Haster 1:79b6cc67d8b4 102 * corresponding LWM2M server.
Christopher Haster 1:79b6cc67d8b4 103 * @param security_object, Security object which contains information
Christopher Haster 1:79b6cc67d8b4 104 * required for registering to the LWM2M server.
Christopher Haster 1:79b6cc67d8b4 105 * If client wants to register to multiple LWM2M servers then it has call
Christopher Haster 1:79b6cc67d8b4 106 * this function once for each of LWM2M server object separately.
Christopher Haster 1:79b6cc67d8b4 107 * @param object_list, Objects which contains information
Christopher Haster 1:79b6cc67d8b4 108 * which the client want to register to the LWM2M server.
Christopher Haster 1:79b6cc67d8b4 109 */
Christopher Haster 1:79b6cc67d8b4 110 virtual void register_object(M2MSecurity *security_object, const M2MObjectList &object_list);
Christopher Haster 1:79b6cc67d8b4 111
Christopher Haster 1:79b6cc67d8b4 112 /**
Christopher Haster 1:79b6cc67d8b4 113 * @brief Updates or refreshes the client's registration on the LWM2M
Christopher Haster 1:79b6cc67d8b4 114 * server.
Christopher Haster 1:79b6cc67d8b4 115 * @param security_object, Security object from which the device object
Christopher Haster 1:79b6cc67d8b4 116 * needs to update registration, if there is only one LWM2M server registered
Christopher Haster 1:79b6cc67d8b4 117 * then this parameter can be NULL.
Christopher Haster 1:79b6cc67d8b4 118 * @param lifetime, Lifetime for the endpoint client in seconds.
Christopher Haster 1:79b6cc67d8b4 119 */
Christopher Haster 1:79b6cc67d8b4 120 virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime = 0);
Christopher Haster 1:79b6cc67d8b4 121
Christopher Haster 1:79b6cc67d8b4 122 /**
Christopher Haster 1:79b6cc67d8b4 123 * @brief Unregisters the registered object from the LWM2M server
Christopher Haster 1:79b6cc67d8b4 124 * @param security_object, Security object from which the device object
Christopher Haster 1:79b6cc67d8b4 125 * needs to be unregistered, if there is only one LWM2M server registered
Christopher Haster 1:79b6cc67d8b4 126 * then this parameter can be NULL.
Christopher Haster 1:79b6cc67d8b4 127 */
Christopher Haster 1:79b6cc67d8b4 128 virtual void unregister_object(M2MSecurity* security = NULL);
Christopher Haster 1:79b6cc67d8b4 129
Christopher Haster 1:79b6cc67d8b4 130 /**
Christopher Haster 1:79b6cc67d8b4 131 * @brief Sets the function which will be called indicating client
Christopher Haster 1:79b6cc67d8b4 132 * is going to sleep when the Binding mode is selected with Queue mode.
Christopher Haster 1:79b6cc67d8b4 133 * @param callback, Function pointer which will be called when client
Christopher Haster 1:79b6cc67d8b4 134 * goes to seleep.
Christopher Haster 1:79b6cc67d8b4 135 */
Christopher Haster 1:79b6cc67d8b4 136 virtual void set_queue_sleep_handler(callback_handler handler);
Christopher Haster 1:79b6cc67d8b4 137
Yogesh Pande 5:e36098b177a4 138 /**
Yogesh Pande 5:e36098b177a4 139 * @brief Sets the network interface handler that is used by client to connect
Yogesh Pande 5:e36098b177a4 140 * to a network over IP..
Yogesh Pande 5:e36098b177a4 141 * @param handler A network interface handler that is used by client to connect.
Yogesh Pande 5:e36098b177a4 142 * This API is optional but provides a mechanism for different platforms to
Yogesh Pande 5:e36098b177a4 143 * manage usage of underlying network interface by client.
Yogesh Pande 5:e36098b177a4 144 */
Yogesh Pande 5:e36098b177a4 145 virtual void set_platform_network_handler(void *handler = NULL);
Yogesh Pande 5:e36098b177a4 146
Christopher Haster 1:79b6cc67d8b4 147 protected: // From M2MNsdlObserver
Christopher Haster 1:79b6cc67d8b4 148
Christopher Haster 1:79b6cc67d8b4 149 virtual void coap_message_ready(uint8_t *data_ptr,
Christopher Haster 1:79b6cc67d8b4 150 uint16_t data_len,
Christopher Haster 1:79b6cc67d8b4 151 sn_nsdl_addr_s *address_ptr);
Christopher Haster 1:79b6cc67d8b4 152
Christopher Haster 1:79b6cc67d8b4 153 virtual void client_registered(M2MServer *server_object);
Christopher Haster 1:79b6cc67d8b4 154
Christopher Haster 1:79b6cc67d8b4 155 virtual void registration_updated(const M2MServer &server_object);
Christopher Haster 1:79b6cc67d8b4 156
Christopher Haster 1:79b6cc67d8b4 157 virtual void registration_error(uint8_t error_code);
Christopher Haster 1:79b6cc67d8b4 158
Christopher Haster 1:79b6cc67d8b4 159 virtual void client_unregistered();
Christopher Haster 1:79b6cc67d8b4 160
Christopher Haster 1:79b6cc67d8b4 161 virtual void bootstrap_done(M2MSecurity *security_object);
Christopher Haster 1:79b6cc67d8b4 162
Christopher Haster 1:79b6cc67d8b4 163 virtual void bootstrap_error();
Christopher Haster 1:79b6cc67d8b4 164
Christopher Haster 1:79b6cc67d8b4 165 virtual void coap_data_processed();
Christopher Haster 1:79b6cc67d8b4 166
Christopher Haster 1:79b6cc67d8b4 167 virtual void value_updated(M2MBase *base);
Christopher Haster 1:79b6cc67d8b4 168
Christopher Haster 1:79b6cc67d8b4 169 protected: // From M2MConnectionObserver
Christopher Haster 1:79b6cc67d8b4 170
Christopher Haster 1:79b6cc67d8b4 171 virtual void data_available(uint8_t* data,
Christopher Haster 1:79b6cc67d8b4 172 uint16_t data_size,
Christopher Haster 1:79b6cc67d8b4 173 const M2MConnectionObserver::SocketAddress &address);
Christopher Haster 1:79b6cc67d8b4 174
Christopher Haster 1:79b6cc67d8b4 175 virtual void socket_error(uint8_t error_code);
Christopher Haster 1:79b6cc67d8b4 176
Christopher Haster 1:79b6cc67d8b4 177 virtual void address_ready(const M2MConnectionObserver::SocketAddress &address,
Christopher Haster 1:79b6cc67d8b4 178 M2MConnectionObserver::ServerType server_type,
Christopher Haster 1:79b6cc67d8b4 179 const uint16_t server_port);
Christopher Haster 1:79b6cc67d8b4 180
Christopher Haster 1:79b6cc67d8b4 181 virtual void data_sent();
Christopher Haster 1:79b6cc67d8b4 182
Christopher Haster 1:79b6cc67d8b4 183 protected: // from M2MTimerObserver
Christopher Haster 1:79b6cc67d8b4 184
Christopher Haster 1:79b6cc67d8b4 185 virtual void timer_expired(M2MTimerObserver::Type type);
Christopher Haster 1:79b6cc67d8b4 186
Christopher Haster 1:79b6cc67d8b4 187
Christopher Haster 1:79b6cc67d8b4 188 private: // state machine state functions
Christopher Haster 1:79b6cc67d8b4 189
Christopher Haster 1:79b6cc67d8b4 190 /**
Christopher Haster 1:79b6cc67d8b4 191 * When the state is Idle.
Christopher Haster 1:79b6cc67d8b4 192 */
Christopher Haster 1:79b6cc67d8b4 193 void state_idle(EventData* data);
Christopher Haster 1:79b6cc67d8b4 194
Christopher Haster 1:79b6cc67d8b4 195 /**
Christopher Haster 1:79b6cc67d8b4 196 * When the client starts bootstrap.
Christopher Haster 1:79b6cc67d8b4 197 */
Christopher Haster 1:79b6cc67d8b4 198 void state_bootstrap( EventData *data);
Christopher Haster 1:79b6cc67d8b4 199
Christopher Haster 1:79b6cc67d8b4 200 /**
Christopher Haster 1:79b6cc67d8b4 201 * When the bootstrap server address is resolved.
Christopher Haster 1:79b6cc67d8b4 202 */
Christopher Haster 1:79b6cc67d8b4 203 void state_bootstrap_address_resolved( EventData *data);
Christopher Haster 1:79b6cc67d8b4 204
Christopher Haster 1:79b6cc67d8b4 205 /**
Christopher Haster 1:79b6cc67d8b4 206 * When the bootstrap resource is created.
Christopher Haster 1:79b6cc67d8b4 207 */
Christopher Haster 1:79b6cc67d8b4 208 void state_bootstrap_resource_created( EventData *data);
Christopher Haster 1:79b6cc67d8b4 209
Christopher Haster 1:79b6cc67d8b4 210 /**
Christopher Haster 1:79b6cc67d8b4 211 * When the server has sent response and bootstrapping is done.
Christopher Haster 1:79b6cc67d8b4 212 */
Christopher Haster 1:79b6cc67d8b4 213 void state_bootstrapped( EventData *data);
Christopher Haster 1:79b6cc67d8b4 214
Christopher Haster 1:79b6cc67d8b4 215 /**
Christopher Haster 1:79b6cc67d8b4 216 * When the client starts register.
Christopher Haster 1:79b6cc67d8b4 217 */
Christopher Haster 1:79b6cc67d8b4 218 void state_register( EventData *data);
Christopher Haster 1:79b6cc67d8b4 219
Christopher Haster 1:79b6cc67d8b4 220 /**
Christopher Haster 1:79b6cc67d8b4 221 * When the server address for register is resolved.
Christopher Haster 1:79b6cc67d8b4 222 */
Christopher Haster 1:79b6cc67d8b4 223 void state_register_address_resolved( EventData *data);
Christopher Haster 1:79b6cc67d8b4 224
Christopher Haster 1:79b6cc67d8b4 225 /**
Christopher Haster 1:79b6cc67d8b4 226 * When the register resource is created.
Christopher Haster 1:79b6cc67d8b4 227 */
Christopher Haster 1:79b6cc67d8b4 228 void state_register_resource_created( EventData *data);
Christopher Haster 1:79b6cc67d8b4 229
Christopher Haster 1:79b6cc67d8b4 230 /**
Christopher Haster 1:79b6cc67d8b4 231 * When the client is registered.
Christopher Haster 1:79b6cc67d8b4 232 */
Christopher Haster 1:79b6cc67d8b4 233 void state_registered( EventData *data);
Christopher Haster 1:79b6cc67d8b4 234
Christopher Haster 1:79b6cc67d8b4 235 /**
Christopher Haster 1:79b6cc67d8b4 236 * When the client is updating registration.
Christopher Haster 1:79b6cc67d8b4 237 */
Christopher Haster 1:79b6cc67d8b4 238 void state_update_registration( EventData *data);
Christopher Haster 1:79b6cc67d8b4 239
Christopher Haster 1:79b6cc67d8b4 240 /**
Christopher Haster 1:79b6cc67d8b4 241 * When the client starts unregister.
Christopher Haster 1:79b6cc67d8b4 242 */
Christopher Haster 1:79b6cc67d8b4 243 void state_unregister( EventData *data);
Christopher Haster 1:79b6cc67d8b4 244
Christopher Haster 1:79b6cc67d8b4 245 /**
Christopher Haster 1:79b6cc67d8b4 246 * When the client has been unregistered.
Christopher Haster 1:79b6cc67d8b4 247 */
Christopher Haster 1:79b6cc67d8b4 248 void state_unregistered( EventData *data);
Christopher Haster 1:79b6cc67d8b4 249
Christopher Haster 1:79b6cc67d8b4 250 /**
Christopher Haster 1:79b6cc67d8b4 251 * When the coap data is been sent through socket.
Christopher Haster 1:79b6cc67d8b4 252 */
Christopher Haster 1:79b6cc67d8b4 253 void state_sending_coap_data( EventData *data);
Christopher Haster 1:79b6cc67d8b4 254
Christopher Haster 1:79b6cc67d8b4 255 /**
Christopher Haster 1:79b6cc67d8b4 256 * When the coap data is sent successfully.
Christopher Haster 1:79b6cc67d8b4 257 */
Christopher Haster 1:79b6cc67d8b4 258 void state_coap_data_sent( EventData *data);
Christopher Haster 1:79b6cc67d8b4 259
Christopher Haster 1:79b6cc67d8b4 260 /**
Christopher Haster 1:79b6cc67d8b4 261 * When the socket is receiving coap data.
Christopher Haster 1:79b6cc67d8b4 262 */
Christopher Haster 1:79b6cc67d8b4 263 void state_receiving_coap_data( EventData *data);
Christopher Haster 1:79b6cc67d8b4 264
Christopher Haster 1:79b6cc67d8b4 265 /**
Christopher Haster 1:79b6cc67d8b4 266 * When the socket has received coap data.
Christopher Haster 1:79b6cc67d8b4 267 */
Christopher Haster 1:79b6cc67d8b4 268 void state_coap_data_received( EventData *data);
Christopher Haster 1:79b6cc67d8b4 269
Christopher Haster 1:79b6cc67d8b4 270 /**
Christopher Haster 1:79b6cc67d8b4 271 * When the coap message is being processed.
Christopher Haster 1:79b6cc67d8b4 272 */
Christopher Haster 1:79b6cc67d8b4 273 void state_processing_coap_data( EventData *data);
Christopher Haster 1:79b6cc67d8b4 274
Christopher Haster 1:79b6cc67d8b4 275 /**
Christopher Haster 1:79b6cc67d8b4 276 * When the coap message has been processed.
Christopher Haster 1:79b6cc67d8b4 277 */
Christopher Haster 1:79b6cc67d8b4 278 void state_coap_data_processed( EventData *data);
Christopher Haster 1:79b6cc67d8b4 279
Christopher Haster 1:79b6cc67d8b4 280 /**
Christopher Haster 1:79b6cc67d8b4 281 * When the client is waiting to receive or send data.
Christopher Haster 1:79b6cc67d8b4 282 */
Christopher Haster 1:79b6cc67d8b4 283 void state_waiting( EventData *data);
Christopher Haster 1:79b6cc67d8b4 284
Christopher Haster 1:79b6cc67d8b4 285 /**
Christopher Haster 1:79b6cc67d8b4 286 * State enumeration order must match the order of state
Christopher Haster 1:79b6cc67d8b4 287 * method entries in the state map
Christopher Haster 1:79b6cc67d8b4 288 */
Christopher Haster 1:79b6cc67d8b4 289 enum E_States {
Christopher Haster 1:79b6cc67d8b4 290 STATE_IDLE = 0,
Christopher Haster 1:79b6cc67d8b4 291 STATE_BOOTSTRAP,
Christopher Haster 1:79b6cc67d8b4 292 STATE_BOOTSTRAP_ADDRESS_RESOLVED,
Christopher Haster 1:79b6cc67d8b4 293 STATE_BOOTSTRAP_RESOURCE_CREATED,
Christopher Haster 1:79b6cc67d8b4 294 STATE_BOOTSTRAPPED,
Christopher Haster 1:79b6cc67d8b4 295 STATE_REGISTER, //5
Christopher Haster 1:79b6cc67d8b4 296 STATE_REGISTER_ADDRESS_RESOLVED,
Christopher Haster 1:79b6cc67d8b4 297 STATE_REGISTER_RESOURCE_CREATED,
Christopher Haster 1:79b6cc67d8b4 298 STATE_REGISTERED,
Christopher Haster 1:79b6cc67d8b4 299 STATE_UPDATE_REGISTRATION,
Christopher Haster 1:79b6cc67d8b4 300 STATE_UNREGISTER, //10
Christopher Haster 1:79b6cc67d8b4 301 STATE_UNREGISTERED,
Christopher Haster 1:79b6cc67d8b4 302 STATE_SENDING_COAP_DATA,
Christopher Haster 1:79b6cc67d8b4 303 STATE_COAP_DATA_SENT,
Christopher Haster 1:79b6cc67d8b4 304 STATE_COAP_DATA_RECEIVED,
Christopher Haster 1:79b6cc67d8b4 305 STATE_PROCESSING_COAP_DATA, //15
Christopher Haster 1:79b6cc67d8b4 306 STATE_COAP_DATA_PROCESSED,
Christopher Haster 1:79b6cc67d8b4 307 STATE_WAITING,
Christopher Haster 1:79b6cc67d8b4 308 STATE_MAX_STATES
Christopher Haster 1:79b6cc67d8b4 309 };
Christopher Haster 1:79b6cc67d8b4 310
Christopher Haster 1:79b6cc67d8b4 311 /**
Christopher Haster 1:79b6cc67d8b4 312 * @brief Redirects the state machine to right function.
Christopher Haster 1:79b6cc67d8b4 313 * @param current_state Current state to be set.
Christopher Haster 1:79b6cc67d8b4 314 * @param data, Data to be passed to the state function.
Christopher Haster 1:79b6cc67d8b4 315 */
Christopher Haster 1:79b6cc67d8b4 316 void state_function( uint8_t current_state, EventData* data );
Christopher Haster 1:79b6cc67d8b4 317
Christopher Haster 1:79b6cc67d8b4 318 /**
Christopher Haster 1:79b6cc67d8b4 319 * @brief State Engine maintaining state machine logic.
Christopher Haster 1:79b6cc67d8b4 320 */
Christopher Haster 1:79b6cc67d8b4 321 void state_engine(void);
Christopher Haster 1:79b6cc67d8b4 322
Christopher Haster 1:79b6cc67d8b4 323 /**
Christopher Haster 1:79b6cc67d8b4 324 * External event which can trigger the state machine.
Christopher Haster 1:79b6cc67d8b4 325 * @param New State which the state machine should go to.
Christopher Haster 1:79b6cc67d8b4 326 * @param data to be passed to the state machine.
Christopher Haster 1:79b6cc67d8b4 327 */
Christopher Haster 1:79b6cc67d8b4 328 void external_event(uint8_t, EventData* = NULL);
Christopher Haster 1:79b6cc67d8b4 329
Christopher Haster 1:79b6cc67d8b4 330 /**
Christopher Haster 1:79b6cc67d8b4 331 * Internal event generated by state machine.
Christopher Haster 1:79b6cc67d8b4 332 * @param New State which the state machine should go to.
Christopher Haster 1:79b6cc67d8b4 333 * @param data to be passed to the state machine.
Christopher Haster 1:79b6cc67d8b4 334 */
Christopher Haster 1:79b6cc67d8b4 335 void internal_event(uint8_t, EventData* = NULL);
Christopher Haster 1:79b6cc67d8b4 336
Christopher Haster 1:79b6cc67d8b4 337 enum
Christopher Haster 1:79b6cc67d8b4 338 {
Christopher Haster 1:79b6cc67d8b4 339 EVENT_IGNORED = 0xFE,
Christopher Haster 1:79b6cc67d8b4 340 CANNOT_HAPPEN
Christopher Haster 1:79b6cc67d8b4 341 };
Christopher Haster 1:79b6cc67d8b4 342
Christopher Haster 1:79b6cc67d8b4 343 private:
Christopher Haster 1:79b6cc67d8b4 344
Christopher Haster 1:79b6cc67d8b4 345 M2MInterfaceObserver &_observer;
Christopher Haster 1:79b6cc67d8b4 346 M2MConnectionHandler *_connection_handler;
Christopher Haster 1:79b6cc67d8b4 347 M2MNsdlInterface *_nsdl_interface;
Christopher Haster 1:79b6cc67d8b4 348 uint8_t _current_state;
Christopher Haster 1:79b6cc67d8b4 349 const int _max_states;
Christopher Haster 1:79b6cc67d8b4 350 bool _event_generated;
Christopher Haster 1:79b6cc67d8b4 351 EventData *_event_data;
Christopher Haster 1:79b6cc67d8b4 352
Christopher Haster 1:79b6cc67d8b4 353 String _endpoint_name;
Christopher Haster 1:79b6cc67d8b4 354 String _endpoint_type;
Christopher Haster 1:79b6cc67d8b4 355 String _domain;
Christopher Haster 1:79b6cc67d8b4 356 int32_t _life_time;
Christopher Haster 1:79b6cc67d8b4 357 BindingMode _binding_mode;
Christopher Haster 1:79b6cc67d8b4 358 String _context_address;
Christopher Haster 1:79b6cc67d8b4 359 uint16_t _listen_port;
Christopher Haster 1:79b6cc67d8b4 360 M2MSecurity *_register_server; //TODO: to be the list not owned
Christopher Haster 1:79b6cc67d8b4 361 bool _event_ignored;
Christopher Haster 1:79b6cc67d8b4 362 bool _register_ongoing;
Christopher Haster 1:79b6cc67d8b4 363 bool _update_register_ongoing;
Christopher Haster 1:79b6cc67d8b4 364 M2MTimer *_queue_sleep_timer;
Christopher Haster 1:79b6cc67d8b4 365 callback_handler _callback_handler;
Christopher Haster 1:79b6cc67d8b4 366
Christopher Haster 1:79b6cc67d8b4 367 friend class Test_M2MInterfaceImpl;
Christopher Haster 1:79b6cc67d8b4 368
Christopher Haster 1:79b6cc67d8b4 369 };
Christopher Haster 1:79b6cc67d8b4 370
Christopher Haster 1:79b6cc67d8b4 371 #define BEGIN_TRANSITION_MAP \
Christopher Haster 1:79b6cc67d8b4 372 static const uint8_t TRANSITIONS[] = {\
Christopher Haster 1:79b6cc67d8b4 373
Christopher Haster 1:79b6cc67d8b4 374 #define TRANSITION_MAP_ENTRY(entry)\
Christopher Haster 1:79b6cc67d8b4 375 entry,
Christopher Haster 1:79b6cc67d8b4 376
Christopher Haster 1:79b6cc67d8b4 377 #define END_TRANSITION_MAP(data) \
Christopher Haster 1:79b6cc67d8b4 378 0 };\
Christopher Haster 1:79b6cc67d8b4 379 external_event(TRANSITIONS[_current_state], data);
Christopher Haster 1:79b6cc67d8b4 380
Christopher Haster 1:79b6cc67d8b4 381 #endif //M2M_INTERFACE_IMPL_H
Christopher Haster 1:79b6cc67d8b4 382
Christopher Haster 1:79b6cc67d8b4 383