Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTSNGWAdapter.h Source File

MQTTSNGWAdapter.h

00001 /**************************************************************************************
00002  * Copyright (c) 2016, Tomoaki Yamaguchi
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
00015  **************************************************************************************/
00016 
00017 #ifndef MQTTSNGATEWAY_SRC_MQTTSNGWADAPTER_H_
00018 #define MQTTSNGATEWAY_SRC_MQTTSNGWADAPTER_H_
00019 
00020 #include <stdint.h>
00021 #include "Timer.h"
00022 namespace MQTTSNGW
00023 {
00024 class Gateway;
00025 class Client;
00026 class Proxy;
00027 class SensorNetAddress;
00028 class MQTTSNPacket;
00029 class MQTTSNGWPacket;
00030 class EventQue;
00031 class Timer;
00032 
00033 /* When you add a new type, Client::setAdapterType() and Client::isAdapter() functions must be modified. */
00034 typedef enum{
00035     Atype_QoSm1Proxy, Atype_Aggregater
00036 }AdapterType;
00037 
00038 /*=====================================
00039      Class Adapter
00040  =====================================*/
00041 class Adapter
00042 {
00043 public:
00044     Adapter(Gateway* gw);
00045     ~Adapter(void);
00046 
00047     void setup(const char* adpterName, AdapterType adapterType);
00048     const char* getClientId(SensorNetAddress* addr);
00049     void setClient(Client* client, bool secure);
00050     Client* getClient(SensorNetAddress* addr);
00051     Client* getClient(void);
00052     Client* getSecureClient(void);
00053     Client* getAdapterClient(Client* client);
00054     void resetPingTimer(bool secure);
00055     void checkConnection(void);
00056     void send(MQTTSNPacket* packet, Client* client);
00057     bool isActive(void);
00058     bool isSecure(SensorNetAddress* addr);
00059     void savePacket(Client* client, MQTTSNPacket* packet);
00060 
00061 private:
00062     Gateway* _gateway {nullptr};
00063     Proxy* _proxy {nullptr};
00064     Proxy* _proxySecure {nullptr};
00065     Client* _client {nullptr};
00066     Client* _clientSecure {nullptr};
00067     bool _isActive {false};
00068     bool _isSecure{false};
00069 };
00070 
00071 
00072 /*=====================================
00073      Class Proxy
00074  =====================================*/
00075 class Proxy
00076 {
00077 public:
00078     Proxy(Gateway* gw);
00079     ~Proxy(void);
00080 
00081     void setKeepAlive(uint16_t secs);
00082     void checkConnection(Client* client);
00083     void resetPingTimer(void);
00084     void recv(MQTTSNPacket* packet, Client* client);
00085     void savePacket(Client* client, MQTTSNPacket* packet);
00086 
00087 private:
00088     void sendSuspendedPacket(void);
00089     Gateway* _gateway;
00090     EventQue* _suspendedPacketEventQue {nullptr};
00091     Timer  _keepAliveTimer;
00092     Timer  _responseTimer;
00093     bool   _isWaitingResp {false};
00094     int _retryCnt {0};
00095 };
00096 
00097 }
00098 
00099 #endif /* MQTTSNGATEWAY_SRC_MQTTSNGWADAPTER_H_ */