24 #include "logreplay_thread.h" 27 #include <blackboard/blackboard.h> 28 #include <logging/logger.h> 29 #include <core/threading/wait_condition.h> 30 #include <core/exceptions/system.h> 31 #include <utils/misc/autofree.h> 33 #include <blackboard/internal/instance_factory.h> 43 # include <sys/endian.h> 44 #elif defined(__MACH__) && defined(__APPLE__) 45 # include <sys/_endian.h> 49 #include <arpa/inet.h> 81 const char *thread_name,
83 :
Thread(thread_name, th_opmode)
85 set_name(
"BBLogReplayThread(%s)", logfile_name);
88 __logfile_name= strdup(logfile_name);
89 __logdir = strdup(logdir);
90 __scenario = strdup(scenario);
92 __cfg_grace_period = grace_period;
93 __cfg_loop_replay = loop_replay;
95 __cfg_non_blocking = non_blocking;
98 __cfg_non_blocking =
false;
106 free(__logfile_name);
121 if (asprintf(&__filename,
"%s/%s", __logdir, __logfile_name) == -1) {
126 __logfile =
new BBLogFile(__filename,
true);
134 throw Exception(
"Log file %s does not have any entries", __filename);
155 if (__filename) free(__filename);
165 __interface->
write();
169 __offsetdiff = __logfile->
entry_offset() - __last_offset;
182 __loopdiff = __now - __last_loop;
183 if ((__offsetdiff.
in_sec() - __loopdiff.
in_sec()) > __cfg_grace_period) {
184 if (__cfg_non_blocking) {
189 __waittime = __offsetdiff - __loopdiff;
194 __interface->
write();
198 __offsetdiff = __logfile->
entry_offset() - __last_offset;
202 if(__cfg_loop_replay){
double in_sec() const
Convet time to seconds.
virtual void init()
Initialize the thread.
Wait until a given condition holds.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
virtual ~BBLogReplayThread()
Destructor.
void rewind()
Rewind file to start.
Fawkes library namespace.
OpMode
Thread operation mode.
const char * interface_id() const
Get interface ID.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
void write()
Write from local copy into BlackBoard memory.
bool has_next()
Check if another entry is available.
Logger * logger
This is the Logger member used to access the logger.
void read_next()
Read next entry.
void wait()
Wait (sleep) for this time.
const fawkes::Time & entry_offset() const
Get current entry offset.
OpMode opmode() const
Get operation mode.
void set_interface(fawkes::Interface *interface)
Set the internal interface.
void set_name(const char *format,...)
Set name of thread.
Base class for exceptions in Fawkes.
operate in continuous mode (default)
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.
const char * name() const
Get name of thread.
virtual void once()
Execute an action exactly once.
void wait()
Wait for the condition forever.
const char * interface_type() const
Get interface type.
virtual void loop()
Code to execute in the thread.
Time & stamp()
Set this time to the current time.
operate in wait-for-wakeup mode
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual void finalize()
Finalize the thread.
Class to easily access bblogger log files.
System ran out of memory and desired operation could not be fulfilled.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual void close(Interface *interface)=0
Close interface.