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 <aspect/blackboard.h>
27 #include <aspect/clock.h>
28 #include <aspect/configurable.h>
29 #include <aspect/logging.h>
30 #include <blackboard/interface_listener.h>
31 #include <core/threading/thread.h>
32 #include <core/threading/thread_list.h>
33 #include <core/utils/lock_queue.h>
34 
35 #include <cstdio>
36 
37 namespace fawkes {
38 class BlackBoard;
39 class Logger;
40 class Mutex;
41 class Time;
42 class SwitchInterface;
43 } // namespace fawkes
44 
45 class BBLoggerThread : public fawkes::Thread,
46  public fawkes::LoggingAspect,
48  public fawkes::ClockAspect,
51 {
52 public:
53  BBLoggerThread(const char * iface_uid,
54  const char * logdir,
55  bool buffering,
56  bool flushing,
57  const char * scenario,
58  fawkes::Time *start_time);
59  virtual ~BBLoggerThread();
60 
61  const char *get_filename() const;
62  void set_threadlist(fawkes::ThreadList &thread_list);
63  void set_enabled(bool enabled);
64 
65  virtual void init();
66  virtual void finalize();
67  virtual void loop();
68 
69  virtual bool bb_interface_message_received(fawkes::Interface *interface,
70  fawkes::Message * message) throw();
71  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
72  virtual void bb_interface_writer_added(fawkes::Interface *interface,
73  unsigned int instance_serial) throw();
74  virtual void bb_interface_writer_removed(fawkes::Interface *interface,
75  unsigned int instance_serial) throw();
76 
77  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
78 protected:
79  virtual void
80  run()
81  {
82  Thread::run();
83  }
84 
85 private:
86  void write_header();
87  void update_header();
88  void write_chunk(const void *chunk);
89 
90 private:
91  fawkes::Interface *iface_;
92 
93  unsigned int num_data_items_;
94  unsigned int session_start_;
95 
96  bool enabled_;
97  bool buffering_;
98  bool flushing_;
99  size_t data_size_;
100  char * scenario_;
101  char * filename_;
102  char * logdir_;
103  char * uid_;
104  std::string type_;
105  std::string id_;
106  FILE * f_data_;
107 
108  fawkes::Time *start_;
109  fawkes::Time *now_;
110 
111  bool is_master_;
112  fawkes::ThreadList threads_;
113  fawkes::SwitchInterface *switch_if_;
114 
115  fawkes::Mutex * queue_mutex_;
116  unsigned int act_queue_;
117  fawkes::LockQueue<void *> queues_[2];
118 };
119 
120 #endif
BBLoggerThread::init
virtual void init()
Initialize the thread.
Definition: log_thread.cpp:130
BBLoggerThread::set_enabled
void set_enabled(bool enabled)
Enable or disable logging.
Definition: log_thread.cpp:229
fawkes::Mutex
Definition: mutex.h:36
fawkes::SwitchInterface
Definition: SwitchInterface.h:37
fawkes::Message
Definition: message.h:40
fawkes::BlackBoardInterfaceListener
Definition: interface_listener.h:45
BBLoggerThread::finalize
virtual void finalize()
Finalize the thread.
Definition: log_thread.cpp:196
BBLoggerThread::bb_interface_message_received
virtual bool bb_interface_message_received(fawkes::Interface *interface, fawkes::Message *message)
BlackBoard message received notification.
Definition: log_thread.cpp:348
BBLoggerThread::BBLoggerThread
BBLoggerThread(const char *iface_uid, const char *logdir, bool buffering, bool flushing, const char *scenario, fawkes::Time *start_time)
Constructor.
Definition: log_thread.cpp:77
BBLoggerThread::bb_interface_writer_removed
virtual void bb_interface_writer_removed(fawkes::Interface *interface, unsigned int instance_serial)
A writing instance has been closed for a watched interface.
Definition: log_thread.cpp:412
BBLoggerThread::bb_interface_data_changed
virtual void bb_interface_data_changed(fawkes::Interface *interface)
BlackBoard data changed notification.
Definition: log_thread.cpp:377
fawkes::BlackBoardAspect
Definition: blackboard.h:36
fawkes
fawkes::LoggingAspect
Definition: logging.h:36
BBLoggerThread::loop
virtual void loop()
Code to execute in the thread.
Definition: log_thread.cpp:331
BBLoggerThread::get_filename
const char * get_filename() const
Get filename.
Definition: log_thread.cpp:220
fawkes::Interface
Definition: interface.h:77
BBLoggerThread::~BBLoggerThread
virtual ~BBLoggerThread()
Destructor.
Definition: log_thread.cpp:119
BBLoggerThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: log_thread.h:79
fawkes::Time
Definition: time.h:96
BBLoggerThread::bb_interface_writer_added
virtual void bb_interface_writer_added(fawkes::Interface *interface, unsigned int instance_serial)
A writing instance has been opened for a watched interface.
Definition: log_thread.cpp:405
fawkes::LockQueue< void * >
fawkes::Thread
Definition: thread.h:44
BBLoggerThread
Definition: log_thread.h:44
fawkes::ConfigurableAspect
Definition: configurable.h:36
fawkes::ClockAspect
Definition: clock.h:38
BBLoggerThread::set_threadlist
void set_threadlist(fawkes::ThreadList &thread_list)
Set threadlist and master status.
Definition: log_thread.cpp:252
fawkes::ThreadList
Definition: thread_list.h:59