class BaseLoop: config option added. (config reload implemented)

This commit is contained in:
Roland Jax
2014-10-03 12:35:15 +02:00
parent 0d02a4ba8e
commit 6e2f29d6c2
8 changed files with 71 additions and 58 deletions
+40 -37
View File
@@ -302,9 +302,9 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
}
// ToDo: check for possible areas
// ToDo: check for possible areas and level
if (strcasecmp(cmd[1].c_str(), "areas") == 0) {
L.getSink(0)->setAreas(calcArea(cmd[2]));
L.getSink(0)->setAreas(calcAreas(cmd[2]));
result << "done";
break;
}
@@ -315,53 +315,56 @@ std::string BaseLoop::decodeMessage(const std::string& data)
break;
}
result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl
<< " 'log level level' (level: error|event|trace|debug)";
break;
//~ case cfgreload:
case config:
if (cmd.size() != 2) {
result << "usage: 'config list'" << std::endl
<< " 'config reload'";
break;
}
// free CYCData
//~ if (m_cycdata != NULL) {
//~ m_cycdata->stop();
//~ delete m_cycdata;
//~ }
// ToDo: ...
if (strcasecmp(cmd[1].c_str(), "list") == 0) {
result << "done";
break;
}
// free EBusLoop
//~ if (m_ebusloop != NULL) {
//~ m_ebusloop->stop();
//~ m_ebusloop->join();
//~ delete m_ebusloop;
//~ }
if (strcasecmp(cmd[1].c_str(), "reload") == 0) {
// free Commands DB
//~ if (m_commands != NULL)
//~ delete m_commands;
m_cycdata->delCommands();
delete m_commands;
// create Commands DB
//~ m_commands = ConfigCommands(A.getParam<const char*>("p_ebusconfdir"), CSV).getCommands();
//~ L.log(bas, debug, "ebus configuration dir: %s", A.getParam<const char*>("p_ebusconfdir"));
//~ L.log(bas, event, "commands DB with %d entries created", m_commands->size());
// create Commands DB
m_commands = ConfigCommands(A.getParam<const char*>("p_ebusconfdir"), CSV).getCommands();
L.log(bas, debug, "ebus configuration dir: %s", A.getParam<const char*>("p_ebusconfdir"));
L.log(bas, event, "commands DB with %d entries created", m_commands->size());
// create EBusLoop
//~ m_ebusloop = new EBusLoop();
//~ m_ebusloop->start("ebusloop");
// add commands to cycDB
m_cycdata->addCommands(m_commands);
// create CYCData
//~ m_cycdata = new CYCData(m_ebusloop, m_commands);
//~ m_cycdata->start("cycdata");
result << "done";
break;
}
//~ result << "done";
//~ break;
result << "usage: 'config list'" << std::endl
<< " 'config reload'";
break;
case help:
result << "commands:" << std::endl
<< " get - fetch ebus data 'get class cmd (sub)'" << std::endl
<< " set - set ebus values 'set class cmd value'" << std::endl
<< " cyc - fetch cycle data 'cyc class cmd (sub)'" << std::endl
<< " hex - send given hex value 'hex type value' (value: ZZPBSBNNDx)" << std::endl << std::endl
<< " dump - change dump state 'dump state' (state: on|off)" << std::endl << std::endl
<< " log areas - change log areas 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl
<< " log level - change log level 'log level level' (level: error|event|trace|debug)" << std::endl << std::endl
//~ << " cfgreload - reload ebus configuration" << std::endl << std::endl
<< " get - fetch ebus data 'get class cmd (sub)'" << std::endl
<< " set - set ebus values 'set class cmd value'" << std::endl
<< " cyc - fetch cycle data 'cyc class cmd (sub)'" << std::endl
<< " hex - send given hex value 'hex type value' (value: ZZPBSBNNDx)" << std::endl << std::endl
<< " dump - change dump state 'dump state' (state: on|off)" << std::endl << std::endl
<< " log - change log areas 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl
<< " - change log level 'log level level' (level: error|event|trace|debug)" << std::endl << std::endl
<< " config - list ebus configuration 'config list'" << std::endl
<< " - reload ebus configuration 'config reload'" << std::endl << std::endl
<< " stop - stop daemon" << std::endl
<< " quit - close connection" << std::endl << std::endl
<< " help - print this page";
+3 -3
View File
@@ -53,8 +53,8 @@ private:
cyc, // fetch cycle data
hex, // send hex value
dump, // change dump state
log, // change loggins settings
//~ cfgreload, // reload ebus configuration
log, // logger settings
config, // ebus configuration
help, // print commands
notfound
};
@@ -67,7 +67,7 @@ private:
if (strcasecmp(item.c_str(), "hex") == 0) return hex;
if (strcasecmp(item.c_str(), "dump") == 0) return dump;
if (strcasecmp(item.c_str(), "log") == 0) return log;
//~ if (strcasecmp(item.c_str(), "cfgreload") == 0) return cfgreload;
if (strcasecmp(item.c_str(), "config") == 0) return config;
if (strcasecmp(item.c_str(), "help") == 0) return help;
return notfound;
+4
View File
@@ -122,6 +122,8 @@ void CYCData::storeData(int index, std::string data)
void CYCData::addCommands(Commands* commands)
{
m_commands = commands;
for (size_t index = 0; index < commands->size(); index++) {
if (strcasecmp((*m_commands)[index][0].c_str(),"cyc") == 0) {
Command* cmd = new Command(index, (*m_commands)[index]);
@@ -136,5 +138,7 @@ void CYCData::delCommands()
{
for (mapCI_t iter = m_cycDB.begin(); iter != m_cycDB.end(); ++iter)
delete iter->second;
m_cycDB.clear();
}
+3 -2
View File
@@ -22,6 +22,7 @@
#include "libebus.h"
#include "ebusloop.h"
#include <map>
using namespace libebus;
@@ -35,8 +36,8 @@ class CYCData : public Thread
public:
CYCData(EBusLoop* ebusloop, Commands* commands)
: m_ebusloop(ebusloop), m_commands(commands), m_stop(false)
{ addCommands(m_commands); }
: m_ebusloop(ebusloop), m_stop(false)
{ addCommands(commands); }
~CYCData() { delCommands(); }
void* run();
+4 -4
View File
@@ -76,8 +76,8 @@ void define_args()
"\tlog file name (/var/log/ebusd.log)",
Appl::type_string, Appl::opt_mandatory);
A.addItem("p_logarea", Appl::Param("all"), "", "logarea",
"\tlog area - bas|net|bus|cyc|all (all)",
A.addItem("p_logareas", Appl::Param("all"), "", "logareas",
"\tlog areas - bas|net|bus|cyc|all (all)",
Appl::type_string, Appl::opt_mandatory);
A.addItem("p_loglevel", Appl::Param("trace"), "", "loglevel",
@@ -170,12 +170,12 @@ int main(int argc, char* argv[])
// make me Daemon
if (A.getParam<bool>("p_foreground") == true) {
L += new LogConsole(calcArea(A.getParam<const char*>("p_logarea")),
L += new LogConsole(calcAreas(A.getParam<const char*>("p_logareas")),
calcLevel(A.getParam<const char*>("p_loglevel")),
"logconsole");
} else {
D.run("/var/run/ebusd.pid");
L += new LogFile(calcArea(A.getParam<const char*>("p_logarea")),
L += new LogFile(calcAreas(A.getParam<const char*>("p_logareas")),
calcLevel(A.getParam<const char*>("p_loglevel")),
"logfile", A.getParam<const char*>("p_logfile"));
}