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#include <utils/uuid.h>
35
36#include <cstdio>
37
38namespace fawkes {
39class BlackBoard;
40class Logger;
41class Mutex;
42class Time;
43class SwitchInterface;
44} // namespace fawkes
45
52{
53public:
54 BBLoggerThread(const char * iface_uid,
55 const char * logdir,
56 bool buffering,
57 bool flushing,
58 const char * scenario,
59 fawkes::Time *start_time);
60 virtual ~BBLoggerThread();
61
62 const char *get_filename() const;
63 void set_threadlist(fawkes::ThreadList &thread_list);
64 void set_enabled(bool enabled);
65
66 virtual void init();
67 virtual void finalize();
68 virtual void loop();
69
71 fawkes::Message * message) noexcept;
72 virtual void bb_interface_data_refreshed(fawkes::Interface *interface) noexcept;
73 virtual void bb_interface_writer_added(fawkes::Interface *interface,
74 fawkes::Uuid instance_serial) noexcept;
75 virtual void bb_interface_writer_removed(fawkes::Interface *interface,
76 fawkes::Uuid instance_serial) noexcept;
77
78 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
79protected:
80 virtual void
82 {
83 Thread::run();
84 }
85
86private:
87 void write_header();
88 void update_header();
89 void write_chunk(const void *chunk);
90
91private:
92 fawkes::Interface *iface_;
93
94 unsigned int num_data_items_;
95 unsigned int session_start_;
96
97 bool enabled_;
98 bool buffering_;
99 bool flushing_;
100 size_t data_size_;
101 char * scenario_;
102 char * filename_;
103 char * logdir_;
104 char * uid_;
105 std::string type_;
106 std::string id_;
107 FILE * f_data_;
108
109 fawkes::Time *start_;
110 fawkes::Time *now_;
111
112 bool is_master_;
113 fawkes::ThreadList threads_;
114 fawkes::SwitchInterface *switch_if_;
115
116 fawkes::Mutex * queue_mutex_;
117 unsigned int act_queue_;
118 fawkes::LockQueue<void *> queues_[2];
119};
120
121#endif
BlackBoard logger thread.
Definition: log_thread.h:52
virtual ~BBLoggerThread()
Destructor.
Definition: log_thread.cpp:120
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: log_thread.h:81
virtual void init()
Initialize the thread.
Definition: log_thread.cpp:131
const char * get_filename() const
Get filename.
Definition: log_thread.cpp:221
virtual void bb_interface_data_refreshed(fawkes::Interface *interface) noexcept
BlackBoard data refreshed notification.
Definition: log_thread.cpp:378
virtual void finalize()
Finalize the thread.
Definition: log_thread.cpp:197
virtual void bb_interface_writer_added(fawkes::Interface *interface, fawkes::Uuid instance_serial) noexcept
A writing instance has been opened for a watched interface.
Definition: log_thread.cpp:406
void set_threadlist(fawkes::ThreadList &thread_list)
Set threadlist and master status.
Definition: log_thread.cpp:253
virtual void loop()
Code to execute in the thread.
Definition: log_thread.cpp:332
virtual bool bb_interface_message_received(fawkes::Interface *interface, fawkes::Message *message) noexcept
BlackBoard message received notification.
Definition: log_thread.cpp:349
BBLoggerThread(const char *iface_uid, const char *logdir, bool buffering, bool flushing, const char *scenario, fawkes::Time *start_time)
Constructor.
Definition: log_thread.cpp:78
virtual void bb_interface_writer_removed(fawkes::Interface *interface, fawkes::Uuid instance_serial) noexcept
A writing instance has been closed for a watched interface.
Definition: log_thread.cpp:412
void set_enabled(bool enabled)
Enable or disable logging.
Definition: log_thread.cpp:230
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
BlackBoard interface listener.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
Thread aspect to access configuration data.
Definition: configurable.h:33
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Thread aspect to log output.
Definition: logging.h:33
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Mutex mutual exclusion lock.
Definition: mutex.h:33
SwitchInterface Fawkes BlackBoard Interface.
List of threads.
Definition: thread_list.h:56
Thread class encapsulation of pthreads.
Definition: thread.h:46
A class for handling time.
Definition: time.h:93
A convenience class for universally unique identifiers (UUIDs).
Definition: uuid.h:29
Fawkes library namespace.