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
+7 -2
View File
@@ -1,12 +1,17 @@
ebusd - ChangeLog
-----------------
2014-10-03 Roland Jax <roland.jax@liwest.at>
* class Logger: minor name changes.
* class CYCData: delCommands fixed.
* class BaseLoop: config option added. (config reload implemented)
2014-10-02 Roland Jax <roland.jax@liwest.at>
* class Network splitted into classes Network and Connection.
* class Message separated from class Baseloop.
* class Message separated from class BaseLoop.
* global Objects (network, commands, ebusloop, cycdata) relocated into
new global Object baseloop.
* daemon log option reworked (logarea -> logareas; loglevel -> log level).
* class BaseLoop: log option reworked (logarea -> logareas; loglevel -> log level).
2014-06-26 Roland Jax <roland.jax@liwest.at>
* ebusdump merged into ebusctl.
+8 -8
View File
@@ -28,31 +28,31 @@
#include <sys/time.h>
#include <unistd.h>
static const char* AreaNames[Size_of_Area] = { "bas", "net", "bus", "cyc" };
static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus", "cyc" };
static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "debug" };
int calcArea(const std::string area)
int calcAreas(const std::string areas)
{
int m_area = 0;
int m_areas = 0;
// prepare data
std::string token;
std::istringstream stream(area);
std::istringstream stream(areas);
std::vector<std::string> cmd;
while (std::getline(stream, token, ',') != 0)
cmd.push_back(token);
for (std::vector<std::string>::iterator it = cmd.begin() ; it != cmd.end(); ++it)
for (int i = 0; i < Size_of_Area; i++) {
for (int i = 0; i < Size_of_Areas; i++) {
if (strcasecmp("all", it->c_str()) == 0)
return (pow(2, (int)Size_of_Area) - 1);
return (pow(2, (int)Size_of_Areas) - 1);
if (strcasecmp(AreaNames[i], it->c_str()) == 0)
m_area += pow(2, i);
m_areas += pow(2, i);
}
return m_area;
return m_areas;
}
int calcLevel(const std::string level)
+2 -2
View File
@@ -28,10 +28,10 @@
#include <vector>
#include <cstdarg>
enum Area { bas=1, net=2, bus=4, cyc=8, all=15, Size_of_Area=4 };
enum Areas { bas=1, net=2, bus=4, cyc=8, all=15, Size_of_Areas=4 };
enum Level { error=0, event, trace, debug, Size_of_Level };
int calcArea(const std::string area);
int calcAreas(const std::string areas);
int calcLevel(const std::string level);
+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"));
}