BBLogFile Class Reference

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

#include <bblogfile.h>

List of all members.

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::Timeentry_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::Timestart_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::Interfaceinterface ()
 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.


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::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:
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.
Exceptions:
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.

Parameters:
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.
Exceptions:
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(), interface(), 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().


Member Function Documentation

uint32_t BBLogFile::data_size (  ) 

Get data size.

Returns:
size of the pure data part of the log entries

Definition at line 591 of file bblogfile.cpp.

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 511 of file bblogfile.cpp.

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

size_t BBLogFile::file_size (  )  const

Get file size.

Returns:
total size of log file including all headers

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.

Returns:
file version

Definition at line 521 of file bblogfile.cpp.

bool BBLogFile::has_next (  ) 

Check if another entry is available.

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

Definition at line 264 of file bblogfile.cpp.

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

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

Get typed interface.

Parameters:
iface will assigned to the interface on success
Returns:
interface of the given type
Exceptions:
TypeMismatchException thrown if interface type or ID do not match

Definition at line 81 of file bblogfile.h.

fawkes::Interface * BBLogFile::interface (  ) 

Get interface instance.

Returns:
internally used interface

Definition at line 477 of file bblogfile.cpp.

Referenced by BBLogFile(), and set_interface().

unsigned char * BBLogFile::interface_hash (  )  const

Get interface hash.

Hash of logged interface.

Returns:
interface hash

Definition at line 581 of file bblogfile.cpp.

Referenced by print_info().

const char * BBLogFile::interface_id (  )  const

Get interface ID.

Returns:
ID of logged interface

Definition at line 570 of file bblogfile.cpp.

Referenced by BBLogReplayThread::init().

const char * BBLogFile::interface_type (  )  const

Get interface type.

Returns:
type of logged interface

Definition at line 560 of file bblogfile.cpp.

Referenced by BBLogReplayThread::init().

bool BBLogFile::is_big_endian (  )  const

Check if file is big endian.

Returns:
true if file is big endian, false otherwise

Definition at line 531 of file bblogfile.cpp.

uint32_t BBLogFile::num_data_items (  )  const

Get number of data items in file.

Returns:
number of data items

Definition at line 540 of file bblogfile.cpp.

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

Print an entry.

Verbose print of a single entry.

Parameters:
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.

Parameters:
line_prefix a prefix printed before each line
outf file handle to print to

Definition at line 412 of file bblogfile.cpp.

References interface_hash(), and fawkes::Time::str().

void BBLogFile::read_index ( unsigned int  index  ) 

Read entry at particular index.

Parameters:
index index of entry, 0-based

Definition at line 234 of file bblogfile.cpp.

References read_next().

void BBLogFile::read_next (  ) 

Read next entry.

Exceptions:
Exception thrown if reading fails, for example because no more entries are left.

Definition at line 281 of file bblogfile.cpp.

References bblog_entry_header::rel_time_sec, bblog_entry_header::rel_time_usec, fawkes::Interface::set_from_chunk(), and fawkes::Time::set_time().

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

unsigned int BBLogFile::remaining_entries (  ) 

Get number of remaining entries.

Returns:
number of remaining entries

Definition at line 611 of file bblogfile.cpp.

References file_size().

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

Repair file.

Parameters:
filename file to repair
See also:
repair()

Definition at line 324 of file bblogfile.cpp.

References repair().

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().

Referenced by BBLogReplayThread::loop().

const char * BBLogFile::scenario (  )  const

Get scenario identifier.

Returns:
scenario identifier

Definition at line 550 of file bblogfile.cpp.

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

Set the internal interface.

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

Definition at line 488 of file bblogfile.cpp.

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

Referenced by BBLogReplayThread::init().

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_entries number of entries

Definition at line 301 of file bblogfile.cpp.

References bblog_file_header::num_data_items.

fawkes::Time & BBLogFile::start_time (  ) 

Get start time.

Returns:
starting time of log

Definition at line 601 of file bblogfile.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Feb 22 13:32:33 2011 for Fawkes API by  doxygen 1.4.7