00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __NETCOMM_UTILS_NETWORK_LOGGER_H_
00025 #define __NETCOMM_UTILS_NETWORK_LOGGER_H_
00026
00027 #include <core/utils/lock_list.h>
00028 #include <core/utils/lock_queue.h>
00029 #include <utils/logging/logger.h>
00030 #include <netcomm/fawkes/handler.h>
00031 #include <netcomm/fawkes/message_content.h>
00032
00033 #include <stdint.h>
00034
00035 namespace fawkes {
00036
00037 class Mutex;
00038 class FawkesNetworkHub;
00039
00040 class NetworkLogger
00041 : public Logger,
00042 public FawkesNetworkHandler
00043 {
00044 public:
00045 NetworkLogger(FawkesNetworkHub *hub, LogLevel log_level = LL_DEBUG);
00046 virtual ~NetworkLogger();
00047
00048 virtual void log_debug(const char *component, const char *format, ...);
00049 virtual void log_info(const char *component, const char *format, ...);
00050 virtual void log_warn(const char *component, const char *format, ...);
00051 virtual void log_error(const char *component, const char *format, ...);
00052
00053 virtual void log_debug(const char *component, Exception &e);
00054 virtual void log_info(const char *component, Exception &e);
00055 virtual void log_warn(const char *component, Exception &e);
00056 virtual void log_error(const char *component, Exception &e);
00057
00058 virtual void vlog_debug(const char *component, const char *format, va_list va);
00059 virtual void vlog_info(const char *component, const char *format, va_list va);
00060 virtual void vlog_warn(const char *component, const char *format, va_list va);
00061 virtual void vlog_error(const char *component, const char *format, va_list va);
00062
00063 virtual void tlog_debug(struct timeval *t, const char *component, const char *format, ...);
00064 virtual void tlog_info(struct timeval *t, const char *component, const char *format, ...);
00065 virtual void tlog_warn(struct timeval *t, const char *component, const char *format, ...);
00066 virtual void tlog_error(struct timeval *t, const char *component, const char *format, ...);
00067
00068 virtual void tlog_debug(struct timeval *t, const char *component, Exception &e);
00069 virtual void tlog_info(struct timeval *t, const char *component, Exception &e);
00070 virtual void tlog_warn(struct timeval *t, const char *component, Exception &e);
00071 virtual void tlog_error(struct timeval *t, const char *component, Exception &e);
00072
00073 virtual void vtlog_debug(struct timeval *t, const char *component,
00074 const char *format, va_list va);
00075 virtual void vtlog_info(struct timeval *t, const char *component,
00076 const char *format, va_list va);
00077 virtual void vtlog_warn(struct timeval *t, const char *component,
00078 const char *format, va_list va);
00079 virtual void vtlog_error(struct timeval *t, const char *component,
00080 const char *format, va_list va);
00081
00082 virtual void handle_network_message(FawkesNetworkMessage *msg);
00083 virtual void client_connected(unsigned int clid);
00084 virtual void client_disconnected(unsigned int clid);
00085
00086
00087 typedef enum {
00088 MSGTYPE_SUBSCRIBE = 1,
00089 MSGTYPE_UNSUBSCRIBE = 2,
00090 MSGTYPE_LOGMESSAGE = 3
00091 } network_logger_msgtype_t;
00092
00093 #pragma pack(push,4)
00094
00095 typedef struct {
00096 uint32_t log_level : 4;
00097 uint32_t exception : 1;
00098 uint32_t reserved : 27;
00099 uint64_t time_sec;
00100 uint32_t time_usec;
00101 } network_logger_header_t;
00102 #pragma pack(pop)
00103
00104 private:
00105 void send_message(Logger::LogLevel level, struct timeval *t,
00106 const char *component, bool is_exception,
00107 const char *format, va_list va);
00108 void send_message(Logger::LogLevel level, struct timeval *t,
00109 const char *component, bool is_exception, const char *message);
00110
00111 FawkesNetworkHub *hub;
00112
00113 LockQueue< FawkesNetworkMessage * > inbound_queue;
00114
00115 LockList<unsigned int> __subscribers;
00116 LockList<unsigned int>::iterator __ssit;
00117 };
00118
00119
00120 class NetworkLoggerMessageContent : public FawkesNetworkMessageContent
00121 {
00122 public:
00123 NetworkLoggerMessageContent(Logger::LogLevel log_level, struct timeval *t,
00124 const char *component, bool is_exception,
00125 const char *message);
00126 NetworkLoggerMessageContent(Logger::LogLevel log_level, struct timeval *t,
00127 const char *component, bool is_exception,
00128 const char *format, va_list va);
00129 NetworkLoggerMessageContent(const NetworkLoggerMessageContent *content);
00130 NetworkLoggerMessageContent(unsigned int component_id, unsigned int msg_id,
00131 void *payload, size_t payload_size);
00132 virtual ~NetworkLoggerMessageContent();
00133
00134 struct timeval get_time() const;
00135 Logger::LogLevel get_loglevel() const;
00136 const char * get_component() const;
00137 const char * get_message() const;
00138 bool is_exception() const;
00139
00140 virtual void serialize();
00141
00142 private:
00143 NetworkLogger::network_logger_header_t *header;
00144 const char *__component;
00145 const char *__message;
00146 bool __own_payload;
00147 };
00148
00149 }
00150
00151 #endif