Fawkes API  Fawkes Development Version
log_thread.h
1 
2 /***************************************************************************
3  * log_thread.h - BB Logger Thread
4  *
5  * Created: Sat Nov 07 23:40:48 2009
6  * Copyright 2006-2009 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.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_BBLOGGER_LOG_THREAD_H_
24 #define __PLUGINS_BBLOGGER_LOG_THREAD_H_
25 
26 #include <core/threading/thread.h>
27 #include <aspect/logging.h>
28 #include <aspect/configurable.h>
29 #include <aspect/blackboard.h>
30 #include <aspect/clock.h>
31 #include <blackboard/interface_listener.h>
32 
33 #include <core/utils/lock_queue.h>
34 #include <core/threading/thread_list.h>
35 
36 #include <cstdio>
37 
38 namespace fawkes {
39  class BlackBoard;
40  class Logger;
41  class Mutex;
42  class Time;
43  class SwitchInterface;
44 }
45 
47 : public fawkes::Thread,
48  public fawkes::LoggingAspect,
50  public fawkes::ClockAspect,
53 {
54  public:
55  BBLoggerThread(const char *iface_uid,
56  const char *logdir, bool buffering, bool flushing,
57  const char *scenario, fawkes::Time *start_time);
58  virtual ~BBLoggerThread();
59 
60  const char * get_filename() const;
61  void set_threadlist(fawkes::ThreadList &thread_list);
62  void set_enabled(bool enabled);
63 
64  virtual void init();
65  virtual void finalize();
66  virtual void loop();
67 
68  virtual bool bb_interface_message_received(fawkes::Interface *interface, fawkes::Message *message) throw();
69  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
70  virtual void bb_interface_writer_added(fawkes::Interface *interface,
71  unsigned int instance_serial) throw();
72  virtual void bb_interface_writer_removed(fawkes::Interface *interface,
73  unsigned int instance_serial) throw();
74 
75  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
76  protected: virtual void run() { Thread::run(); }
77 
78  private:
79  void write_header();
80  void update_header();
81  void write_chunk(const void *chunk);
82 
83 
84  private:
85  fawkes::Interface *__iface;
86 
87  unsigned int __num_data_items;
88  unsigned int __session_start;
89 
90  bool __enabled;
91  bool __buffering;
92  bool __flushing;
93  size_t __data_size;
94  char *__scenario;
95  char *__filename;
96  char *__logdir;
97  char *__uid;
98  std::string __type;
99  std::string __id;
100  FILE *__f_data;
101 
102  fawkes::Time *__start;
103  fawkes::Time *__now;
104 
105  bool __is_master;
106  fawkes::ThreadList __threads;
107  fawkes::SwitchInterface *__switch_if;
108 
109  fawkes::Mutex *__queue_mutex;
110  unsigned int __act_queue;
111  fawkes::LockQueue<void *> __queues[2];
112 };
113 
114 
115 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
A class for handling time.
Definition: time.h:91
Thread class encapsulation of pthreads.
Definition: thread.h:42
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
BlackBoard logger thread.
Definition: log_thread.h:46
List of threads.
Definition: thread_list.h:57
SwitchInterface Fawkes BlackBoard Interface.
Thread aspect to log output.
Definition: logging.h:35
Queue with a lock.
Definition: lock_queue.h:43
Thread aspect to access configuration data.
Definition: configurable.h:35
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: log_thread.h:76
Mutex mutual exclusion lock.
Definition: mutex.h:32
BlackBoard interface listener.