removed stop command, initialize thread
This commit is contained in:
@@ -316,7 +316,7 @@ public:
|
|||||||
const unsigned int transferLatency, const unsigned int busAcquireTimeout, const unsigned int slaveRecvTimeout,
|
const unsigned int transferLatency, const unsigned int busAcquireTimeout, const unsigned int slaveRecvTimeout,
|
||||||
const unsigned int lockCount, const bool generateSyn,
|
const unsigned int lockCount, const bool generateSyn,
|
||||||
const unsigned int pollInterval)
|
const unsigned int pollInterval)
|
||||||
: m_device(device), m_messages(messages),
|
: WaitThread(), m_device(device), m_messages(messages),
|
||||||
m_ownMasterAddress(ownAddress), m_ownSlaveAddress((unsigned char)(ownAddress+5)), m_answer(answer),
|
m_ownMasterAddress(ownAddress), m_ownSlaveAddress((unsigned char)(ownAddress+5)), m_answer(answer),
|
||||||
m_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries),
|
m_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries),
|
||||||
m_transferLatency(transferLatency), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout),
|
m_transferLatency(transferLatency), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout),
|
||||||
|
|||||||
+6
-19
@@ -42,7 +42,7 @@ static const char* columnNames[] = {
|
|||||||
static const size_t columnCount = sizeof(columnNames) / sizeof(char*);
|
static const size_t columnCount = sizeof(columnNames) / sizeof(char*);
|
||||||
|
|
||||||
MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* messages)
|
MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* messages)
|
||||||
: m_device(device), m_messages(messages), m_address(opt.address), m_scanConfig(opt.scanConfig), m_initialScan(opt.initialScan), m_enableHex(opt.enableHex)
|
: Thread(), m_device(device), m_messages(messages), m_address(opt.address), m_scanConfig(opt.scanConfig), m_initialScan(opt.initialScan), m_enableHex(opt.enableHex)
|
||||||
{
|
{
|
||||||
// setup Device
|
// setup Device
|
||||||
m_device->setLogRaw(opt.logRaw);
|
m_device->setLogRaw(opt.logRaw);
|
||||||
@@ -80,6 +80,7 @@ MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* message
|
|||||||
|
|
||||||
MainLoop::~MainLoop()
|
MainLoop::~MainLoop()
|
||||||
{
|
{
|
||||||
|
join();
|
||||||
if (m_network != NULL) {
|
if (m_network != NULL) {
|
||||||
delete m_network;
|
delete m_network;
|
||||||
m_network = NULL;
|
m_network = NULL;
|
||||||
@@ -96,14 +97,14 @@ MainLoop::~MainLoop()
|
|||||||
|
|
||||||
void MainLoop::run()
|
void MainLoop::run()
|
||||||
{
|
{
|
||||||
bool running = true, reload = true;
|
bool reload = true;
|
||||||
time_t lastTaskRun, now;
|
time_t lastTaskRun, now;
|
||||||
int taskDelay = 5;
|
int taskDelay = 5;
|
||||||
unsigned char lastScanAddress = 0; // 0 is known to be a master
|
unsigned char lastScanAddress = 0; // 0 is known to be a master
|
||||||
time(&now);
|
time(&now);
|
||||||
lastTaskRun = now;
|
lastTaskRun = now;
|
||||||
|
|
||||||
while (running) {
|
while (true) {
|
||||||
string result;
|
string result;
|
||||||
|
|
||||||
// pick the next message to handle
|
// pick the next message to handle
|
||||||
@@ -189,7 +190,7 @@ void MainLoop::run()
|
|||||||
bool connected = true;
|
bool connected = true;
|
||||||
if (request.length() > 0) {
|
if (request.length() > 0) {
|
||||||
logDebug(lf_main, ">>> %s", request.c_str());
|
logDebug(lf_main, ">>> %s", request.c_str());
|
||||||
result = decodeMessage(request, message->isHttp(), connected, listening, running, reload);
|
result = decodeMessage(request, message->isHttp(), connected, listening, reload);
|
||||||
|
|
||||||
if (result.length() == 0 && !message->isHttp())
|
if (result.length() == 0 && !message->isHttp())
|
||||||
result = getResultCode(RESULT_EMPTY);
|
result = getResultCode(RESULT_EMPTY);
|
||||||
@@ -213,7 +214,7 @@ void MainLoop::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& connected, bool& listening, bool& running, bool& reload)
|
string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& connected, bool& listening, bool& reload)
|
||||||
{
|
{
|
||||||
ostringstream result;
|
ostringstream result;
|
||||||
|
|
||||||
@@ -301,8 +302,6 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn
|
|||||||
reload = true;
|
reload = true;
|
||||||
return executeReload(args);
|
return executeReload(args);
|
||||||
}
|
}
|
||||||
if (strcasecmp(str, "STOP") == 0)
|
|
||||||
return executeStop(args, running);
|
|
||||||
if (strcasecmp(str, "Q") == 0 || strcasecmp(str, "QUIT") == 0)
|
if (strcasecmp(str, "Q") == 0 || strcasecmp(str, "QUIT") == 0)
|
||||||
return executeQuit(args, connected);
|
return executeQuit(args, connected);
|
||||||
if (strcasecmp(str, "I") == 0 || strcasecmp(str, "INFO") == 0)
|
if (strcasecmp(str, "I") == 0 || strcasecmp(str, "INFO") == 0)
|
||||||
@@ -1148,17 +1147,6 @@ string MainLoop::executeReload(vector<string> &args)
|
|||||||
return getResultCode(result);
|
return getResultCode(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
string MainLoop::executeStop(vector<string> &args, bool& running)
|
|
||||||
{
|
|
||||||
if (args.size() == 1) {
|
|
||||||
running = false;
|
|
||||||
return "daemon stopped";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "usage: stop\n"
|
|
||||||
" Stop the daemon.";
|
|
||||||
}
|
|
||||||
|
|
||||||
string MainLoop::executeInfo(vector<string> &args)
|
string MainLoop::executeInfo(vector<string> &args)
|
||||||
{
|
{
|
||||||
if (args.size() == 0)
|
if (args.size() == 0)
|
||||||
@@ -1212,7 +1200,6 @@ string MainLoop::executeHelp()
|
|||||||
" raw Toggle logging raw bytes\n"
|
" raw Toggle logging raw bytes\n"
|
||||||
" dump Toggle dumping raw bytes\n"
|
" dump Toggle dumping raw bytes\n"
|
||||||
" reload Reload CSV config files\n"
|
" reload Reload CSV config files\n"
|
||||||
" stop Stop the daemon\n"
|
|
||||||
" quit|q Close connection\n"
|
" quit|q Close connection\n"
|
||||||
" help|h Print help help [COMMAND]";
|
" help|h Print help help [COMMAND]";
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-10
@@ -96,11 +96,10 @@ private:
|
|||||||
* @param connected set to false when the client connection shall be closed.
|
* @param connected set to false when the client connection shall be closed.
|
||||||
* @param isHttp true for HTTP message.
|
* @param isHttp true for HTTP message.
|
||||||
* @param listening set to true when the client is in listening mode.
|
* @param listening set to true when the client is in listening mode.
|
||||||
* @param running set to false when the server shall be stopped.
|
|
||||||
* @param reload set to true when the configuration files were reloaded.
|
* @param reload set to true when the configuration files were reloaded.
|
||||||
* @return result string to send back to the client.
|
* @return result string to send back to the client.
|
||||||
*/
|
*/
|
||||||
string decodeMessage(const string& data, const bool isHttp, bool& connected, bool& listening, bool& running, bool& reload);
|
string decodeMessage(const string& data, const bool isHttp, bool& connected, bool& listening, bool& reload);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the hex master message from the remaining arguments.
|
* Parse the hex master message from the remaining arguments.
|
||||||
@@ -205,14 +204,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
string executeReload(vector<string> &args);
|
string executeReload(vector<string> &args);
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the stop command.
|
|
||||||
* @param args the arguments passed to the command (starting with the command itself), or empty for help.
|
|
||||||
* @param running set to false when the server shall be stopped.
|
|
||||||
* @return the result string.
|
|
||||||
*/
|
|
||||||
string executeStop(vector<string> &args, bool& running);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the info command.
|
* Execute the info command.
|
||||||
* @param args the arguments passed to the command (starting with the command itself), or empty for help.
|
* @param args the arguments passed to the command (starting with the command itself), or empty for help.
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ void Connection::run()
|
|||||||
|
|
||||||
|
|
||||||
Network::Network(const bool local, const uint16_t port, const uint16_t httpPort, Queue<NetMessage*>* netQueue)
|
Network::Network(const bool local, const uint16_t port, const uint16_t httpPort, Queue<NetMessage*>* netQueue)
|
||||||
: m_netQueue(netQueue), m_listening(false)
|
: Thread(), m_netQueue(netQueue), m_listening(false)
|
||||||
{
|
{
|
||||||
if (local)
|
if (local)
|
||||||
m_tcpServer = new TCPServer(port, "127.0.0.1");
|
m_tcpServer = new TCPServer(port, "127.0.0.1");
|
||||||
|
|||||||
+1
-1
@@ -215,7 +215,7 @@ public:
|
|||||||
* @param netQueue the reference to the @a NetMessage @a Queue.
|
* @param netQueue the reference to the @a NetMessage @a Queue.
|
||||||
*/
|
*/
|
||||||
Connection(TCPSocket* socket, const bool isHttp, Queue<NetMessage*>* netQueue)
|
Connection(TCPSocket* socket, const bool isHttp, Queue<NetMessage*>* netQueue)
|
||||||
: m_isHttp(isHttp), m_socket(socket), m_netQueue(netQueue)
|
: Thread(), m_isHttp(isHttp), m_socket(socket), m_netQueue(netQueue)
|
||||||
{ m_id = ++m_ids; }
|
{ m_id = ++m_ids; }
|
||||||
|
|
||||||
virtual ~Connection() { if (m_socket) delete m_socket; }
|
virtual ~Connection() { if (m_socket) delete m_socket; }
|
||||||
|
|||||||
Reference in New Issue
Block a user