Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mconnectionobserver.h Source File

m2mconnectionobserver.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef M2M_CONNECTION_OBSERVER_H__
00017 #define M2M_CONNECTION_OBSERVER_H__
00018 
00019 #include "mbed-client/m2minterface.h"
00020 
00021 /*! \file m2mconnectionobserver.h
00022  * \brief M2MConnectionObserver.
00023  * The observer class for passing the socket activity to the state machine.
00024  */
00025 
00026 class M2MConnectionObserver
00027 {
00028 
00029 public :
00030 
00031     /**
00032       * \enum ServerType, Defines the type of the
00033       * server that the client wants to use.
00034       */
00035     typedef enum {
00036         Bootstrap,
00037         LWM2MServer
00038     }ServerType;
00039 
00040     /**
00041      * \brief The M2MSocketAddress struct.
00042      * A unified container for holding socket address data
00043      * across different platforms.
00044      */
00045     struct SocketAddress{
00046         M2MInterface::NetworkStack  _stack;
00047         void                        *_address;
00048         uint8_t                     _length;
00049         uint16_t                    _port;
00050     };
00051 
00052     /**
00053     * \brief Indicates that data is available from socket.
00054     * \param data The data read from the socket.
00055     * \param data_size The length of the data read from the socket.
00056     * \param address The address of the server where the data is coming from.
00057     */
00058     virtual void data_available(uint8_t* data,
00059                                 uint16_t data_size,
00060                                 const M2MConnectionObserver::SocketAddress &address) = 0;
00061 
00062     /**
00063     * \brief Indicates an error occured in socket.
00064     * \param error_code The error code from socket, it cannot be used any further.
00065     * \param retry Indicates whether to re-establish the connection.
00066     */
00067     virtual void socket_error(uint8_t error_code, bool retry = true) = 0;
00068 
00069     /**
00070     * \brief Indicates that the server address resolving is ready.
00071     * \param address The resolved socket address.
00072     * \param server_type The type of the server.
00073     * \param server_port The port of the resolved server address.
00074     */
00075     virtual void address_ready(const M2MConnectionObserver::SocketAddress &address,
00076                                M2MConnectionObserver::ServerType server_type,
00077                                const uint16_t server_port) = 0;
00078 
00079     /**
00080     * \brief Indicates that data has been sent successfully.
00081     */
00082     virtual void data_sent() = 0;
00083 };
00084 
00085 #endif // M2M_CONNECTION_OBSERVER_H__