mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 15:36:51 +01:00
Update: DISCONNECT (Issue #31) and others
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -31,6 +31,17 @@ Gateway::Gateway()
|
||||
theProcess = this;
|
||||
_params.loginId = 0;
|
||||
_params.password = 0;
|
||||
_params.keepAlive = 0;
|
||||
_params.gatewayId = 0;
|
||||
_params.mqttVersion = 0;
|
||||
_params.maxInflightMsgs = 0;
|
||||
_params.gatewayName = 0;
|
||||
_params.brokerName = 0;
|
||||
_params.port = 0;
|
||||
_params.portSecure = 0;
|
||||
_params.rootCApath = 0;
|
||||
_params.rootCAfile = 0;
|
||||
_params.certDirectory = 0;
|
||||
_packetEventQue.setMaxSize(MAX_INFLIGHTMESSAGES * MAX_CLIENTS);
|
||||
}
|
||||
|
||||
@@ -44,15 +55,71 @@ Gateway::~Gateway()
|
||||
{
|
||||
free(_params.password);
|
||||
}
|
||||
if ( _params.gatewayName )
|
||||
{
|
||||
free(_params.gatewayName);
|
||||
}
|
||||
if ( _params.brokerName )
|
||||
{
|
||||
free(_params.brokerName);
|
||||
}
|
||||
if ( _params.port )
|
||||
{
|
||||
free(_params.port);
|
||||
}
|
||||
if ( _params.portSecure )
|
||||
{
|
||||
free(_params.portSecure);
|
||||
}
|
||||
if ( _params.rootCApath )
|
||||
{
|
||||
free(_params.rootCApath);
|
||||
}
|
||||
|
||||
if ( _params.clientListName )
|
||||
{
|
||||
free(_params.clientListName);
|
||||
}
|
||||
if ( _params.configName )
|
||||
{
|
||||
free(_params.configName);
|
||||
}
|
||||
}
|
||||
|
||||
void Gateway::initialize(int argc, char** argv)
|
||||
{
|
||||
char param[MQTTSNGW_PARAM_MAX];
|
||||
string fileName;
|
||||
MultiTaskProcess::initialize(argc, argv);
|
||||
resetRingBuffer();
|
||||
|
||||
_params.gatewayId = 0;
|
||||
|
||||
if (getParam("BrokerName", param) == 0)
|
||||
{
|
||||
_params.brokerName = strdup(param);
|
||||
}
|
||||
if (getParam("BrokerPortNo", param) == 0)
|
||||
{
|
||||
_params.port = strdup(param);
|
||||
}
|
||||
if (getParam("BrokerSecurePortNo", param) == 0)
|
||||
{
|
||||
_params.portSecure = strdup(param);
|
||||
}
|
||||
|
||||
if (getParam("CertsDirectory", param) == 0)
|
||||
{
|
||||
_params.certDirectory = strdup(param);
|
||||
}
|
||||
if (getParam("RootCApath", param) == 0)
|
||||
{
|
||||
_params.rootCApath = strdup(param);
|
||||
}
|
||||
if (getParam("RootCAfile", param) == 0)
|
||||
{
|
||||
_params.rootCAfile = strdup(param);
|
||||
}
|
||||
|
||||
if (getParam("GatewayID", param) == 0)
|
||||
{
|
||||
_params.gatewayId = atoi(param);
|
||||
@@ -65,7 +132,7 @@ void Gateway::initialize(int argc, char** argv)
|
||||
|
||||
if (getParam("GatewayName", param) == 0)
|
||||
{
|
||||
_params.gatewayName = (uint8_t*) strdup(param);
|
||||
_params.gatewayName = strdup(param);
|
||||
}
|
||||
|
||||
_params.mqttVersion = DEFAULT_MQTT_VERSION;
|
||||
@@ -94,17 +161,16 @@ void Gateway::initialize(int argc, char** argv)
|
||||
|
||||
if (getParam("LoginID", param) == 0)
|
||||
{
|
||||
_params.loginId = (uint8_t*) strdup(param);
|
||||
_params.loginId = strdup(param);
|
||||
}
|
||||
|
||||
if (getParam("Password", param) == 0)
|
||||
{
|
||||
_params.password = (uint8_t*) strdup(param);
|
||||
_params.password = strdup(param);
|
||||
}
|
||||
|
||||
if (getParam("ClientAuthentication", param) == 0)
|
||||
{
|
||||
string fileName;
|
||||
if (!strcasecmp(param, "YES"))
|
||||
{
|
||||
if (getParam("ClientsList", param) == 0)
|
||||
@@ -113,15 +179,18 @@ void Gateway::initialize(int argc, char** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
fileName = *getConfigDirName() + string(MQTTSNGW_CLIENT_LIST);
|
||||
fileName = *getConfigDirName() + string(CLIENT_LIST);
|
||||
}
|
||||
|
||||
if (!_clientList.authorize(fileName.c_str()))
|
||||
{
|
||||
throw Exception("Gateway::initialize: No client list defined by configuration.");
|
||||
}
|
||||
_params.clientListName = strdup(fileName.c_str());
|
||||
}
|
||||
}
|
||||
fileName = *getConfigDirName() + *getConfigFileName();
|
||||
_params.configName = strdup(fileName.c_str());
|
||||
}
|
||||
|
||||
void Gateway::run(void)
|
||||
@@ -134,15 +203,19 @@ void Gateway::run(void)
|
||||
WRITELOG(" *\n%s\n", PAHO_COPYRIGHT3);
|
||||
WRITELOG("%s\n", GATEWAY_VERSION);
|
||||
WRITELOG("%s\n", PAHO_COPYRIGHT4);
|
||||
WRITELOG("\n%s %s has been started.\n listening on, %s\n", currentDateTime(), _params.gatewayName, _sensorNetwork.getDescription());
|
||||
|
||||
WRITELOG("\n%s %s has been started.\n\n", currentDateTime(), _params.gatewayName);
|
||||
WRITELOG(" ConfigFile: %s\n", _params.configName);
|
||||
if ( getClientList()->isAuthorized() )
|
||||
{
|
||||
WRITELOG("\nClient authentication is required by the configuration settings.\n\n");
|
||||
WRITELOG(" ClientList: %s\n", _params.clientListName);
|
||||
}
|
||||
WRITELOG(" SensorN/W: %s\n", _sensorNetwork.getDescription());
|
||||
WRITELOG(" Broker: %s : %s, %s\n", _params.brokerName, _params.port, _params.portSecure);
|
||||
WRITELOG(" RootCApath: %s\n", _params.rootCApath);
|
||||
WRITELOG(" RootCAfile: %s\n", _params.rootCAfile);
|
||||
WRITELOG(" ClientCerts: %s\n", _params.certDirectory);
|
||||
|
||||
/* execute threads & wait StopProcessEvent MQTTSNGWPacketHandleTask posts by CTL-C */
|
||||
|
||||
/* Execute threads and wait StopProcessEvent from MQTTSNGWPacketHandleTask */
|
||||
MultiTaskProcess::run();
|
||||
WRITELOG("%s MQTT-SN Gateway stoped\n", currentDateTime());
|
||||
_lightIndicator.allLightOff();
|
||||
|
||||
Reference in New Issue
Block a user