sandbox / mbed-client

Fork of mbed-client by Christopher Haster

Committer:
Christopher Haster
Date:
Fri Jan 22 14:57:00 2016 -0600
Revision:
1:79b6cc67d8b4
Child:
5:e36098b177a4
Initial move of mbed-client to mercurial

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
Christopher Haster 1:79b6cc67d8b4 138 protected: // From M2MNsdlObserver
Christopher Haster 1:79b6cc67d8b4 139
Christopher Haster 1:79b6cc67d8b4 140 virtual void coap_message_ready(uint8_t *data_ptr,
Christopher Haster 1:79b6cc67d8b4 141 uint16_t data_len,
Christopher Haster 1:79b6cc67d8b4 142 sn_nsdl_addr_s *address_ptr);
Christopher Haster 1:79b6cc67d8b4 143
Christopher Haster 1:79b6cc67d8b4 144 virtual void client_registered(M2MServer *server_object);
Christopher Haster 1:79b6cc67d8b4 145
Christopher Haster 1:79b6cc67d8b4 146 virtual void registration_updated(const M2MServer &server_object);
Christopher Haster 1:79b6cc67d8b4 147
Christopher Haster 1:79b6cc67d8b4 148 virtual void registration_error(uint8_t error_code);
Christopher Haster 1:79b6cc67d8b4 149
Christopher Haster 1:79b6cc67d8b4 150 virtual void client_unregistered();
Christopher Haster 1:79b6cc67d8b4 151
Christopher Haster 1:79b6cc67d8b4 152 virtual void bootstrap_done(M2MSecurity *security_object);
Christopher Haster 1:79b6cc67d8b4 153
Christopher Haster 1:79b6cc67d8b4 154 virtual void bootstrap_error();
Christopher Haster 1:79b6cc67d8b4 155
Christopher Haster 1:79b6cc67d8b4 156 virtual void coap_data_processed();
Christopher Haster 1:79b6cc67d8b4 157
Christopher Haster 1:79b6cc67d8b4 158 virtual void value_updated(M2MBase *base);
Christopher Haster 1:79b6cc67d8b4 159
Christopher Haster 1:79b6cc67d8b4 160 protected: // From M2MConnectionObserver
Christopher Haster 1:79b6cc67d8b4 161
Christopher Haster 1:79b6cc67d8b4 162 virtual void data_available(uint8_t* data,
Christopher Haster 1:79b6cc67d8b4 163 uint16_t data_size,
Christopher Haster 1:79b6cc67d8b4 164 const M2MConnectionObserver::SocketAddress &address);
Christopher Haster 1:79b6cc67d8b4 165
Christopher Haster 1:79b6cc67d8b4 166 virtual void socket_error(uint8_t error_code);
Christopher Haster 1:79b6cc67d8b4 167
Christopher Haster 1:79b6cc67d8b4 168 virtual void address_ready(const M2MConnectionObserver::SocketAddress &address,
Christopher Haster 1:79b6cc67d8b4 169 M2MConnectionObserver::ServerType server_type,
Christopher Haster 1:79b6cc67d8b4 170 const uint16_t server_port);
Christopher Haster 1:79b6cc67d8b4 171
Christopher Haster 1:79b6cc67d8b4 172 virtual void data_sent();
Christopher Haster 1:79b6cc67d8b4 173
Christopher Haster 1:79b6cc67d8b4 174 protected: // from M2MTimerObserver
Christopher Haster 1:79b6cc67d8b4 175
Christopher Haster 1:79b6cc67d8b4 176 virtual void timer_expired(M2MTimerObserver::Type type);
Christopher Haster 1:79b6cc67d8b4 177
Christopher Haster 1:79b6cc67d8b4 178
Christopher Haster 1:79b6cc67d8b4 179 private: // state machine state functions
Christopher Haster 1:79b6cc67d8b4 180
Christopher Haster 1:79b6cc67d8b4 181 /**
Christopher Haster 1:79b6cc67d8b4 182 * When the state is Idle.
Christopher Haster 1:79b6cc67d8b4 183 */
Christopher Haster 1:79b6cc67d8b4 184 void state_idle(EventData* data);
Christopher Haster 1:79b6cc67d8b4 185
Christopher Haster 1:79b6cc67d8b4 186 /**
Christopher Haster 1:79b6cc67d8b4 187 * When the client starts bootstrap.
Christopher Haster 1:79b6cc67d8b4 188 */
Christopher Haster 1:79b6cc67d8b4 189 void state_bootstrap( EventData *data);
Christopher Haster 1:79b6cc67d8b4 190
Christopher Haster 1:79b6cc67d8b4 191 /**
Christopher Haster 1:79b6cc67d8b4 192 * When the bootstrap server address is resolved.
Christopher Haster 1:79b6cc67d8b4 193 */
Christopher Haster 1:79b6cc67d8b4 194 void state_bootstrap_address_resolved( EventData *data);
Christopher Haster 1:79b6cc67d8b4 195
Christopher Haster 1:79b6cc67d8b4 196 /**
Christopher Haster 1:79b6cc67d8b4 197 * When the bootstrap resource is created.
Christopher Haster 1:79b6cc67d8b4 198 */
Christopher Haster 1:79b6cc67d8b4 199 void state_bootstrap_resource_created( EventData *data);
Christopher Haster 1:79b6cc67d8b4 200
Christopher Haster 1:79b6cc67d8b4 201 /**
Christopher Haster 1:79b6cc67d8b4 202 * When the server has sent response and bootstrapping is done.
Christopher Haster 1:79b6cc67d8b4 203 */
Christopher Haster 1:79b6cc67d8b4 204 void state_bootstrapped( EventData *data);
Christopher Haster 1:79b6cc67d8b4 205
Christopher Haster 1:79b6cc67d8b4 206 /**
Christopher Haster 1:79b6cc67d8b4 207 * When the client starts register.
Christopher Haster 1:79b6cc67d8b4 208 */
Christopher Haster 1:79b6cc67d8b4 209 void state_register( EventData *data);
Christopher Haster 1:79b6cc67d8b4 210
Christopher Haster 1:79b6cc67d8b4 211 /**
Christopher Haster 1:79b6cc67d8b4 212 * When the server address for register is resolved.
Christopher Haster 1:79b6cc67d8b4 213 */
Christopher Haster 1:79b6cc67d8b4 214 void state_register_address_resolved( EventData *data);
Christopher Haster 1:79b6cc67d8b4 215
Christopher Haster 1:79b6cc67d8b4 216 /**
Christopher Haster 1:79b6cc67d8b4 217 * When the register resource is created.
Christopher Haster 1:79b6cc67d8b4 218 */
Christopher Haster 1:79b6cc67d8b4 219 void state_register_resource_created( EventData *data);
Christopher Haster 1:79b6cc67d8b4 220
Christopher Haster 1:79b6cc67d8b4 221 /**
Christopher Haster 1:79b6cc67d8b4 222 * When the client is registered.
Christopher Haster 1:79b6cc67d8b4 223 */
Christopher Haster 1:79b6cc67d8b4 224 void state_registered( EventData *data);
Christopher Haster 1:79b6cc67d8b4 225
Christopher Haster 1:79b6cc67d8b4 226 /**
Christopher Haster 1:79b6cc67d8b4 227 * When the client is updating registration.
Christopher Haster 1:79b6cc67d8b4 228 */
Christopher Haster 1:79b6cc67d8b4 229 void state_update_registration( EventData *data);
Christopher Haster 1:79b6cc67d8b4 230
Christopher Haster 1:79b6cc67d8b4 231 /**
Christopher Haster 1:79b6cc67d8b4 232 * When the client starts unregister.
Christopher Haster 1:79b6cc67d8b4 233 */
Christopher Haster 1:79b6cc67d8b4 234 void state_unregister( EventData *data);
Christopher Haster 1:79b6cc67d8b4 235
Christopher Haster 1:79b6cc67d8b4 236 /**
Christopher Haster 1:79b6cc67d8b4 237 * When the client has been unregistered.
Christopher Haster 1:79b6cc67d8b4 238 */
Christopher Haster 1:79b6cc67d8b4 239 void state_unregistered( EventData *data);
Christopher Haster 1:79b6cc67d8b4 240
Christopher Haster 1:79b6cc67d8b4 241 /**
Christopher Haster 1:79b6cc67d8b4 242 * When the coap data is been sent through socket.
Christopher Haster 1:79b6cc67d8b4 243 */
Christopher Haster 1:79b6cc67d8b4 244 void state_sending_coap_data( EventData *data);
Christopher Haster 1:79b6cc67d8b4 245
Christopher Haster 1:79b6cc67d8b4 246 /**
Christopher Haster 1:79b6cc67d8b4 247 * When the coap data is sent successfully.
Christopher Haster 1:79b6cc67d8b4 248 */
Christopher Haster 1:79b6cc67d8b4 249 void state_coap_data_sent( EventData *data);
Christopher Haster 1:79b6cc67d8b4 250
Christopher Haster 1:79b6cc67d8b4 251 /**
Christopher Haster 1:79b6cc67d8b4 252 * When the socket is receiving coap data.
Christopher Haster 1:79b6cc67d8b4 253 */
Christopher Haster 1:79b6cc67d8b4 254 void state_receiving_coap_data( EventData *data);
Christopher Haster 1:79b6cc67d8b4 255
Christopher Haster 1:79b6cc67d8b4 256 /**
Christopher Haster 1:79b6cc67d8b4 257 * When the socket has received coap data.
Christopher Haster 1:79b6cc67d8b4 258 */
Christopher Haster 1:79b6cc67d8b4 259 void state_coap_data_received( EventData *data);
Christopher Haster 1:79b6cc67d8b4 260
Christopher Haster 1:79b6cc67d8b4 261 /**
Christopher Haster 1:79b6cc67d8b4 262 * When the coap message is being processed.
Christopher Haster 1:79b6cc67d8b4 263 */
Christopher Haster 1:79b6cc67d8b4 264 void state_processing_coap_data( EventData *data);
Christopher Haster 1:79b6cc67d8b4 265
Christopher Haster 1:79b6cc67d8b4 266 /**
Christopher Haster 1:79b6cc67d8b4 267 * When the coap message has been processed.
Christopher Haster 1:79b6cc67d8b4 268 */
Christopher Haster 1:79b6cc67d8b4 269 void state_coap_data_processed( EventData *data);
Christopher Haster 1:79b6cc67d8b4 270
Christopher Haster 1:79b6cc67d8b4 271 /**
Christopher Haster 1:79b6cc67d8b4 272 * When the client is waiting to receive or send data.
Christopher Haster 1:79b6cc67d8b4 273 */
Christopher Haster 1:79b6cc67d8b4 274 void state_waiting( EventData *data);
Christopher Haster 1:79b6cc67d8b4 275
Christopher Haster 1:79b6cc67d8b4 276 /**
Christopher Haster 1:79b6cc67d8b4 277 * State enumeration order must match the order of state
Christopher Haster 1:79b6cc67d8b4 278 * method entries in the state map
Christopher Haster 1:79b6cc67d8b4 279 */
Christopher Haster 1:79b6cc67d8b4 280 enum E_States {
Christopher Haster 1:79b6cc67d8b4 281 STATE_IDLE = 0,
Christopher Haster 1:79b6cc67d8b4 282 STATE_BOOTSTRAP,
Christopher Haster 1:79b6cc67d8b4 283 STATE_BOOTSTRAP_ADDRESS_RESOLVED,
Christopher Haster 1:79b6cc67d8b4 284 STATE_BOOTSTRAP_RESOURCE_CREATED,
Christopher Haster 1:79b6cc67d8b4 285 STATE_BOOTSTRAPPED,
Christopher Haster 1:79b6cc67d8b4 286 STATE_REGISTER, //5
Christopher Haster 1:79b6cc67d8b4 287 STATE_REGISTER_ADDRESS_RESOLVED,
Christopher Haster 1:79b6cc67d8b4 288 STATE_REGISTER_RESOURCE_CREATED,
Christopher Haster 1:79b6cc67d8b4 289 STATE_REGISTERED,
Christopher Haster 1:79b6cc67d8b4 290 STATE_UPDATE_REGISTRATION,
Christopher Haster 1:79b6cc67d8b4 291 STATE_UNREGISTER, //10
Christopher Haster 1:79b6cc67d8b4 292 STATE_UNREGISTERED,
Christopher Haster 1:79b6cc67d8b4 293 STATE_SENDING_COAP_DATA,
Christopher Haster 1:79b6cc67d8b4 294 STATE_COAP_DATA_SENT,
Christopher Haster 1:79b6cc67d8b4 295 STATE_COAP_DATA_RECEIVED,
Christopher Haster 1:79b6cc67d8b4 296 STATE_PROCESSING_COAP_DATA, //15
Christopher Haster 1:79b6cc67d8b4 297 STATE_COAP_DATA_PROCESSED,
Christopher Haster 1:79b6cc67d8b4 298 STATE_WAITING,
Christopher Haster 1:79b6cc67d8b4 299 STATE_MAX_STATES
Christopher Haster 1:79b6cc67d8b4 300 };
Christopher Haster 1:79b6cc67d8b4 301
Christopher Haster 1:79b6cc67d8b4 302 /**
Christopher Haster 1:79b6cc67d8b4 303 * @brief Redirects the state machine to right function.
Christopher Haster 1:79b6cc67d8b4 304 * @param current_state Current state to be set.
Christopher Haster 1:79b6cc67d8b4 305 * @param data, Data to be passed to the state function.
Christopher Haster 1:79b6cc67d8b4 306 */
Christopher Haster 1:79b6cc67d8b4 307 void state_function( uint8_t current_state, EventData* data );
Christopher Haster 1:79b6cc67d8b4 308
Christopher Haster 1:79b6cc67d8b4 309 /**
Christopher Haster 1:79b6cc67d8b4 310 * @brief State Engine maintaining state machine logic.
Christopher Haster 1:79b6cc67d8b4 311 */
Christopher Haster 1:79b6cc67d8b4 312 void state_engine(void);
Christopher Haster 1:79b6cc67d8b4 313
Christopher Haster 1:79b6cc67d8b4 314 /**
Christopher Haster 1:79b6cc67d8b4 315 * External event which can trigger the state machine.
Christopher Haster 1:79b6cc67d8b4 316 * @param New State which the state machine should go to.
Christopher Haster 1:79b6cc67d8b4 317 * @param data to be passed to the state machine.
Christopher Haster 1:79b6cc67d8b4 318 */
Christopher Haster 1:79b6cc67d8b4 319 void external_event(uint8_t, EventData* = NULL);
Christopher Haster 1:79b6cc67d8b4 320
Christopher Haster 1:79b6cc67d8b4 321 /**
Christopher Haster 1:79b6cc67d8b4 322 * Internal event generated by state machine.
Christopher Haster 1:79b6cc67d8b4 323 * @param New State which the state machine should go to.
Christopher Haster 1:79b6cc67d8b4 324 * @param data to be passed to the state machine.
Christopher Haster 1:79b6cc67d8b4 325 */
Christopher Haster 1:79b6cc67d8b4 326 void internal_event(uint8_t, EventData* = NULL);
Christopher Haster 1:79b6cc67d8b4 327
Christopher Haster 1:79b6cc67d8b4 328 enum
Christopher Haster 1:79b6cc67d8b4 329 {
Christopher Haster 1:79b6cc67d8b4 330 EVENT_IGNORED = 0xFE,
Christopher Haster 1:79b6cc67d8b4 331 CANNOT_HAPPEN
Christopher Haster 1:79b6cc67d8b4 332 };
Christopher Haster 1:79b6cc67d8b4 333
Christopher Haster 1:79b6cc67d8b4 334 private:
Christopher Haster 1:79b6cc67d8b4 335
Christopher Haster 1:79b6cc67d8b4 336 M2MInterfaceObserver &_observer;
Christopher Haster 1:79b6cc67d8b4 337 M2MConnectionHandler *_connection_handler;
Christopher Haster 1:79b6cc67d8b4 338 M2MNsdlInterface *_nsdl_interface;
Christopher Haster 1:79b6cc67d8b4 339 uint8_t _current_state;
Christopher Haster 1:79b6cc67d8b4 340 const int _max_states;
Christopher Haster 1:79b6cc67d8b4 341 bool _event_generated;
Christopher Haster 1:79b6cc67d8b4 342 EventData *_event_data;
Christopher Haster 1:79b6cc67d8b4 343
Christopher Haster 1:79b6cc67d8b4 344 String _endpoint_name;
Christopher Haster 1:79b6cc67d8b4 345 String _endpoint_type;
Christopher Haster 1:79b6cc67d8b4 346 String _domain;
Christopher Haster 1:79b6cc67d8b4 347 int32_t _life_time;
Christopher Haster 1:79b6cc67d8b4 348 BindingMode _binding_mode;
Christopher Haster 1:79b6cc67d8b4 349 String _context_address;
Christopher Haster 1:79b6cc67d8b4 350 uint16_t _listen_port;
Christopher Haster 1:79b6cc67d8b4 351 M2MSecurity *_register_server; //TODO: to be the list not owned
Christopher Haster 1:79b6cc67d8b4 352 bool _event_ignored;
Christopher Haster 1:79b6cc67d8b4 353 bool _register_ongoing;
Christopher Haster 1:79b6cc67d8b4 354 bool _update_register_ongoing;
Christopher Haster 1:79b6cc67d8b4 355 M2MTimer *_queue_sleep_timer;
Christopher Haster 1:79b6cc67d8b4 356 callback_handler _callback_handler;
Christopher Haster 1:79b6cc67d8b4 357
Christopher Haster 1:79b6cc67d8b4 358 friend class Test_M2MInterfaceImpl;
Christopher Haster 1:79b6cc67d8b4 359
Christopher Haster 1:79b6cc67d8b4 360 };
Christopher Haster 1:79b6cc67d8b4 361
Christopher Haster 1:79b6cc67d8b4 362 #define BEGIN_TRANSITION_MAP \
Christopher Haster 1:79b6cc67d8b4 363 static const uint8_t TRANSITIONS[] = {\
Christopher Haster 1:79b6cc67d8b4 364
Christopher Haster 1:79b6cc67d8b4 365 #define TRANSITION_MAP_ENTRY(entry)\
Christopher Haster 1:79b6cc67d8b4 366 entry,
Christopher Haster 1:79b6cc67d8b4 367
Christopher Haster 1:79b6cc67d8b4 368 #define END_TRANSITION_MAP(data) \
Christopher Haster 1:79b6cc67d8b4 369 0 };\
Christopher Haster 1:79b6cc67d8b4 370 external_event(TRANSITIONS[_current_state], data);
Christopher Haster 1:79b6cc67d8b4 371
Christopher Haster 1:79b6cc67d8b4 372 #endif //M2M_INTERFACE_IMPL_H
Christopher Haster 1:79b6cc67d8b4 373
Christopher Haster 1:79b6cc67d8b4 374