removed stop command, initialize thread

This commit is contained in:
john30
2016-10-16 12:21:31 +02:00
parent 72c4d5a3a0
commit 3683ef6a51
5 changed files with 10 additions and 32 deletions
+1 -1
View File
@@ -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),
+6 -19
View File
@@ -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<string> &args)
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)
{
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]";
}
+1 -10
View File
@@ -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<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.
* @param args the arguments passed to the command (starting with the command itself), or empty for help.
+1 -1
View File
@@ -152,7 +152,7 @@ void Connection::run()
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)
m_tcpServer = new TCPServer(port, "127.0.0.1");
+1 -1
View File
@@ -215,7 +215,7 @@ public:
* @param netQueue the reference to the @a NetMessage @a Queue.
*/
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; }
virtual ~Connection() { if (m_socket) delete m_socket; }