Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * log_thread.h - BB Logger Thread 00004 * 00005 * Created: Sat Nov 07 23:40:48 2009 00006 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_BBLOGGER_LOG_THREAD_H_ 00024 #define __PLUGINS_BBLOGGER_LOG_THREAD_H_ 00025 00026 #include <core/threading/thread.h> 00027 #include <aspect/logging.h> 00028 #include <aspect/configurable.h> 00029 #include <aspect/blackboard.h> 00030 #include <aspect/clock.h> 00031 #include <blackboard/interface_listener.h> 00032 00033 #include <core/utils/lock_queue.h> 00034 #include <core/threading/thread_list.h> 00035 00036 #include <cstdio> 00037 00038 namespace fawkes { 00039 class BlackBoard; 00040 class Logger; 00041 class Mutex; 00042 class Time; 00043 class SwitchInterface; 00044 } 00045 00046 class BBLoggerThread 00047 : public fawkes::Thread, 00048 public fawkes::LoggingAspect, 00049 public fawkes::ConfigurableAspect, 00050 public fawkes::ClockAspect, 00051 public fawkes::BlackBoardAspect, 00052 public fawkes::BlackBoardInterfaceListener 00053 { 00054 public: 00055 BBLoggerThread(const char *iface_uid, 00056 const char *logdir, bool buffering, bool flushing, 00057 const char *scenario, fawkes::Time *start_time); 00058 virtual ~BBLoggerThread(); 00059 00060 const char * get_filename() const; 00061 void set_threadlist(fawkes::ThreadList &thread_list); 00062 void set_enabled(bool enabled); 00063 00064 virtual void init(); 00065 virtual void finalize(); 00066 virtual void loop(); 00067 00068 virtual bool bb_interface_message_received(fawkes::Interface *interface, fawkes::Message *message) throw(); 00069 virtual void bb_interface_data_changed(fawkes::Interface *interface) throw(); 00070 virtual void bb_interface_writer_added(fawkes::Interface *interface, 00071 unsigned int instance_serial) throw(); 00072 virtual void bb_interface_writer_removed(fawkes::Interface *interface, 00073 unsigned int instance_serial) throw(); 00074 00075 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00076 protected: virtual void run() { Thread::run(); } 00077 00078 private: 00079 void write_header(); 00080 void update_header(); 00081 void write_chunk(const void *chunk); 00082 00083 00084 private: 00085 fawkes::Interface *__iface; 00086 00087 unsigned int __num_data_items; 00088 unsigned int __session_start; 00089 00090 bool __enabled; 00091 bool __buffering; 00092 bool __flushing; 00093 size_t __data_size; 00094 char *__scenario; 00095 char *__filename; 00096 char *__logdir; 00097 char *__uid; 00098 char *__type; 00099 char *__id; 00100 FILE *__f_data; 00101 FILE *__f_msgs; 00102 00103 fawkes::Time *__start; 00104 fawkes::Time *__now; 00105 00106 bool __is_master; 00107 fawkes::ThreadList __threads; 00108 fawkes::SwitchInterface *__switch_if; 00109 00110 fawkes::Mutex *__queue_mutex; 00111 unsigned int __act_queue; 00112 fawkes::LockQueue<void *> __queues[2]; 00113 }; 00114 00115 00116 #endif