class LogInstance renamed to Logger; documentation for logging subsystem added.
This commit is contained in:
+25
-25
@@ -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);
|
||||
|
||||
|
||||
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user