class BaseLoop: config option added. (config reload implemented)
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
ebusd - ChangeLog
|
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>
|
2014-10-02 Roland Jax <roland.jax@liwest.at>
|
||||||
* class Network splitted into classes Network and Connection.
|
* 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
|
* global Objects (network, commands, ebusloop, cycdata) relocated into
|
||||||
new global Object baseloop.
|
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>
|
2014-06-26 Roland Jax <roland.jax@liwest.at>
|
||||||
* ebusdump merged into ebusctl.
|
* ebusdump merged into ebusctl.
|
||||||
|
|||||||
+8
-8
@@ -28,31 +28,31 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.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" };
|
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
|
// prepare data
|
||||||
std::string token;
|
std::string token;
|
||||||
std::istringstream stream(area);
|
std::istringstream stream(areas);
|
||||||
std::vector<std::string> cmd;
|
std::vector<std::string> cmd;
|
||||||
|
|
||||||
while (std::getline(stream, token, ',') != 0)
|
while (std::getline(stream, token, ',') != 0)
|
||||||
cmd.push_back(token);
|
cmd.push_back(token);
|
||||||
|
|
||||||
for (std::vector<std::string>::iterator it = cmd.begin() ; it != cmd.end(); ++it)
|
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)
|
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)
|
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)
|
int calcLevel(const std::string level)
|
||||||
|
|||||||
+2
-2
@@ -28,10 +28,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdarg>
|
#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 };
|
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);
|
int calcLevel(const std::string level);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+40
-37
@@ -302,9 +302,9 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: check for possible areas
|
// ToDo: check for possible areas and level
|
||||||
if (strcasecmp(cmd[1].c_str(), "areas") == 0) {
|
if (strcasecmp(cmd[1].c_str(), "areas") == 0) {
|
||||||
L.getSink(0)->setAreas(calcArea(cmd[2]));
|
L.getSink(0)->setAreas(calcAreas(cmd[2]));
|
||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -315,53 +315,56 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl
|
||||||
|
<< " 'log level level' (level: error|event|trace|debug)";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//~ case cfgreload:
|
case config:
|
||||||
|
if (cmd.size() != 2) {
|
||||||
|
result << "usage: 'config list'" << std::endl
|
||||||
|
<< " 'config reload'";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// free CYCData
|
// ToDo: ...
|
||||||
//~ if (m_cycdata != NULL) {
|
if (strcasecmp(cmd[1].c_str(), "list") == 0) {
|
||||||
//~ m_cycdata->stop();
|
result << "done";
|
||||||
//~ delete m_cycdata;
|
break;
|
||||||
//~ }
|
}
|
||||||
|
|
||||||
// free EBusLoop
|
if (strcasecmp(cmd[1].c_str(), "reload") == 0) {
|
||||||
//~ if (m_ebusloop != NULL) {
|
|
||||||
//~ m_ebusloop->stop();
|
|
||||||
//~ m_ebusloop->join();
|
|
||||||
//~ delete m_ebusloop;
|
|
||||||
//~ }
|
|
||||||
|
|
||||||
// free Commands DB
|
m_cycdata->delCommands();
|
||||||
//~ if (m_commands != NULL)
|
delete m_commands;
|
||||||
//~ delete m_commands;
|
|
||||||
|
|
||||||
// create Commands DB
|
// create Commands DB
|
||||||
//~ m_commands = ConfigCommands(A.getParam<const char*>("p_ebusconfdir"), CSV).getCommands();
|
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, debug, "ebus configuration dir: %s", A.getParam<const char*>("p_ebusconfdir"));
|
||||||
//~ L.log(bas, event, "commands DB with %d entries created", m_commands->size());
|
L.log(bas, event, "commands DB with %d entries created", m_commands->size());
|
||||||
|
|
||||||
// create EBusLoop
|
// add commands to cycDB
|
||||||
//~ m_ebusloop = new EBusLoop();
|
m_cycdata->addCommands(m_commands);
|
||||||
//~ m_ebusloop->start("ebusloop");
|
|
||||||
|
|
||||||
// create CYCData
|
result << "done";
|
||||||
//~ m_cycdata = new CYCData(m_ebusloop, m_commands);
|
break;
|
||||||
//~ m_cycdata->start("cycdata");
|
}
|
||||||
|
|
||||||
//~ result << "done";
|
result << "usage: 'config list'" << std::endl
|
||||||
//~ break;
|
<< " 'config reload'";
|
||||||
|
break;
|
||||||
|
|
||||||
case help:
|
case help:
|
||||||
result << "commands:" << std::endl
|
result << "commands:" << std::endl
|
||||||
<< " get - fetch ebus data 'get class cmd (sub)'" << std::endl
|
<< " get - fetch ebus data 'get class cmd (sub)'" << std::endl
|
||||||
<< " set - set ebus values 'set class cmd value'" << std::endl
|
<< " set - set ebus values 'set class cmd value'" << std::endl
|
||||||
<< " cyc - fetch cycle data 'cyc class cmd (sub)'" << 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
|
<< " 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
|
<< " 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 - 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
|
<< " - change log level 'log level level' (level: error|event|trace|debug)" << std::endl << std::endl
|
||||||
//~ << " cfgreload - reload ebus configuration" << 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
|
<< " stop - stop daemon" << std::endl
|
||||||
<< " quit - close connection" << std::endl << std::endl
|
<< " quit - close connection" << std::endl << std::endl
|
||||||
<< " help - print this page";
|
<< " help - print this page";
|
||||||
|
|||||||
+3
-3
@@ -53,8 +53,8 @@ private:
|
|||||||
cyc, // fetch cycle data
|
cyc, // fetch cycle data
|
||||||
hex, // send hex value
|
hex, // send hex value
|
||||||
dump, // change dump state
|
dump, // change dump state
|
||||||
log, // change loggins settings
|
log, // logger settings
|
||||||
//~ cfgreload, // reload ebus configuration
|
config, // ebus configuration
|
||||||
help, // print commands
|
help, // print commands
|
||||||
notfound
|
notfound
|
||||||
};
|
};
|
||||||
@@ -67,7 +67,7 @@ private:
|
|||||||
if (strcasecmp(item.c_str(), "hex") == 0) return hex;
|
if (strcasecmp(item.c_str(), "hex") == 0) return hex;
|
||||||
if (strcasecmp(item.c_str(), "dump") == 0) return dump;
|
if (strcasecmp(item.c_str(), "dump") == 0) return dump;
|
||||||
if (strcasecmp(item.c_str(), "log") == 0) return log;
|
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;
|
if (strcasecmp(item.c_str(), "help") == 0) return help;
|
||||||
|
|
||||||
return notfound;
|
return notfound;
|
||||||
|
|||||||
@@ -122,6 +122,8 @@ void CYCData::storeData(int index, std::string data)
|
|||||||
|
|
||||||
void CYCData::addCommands(Commands* commands)
|
void CYCData::addCommands(Commands* commands)
|
||||||
{
|
{
|
||||||
|
m_commands = commands;
|
||||||
|
|
||||||
for (size_t index = 0; index < commands->size(); index++) {
|
for (size_t index = 0; index < commands->size(); index++) {
|
||||||
if (strcasecmp((*m_commands)[index][0].c_str(),"cyc") == 0) {
|
if (strcasecmp((*m_commands)[index][0].c_str(),"cyc") == 0) {
|
||||||
Command* cmd = new Command(index, (*m_commands)[index]);
|
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)
|
for (mapCI_t iter = m_cycDB.begin(); iter != m_cycDB.end(); ++iter)
|
||||||
delete iter->second;
|
delete iter->second;
|
||||||
|
|
||||||
|
m_cycDB.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "libebus.h"
|
#include "libebus.h"
|
||||||
#include "ebusloop.h"
|
#include "ebusloop.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
using namespace libebus;
|
using namespace libebus;
|
||||||
|
|
||||||
@@ -35,8 +36,8 @@ class CYCData : public Thread
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CYCData(EBusLoop* ebusloop, Commands* commands)
|
CYCData(EBusLoop* ebusloop, Commands* commands)
|
||||||
: m_ebusloop(ebusloop), m_commands(commands), m_stop(false)
|
: m_ebusloop(ebusloop), m_stop(false)
|
||||||
{ addCommands(m_commands); }
|
{ addCommands(commands); }
|
||||||
~CYCData() { delCommands(); }
|
~CYCData() { delCommands(); }
|
||||||
|
|
||||||
void* run();
|
void* run();
|
||||||
|
|||||||
+4
-4
@@ -76,8 +76,8 @@ void define_args()
|
|||||||
"\tlog file name (/var/log/ebusd.log)",
|
"\tlog file name (/var/log/ebusd.log)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_logarea", Appl::Param("all"), "", "logarea",
|
A.addItem("p_logareas", Appl::Param("all"), "", "logareas",
|
||||||
"\tlog area - bas|net|bus|cyc|all (all)",
|
"\tlog areas - bas|net|bus|cyc|all (all)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_loglevel", Appl::Param("trace"), "", "loglevel",
|
A.addItem("p_loglevel", Appl::Param("trace"), "", "loglevel",
|
||||||
@@ -170,12 +170,12 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// make me Daemon
|
// make me Daemon
|
||||||
if (A.getParam<bool>("p_foreground") == true) {
|
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")),
|
calcLevel(A.getParam<const char*>("p_loglevel")),
|
||||||
"logconsole");
|
"logconsole");
|
||||||
} else {
|
} else {
|
||||||
D.run("/var/run/ebusd.pid");
|
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")),
|
calcLevel(A.getParam<const char*>("p_loglevel")),
|
||||||
"logfile", A.getParam<const char*>("p_logfile"));
|
"logfile", A.getParam<const char*>("p_logfile"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user