diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index e3d9aead..983e9bcd 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -316,7 +316,7 @@ public: const unsigned int transferLatency, const unsigned int busAcquireTimeout, const unsigned int slaveRecvTimeout, const unsigned int lockCount, const bool generateSyn, 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_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries), m_transferLatency(transferLatency), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout), diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index d427acbf..38a2b295 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -42,7 +42,7 @@ static const char* columnNames[] = { static const size_t columnCount = sizeof(columnNames) / sizeof(char*); 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 m_device->setLogRaw(opt.logRaw); @@ -80,6 +80,7 @@ MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* message MainLoop::~MainLoop() { + join(); if (m_network != NULL) { delete m_network; m_network = NULL; @@ -96,14 +97,14 @@ MainLoop::~MainLoop() void MainLoop::run() { - bool running = true, reload = true; + bool reload = true; time_t lastTaskRun, now; int taskDelay = 5; unsigned char lastScanAddress = 0; // 0 is known to be a master time(&now); lastTaskRun = now; - while (running) { + while (true) { string result; // pick the next message to handle @@ -189,7 +190,7 @@ void MainLoop::run() bool connected = true; if (request.length() > 0) { 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()) 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; @@ -301,8 +302,6 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn reload = true; return executeReload(args); } - if (strcasecmp(str, "STOP") == 0) - return executeStop(args, running); if (strcasecmp(str, "Q") == 0 || strcasecmp(str, "QUIT") == 0) return executeQuit(args, connected); if (strcasecmp(str, "I") == 0 || strcasecmp(str, "INFO") == 0) @@ -1148,17 +1147,6 @@ string MainLoop::executeReload(vector &args) return getResultCode(result); } -string MainLoop::executeStop(vector &args, bool& running) -{ - if (args.size() == 1) { - running = false; - return "daemon stopped"; - } - - return "usage: stop\n" - " Stop the daemon."; -} - string MainLoop::executeInfo(vector &args) { if (args.size() == 0) @@ -1212,7 +1200,6 @@ string MainLoop::executeHelp() " raw Toggle logging raw bytes\n" " dump Toggle dumping raw bytes\n" " reload Reload CSV config files\n" - " stop Stop the daemon\n" " quit|q Close connection\n" " help|h Print help help [COMMAND]"; } diff --git a/src/ebusd/mainloop.h b/src/ebusd/mainloop.h index 34c2efa1..373df072 100644 --- a/src/ebusd/mainloop.h +++ b/src/ebusd/mainloop.h @@ -96,11 +96,10 @@ private: * @param connected set to false when the client connection shall be closed. * @param isHttp true for HTTP message. * @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. * @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. @@ -205,14 +204,6 @@ private: */ string executeReload(vector &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 &args, bool& running); - /** * Execute the info command. * @param args the arguments passed to the command (starting with the command itself), or empty for help. diff --git a/src/ebusd/network.cpp b/src/ebusd/network.cpp index 7d586c6f..b37f99bf 100644 --- a/src/ebusd/network.cpp +++ b/src/ebusd/network.cpp @@ -152,7 +152,7 @@ void Connection::run() Network::Network(const bool local, const uint16_t port, const uint16_t httpPort, Queue* netQueue) - : m_netQueue(netQueue), m_listening(false) + : Thread(), m_netQueue(netQueue), m_listening(false) { if (local) m_tcpServer = new TCPServer(port, "127.0.0.1"); diff --git a/src/ebusd/network.h b/src/ebusd/network.h index 20bd63bc..84367dc9 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -215,7 +215,7 @@ public: * @param netQueue the reference to the @a NetMessage @a Queue. */ Connection(TCPSocket* socket, const bool isHttp, Queue* netQueue) - : m_isHttp(isHttp), m_socket(socket), m_netQueue(netQueue) + : Thread(), m_isHttp(isHttp), m_socket(socket), m_netQueue(netQueue) { m_id = ++m_ids; } virtual ~Connection() { if (m_socket) delete m_socket; }