24 #include <gui_utils/connection_dispatcher.h> 25 #include <gui_utils/logview.h> 26 #include <netcomm/fawkes/client.h> 27 #include <network_logger/network_logger.h> 61 : Gtk::TreeView(cobject)
75 delete connection_dispatcher_;
80 LogView::ctor(
const char *hostname,
unsigned short int port)
82 list_ = Gtk::ListStore::create(record_);
84 have_recently_added_path_ =
false;
86 list_->signal_row_inserted().connect(sigc::mem_fun(*
this, &LogView::on_row_inserted));
87 get_selection()->set_mode(Gtk::SELECTION_NONE);
89 if ((hostname != NULL) && (port != 0)) {
92 connection_dispatcher_ =
new ConnectionDispatcher(FAWKES_CID_NETWORKLOGGER);
95 append_column(
"Level", record_.loglevel);
96 append_column(
"Time", record_.time);
97 int compcol = append_column(
"Component", record_.component);
98 int msgcol = append_column(
"Message", record_.message);
105 Glib::ListHandle<Gtk::TreeViewColumn *> columns = get_columns();
107 for (Glib::ListHandle<Gtk::TreeViewColumn *>::iterator c = columns.begin(); c != columns.end();
110 #if GTK_VERSION_GE(3, 0) 111 Gtk::CellRenderer *cell_renderer = (*c)->get_first_cell();
113 Gtk::CellRenderer *cell_renderer = (*c)->get_first_cell_renderer();
115 Gtk::CellRendererText *text_renderer = dynamic_cast<Gtk::CellRendererText *>(cell_renderer);
117 #ifdef GLIBMM_PROPERTIES_ENABLED 118 if ((colnum == compcol) || (colnum == msgcol)) {
119 (*c)->set_resizable();
121 if (colnum == compcol) {
122 text_renderer->property_ellipsize().set_value(Pango::ELLIPSIZE_END);
125 (*c)->add_attribute(text_renderer->property_background_gdk(), record_.background);
126 (*c)->add_attribute(text_renderer->property_foreground_gdk(), record_.foreground);
128 (*c)->add_attribute(*text_renderer,
"background-gdk", record_.background);
129 (*c)->add_attribute(*text_renderer,
"foreground-gdk", record_.background);
135 sigc::mem_fun(*
this, &LogView::on_message_received));
137 sigc::mem_fun(*
this, &LogView::on_client_connected));
139 sigc::mem_fun(*
this, &LogView::on_client_disconnected));
140 #if GTK_VERSION_LT(3, 0) 141 signal_expose_event().connect_notify(sigc::mem_fun(*
this, &LogView::on_expose_notify));
180 return connection_dispatcher_;
195 LogView::on_row_inserted(
const Gtk::TreeModel::Path &path,
const Gtk::TreeModel::iterator &iter)
197 Gtk::TreeModel::Path vstart, vend;
198 Gtk::TreeModel::Path prev = path;
199 get_visible_range(vstart, vend);
201 if (!get_visible_range(vstart, vend)
203 && ((vend == prev) || (have_recently_added_path_ && (recently_added_path_ == prev))))) {
209 have_recently_added_path_ =
true;
210 recently_added_path_ = path;
214 #if GTK_VERSION_GE(3, 0) 216 LogView::on_draw(
const Cairo::RefPtr<Cairo::Context> &cr)
218 have_recently_added_path_ =
false;
219 return Gtk::TreeView::on_draw(cr);
223 LogView::on_expose_notify(GdkEventExpose *event)
225 have_recently_added_path_ =
false;
230 LogView::on_client_connected()
232 FawkesNetworkClient *c = connection_dispatcher_->
get_client();
233 if (c && c->connected()) {
234 FawkesNetworkMessage *msg =
238 gettimeofday(&t, NULL);
244 LogView::on_client_disconnected()
247 gettimeofday(&t, NULL);
261 const char * component,
263 const char * message)
265 const char *loglevel;
269 bool set_foreground =
false;
270 bool set_background =
false;
275 color.set_rgb_p(0.4, 0.4, 0.4);
276 set_foreground =
true;
281 color.set_rgb_p(1.0, 1.0, 0.7);
282 set_background =
true;
286 color.set_rgb_p(1.0, 0.8, 0.8);
287 set_background =
true;
291 color.set_rgb_p(1.0, 0.0, 0.0);
292 set_background =
true;
297 localtime_r(&(t.tv_sec), &time_tm);
299 &time,
"%02d:%02d:%02d.%06ld", time_tm.tm_hour, time_tm.tm_min, time_tm.tm_sec, t.tv_usec)
301 timestr =
"OutOfMemory";
306 Gtk::TreeModel::Row row = *list_->append();
307 row[record_.loglevel] = loglevel;
308 row[record_.time] = timestr;
309 row[record_.component] = component;
311 row[record_.message] = std::string(
"[EXCEPTION] ") + message;
313 row[record_.message] = message;
316 row[record_.foreground] = color;
318 row[record_.background] = color;
330 if ((msg->
cid() == FAWKES_CID_NETWORKLOGGER)
349 LogView::LogRecord::LogRecord()
const char * get_component() const
Get component.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
const char * get_message() const
Get message.
sigc::signal< void > signal_connected()
Get "connected" signal.
Message sent over the network with a log message.
informational output about normal procedures
ConnectionDispatcher * get_connection_dispatcher() const
Get ConnectionDispatcher instance that is used internally.
Simple Fawkes network client.
void clear()
Clear all records.
unsigned short int cid() const
Get component ID.
FawkesNetworkClient * get_client()
Get the used FawkesNetworkClient.
Fawkes library namespace.
void enqueue(FawkesNetworkMessage *message)
Enqueue message to send.
Representation of a message that is sent over the network.
warning, should be investigated but software still functions, an example is that something was reques...
Logger::LogLevel get_loglevel() const
Log level.
void set_client(FawkesNetworkClient *client)
Set Fawkes network client.
MT * msgc() const
Get correctly parsed output.
void append_message(Logger::LogLevel log_level, struct timeval t, const char *component, bool is_exception, const char *message)
Append a single message.
error, may be recoverable (software still running) or not (software has to terminate).
bool is_exception() const
Check if message was generated by exception.
debug output, relevant only when tracking down problems
unsigned short int msgid() const
Get message type ID.
Unsubscribe from receiving logging messages.
sigc::signal< void, FawkesNetworkMessage * > signal_message_received()
Get "message received" signal.
bool connected() const
Check if connection is alive.
void set_client(FawkesNetworkClient *client)
Set FawkesNetworkClient instance.
FawkesNetworkClient * get_client()
Get client.
Watches network client events and dispatches them as signals.
struct timeval get_time() const
Get time.
Subscribe for logging messages.