Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * bblogfile.h - BlackBoard log file access convenience class 00004 * 00005 * Created: Sun Feb 21 11:12:47 2010 00006 * Copyright 2006-2010 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_BBLOGGER_BBLOGFILE_H_ 00024 #define __PLUGINS_BBLOGGER_BBLOGFILE_H_ 00025 00026 #include "file.h" 00027 00028 #include <core/exceptions/software.h> 00029 #include <utils/time/time.h> 00030 00031 #include <cstdio> 00032 00033 namespace fawkes { 00034 class Interface; 00035 class BlackBoardInstanceFactory; 00036 } 00037 00038 class BBLogFile { 00039 public: 00040 BBLogFile(const char *filename, bool do_sanity_check); 00041 BBLogFile(const char *filename, fawkes::Interface *interface = NULL, 00042 bool do_sanity_check = true); 00043 ~BBLogFile(); 00044 00045 bool has_next(); 00046 void read_next(); 00047 void read_index(unsigned int index); 00048 const fawkes::Time & entry_offset() const; 00049 void print_entry(FILE *outf = stdout); 00050 00051 void rewind(); 00052 00053 void set_num_entries(size_t num_entries); 00054 void print_info(const char *line_prefix = "", FILE *outf = stdout); 00055 00056 // Header information 00057 uint32_t file_version() const; 00058 bool is_big_endian() const; 00059 uint32_t num_data_items() const; 00060 const char * scenario() const; 00061 const char * interface_type() const; 00062 const char * interface_id() const; 00063 unsigned char * interface_hash() const; 00064 uint32_t data_size(); 00065 fawkes::Time & start_time(); 00066 00067 size_t file_size() const; 00068 unsigned int remaining_entries(); 00069 00070 static void repair_file(const char *filename); 00071 00072 void set_interface(fawkes::Interface *interface); 00073 fawkes::Interface * interface(); 00074 00075 /** Get typed interface. 00076 * @param iface will assigned to the interface on success 00077 * @return interface of the given type 00078 * @exception TypeMismatchException thrown if interface type or ID do not match 00079 */ 00080 template <class IT> 00081 IT * interface(IT*& iface = 0) const 00082 { 00083 IT *rv = dynamic_cast<IT *>(__interface); 00084 if (rv) { 00085 iface = rv; 00086 return rv; 00087 } else { 00088 throw fawkes::TypeMismatchException("Interface types do not match."); 00089 } 00090 } 00091 00092 private: // methods 00093 void ctor(const char *filename, bool do_sanity_check); 00094 void read_file_header(); 00095 void sanity_check(); 00096 void repair(); 00097 00098 00099 private: // members 00100 FILE *__f; 00101 bblog_file_header *__header; 00102 00103 void *__ifdata; 00104 00105 char *__filename; 00106 char *__scenario; 00107 char *__interface_type; 00108 char *__interface_id; 00109 00110 fawkes::Interface *__interface; 00111 fawkes::BlackBoardInstanceFactory *__instance_factory; 00112 fawkes::Time __start_time; 00113 fawkes::Time __entry_offset; 00114 }; 00115 00116 00117 #endif