Fawkes API
Fawkes Development Version
|
23 #include <logging/console.h>
24 #include <netcomm/fawkes/client.h>
25 #include <netcomm/fawkes/client_handler.h>
26 #include <netcomm/fawkes/component_ids.h>
27 #include <network_logger/network_logger.h>
28 #include <utils/system/argparser.h>
29 #include <utils/system/signal.h>
42 explicit NetLogConsolePrinter(
const char *hostport)
47 char * hp = strdup(hostport);
48 const char *hostname = strtok(hp,
":");
49 const char *portstr = strtok(NULL,
"");
53 if ((port < 0) || (port > 0xFFFF)) {
54 printf(
"Invalid port given, must be in range [1:65535]. Using default 1910 instead\n");
61 client->register_handler(
this, FAWKES_CID_NETWORKLOGGER);
67 ~NetLogConsolePrinter()
74 handle_signal(
int signal)
77 client->wake(FAWKES_CID_NETWORKLOGGER);
83 if ((m->cid() == FAWKES_CID_NETWORKLOGGER)
86 struct timeval t = content->
get_time();
93 deregistered(
unsigned int id)
throw()
99 connection_died(
unsigned int id)
throw()
101 printf(
"Connection to host died. Aborting.\n");
106 connection_established(
unsigned int id)
throw()
114 client->wait(FAWKES_CID_NETWORKLOGGER);
116 client->disconnect();
127 print_usage(
const char *program_name)
129 printf(
"Usage: %s [hostname[:port]]\n", program_name);
133 main(
int argc,
char **argv)
137 if (argp.has_arg(
"h")) {
138 print_usage(argv[0]);
142 const char * hostport = (argp.num_items() > 0) ? argp.items()[0] :
"localhost:1910";
143 NetLogConsolePrinter printer(hostport);
Message sent over the network with a log message.
Interface for logging to stderr.
Interface for signal handling.
struct timeval get_time() const
Get time.
@ MSGTYPE_SUBSCRIBE
Subscribe for logging messages.
static SignalHandler * register_handler(int signum, SignalHandler *handler)
Register a SignalHandler for a signal.
virtual void tlog(LogLevel level, struct timeval *t, const char *component, const char *format,...)
Log message of given log level and time.
Message handler for FawkesNetworkClient.
Logger::LogLevel get_loglevel() const
Log level.
Fawkes library namespace.
Parse command line arguments.
@ MSGTYPE_LOGMESSAGE
Log message.
Representation of a message that is sent over the network.
Simple Fawkes network client.
const char * get_component() const
Get component.
const char * get_message() const
Get message.