Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
network.h
1
2
/***************************************************************************
3
* network - Fawkes network logger
4
*
5
* Created: Sat Dec 15 00:45:54 2007 (after I5 xmas party)
6
* Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#ifndef __LOGGING_NETWORK_H_
25
#define __LOGGING_NETWORK_H_
26
27
#include <core/utils/lock_list.h>
28
#include <core/utils/lock_queue.h>
29
#include <logging/logger.h>
30
#include <netcomm/fawkes/handler.h>
31
#include <netcomm/fawkes/message_content.h>
32
33
#include <stdint.h>
34
35
namespace
fawkes {
36
37
class
Mutex;
38
class
FawkesNetworkHub;
39
40
class
NetworkLogger
41
:
public
Logger
,
42
public
FawkesNetworkHandler
43
{
44
public
:
45
NetworkLogger
(
FawkesNetworkHub
*hub,
LogLevel
log_level
=
LL_DEBUG
);
46
virtual
~NetworkLogger
();
47
48
virtual
void
log_debug
(
const
char
*component,
const
char
*format, ...);
49
virtual
void
log_info
(
const
char
*component,
const
char
*format, ...);
50
virtual
void
log_warn
(
const
char
*component,
const
char
*format, ...);
51
virtual
void
log_error
(
const
char
*component,
const
char
*format, ...);
52
53
virtual
void
log_debug
(
const
char
*component,
Exception
&e);
54
virtual
void
log_info
(
const
char
*component,
Exception
&e);
55
virtual
void
log_warn
(
const
char
*component,
Exception
&e);
56
virtual
void
log_error
(
const
char
*component,
Exception
&e);
57
58
virtual
void
vlog_debug
(
const
char
*component,
const
char
*format, va_list va);
59
virtual
void
vlog_info
(
const
char
*component,
const
char
*format, va_list va);
60
virtual
void
vlog_warn
(
const
char
*component,
const
char
*format, va_list va);
61
virtual
void
vlog_error
(
const
char
*component,
const
char
*format, va_list va);
62
63
virtual
void
tlog_debug
(
struct
timeval *t,
const
char
*component,
const
char
*format, ...);
64
virtual
void
tlog_info
(
struct
timeval *t,
const
char
*component,
const
char
*format, ...);
65
virtual
void
tlog_warn
(
struct
timeval *t,
const
char
*component,
const
char
*format, ...);
66
virtual
void
tlog_error
(
struct
timeval *t,
const
char
*component,
const
char
*format, ...);
67
68
virtual
void
tlog_debug
(
struct
timeval *t,
const
char
*component,
Exception
&e);
69
virtual
void
tlog_info
(
struct
timeval *t,
const
char
*component,
Exception
&e);
70
virtual
void
tlog_warn
(
struct
timeval *t,
const
char
*component,
Exception
&e);
71
virtual
void
tlog_error
(
struct
timeval *t,
const
char
*component,
Exception
&e);
72
73
virtual
void
vtlog_debug
(
struct
timeval *t,
const
char
*component,
74
const
char
*format, va_list va);
75
virtual
void
vtlog_info
(
struct
timeval *t,
const
char
*component,
76
const
char
*format, va_list va);
77
virtual
void
vtlog_warn
(
struct
timeval *t,
const
char
*component,
78
const
char
*format, va_list va);
79
virtual
void
vtlog_error
(
struct
timeval *t,
const
char
*component,
80
const
char
*format, va_list va);
81
82
virtual
void
handle_network_message
(
FawkesNetworkMessage
*msg);
83
virtual
void
client_connected
(
unsigned
int
clid);
84
virtual
void
client_disconnected
(
unsigned
int
clid);
85
86
/** NetworkLogger message types. */
87
typedef
enum
{
88
MSGTYPE_SUBSCRIBE
= 1,
/**< Subscribe for logging messages. */
89
MSGTYPE_UNSUBSCRIBE
= 2,
/**< Unsubscribe from receiving logging messages. */
90
MSGTYPE_LOGMESSAGE
= 3
/**< Log message. */
91
}
network_logger_msgtype_t
;
92
93
#pragma pack(push,4)
94
/** Network logging message header. */
95
typedef
struct
{
96
uint32_t
log_level
: 4;
/**< LogLevel, @see Logger::LogLevel */
97
uint32_t exception : 1;
/**< 1 if message was generated by exception, 0 otherwise */
98
uint32_t reserved : 27;
/**< reserved for future use */
99
uint64_t
time_sec
;
/**< time in seconds since the epoch, encoded in network byte order */
100
uint32_t
time_usec
;
/**< addition to time in usec, encoded in network byte order */
101
}
network_logger_header_t
;
102
#pragma pack(pop)
103
104
private
:
105
void
send_message(
Logger::LogLevel
level,
struct
timeval *t,
106
const
char
*component,
bool
is_exception,
107
const
char
*format, va_list va);
108
void
send_message(
Logger::LogLevel
level,
struct
timeval *t,
109
const
char
*component,
bool
is_exception,
const
char
*message);
110
111
FawkesNetworkHub
*hub;
112
113
LockQueue< FawkesNetworkMessage * >
inbound_queue;
114
115
LockList<unsigned int>
__subscribers;
116
LockList<unsigned int>::iterator
__ssit;
117
};
118
119
120
class
NetworkLoggerMessageContent
:
public
FawkesNetworkMessageContent
121
{
122
public
:
123
NetworkLoggerMessageContent
(
Logger::LogLevel
log_level,
struct
timeval *t,
124
const
char
*component,
bool
is_exception
,
125
const
char
*message);
126
NetworkLoggerMessageContent
(
Logger::LogLevel
log_level,
struct
timeval *t,
127
const
char
*component,
bool
is_exception,
128
const
char
*format, va_list va);
129
NetworkLoggerMessageContent
(
const
NetworkLoggerMessageContent
*content);
130
NetworkLoggerMessageContent
(
unsigned
int
component_id,
unsigned
int
msg_id,
131
void
*
payload
,
size_t
payload_size
);
132
virtual
~NetworkLoggerMessageContent
();
133
134
struct
timeval get_time() const;
135
Logger::LogLevel
get_loglevel
()
const
;
136
const
char
*
get_component
()
const
;
137
const
char
*
get_message
()
const
;
138
bool
is_exception
()
const
;
139
140
virtual
void
serialize
();
141
142
private
:
143
NetworkLogger::network_logger_header_t
*header;
144
const
char
*__component;
145
const
char
*__message;
146
bool
__own_payload;
147
};
148
149
}
// end namespace fawkes
150
151
#endif
src
libs
logging
network.h
Generated by
1.8.1.2