Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MQTTSNGateway.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 #ifndef MQTTSNGATEWAY_H_ 00017 #define MQTTSNGATEWAY_H_ 00018 00019 #include <MQTTSNGWAdapterManager.h> 00020 #include "MQTTSNGWProcess.h" 00021 #include "MQTTSNPacket.h" 00022 #include "MQTTSNGWClient.h" 00023 00024 namespace MQTTSNGW 00025 { 00026 /*================================= 00027 * Starting prompt 00028 ==================================*/ 00029 #define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway" 00030 #define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse" 00031 #define PAHO_COPYRIGHT2 " * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)" 00032 #define PAHO_COPYRIGHT3 " * Author : Tomoaki YAMAGUCHI" 00033 #define PAHO_COPYRIGHT4 " ***************************************************************************" 00034 /*========================================================== 00035 * Log Formats 00036 * 00037 * RED : \033[0m\033[1;31m 00038 * green : \033[0m\033[0;32m 00039 * yellow : \033[0m\033[0;33m 00040 * blue : \033[0m\033[0;34m 00041 * white : \033[0m\033[0;37m 00042 ===========================================================*/ 00043 #define CLIENT "Client" 00044 #define CLIENTS "Clients" 00045 #define UNKNOWNCL "Unknown Client !" 00046 00047 #define LEFTARROW "<---" 00048 #define RIGHTARROW "--->" 00049 #define LEFTARROWB "<===" 00050 #define RIGHTARROWB "===>" 00051 00052 #define FORMAT_Y_G_G_NL "\n%s \033[0m\033[0;33m%-18s\033[0m\033[0;32m%-6s%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00053 #define FORMAT_Y_G_G "%s \033[0m\033[0;33m%-18s\033[0m\033[0;32m%-6s%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00054 #define FORMAT_Y_Y_G "%s \033[0m\033[0;33m%-18s%-6s\033[0m\033[0;32m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00055 #define FORMAT_Y_W_G "%s \033[0m\033[0;33m%-18s\033[0m\033[0;37m%-6s\033[0m\033[0;32m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00056 #define FORMAT_Y_Y_W "%s \033[0m\033[0;33m%-18s%-6s\033[0m\033[0;37m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00057 00058 #define FORMAT_G_MSGID_G_G_NL "\n%s \033[0m\033[0;32m%-11s%-5s %-6s%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00059 #define FORMAT_G_MSGID_G_G "%s \033[0m\033[0;32m%-11s%-5s %-6s%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00060 #define FORMAT_G_MSGID_W_G "%s \033[0m\033[0;32m%-11s%-5s \033[0m\033[0;37m%-6s\033[0m\033[0;32m%-34.32 s\033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00061 #define FORMAT_G_MSGID_Y_W "%s \033[0m\033[0;32m%-11s%-5s \033[0m\033[0;33m%-6s\033[0m\033[0;37m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00062 00063 #define FORMAT_W_MSGID_Y_W_NL "\n%s %-11s%-5s \033[0m\033[0;33m%-6s\033[0m\033[0;37m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00064 #define FORMAT_W_MSGID_Y_W "%s %-11s%-5s \033[0m\033[0;33m%-6s\033[0m\033[0;37m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00065 #define FORMAT_W_MSGID_W_G "%s %-11s%-5s %-6s\033[0m\033[0;32m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00066 #define FORMAT_W_MSGID_G_G "%s %-11s%-5s \033[0m\033[0;32m%-6s%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n" 00067 00068 #define FORMAT_BL_NL "\n%s \033[0m\033[0;34m%-18s%-6s%-34.32s %s\033[0m\033[0;37m\n" 00069 #define FORMAT_W_NL "\n%s %-18s%-6s%-34.32s %s\n" 00070 00071 #define ERRMSG_HEADER "\033[0m\033[0;31mError:" 00072 #define ERRMSG_FOOTER "\033[0m\033[0;37m" 00073 00074 /*===================================== 00075 Class Event 00076 ====================================*/ 00077 class Client; 00078 00079 enum EventType{ 00080 Et_NA = 0, 00081 EtStop, 00082 EtTimeout, 00083 EtBrokerRecv, 00084 EtBrokerSend, 00085 EtClientRecv, 00086 EtClientSend, 00087 EtBroadcast, 00088 EtSensornetSend 00089 }; 00090 00091 00092 class Event{ 00093 public: 00094 Event(); 00095 ~Event(); 00096 EventType getEventType(void); 00097 void setClientRecvEvent(Client*, MQTTSNPacket*); 00098 void setClientSendEvent(Client*, MQTTSNPacket*); 00099 void setBrokerRecvEvent(Client*, MQTTGWPacket*); 00100 void setBrokerSendEvent(Client*, MQTTGWPacket*); 00101 void setBrodcastEvent(MQTTSNPacket*); // ADVERTISE and GWINFO 00102 void setTimeout(void); // Required by EventQue<Event>.timedwait() 00103 void setStop(void); 00104 void setClientSendEvent(SensorNetAddress*, MQTTSNPacket*); 00105 Client* getClient(void); 00106 SensorNetAddress* getSensorNetAddress(void); 00107 MQTTSNPacket* getMQTTSNPacket(void); 00108 MQTTGWPacket* getMQTTGWPacket(void); 00109 00110 private: 00111 EventType _eventType {Et_NA}; 00112 Client* _client {nullptr}; 00113 SensorNetAddress* _sensorNetAddr {nullptr}; 00114 MQTTSNPacket* _mqttSNPacket {nullptr}; 00115 MQTTGWPacket* _mqttGWPacket {nullptr}; 00116 }; 00117 00118 00119 /*===================================== 00120 Class EventQue 00121 ====================================*/ 00122 class EventQue 00123 { 00124 public: 00125 EventQue(); 00126 ~EventQue(); 00127 Event* wait(void); 00128 Event* timedwait(uint16_t millsec); 00129 void setMaxSize(uint16_t maxSize); 00130 void post(Event*); 00131 int size(); 00132 00133 private: 00134 Que<Event> _que; 00135 Mutex _mutex; 00136 Semaphore _sem; 00137 }; 00138 00139 00140 00141 /*===================================== 00142 Class GatewayParams 00143 ====================================*/ 00144 class GatewayParams 00145 { 00146 public: 00147 string configDir; 00148 char* configName {nullptr}; 00149 char* clientListName {nullptr}; 00150 char* loginId {nullptr}; 00151 char* password {nullptr}; 00152 uint16_t keepAlive {0}; 00153 uint8_t gatewayId {0}; 00154 uint8_t mqttVersion {0}; 00155 uint16_t maxInflightMsgs {0}; 00156 char* gatewayName {nullptr}; 00157 char* brokerName {nullptr}; 00158 char* port {nullptr}; 00159 char* portSecure {nullptr}; 00160 char* rootCApath {nullptr}; 00161 char* rootCAfile {nullptr}; 00162 char* certKey {nullptr}; 00163 char* privateKey {nullptr}; 00164 char* predefinedTopicFileName {nullptr}; 00165 char* qosMinusClientListName {nullptr}; 00166 bool clientAuthentication {false}; 00167 }; 00168 00169 00170 00171 /*===================================== 00172 Class Gateway 00173 =====================================*/ 00174 class AdapterManager; 00175 class ClientList; 00176 00177 class Gateway: public MultiTaskProcess{ 00178 public: 00179 Gateway(void); 00180 ~Gateway(); 00181 virtual void initialize(int argc, char** argv); 00182 void run(void); 00183 00184 EventQue* getPacketEventQue(void); 00185 EventQue* getClientSendQue(void); 00186 EventQue* getBrokerSendQue(void); 00187 ClientList* getClientList(void); 00188 SensorNetwork* getSensorNetwork(void); 00189 LightIndicator* getLightIndicator(void); 00190 GatewayParams* getGWParams(void); 00191 AdapterManager* getAdapterManager(void); 00192 int getParam(const char* parameter, char* value); 00193 bool hasSecureConnection(void); 00194 Topics* getTopics(void); 00195 00196 private: 00197 GatewayParams _params; 00198 ClientList* _clientList {nullptr}; 00199 EventQue _packetEventQue; 00200 EventQue _brokerSendQue; 00201 EventQue _clientSendQue; 00202 LightIndicator _lightIndicator; 00203 SensorNetwork _sensorNetwork; 00204 AdapterManager* _adapterManager {nullptr}; 00205 Topics* _topics; 00206 }; 00207 00208 } 00209 00210 #endif /* MQTTSNGATEWAY_H_ */
Generated on Wed Jul 13 2022 10:46:02 by
1.7.2