From 835c901da6664c083e6018e12eb7c64b6fb397af Mon Sep 17 00:00:00 2001 From: Roland Jax Date: Thu, 20 Nov 2014 18:43:07 +0100 Subject: [PATCH] documentation for class BaseLoop added; most enum types adapted. --- src/ebusd/baseloop.cpp | 26 ++++---- src/ebusd/baseloop.h | 86 +++++++++++++++++++-------- src/ebusd/busloop.h | 21 ++++--- src/lib/ebus/configfile.cpp | 2 +- src/lib/ebus/configfile.h | 4 +- src/lib/ebus/port.cpp | 8 +-- src/lib/ebus/port.h | 5 +- src/lib/ebus/test/test_commands.cpp | 2 +- src/lib/ebus/test/test_configfile.cpp | 2 +- src/lib/utils/tcpsocket.h | 1 + 10 files changed, 101 insertions(+), 56 deletions(-) diff --git a/src/ebusd/baseloop.cpp b/src/ebusd/baseloop.cpp index 8e1fffd9..40fbadd7 100644 --- a/src/ebusd/baseloop.cpp +++ b/src/ebusd/baseloop.cpp @@ -28,7 +28,7 @@ extern Appl& A; BaseLoop::BaseLoop() { // create commands DB - m_commands = ConfigCommands(A.getOptVal("ebusconfdir"), CSV).getCommands(); + m_commands = ConfigCommands(A.getOptVal("ebusconfdir"), ft_csv).getCommands(); L.log(bas, trace, "ebus configuration dir: %s", A.getOptVal("ebusconfdir")); L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB()); L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB()); @@ -112,11 +112,11 @@ std::string BaseLoop::decodeMessage(const std::string& data) return "command missing"; switch (getCase(cmd[0])) { - case notfound: + case ct_invalid: result << "command not found"; break; - case get: + case ct_get: if (cmd.size() < 3 || cmd.size() > 4) { result << "usage: 'get class cmd (sub)'"; break; @@ -176,7 +176,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; - case set: + case ct_set: if (cmd.size() != 4) { result << "usage: 'set class cmd value'"; break; @@ -231,7 +231,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; - case cyc: + case ct_cyc: if (cmd.size() < 3 || cmd.size() > 4) { result << "usage: 'cyc class cmd (sub)'"; break; @@ -259,7 +259,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; - case hex: + case ct_hex: if (cmd.size() != 2) { result << "usage: 'hex value' (value: ZZPBSBNNDx)"; break; @@ -289,7 +289,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; - case scan: + case ct_scan: if (cmd.size() == 1) { m_busloop->scan(); result << "done"; @@ -315,7 +315,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) << " 'scan result'"; break; - case log: + case ct_log: if (cmd.size() != 3 ) { result << "usage: 'log areas area,area,..' (areas: bas|net|bus|cyc|all)" << std::endl << " 'log level level' (level: error|event|trace|debug)"; @@ -340,7 +340,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; - case raw: + case ct_raw: if (cmd.size() != 1) { result << "usage: 'raw'"; break; @@ -350,7 +350,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) result << "done"; break; - case dump: + case ct_dump: if (cmd.size() != 1) { result << "usage: 'dump'"; break; @@ -360,7 +360,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) result << "done"; break; - case reload: + case ct_reload: if (cmd.size() != 1) { result << "usage: 'reload'"; break; @@ -368,7 +368,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) { // create commands DB - Commands* commands = ConfigCommands(A.getOptVal("ebusconfdir"), CSV).getCommands(); + Commands* commands = ConfigCommands(A.getOptVal("ebusconfdir"), ft_csv).getCommands(); L.log(bas, trace, "ebus configuration dir: %s", A.getOptVal("ebusconfdir")); L.log(bas, event, "commands DB: %d ", m_commands->sizeCmdDB()); L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB()); @@ -382,7 +382,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) break; } - case help: + case ct_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 diff --git a/src/ebusd/baseloop.h b/src/ebusd/baseloop.h index bd0f8df6..03de7c69 100644 --- a/src/ebusd/baseloop.h +++ b/src/ebusd/baseloop.h @@ -24,54 +24,88 @@ #include "network.h" #include "busloop.h" +/** possible client commands */ +enum CommandType { + ct_get, // get ebus data + ct_set, // set ebus value + ct_cyc, // fetch cycle data + ct_hex, // send hex value + ct_scan, // scan ebus + ct_log, // logger settings + ct_raw, // toggle log raw data + ct_dump, // toggle dump state + ct_reload, // reload ebus configuration + ct_help, // print commands + ct_invalid, // invalid +}; + +/** + * @brief class baseloop which handle client messages. + */ class BaseLoop { public: + /** + * @brief construct the baseloop and creates commads, network and busloop subsystems. + */ BaseLoop(); + + /** + * @brief destructor. + */ ~BaseLoop(); + /** + * @brief start baseloop instance. + */ void start(); + /** + * @brief add a new network message to internal message queue. + * @param message the network message. + */ void addMessage(NetMessage* message) { m_netQueue.add(message); } private: + /** the commands instance */ Commands* m_commands; + + /** the busloop instance */ BusLoop* m_busloop; + + /** the network instance */ Network* m_network; + /** queue for network messages */ WQueue m_netQueue; - enum ClientCommand { - get, // get ebus data - set, // set ebus value - cyc, // fetch cycle data - hex, // send hex value - scan, // scan ebus - log, // logger settings - raw, // toggle log raw data - dump, // toggle dump state - reload, // reload ebus configuration - help, // print commands - notfound - }; - - ClientCommand getCase(const std::string& item) + /** + * @brief compare client command with defined. + * @param item the client command to compare. + * @return the founded client command type. + */ + CommandType getCase(const std::string& item) { - if (strcasecmp(item.c_str(), "GET") == 0) return get; - if (strcasecmp(item.c_str(), "SET") == 0) return set; - if (strcasecmp(item.c_str(), "CYC") == 0) return cyc; - if (strcasecmp(item.c_str(), "HEX") == 0) return hex; - if (strcasecmp(item.c_str(), "SCAN") == 0) return scan; - if (strcasecmp(item.c_str(), "LOG") == 0) return log; - if (strcasecmp(item.c_str(), "RAW") == 0) return raw; - if (strcasecmp(item.c_str(), "DUMP") == 0) return dump; - if (strcasecmp(item.c_str(), "RELOAD") == 0) return reload; - if (strcasecmp(item.c_str(), "HELP") == 0) return help; + if (strcasecmp(item.c_str(), "GET") == 0) return ct_get; + if (strcasecmp(item.c_str(), "SET") == 0) return ct_set; + if (strcasecmp(item.c_str(), "CYC") == 0) return ct_cyc; + if (strcasecmp(item.c_str(), "HEX") == 0) return ct_hex; + if (strcasecmp(item.c_str(), "SCAN") == 0) return ct_scan; + if (strcasecmp(item.c_str(), "LOG") == 0) return ct_log; + if (strcasecmp(item.c_str(), "RAW") == 0) return ct_raw; + if (strcasecmp(item.c_str(), "DUMP") == 0) return ct_dump; + if (strcasecmp(item.c_str(), "RELOAD") == 0) return ct_reload; + if (strcasecmp(item.c_str(), "HELP") == 0) return ct_help; - return notfound; + return ct_invalid; } + /** + * @brief decode and execute client message + * @param data the data string to decode + * @return result string to send back to client + */ std::string decodeMessage(const std::string& data); }; diff --git a/src/ebusd/busloop.h b/src/ebusd/busloop.h index 5021351b..0e609dbb 100644 --- a/src/ebusd/busloop.h +++ b/src/ebusd/busloop.h @@ -30,8 +30,13 @@ /** the maximum time [us] allowed for retrieving a byte from an addressed slave */ #define RECV_TIMEOUT 10000 -/** possible command types */ -enum CommandType { invalid, broadcast, masterMaster, masterSlave }; +/** possible bus command types */ +enum BusCommandType { + invalid, // invalid command type + broadcast, // broadcast + masterMaster, // master - master + masterSlave, // master - slave +}; /** * @brief class for data/message transfer between baseloop and busloop. @@ -41,7 +46,7 @@ class BusMessage public: /** - * @brief constructs a new bus message instance and determine command type. + * @brief construct a new bus message instance and determine command type. * @param command the command data to write on bus. * @param poll true if message type is polling. * @param scan true if message type is scanning. @@ -58,10 +63,10 @@ public: } /** - * @brief get the command type. - * @return the command type. + * @brief get the bus command type. + * @return the bus command type. */ - CommandType getType() const { return m_type; } + BusCommandType getType() const { return m_type; } /** * @brief get the command string. @@ -124,8 +129,8 @@ public: void sendSignal() { pthread_cond_signal(&m_cond); } private: - /** the command type */ - CommandType m_type; + /** the bus command type */ + BusCommandType m_type; /** true if message is of type polling */ bool m_poll; diff --git a/src/lib/ebus/configfile.cpp b/src/lib/ebus/configfile.cpp index 1dfa0aba..eddf4dba 100644 --- a/src/lib/ebus/configfile.cpp +++ b/src/lib/ebus/configfile.cpp @@ -60,7 +60,7 @@ void ConfigCommands::setType(const FileType type) delete m_configfile; switch (type) { - case CSV: + case ft_csv: m_configfile = new ConfigFileCSV(); m_extension = "csv"; break; diff --git a/src/lib/ebus/configfile.h b/src/lib/ebus/configfile.h index 03996926..1ace119d 100644 --- a/src/lib/ebus/configfile.h +++ b/src/lib/ebus/configfile.h @@ -25,7 +25,9 @@ #include /** available file endings / types. */ -enum FileType { CSV }; +enum FileType { + ft_csv +}; /** * @brief base class for config files. diff --git a/src/lib/ebus/port.cpp b/src/lib/ebus/port.cpp index cf941aa8..16872806 100644 --- a/src/lib/ebus/port.cpp +++ b/src/lib/ebus/port.cpp @@ -232,9 +232,9 @@ Port::Port(const std::string deviceName, const bool noDeviceCheck) if (strchr(deviceName.c_str(), '/') == NULL && strchr(deviceName.c_str(), ':') != NULL) - setType(NETWORK); + setType(dt_network); else - setType(SERIAL); + setType(dt_serial); } void Port::setType(const DeviceType type) @@ -243,10 +243,10 @@ void Port::setType(const DeviceType type) delete m_device; switch (type) { - case SERIAL: + case dt_serial: m_device = new DeviceSerial(); break; - case NETWORK: + case dt_network: m_device = new DeviceNetwork(); break; }; diff --git a/src/lib/ebus/port.h b/src/lib/ebus/port.h index 213bf5a4..793d97d1 100644 --- a/src/lib/ebus/port.h +++ b/src/lib/ebus/port.h @@ -26,7 +26,10 @@ #include /** available device types. */ -enum DeviceType { SERIAL, NETWORK }; +enum DeviceType { + dt_serial, + dt_network, +}; /** max bytes write to bus. */ #define MAX_WRITE_SIZE 1 diff --git a/src/lib/ebus/test/test_commands.cpp b/src/lib/ebus/test/test_commands.cpp index befbd46a..cfd76e9a 100644 --- a/src/lib/ebus/test/test_commands.cpp +++ b/src/lib/ebus/test/test_commands.cpp @@ -51,7 +51,7 @@ void readCSV(std::istream& is, Commands& commands){ int main() { - Commands* commands = ConfigCommands("test", CSV).getCommands(); + Commands* commands = ConfigCommands("test", ft_csv).getCommands(); std::cout << "Commands: " << commands->sizeCmdDB() << std::endl; //~ std::string data("g ci password pin1"); diff --git a/src/lib/ebus/test/test_configfile.cpp b/src/lib/ebus/test/test_configfile.cpp index beac4fb5..90e78f71 100644 --- a/src/lib/ebus/test/test_configfile.cpp +++ b/src/lib/ebus/test/test_configfile.cpp @@ -27,7 +27,7 @@ int main() { std::string dir("test"); - ConfigCommands config(dir, CSV); + ConfigCommands config(dir, ft_csv); Commands* commands = config.getCommands(); diff --git a/src/lib/utils/tcpsocket.h b/src/lib/utils/tcpsocket.h index f7861bdb..142e7da2 100644 --- a/src/lib/utils/tcpsocket.h +++ b/src/lib/utils/tcpsocket.h @@ -137,6 +137,7 @@ public: /** * @brief start listening of tcp socket. + * @return result of low level functions. */ int start();