Fawkes API
Fawkes Development Version
|
24 #include "logreplay_thread.h"
28 #include <blackboard/blackboard.h>
29 #include <blackboard/internal/instance_factory.h>
30 #include <core/exceptions/system.h>
31 #include <core/threading/wait_condition.h>
32 #include <logging/logger.h>
33 #include <utils/misc/autofree.h>
42 # include <sys/endian.h>
43 #elif defined(__MACH__) && defined(__APPLE__)
44 # include <sys/_endian.h>
48 #include <arpa/inet.h>
76 const char * scenario,
80 const char * thread_name,
82 :
Thread(thread_name, th_opmode)
84 set_name(
"BBLogReplayThread(%s)", logfile_name);
87 logfile_name_ = strdup(logfile_name);
88 logdir_ = strdup(logdir);
89 scenario_ = strdup(scenario);
91 cfg_grace_period_ = grace_period;
92 cfg_loop_replay_ = loop_replay;
94 cfg_non_blocking_ = non_blocking;
97 cfg_non_blocking_ =
false;
116 if (asprintf(&filename_,
"%s/%s", logdir_, logfile_name_) == -1) {
121 logfile_ =
new BBLogFile(filename_,
true);
129 throw Exception(
"Log file %s does not have any entries", filename_);
174 loopdiff_ = now_ - last_loop_;
175 if ((offsetdiff_.
in_sec() - loopdiff_.
in_sec()) > cfg_grace_period_) {
176 if (cfg_non_blocking_) {
181 waittime_ = offsetdiff_ - loopdiff_;
194 if (cfg_loop_replay_) {
virtual void init()
Initialize the thread.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
void set_interface(fawkes::Interface *interface)
Set the internal interface.
void read_next()
Read next entry.
Wait until a given condition holds.
virtual ~BBLogReplayThread()
Destructor.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
@ OPMODE_CONTINUOUS
operate in continuous mode (default)
const char * interface_id() const
Get interface ID.
void rewind()
Rewind file to start.
const char * name() const
Get name of thread.
void wait()
Wait (sleep) for this time.
void wait()
Wait for the condition forever.
bool has_next()
Check if another entry is available.
Logger * logger
This is the Logger member used to access the logger.
virtual void close(Interface *interface)=0
Close interface.
BBLogReplayThread(const char *logfile_name, const char *logdir, const char *scenario, float grace_period, bool loop_replay, bool non_blocking=false, const char *thread_name="BBLogReplayThread", fawkes::Thread::OpMode th_opmode=Thread::OPMODE_CONTINUOUS)
Constructor.
Fawkes library namespace.
@ OPMODE_WAITFORWAKEUP
operate in wait-for-wakeup mode
virtual void once()
Execute an action exactly once.
Thread class encapsulation of pthreads.
OpMode opmode() const
Get operation mode.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Time & stamp()
Set this time to the current time.
System ran out of memory and desired operation could not be fulfilled.
OpMode
Thread operation mode.
const char * interface_type() const
Get interface type.
void write()
Write from local copy into BlackBoard memory.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
double in_sec() const
Convet time to seconds.
const fawkes::Time & entry_offset() const
Get current entry offset.
void set_name(const char *format,...)
Set name of thread.
virtual void loop()
Code to execute in the thread.
virtual void finalize()
Finalize the thread.
Class to easily access bblogger log files.
Base class for exceptions in Fawkes.