Fawkes API  Fawkes Development Version
BBLogFile Class Reference

Class to easily access bblogger log files. More...

#include "bblogfile.h"

Public Member Functions

 BBLogFile (const char *filename, bool do_sanity_check)
 Constructor. More...
 
 BBLogFile (const char *filename, fawkes::Interface *interface=NULL, bool do_sanity_check=true)
 Constructor. More...
 
 ~BBLogFile ()
 Destructor. More...
 
bool has_next ()
 Check if another entry is available. More...
 
void read_next ()
 Read next entry. More...
 
void read_index (unsigned int index)
 Read entry at particular index. More...
 
const fawkes::Timeentry_offset () const
 Get current entry offset. More...
 
void print_entry (FILE *outf=stdout)
 Print an entry. More...
 
void rewind ()
 Rewind file to start. More...
 
void set_num_entries (size_t num_entries)
 Set number of entries. More...
 
void print_info (const char *line_prefix="", FILE *outf=stdout)
 Print file meta info. More...
 
uint32_t file_version () const
 Get file version. More...
 
bool is_big_endian () const
 Check if file is big endian. More...
 
uint32_t num_data_items () const
 Get number of data items in file. More...
 
const char * scenario () const
 Get scenario identifier. More...
 
const char * interface_type () const
 Get interface type. More...
 
const char * interface_id () const
 Get interface ID. More...
 
unsigned char * interface_hash () const
 Get interface hash. More...
 
uint32_t data_size ()
 Get data size. More...
 
fawkes::Timestart_time ()
 Get start time. More...
 
size_t file_size () const
 Get file size. More...
 
unsigned int remaining_entries ()
 Get number of remaining entries. More...
 
void set_interface (fawkes::Interface *interface)
 Set the internal interface. More...
 
fawkes::Interfaceinterface ()
 Get interface instance. More...
 
template<class IT >
IT * interface (IT *&iface=0) const
 Get typed interface. More...
 

Static Public Member Functions

static void repair_file (const char *filename)
 Repair file. More...
 

Detailed Description

Class to easily access bblogger log files.

This class provides an easy way to interact with bblogger log files.

Author
Tim Niemueller

Definition at line 38 of file bblogfile.h.

Constructor & Destructor Documentation

◆ BBLogFile() [1/2]

BBLogFile::BBLogFile ( const char *  filename,
bool  do_sanity_check 
)

Constructor.

Opens the given file and performs basic sanity checks. No internal interface is created. You must take care to set it using set_interface() before any reading is done.

Parameters
filenamelog file to open
do_sanity_checktrue to perform a sanity check on the file on opening. Turn this off only if you know what you are doing.
Exceptions
CouldNotOpenFileExceptionthrown if file cannot be opened
FileReadExceptionsome error occured while reading data from

Definition at line 101 of file bblogfile.cpp.

◆ BBLogFile() [2/2]

BBLogFile::BBLogFile ( const char *  filename,
fawkes::Interface interface = NULL,
bool  do_sanity_check = true 
)

Constructor.

Opens the given file and performs basic sanity checks.

Parameters
filenamelog file to open
interfaceoptional interface instance which must match the data from the log file. Read methods will store read data in this interface instance. If no interface is given an instance is created that is not tied to a blackboard.
do_sanity_checktrue to perform a sanity check on the file on opening. Turn this off only if you know what you are doing.
Exceptions
CouldNotOpenFileExceptionthrown if file cannot be opened
FileReadExceptionsome error occured while reading data from

Definition at line 65 of file bblogfile.cpp.

◆ ~BBLogFile()

BBLogFile::~BBLogFile ( )

Destructor.

Definition at line 137 of file bblogfile.cpp.

References fawkes::Exception::set_type_id().

Member Function Documentation

◆ data_size()

uint32_t BBLogFile::data_size ( )

Get data size.

Returns
size of the pure data part of the log entries

Definition at line 594 of file bblogfile.cpp.

◆ entry_offset()

const fawkes::Time & BBLogFile::entry_offset ( ) const

Get current entry offset.

Returns
offset from start time of current entry (may be 0 if no entry has been read, yet, or after rewind()).

Definition at line 514 of file bblogfile.cpp.

Referenced by BBLogReplayThread::loop(), and BBLogReplayThread::once().

◆ file_size()

size_t BBLogFile::file_size ( ) const

Get file size.

Returns
total size of log file including all headers

Definition at line 633 of file bblogfile.cpp.

References fawkes::Exception::set_type_id().

◆ file_version()

uint32_t BBLogFile::file_version ( ) const

Get file version.

Returns
file version

Definition at line 524 of file bblogfile.cpp.

◆ has_next()

bool BBLogFile::has_next ( )

Check if another entry is available.

Returns
true if a consecutive read_next() will succeed, false otherwise

Definition at line 267 of file bblogfile.cpp.

Referenced by BBLogReplayThread::init(), BBLogReplayThread::loop(), and BBLogReplayThread::once().

◆ interface() [1/2]

fawkes::Interface * BBLogFile::interface ( )

Get interface instance.

Returns
internally used interface

Definition at line 480 of file bblogfile.cpp.

◆ interface() [2/2]

template<class IT >
IT* BBLogFile::interface ( IT *&  iface = 0) const
inline

Get typed interface.

Parameters
ifacewill assigned to the interface on success
Returns
interface of the given type
Exceptions
TypeMismatchExceptionthrown if interface type or ID do not match

Definition at line 81 of file bblogfile.h.

◆ interface_hash()

unsigned char * BBLogFile::interface_hash ( ) const

Get interface hash.

Hash of logged interface.

Returns
interface hash

Definition at line 584 of file bblogfile.cpp.

◆ interface_id()

const char * BBLogFile::interface_id ( ) const

Get interface ID.

Returns
ID of logged interface

Definition at line 573 of file bblogfile.cpp.

Referenced by BBLogReplayThread::init().

◆ interface_type()

const char * BBLogFile::interface_type ( ) const

Get interface type.

Returns
type of logged interface

Definition at line 563 of file bblogfile.cpp.

Referenced by BBLogReplayThread::init().

◆ is_big_endian()

bool BBLogFile::is_big_endian ( ) const

Check if file is big endian.

Returns
true if file is big endian, false otherwise

Definition at line 534 of file bblogfile.cpp.

◆ num_data_items()

uint32_t BBLogFile::num_data_items ( ) const

Get number of data items in file.

Returns
number of data items

Definition at line 543 of file bblogfile.cpp.

◆ print_entry()

void BBLogFile::print_entry ( FILE *  outf = stdout)

Print an entry.

Verbose print of a single entry.

Parameters
outffile handle to print to

Definition at line 453 of file bblogfile.cpp.

◆ print_info()

void BBLogFile::print_info ( const char *  line_prefix = "",
FILE *  outf = stdout 
)

Print file meta info.

Parameters
line_prefixa prefix printed before each line
outffile handle to print to

Definition at line 415 of file bblogfile.cpp.

◆ read_index()

void BBLogFile::read_index ( unsigned int  index)

Read entry at particular index.

Parameters
indexindex of entry, 0-based

Definition at line 237 of file bblogfile.cpp.

◆ read_next()

void BBLogFile::read_next ( )

Read next entry.

Exceptions
Exceptionthrown if reading fails, for example because no more entries are left.

Definition at line 284 of file bblogfile.cpp.

References bblog_entry_header::rel_time_sec, and bblog_entry_header::rel_time_usec.

Referenced by BBLogReplayThread::loop(), and BBLogReplayThread::once().

◆ remaining_entries()

unsigned int BBLogFile::remaining_entries ( )

Get number of remaining entries.

Returns
number of remaining entries

Definition at line 614 of file bblogfile.cpp.

◆ repair_file()

void BBLogFile::repair_file ( const char *  filename)
static

Repair file.

Parameters
filenamefile to repair
See also
repair()

Definition at line 327 of file bblogfile.cpp.

References fawkes::Exception::append(), and fawkes::Exception::set_type_id().

◆ rewind()

void BBLogFile::rewind ( )

Rewind file to start.

This moves the file cursor immediately before the first entry.

Definition at line 254 of file bblogfile.cpp.

Referenced by BBLogReplayThread::loop().

◆ scenario()

const char * BBLogFile::scenario ( ) const

Get scenario identifier.

Returns
scenario identifier

Definition at line 553 of file bblogfile.cpp.

◆ set_interface()

void BBLogFile::set_interface ( fawkes::Interface interface)

Set the internal interface.

Parameters
interfacean interface matching the type and ID given in the log file.

Definition at line 491 of file bblogfile.cpp.

References fawkes::Interface::hash(), fawkes::Interface::id(), and fawkes::Interface::type().

Referenced by BBLogReplayThread::init().

◆ set_num_entries()

void BBLogFile::set_num_entries ( size_t  num_entries)

Set number of entries.

Set the number of entries in the file. Attention, this is only to be used by the repair() method.

Parameters
num_entriesnumber of entries

Definition at line 304 of file bblogfile.cpp.

References bblog_file_header::num_data_items.

◆ start_time()

fawkes::Time & BBLogFile::start_time ( )

Get start time.

Returns
starting time of log

Definition at line 604 of file bblogfile.cpp.


The documentation for this class was generated from the following files: