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>
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_) {
Class to easily access bblogger log files.
const char * interface_type() const
Get interface type.
bool has_next()
Check if another entry is available.
void set_interface(fawkes::Interface *interface)
Set the internal interface.
void read_next()
Read next entry.
const char * interface_id() const
Get interface ID.
const fawkes::Time & entry_offset() const
Get current entry offset.
void rewind()
Rewind file to start.
virtual void init()
Initialize the thread.
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.
virtual void loop()
Code to execute in the thread.
virtual ~BBLogReplayThread()
Destructor.
virtual void once()
Execute an action exactly once.
virtual void finalize()
Finalize the thread.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual void close(Interface *interface)=0
Close interface.
Base class for exceptions in Fawkes.
void write()
Write from local copy into BlackBoard memory.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Logger * logger
This is the Logger member used to access the logger.
System ran out of memory and desired operation could not be fulfilled.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
const char * name() const
Get name of thread.
OpMode opmode() const
Get operation mode.
void set_name(const char *format,...)
Set name of thread.
OpMode
Thread operation mode.
@ OPMODE_CONTINUOUS
operate in continuous mode (default)
@ OPMODE_WAITFORWAKEUP
operate in wait-for-wakeup mode
Time & stamp()
Set this time to the current time.
void wait()
Wait (sleep) for this time.
double in_sec() const
Convet time to seconds.
Wait until a given condition holds.
void wait()
Wait for the condition forever.
Fawkes library namespace.