Class to easily access bblogger log files. More...
#include "bblogfile.h"
Public Member Functions | |
BBLogFile (const char *filename, bool do_sanity_check) | |
Constructor. | |
BBLogFile (const char *filename, fawkes::Interface *interface=NULL, bool do_sanity_check=true) | |
Constructor. | |
~BBLogFile () | |
Destructor. | |
bool | has_next () |
Check if another entry is available. | |
void | read_next () |
Read next entry. | |
void | read_index (unsigned int index) |
Read entry at particular index. | |
const fawkes::Time & | entry_offset () const |
Get current entry offset. | |
void | print_entry (FILE *outf=stdout) |
Print an entry. | |
void | rewind () |
Rewind file to start. | |
void | set_num_entries (size_t num_entries) |
Set number of entries. | |
void | print_info (const char *line_prefix="", FILE *outf=stdout) |
Print file meta info. | |
uint32_t | file_version () const |
Get file version. | |
bool | is_big_endian () const |
Check if file is big endian. | |
uint32_t | num_data_items () const |
Get number of data items in file. | |
const char * | scenario () const |
Get scenario identifier. | |
const char * | interface_type () const |
Get interface type. | |
const char * | interface_id () const |
Get interface ID. | |
unsigned char * | interface_hash () const |
Get interface hash. | |
uint32_t | data_size () |
Get data size. | |
fawkes::Time & | start_time () |
Get start time. | |
size_t | file_size () const |
Get file size. | |
unsigned int | remaining_entries () |
Get number of remaining entries. | |
void | set_interface (fawkes::Interface *interface) |
Set the internal interface. | |
fawkes::Interface * | interface () |
Get interface instance. | |
template<class IT > | |
IT * | interface (IT *&iface=0) const |
Get typed interface. | |
Static Public Member Functions | |
static void | repair_file (const char *filename) |
Repair file. |
Class to easily access bblogger log files.
This class provides an easy way to interact with bblogger log files.
Definition at line 38 of file bblogfile.h.
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.
filename | log file to open | |
do_sanity_check | true to perform a sanity check on the file on opening. Turn this off only if you know what you are doing. |
CouldNotOpenFileException | thrown if file cannot be opened | |
FileReadException | some error occured while reading data from |
Definition at line 98 of file bblogfile.cpp.
BBLogFile::BBLogFile | ( | const char * | filename, | |
fawkes::Interface * | interface = NULL , |
|||
bool | do_sanity_check = true | |||
) |
Constructor.
Opens the given file and performs basic sanity checks.
filename | log file to open | |
interface | optional 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_check | true to perform a sanity check on the file on opening. Turn this off only if you know what you are doing. |
CouldNotOpenFileException | thrown if file cannot be opened | |
FileReadException | some error occured while reading data from |
Definition at line 62 of file bblogfile.cpp.
References fawkes::Interface::id(), fawkes::BlackBoardInstanceFactory::new_interface_instance(), fawkes::Interface::type(), and fawkes::Interface::uid().
BBLogFile::~BBLogFile | ( | ) |
Destructor.
Definition at line 134 of file bblogfile.cpp.
References fawkes::BlackBoardInstanceFactory::delete_interface_instance().
uint32_t BBLogFile::data_size | ( | ) |
Get data size.
Definition at line 591 of file bblogfile.cpp.
References bblog_file_header::data_size.
const fawkes::Time & BBLogFile::entry_offset | ( | ) | const |
Get current entry offset.
Definition at line 511 of file bblogfile.cpp.
size_t BBLogFile::file_size | ( | ) | const |
Get file size.
Definition at line 630 of file bblogfile.cpp.
References fawkes::Exception::set_type_id().
Referenced by remaining_entries().
uint32_t BBLogFile::file_version | ( | ) | const |
Get file version.
Definition at line 521 of file bblogfile.cpp.
References bblog_file_header::file_version.
bool BBLogFile::has_next | ( | ) |
Check if another entry is available.
Definition at line 264 of file bblogfile.cpp.
fawkes::Interface * BBLogFile::interface | ( | ) |
Get interface instance.
Definition at line 477 of file bblogfile.cpp.
IT* BBLogFile::interface | ( | IT *& | iface = 0 |
) | const [inline] |
Get typed interface.
iface | will assigned to the interface on success |
TypeMismatchException | thrown if interface type or ID do not match |
Definition at line 81 of file bblogfile.h.
unsigned char * BBLogFile::interface_hash | ( | ) | const |
Get interface hash.
Hash of logged interface.
Definition at line 581 of file bblogfile.cpp.
References bblog_file_header::interface_hash.
Referenced by print_info().
const char * BBLogFile::interface_id | ( | ) | const |
const char * BBLogFile::interface_type | ( | ) | const |
bool BBLogFile::is_big_endian | ( | ) | const |
Check if file is big endian.
Definition at line 531 of file bblogfile.cpp.
References bblog_file_header::endianess.
uint32_t BBLogFile::num_data_items | ( | ) | const |
Get number of data items in file.
Definition at line 540 of file bblogfile.cpp.
References bblog_file_header::num_data_items.
void BBLogFile::print_entry | ( | FILE * | outf = stdout |
) |
Print an entry.
Verbose print of a single entry.
outf | file handle to print to |
Definition at line 450 of file bblogfile.cpp.
References fawkes::Interface::fields(), fawkes::Interface::fields_end(), and fawkes::Time::in_sec().
void BBLogFile::print_info | ( | const char * | line_prefix = "" , |
|
FILE * | outf = stdout | |||
) |
Print file meta info.
line_prefix | a prefix printed before each line | |
outf | file handle to print to |
Definition at line 412 of file bblogfile.cpp.
References bblog_file_header::data_size, bblog_file_header::endianess, bblog_file_header::file_version, bblog_file_header::interface_hash, interface_hash(), bblog_file_header::num_data_items, and fawkes::Time::str().
void BBLogFile::read_index | ( | unsigned int | index | ) |
Read entry at particular index.
index | index of entry, 0-based |
Definition at line 234 of file bblogfile.cpp.
References bblog_file_header::data_size, and read_next().
void BBLogFile::read_next | ( | ) |
Read next entry.
Exception | thrown if reading fails, for example because no more entries are left. |
Definition at line 281 of file bblogfile.cpp.
References bblog_file_header::data_size, bblog_entry_header::rel_time_sec, bblog_entry_header::rel_time_usec, fawkes::Interface::set_from_chunk(), and fawkes::Time::set_time().
Referenced by read_index().
unsigned int BBLogFile::remaining_entries | ( | ) |
Get number of remaining entries.
Definition at line 611 of file bblogfile.cpp.
References bblog_file_header::data_size, and file_size().
void BBLogFile::repair_file | ( | const char * | filename | ) | [static] |
Repair file.
filename | file to repair |
Definition at line 324 of file bblogfile.cpp.
void BBLogFile::rewind | ( | ) |
Rewind file to start.
This moves the file cursor immediately before the first entry.
Definition at line 251 of file bblogfile.cpp.
References fawkes::Time::set_time().
const char * BBLogFile::scenario | ( | ) | const |
void BBLogFile::set_interface | ( | fawkes::Interface * | interface | ) |
Set the internal interface.
interface | an interface matching the type and ID given in the log file. |
Definition at line 488 of file bblogfile.cpp.
References fawkes::BlackBoardInstanceFactory::delete_interface_instance(), fawkes::Interface::hash(), fawkes::Interface::id(), bblog_file_header::interface_hash, and fawkes::Interface::type().
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.
num_entries | number of entries |
Definition at line 301 of file bblogfile.cpp.
References bblog_file_header::num_data_items.
fawkes::Time & BBLogFile::start_time | ( | ) |