class LogInstance renamed to Logger; documentation for logging subsystem added.

This commit is contained in:
Roland Jax
2014-11-18 20:15:01 +01:00
parent 1415b143af
commit e2f6bbffb0
21 changed files with 347 additions and 157 deletions
+2 -2
View File
@@ -6,8 +6,7 @@ AM_CXXFLAGS = -fpic \
bin_PROGRAMS = ebusd
ebusd_SOURCES = message.h \
connection.cpp \
ebusd_SOURCES = connection.cpp \
connection.h \
network.cpp \
network.h \
@@ -15,6 +14,7 @@ ebusd_SOURCES = message.h \
ebusloop.h \
baseloop.cpp \
baseloop.h \
netmessage.h \
ebusd.cpp
ebusd_LDADD = $(top_srcdir)/src/lib/utils/libutils.a \
+3 -3
View File
@@ -22,7 +22,7 @@
#include "logger.h"
#include "appl.h"
extern LogInstance& L;
extern Logger& L;
extern Appl& A;
BaseLoop::BaseLoop()
@@ -67,7 +67,7 @@ void BaseLoop::start()
std::string result;
// recv new message from client
Message* message = m_msgQueue.remove();
NetMessage* message = m_msgQueue.remove();
std::string data = message->getData();
data.erase(std::remove(data.begin(), data.end(), '\r'), data.end());
@@ -86,7 +86,7 @@ void BaseLoop::start()
// send result to client
result += '\n';
Connection* connection = message->getConnection();
connection->addResult(Message(result));
connection->addResult(NetMessage(result));
delete message;
+2 -2
View File
@@ -36,14 +36,14 @@ public:
void start();
void addMessage(Message* message) { m_msgQueue.add(message); }
void addMessage(NetMessage* message) { m_msgQueue.add(message); }
private:
Commands* m_commands;
EBusLoop* m_ebusloop;
Network* m_network;
WQueue<Message*> m_msgQueue;
WQueue<NetMessage*> m_msgQueue;
enum ClientCommand {
get, // get ebus data
+5 -5
View File
@@ -22,13 +22,13 @@
#include <cstring>
#include <poll.h>
extern LogInstance& L;
extern Logger& L;
int Connection::m_sum = 0;
void Connection::addResult(Message message)
void Connection::addResult(NetMessage message)
{
Message* tmp = new Message(Message(message));
NetMessage* tmp = new NetMessage(NetMessage(message));
m_result.add(tmp);
}
@@ -80,11 +80,11 @@ void* Connection::run()
// send data
data[datalen] = '\0';
m_data->add(new Message(data, this));
m_data->add(new NetMessage(data, this));
// wait for result
L.log(net, debug, "[%05d] wait for result", getID());
Message* message = m_result.remove();
NetMessage* message = m_result.remove();
L.log(net, debug, "[%05d] result added", getID());
std::string result(message->getData());
+5 -5
View File
@@ -24,16 +24,16 @@
#include "wqueue.h"
#include "notify.h"
#include "thread.h"
#include "message.h"
#include "netmessage.h"
class Connection : public Thread
{
public:
Connection(TCPSocket* socket, WQueue<Message*>* data)
Connection(TCPSocket* socket, WQueue<NetMessage*>* data)
: m_socket(socket), m_data(data), m_running(false) { m_sum++; m_id = m_sum;}
void addResult(Message message);
void addResult(NetMessage message);
void* run();
void stop() const { m_notify.notify(); }
@@ -43,8 +43,8 @@ public:
private:
TCPSocket* m_socket;
WQueue<Message*>* m_data;
WQueue<Message*> m_result;
WQueue<NetMessage*>* m_data;
WQueue<NetMessage*> m_result;
Notify m_notify;
bool m_running;
int m_id;
+1 -1
View File
@@ -32,7 +32,7 @@ using namespace libebus;
Appl& A = Appl::Instance();
Daemon& D = Daemon::Instance();
LogInstance& L = LogInstance::Instance();
Logger& L = Logger::Instance();
BaseLoop* baseloop;
+1 -1
View File
@@ -22,7 +22,7 @@
#include "appl.h"
#include <iomanip>
extern LogInstance& L;
extern Logger& L;
extern Appl& A;
EBusLoop::EBusLoop(Commands* commands)
@@ -17,8 +17,8 @@
* along with ebusd. If not, see http://www.gnu.org/licenses/.
*/
#ifndef MESSAGE_H_
#define MESSAGE_H_
#ifndef NETMESSAGE_H_
#define NETMESSAGE_H_
#include <string>
@@ -28,7 +28,7 @@ class Connection;
/**
* @brief class for data/message transfer between connection and baseloop
*/
class Message
class NetMessage
{
public:
@@ -37,14 +37,14 @@ public:
* @param data from client
* @param connection to return result to correct client
*/
Message(const std::string data, Connection* connection=NULL)
NetMessage(const std::string data, Connection* connection=NULL)
: m_data(data), m_connection(connection) {}
/**
* @brief copy constructor.
* @param src message object for copy
*/
Message(const Message& src) : m_data(src.m_data), m_connection(src.m_connection) {}
NetMessage(const NetMessage& src) : m_data(src.m_data), m_connection(src.m_connection) {}
/**
* @brief data from client
@@ -61,10 +61,11 @@ public:
private:
/** the data/message string */
std::string m_data;
/** the source connection */
Connection* m_connection;
};
#endif // MESSAGE_H_
#endif // NETMESSAGE_H_
+2 -2
View File
@@ -22,11 +22,11 @@
#include "appl.h"
#include <poll.h>
extern LogInstance& L;
extern Logger& L;
extern Appl& A;
Network::Network(const bool localhost, WQueue<Message*>* msgQueue)
Network::Network(const bool localhost, WQueue<NetMessage*>* msgQueue)
: m_msgQueue(msgQueue), m_listening(false), m_running(false)
{
if (localhost == true)
+2 -2
View File
@@ -26,7 +26,7 @@ class Network : public Thread
{
public:
Network(const bool localhost, WQueue<Message*>* msgQueue);
Network(const bool localhost, WQueue<NetMessage*>* msgQueue);
~Network();
void* run();
@@ -34,7 +34,7 @@ public:
private:
std::list<Connection*> m_connections;
WQueue<Message*>* m_msgQueue;
WQueue<NetMessage*>* m_msgQueue;
TCPServer* m_tcpServer;
Notify m_notify;
bool m_listening;
+15 -12
View File
@@ -31,14 +31,14 @@ namespace libebus
enum FileType { CSV, XML };
/**
* @brief Base class for config files.
* @brief base class for config files.
*/
class ConfigFile
{
public:
/**
* @brief Destructor.
* @brief destructor.
*/
virtual ~ConfigFile() {}
@@ -52,14 +52,14 @@ public:
};
/**
* @brief Class for CSV config files.
* @brief class for CSV config files.
*/
class ConfigFileCSV : public ConfigFile
{
public:
/**
* @brief Destructor.
* @brief destructor.
*/
~ConfigFileCSV() {}
@@ -73,14 +73,14 @@ public:
};
/**
* @brief Class for XML config files.
* @brief class for XML config files.
*/
class ConfigFileXML : public ConfigFile
{
public:
/**
* @brief Destructor.
* @brief destructor.
*/
~ConfigFileXML() {}
@@ -95,32 +95,32 @@ public:
/**
* @brief Class for class Device.
* @brief class for class device.
*/
class ConfigCommands
{
public:
/**
* @brief Set file type and add recursive files from given path.
* @brief set file type and add recursive files from given path.
* @param path to configuration files.
* @param Filetype to parse.
* @param filetype to parse.
*/
ConfigCommands(const std::string path, const FileType type);
/**
* @brief Destructor.
* @brief destructor.
*/
~ConfigCommands() { delete m_configfile; }
/**
* @brief setter for file type.
* @param FileType of files.
* @param filetype of files.
*/
void setType(const FileType type);
/**
* @brief Parse files for commands and store them into commands instance.
* @brief parse files for commands and store them into commands instance.
* @return a commands instance
*/
Commands* getCommands();
@@ -128,10 +128,13 @@ public:
private:
/** the configfile instance */
ConfigFile* m_configfile;
/** main path for configuration files */
std::string m_path;
/** valid file extension */
std::string m_extension;
/** vector of configuration files */
std::vector<std::string> m_files;
+1
View File
@@ -62,6 +62,7 @@ public:
private:
/** the name of dump file*/
std::string m_filename;
/** max. size of dump file */
long m_filesize;
+16 -10
View File
@@ -39,19 +39,19 @@ enum DeviceType { SERIAL, NETWORK };
/**
* @brief Base class for input devices.
* @brief base class for input devices.
*/
class Device
{
public:
/**
* @brief Constructs a new instance.
* @brief constructs a new instance.
*/
Device() : m_fd(-1), m_open(false), m_noDeviceCheck(false) {}
/**
* @brief Destructor.
* @brief destructor.
*/
virtual ~Device() {}
@@ -104,12 +104,16 @@ public:
protected:
/** if of file descriptor */
int m_fd;
/** state of device*/
bool m_open;
/** state of device check */
bool m_noDeviceCheck;
/** queue for received bytes */
std::queue<unsigned char> m_recvBuffer;
/** receive buffer */
unsigned char m_buffer[MAX_READ_SIZE];
@@ -123,14 +127,14 @@ private:
};
/**
* @brief Class for serial input device.
* @brief class for serial input device.
*/
class DeviceSerial : public Device
{
public:
/**
* @brief Destructor.
* @brief destructor.
*/
~DeviceSerial() { closeDevice(); }
@@ -153,14 +157,14 @@ private:
};
/**
* @brief Class for network input device.
* @brief class for network input device.
*/
class DeviceNetwork : public Device
{
public:
/**
* @brief Destructor.
* @brief destructor.
*/
~DeviceNetwork() { closeDevice(); }
@@ -181,21 +185,21 @@ private:
};
/**
* @brief Wrapper class for class Device.
* @brief wrapper class for class device.
*/
class Port
{
public:
/**
* @brief Constructs a new instance and determine device type.
* @brief constructs a new instance and determine device type.
* @param deviceName to determine device type.
* @param noDeviceCheck en-/disable device check.
*/
Port(const std::string deviceName, const bool noDeviceCheck);
/**
* @brief Destructor.
* @brief destructor.
*/
~Port() { delete m_device; }
@@ -248,8 +252,10 @@ public:
private:
/** the device name */
std::string m_deviceName;
/** the device instance */
Device* m_device;
/** true if device check is disabled */
bool m_noDeviceCheck;
+25 -25
View File
@@ -76,7 +76,7 @@ class Appl
public:
/**
* @brief create an appl instance and return the reference.
* @brief create an instance and return the reference.
* @param command is true if an command is needed.
* @return the reference to instance.
*/
@@ -89,32 +89,32 @@ public:
/**
* @brief save application version string.
* @param version string
* @param version string.
*/
void setVersion(const char* version) { m_version = version; }
/**
* @brief create new entry of application option only for help page.
* @param text string to print
* @param text string to print.
*/
void addText(const char* text);
/**
* @brief create new entry of application option.
* @param name the long name
* @param shortname optional short name
* @param optval value of option
* @param datatype data type of option value
* @param optiontype type of given option
* @param description hint text for help page
* @param name the long name.
* @param shortname optional short name.
* @param optval value of option.
* @param datatype data type of option value.
* @param optiontype type of given option.
* @param description hint text for help page.
*/
void addOption(const char* name, const char* shortname, OptVal optval,
DataType datatype, OptionType optiontype, const char* description);
/**
* @brief returns the value of the interested option
* @param name the interested option
* @return casted value
* @brief returns the value of the interested option.
* @param name the interested option.
* @return casted value.
*/
template <typename T>
T getOptVal(const char* name)
@@ -125,26 +125,26 @@ public:
/**
* @brief parse application arguments.
* @param argc the number of options
* @param argv the given options
* @param argc the number of options.
* @param argv the given options.
*/
void parseArgs(int argc, char* argv[]);
/**
* @brief returns the number of saved commands and arguments
* @return number of commands and arguments
* @brief returns the number of saved commands and arguments.
* @return number of commands and arguments.
*/
int numArgs() const { return m_arguments.size(); }
/**
* @brief returns the string of an interested argument (0 = command)
* @param num number of interested argument
* @return string value
* @brief returns the string of an interested argument (0 = command).
* @param num number of interested argument.
* @return string value.
*/
std::string getArg(const int num) const { return m_arguments[num]; }
private:
/** private constructor - singleton pattern*/
/** private constructor - singleton pattern */
Appl(const bool command) : m_needCommand(command) {}
Appl(const Appl&);
Appl& operator=(const Appl&);
@@ -171,16 +171,16 @@ private:
/**
* @brief checks the passed parameter if this is a valid option.
* @param option to check
* @param value to save if paramter is a valid option
* @param option to check.
* @param value to save if paramter is a valid option.
*/
bool checkOption(const std::string& option, const std::string& value);
/**
* @brief save the passed value to option.
* @param option name
* @param value to save
* @param datatype of given option
* @param option name.
* @param value to save.
* @param datatype of given option.
*/
void setOptVal(const char* option, const std::string value, DataType datatype);
+3 -1
View File
@@ -28,7 +28,7 @@ class Daemon
public:
/**
* @brief create an daemon instance and return the reference.
* @brief create an instance and return the reference.
* @return the reference to instance.
*/
static Daemon& Instance();
@@ -58,8 +58,10 @@ private:
/** status of process; true if we are a daemon */
bool m_status;
/** name of the pid file*/
const char* m_pidfile;
/** file descriptor of the pid file */
int m_pidfd;
+25 -25
View File
@@ -28,7 +28,10 @@
#include <sys/time.h>
#include <unistd.h>
/** */
static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus" };
/** */
static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "debug" };
int calcAreas(const std::string areas)
@@ -66,8 +69,8 @@ int calcLevel(const std::string level)
}
LogMessage::LogMessage(const int area, const int level, const std::string text, const bool run)
: m_area(area), m_level(level), m_text(text), m_run(run)
LogMessage::LogMessage(const int area, const int level, const std::string text, const bool running)
: m_area(area), m_level(level), m_text(text), m_running(running)
{
char time[24];
struct timeval tv;
@@ -89,17 +92,17 @@ LogMessage::LogMessage(const int area, const int level, const std::string text,
void LogSink::addMessage(const LogMessage& message)
{
LogMessage* tmp = new LogMessage(LogMessage(message));
m_queue.add((tmp));
m_logMessages.add((tmp));
}
void* LogSink::run()
{
while (1) {
LogMessage* message = m_queue.remove();
LogMessage* message = m_logMessages.remove();
if (message->isRunning() == false) {
delete message;
while (m_queue.size() == true) {
LogMessage* message = m_queue.remove();
while (m_logMessages.size() == true) {
LogMessage* message = m_logMessages.remove();
write(*message);
delete message;
}
@@ -114,8 +117,6 @@ void* LogSink::run()
int LogConsole::m_numInstance = 0;
void LogConsole::write(const LogMessage& message) const
{
std::cout << message.getTime() << " ["
@@ -126,11 +127,9 @@ void LogConsole::write(const LogMessage& message) const
int LogFile::m_numInstance = 0;
void LogFile::write(const LogMessage& message) const
{
std::fstream file(m_filename.c_str(), std::ios::out | std::ios::app);
std::fstream file(m_file.c_str(), std::ios::out | std::ios::app);
if (file.is_open() == true) {
file << message.getTime() << " ["
@@ -143,19 +142,19 @@ void LogFile::write(const LogMessage& message) const
LogInstance& LogInstance::Instance()
Logger& Logger::Instance()
{
static LogInstance instance;
static Logger instance;
return (instance);
}
LogInstance::~LogInstance()
Logger::~Logger()
{
while (m_sinks.empty() == false)
*this -= *(m_sinks.begin());
}
LogInstance& LogInstance::operator+= (LogSink* sink)
Logger& Logger::operator+=(LogSink* sink)
{
sinkCI_t itEnd = m_sinks.end();
sinkCI_t it = std::find(m_sinks.begin(), itEnd, sink);
@@ -166,7 +165,7 @@ LogInstance& LogInstance::operator+= (LogSink* sink)
return (*this);
}
LogInstance& LogInstance::operator-= (const LogSink* sink)
Logger& Logger::operator-=(const LogSink* sink)
{
sinkCI_t itEnd = m_sinks.end();
sinkCI_t it = std::find(m_sinks.begin(), itEnd, sink);
@@ -181,7 +180,7 @@ LogInstance& LogInstance::operator-= (const LogSink* sink)
return (*this);
}
void LogInstance::log(const int area, const int level, const std::string& data, ...)
void Logger::log(const int area, const int level, const std::string& data, ...)
{
if (m_running == true) {
char* tmp;
@@ -190,7 +189,7 @@ void LogInstance::log(const int area, const int level, const std::string& data,
if (vasprintf(&tmp, data.c_str(), ap) != -1) {
std::string buffer(tmp);
m_messages.add(new LogMessage(LogMessage(area, level, buffer)));
m_logMessages.add(new LogMessage(LogMessage(area, level, buffer)));
}
va_end(ap);
@@ -199,12 +198,12 @@ void LogInstance::log(const int area, const int level, const std::string& data,
}
void* LogInstance::run()
void* Logger::run()
{
m_running = true;
while (m_running == true) {
LogMessage* message = m_messages.remove();
LogMessage* message = m_logMessages.remove();
sinkCI_t iter = m_sinks.begin();
@@ -213,12 +212,13 @@ void* LogInstance::run()
if (((*iter)->getAreas() & message->getArea()
&& (*iter)->getLevel() >= message->getLevel())
&& message->isRunning() == true) {
&& message->isRunning() == true)
(*iter)->addMessage(*message);
} else if (message->isRunning() == false) {
else if (message->isRunning() == false)
(*iter)->addMessage(*message);
m_running = false;
}
}
}
@@ -229,8 +229,8 @@ void* LogInstance::run()
return NULL;
}
void LogInstance::stop()
void Logger::stop()
{
m_messages.add(new LogMessage(LogMessage(bas, error, "", false)));
m_logMessages.add(new LogMessage(LogMessage(bas, error, "", false)));
usleep(100000);
}
+209 -42
View File
@@ -28,142 +28,309 @@
#include <vector>
#include <cstdarg>
enum Areas { bas=1, net=2, bus=4, all=7, Size_of_Areas=3 };
enum Level { error=0, event, trace, debug, Size_of_Level };
/** available types for all subsystems */
enum AreasType {
bas=1, // basis
net=2, // network
bus=4, // ebus
all=7, // type for all subsystems
Size_of_Areas=3, // number of possible areas
};
/** available logging levels */
enum LevelType {
error=0, //
event, //
trace, //
debug, //
Size_of_Level, // number of possible levels
};
/** global function to get calculate logging areas */
int calcAreas(const std::string areas);
/** global function to get calculate logging level */
int calcLevel(const std::string level);
/**
* @brief class which describes a logging message itself.
*/
class LogMessage
{
public:
LogMessage(const int area, const int level, const std::string text, const bool run=true);
/**
* @brief creates a new logging message.
* @param area the logging area of the message.
* @param level the logging level of the message.
* @param text the logging message.
* @param running the status of logging subsystem.
*/
LogMessage(const int area, const int level, const std::string text, const bool running=true);
/**
* @brief copy constructor to duplicate a logging message.
* @param src a reference to logging message.
*/
LogMessage(const LogMessage& src)
: m_area(src.m_area), m_level(src.m_level), m_text(src.m_text),
m_run(src.m_run), m_time(src.m_time) {}
m_running(src.m_running), m_time(src.m_time) {}
void operator= (const LogMessage& src)
/**
* @brief copy operator to duplicate a logging message.
* @param src a reference to logging message.
*/
void operator=(const LogMessage& src)
{ m_area = src.m_area; m_level = src.m_level; m_text = src.m_text;
m_run = src.m_run; m_time = src.m_time; }
m_running = src.m_running; m_time = src.m_time; }
/**
* @brief get the logging area.
* @return the logging area.
*/
int getArea() const { return (m_area); }
/**
* @brief get the logging level.
* @return the logging level.
*/
int getLevel() const { return(m_level); }
/**
* @brief get the logging text.
* @return the logging text.
*/
std::string getText() const { return (m_text.c_str()); }
bool isRunning() const { return (m_run); }
/**
* @brief status of logging subsystem.
* @return false if logging subsystem is going down.
*/
bool isRunning() const { return m_running; }
/**
* @brief get the logging timestamp.
* @return the logging timestamp.
*/
std::string getTime() const { return (m_time.c_str()); }
private:
/** the logging area */
int m_area;
/** the logging level */
int m_level;
/** the logging message */
std::string m_text;
bool m_run;
/** true if this instance is running */
bool m_running;
/** the logging timestamp */
std::string m_time;
};
enum Type { Console, Logfile };
/**
* @brief base class for all type of logging sinks.
*/
class LogSink : public Thread
{
public:
LogSink(const int areas, const int level, const Type type, const char* name)
: m_areas(areas), m_level(level), m_type(type), m_name(name) {}
/**
* @brief creates a virtual logging sink.
* @param areas the logging areas.
* @param level the logging level.
*/
LogSink(const int areas, const int level) : m_areas(areas), m_level(level) {}
/**
* @brief adds the logging message to internal message queue.
* @param message a reference to logging message.
*/
void addMessage(const LogMessage& message);
/**
* @brief endless loop for logging sink instance.
* @return void pointer.
*/
void* run();
/**
* @brief get the logging areas.
* @return the logging areas.
*/
int getAreas() const { return (m_areas); }
/**
* @brief set the logging areas.
* @param areas the logging areas.
*/
void setAreas(const int& areas) { m_areas = areas; }
/**
* @brief get the logging level.
* @return the logging level.
*/
int getLevel() const { return (m_level); }
/**
* @brief set the logging level.
* @param level the logging level.
*/
void setLevel(const int& level) { m_level = level; }
Type getType() const { return (m_type); }
const char* getName() const { return (m_name.c_str()); }
protected:
WQueue<LogMessage*> m_queue;
/** queue for logging messages */
WQueue<LogMessage*> m_logMessages;
private:
/** the logging areas */
int m_areas;
int m_level;
Type m_type;
std::string m_name;
/** the logging level */
int m_level;
/**
* @brief virtual function for writing the logging message.
* @param message the logging message.
*/
virtual void write(const LogMessage& message) const = 0;
};
/**
* @brief class for console logging sink type.
*/
class LogConsole : public LogSink
{
public:
/**
* @brief creates a console logging sink.
* @param areas the logging areas.
* @param level the logging level.
* @param name the thread name for logging sink.
*/
LogConsole(const int areas, const int level, const char* name)
: LogSink(areas, level, Console, name), m_instance(++m_numInstance)
{ this->start(name); }
: LogSink(areas, level) { this->start(name); }
private:
const int m_instance;
static int m_numInstance;
/**
* @brief write the logging message to stdout.
* @param message the logging message.
*/
void write(const LogMessage& message) const;
};
/**
* @brief class for logfile logging sink type.
*/
class LogFile : public LogSink
{
public:
LogFile(const int areas, const int level, const char* name, const char* filename)
: LogSink(areas, level, Logfile, name), m_filename(filename), m_instance(++m_numInstance)
{ this->start(name); }
/**
* @brief creates a log file logging sink.
* @param areas the logging areas.
* @param level the logging level.
* @param name the thread name for logging sink.
* @param file the log file.
*/
LogFile(const int areas, const int level, const char* name, const char* file)
: LogSink(areas, level), m_file(file) { this->start(name); }
private:
std::string m_filename;
const int m_instance;
static int m_numInstance;
/** the logging file */
std::string m_file;
/**
* @brief write the logging message to specific log file.
* @param message the logging message.
*/
void write(const LogMessage& message) const;
};
class LogInstance : public Thread
/**
* @brief logger base class which provide the logging interface.
*/
class Logger : public Thread
{
public:
static LogInstance& Instance();
/**
* @brief create an instance and return the reference.
* @return the reference to instance.
*/
static Logger& Instance();
~LogInstance();
/**
* @brief destructor.
*/
~Logger();
LogInstance& operator+= (LogSink* sink);
LogInstance& operator-= (const LogSink* sink);
/**
* @brief adds a logging sink and returns the reference to logger.
* @param pointer of logging sink.
* @return the reference to logger.
*/
Logger& operator+=(LogSink* sink);
/**
* @brief removes a logging sink and returns the reference to logger.
* @param pointer of logging sink.
* @return the reference to logger.
*/
Logger& operator-=(const LogSink* sink);
/**
* @brief creates a logging message and add them to internal message queue.
* @param area the logging area of the message.
* @param level the logging level of the message.
* @param text the logging message.
* @param ... possible 'variable argument lists'.
*/
void log(const int area, const int level, const std::string& text, ...);
int getNumberOfSinks() const { return(m_sinks.size()); }
LogSink* getSink(const int Index) const { return(m_sinks[Index]); }
/**
* @brief returns the sink at the specified index.
* @param index the index of the sink to return.
* @return the sink at the specified index.
*/
LogSink* getSink(const int index) const { return(m_sinks[index]); }
/**
* @brief endless loop for logger instance.
* @return void pointer.
*/
void* run();
/**
* @brief shutdown logger subsystem.
*/
void stop();
private:
LogInstance() {}
LogInstance(const LogInstance&);
LogInstance& operator=(const LogInstance&);
/** private constructor - singleton pattern */
Logger() {}
Logger(const Logger&);
Logger& operator=(const Logger&);
/** typedefs for a vector of type LogSink* */
typedef std::vector<LogSink*> sink_t;
typedef std::vector<LogSink*>::iterator sinkCI_t;
/** vector of available logging sinks */
sink_t m_sinks;
WQueue<LogMessage*> m_messages;
/** queue for logging messages */
WQueue<LogMessage*> m_logMessages;
/** true if this instance is running */
bool m_running;
};
+6 -5
View File
@@ -42,21 +42,22 @@ public:
/**
* @brief file descriptor to watch for notify event.
* @return the notification value
* @return the notification value.
*/
int notifyFD() { return m_recvfd; }
/**
* @brief write notify event to file descriptor.
* @return result of writing notification
* @return result of writing notification.
*/
int notify() const { return write(m_sendfd,"1",1); }
private:
/** file descriptor to watch */
int m_recvfd;
/** file descriptor to notify */
int m_sendfd;
int m_recvfd;
/** file descriptor to notify */
int m_sendfd;
};
+8 -3
View File
@@ -24,7 +24,7 @@
#include <string>
/**
* @brief class for low level tcp socket operations. (open, close, send, receive)
* @brief class for low level tcp socket operations. (open, close, send, receive).
*/
class TCPSocket
{
@@ -82,8 +82,10 @@ public:
private:
/** file descriptor from tcp socket */
int m_sfd;
/** port of tcp socket */
int m_port;
/** ip address of tcp socket */
std::string m_ip;
@@ -122,8 +124,8 @@ class TCPServer
public:
/**
* @brief creates a new instance of a listening tcp server.
* @param port the tcp port
* @param address the ip address
* @param port the tcp port.
* @param address the ip address.
*/
TCPServer(const int port, const std::string address)
: m_lfd(0), m_port(port), m_address(address), m_listening(false) {}
@@ -153,10 +155,13 @@ public:
private:
/** file descriptor from listening tcp socket */
int m_lfd;
/** listening tcp port */
int m_port;
/** listening tcp socket ip address */
std::string m_address;
/** true if object is already listening */
bool m_listening;
+3 -1
View File
@@ -65,7 +65,7 @@ public:
pthread_t self() {return m_threadid; }
/**
* @brief virtul function which must be implented in derived class.
* @brief virtul function which must be implemented in derived class.
* @return void pointer.
*/
virtual void* run() = 0;
@@ -73,8 +73,10 @@ public:
private:
/** own thread id */
pthread_t m_threadid;
/** true if thread is running */
bool m_running;
/** true if thread is detached */
bool m_detached;
+6 -4
View File
@@ -51,7 +51,7 @@ public:
/**
* @brief add a new item to the end of queue.
* @param item
* @param item to add.
*/
void add(T item)
{
@@ -65,7 +65,7 @@ public:
/**
* @brief remove the first item from queue.
* @return the item
* @return the item.
*/
T remove()
{
@@ -84,7 +84,7 @@ public:
/**
* @brief return the first item from queue without remove.
* @return the item
* @return the item.
*/
T next()
{
@@ -102,7 +102,7 @@ public:
/**
* @brief the number of entries inside queue.
* @return the size
* @return the size.
*/
int size()
{
@@ -118,8 +118,10 @@ public:
private:
/** the queue itself */
std::list<T> m_queue;
/** mutex variable for exclusive lock */
pthread_mutex_t m_mutex;
/** condition variable for exclusive lock */
pthread_cond_t m_cond;