mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 15:36:51 +01:00
Update: config file is a command line parameter.
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <Timer.h>
|
#include <Timer.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <getopt.h>
|
||||||
#include "MQTTSNGWProcess.h"
|
#include "MQTTSNGWProcess.h"
|
||||||
#include "Threading.h"
|
#include "Threading.h"
|
||||||
|
|
||||||
@@ -74,6 +75,18 @@ void Process::initialize(int argc, char** argv)
|
|||||||
signal(SIGINT, signalHandler);
|
signal(SIGINT, signalHandler);
|
||||||
signal(SIGTERM, signalHandler);
|
signal(SIGTERM, signalHandler);
|
||||||
signal(SIGHUP, signalHandler);
|
signal(SIGHUP, signalHandler);
|
||||||
|
|
||||||
|
_configFile = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_CONFIG_FILE);
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
while ((opt = getopt(_argc, _argv, "f:")) != -1)
|
||||||
|
{
|
||||||
|
if ( opt == 'f' )
|
||||||
|
{
|
||||||
|
_configFile = string(optarg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WRITELOG("Using config file:[%s]\n", _configFile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::getArgc()
|
int Process::getArgc()
|
||||||
@@ -92,13 +105,11 @@ int Process::getParam(const char* parameter, char* value)
|
|||||||
char param[MQTTSNGW_PARAM_MAX];
|
char param[MQTTSNGW_PARAM_MAX];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
string filename = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_CONFIG_FILE);
|
|
||||||
|
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
|
|
||||||
if ((fp = fopen(filename.c_str(), "r")) == NULL)
|
if ((fp = fopen(_configFile.c_str(), "r")) == NULL)
|
||||||
{
|
{
|
||||||
WRITELOG("No config file:[%s]\n", filename.c_str());
|
WRITELOG("No config file:[%s]\n", _configFile.c_str());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
int _argc;
|
int _argc;
|
||||||
char** _argv;
|
char** _argv;
|
||||||
|
string _configFile;
|
||||||
RingBuffer* _rb;
|
RingBuffer* _rb;
|
||||||
Semaphore* _rbsem;
|
Semaphore* _rbsem;
|
||||||
Mutex _mt;
|
Mutex _mt;
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ Gateway::~Gateway()
|
|||||||
void Gateway::initialize(int argc, char** argv)
|
void Gateway::initialize(int argc, char** argv)
|
||||||
{
|
{
|
||||||
char param[MQTTSNGW_PARAM_MAX];
|
char param[MQTTSNGW_PARAM_MAX];
|
||||||
|
MultiTaskProcess::initialize(argc, argv);
|
||||||
|
|
||||||
_params.gatewayId = 0;
|
_params.gatewayId = 0;
|
||||||
if (getParam("GatewayID", param) == 0)
|
if (getParam("GatewayID", param) == 0)
|
||||||
@@ -113,8 +114,6 @@ void Gateway::initialize(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiTaskProcess::initialize(argc, argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gateway::run(void)
|
void Gateway::run(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user