Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * qa_bb_listall.cpp - BlackBoard interface QA: list all 00004 * 00005 * Created: Mon Mar 03 16:27:23 2008 00006 * Copyright 2006-2008 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. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 00025 /// @cond QA 00026 00027 #include <blackboard/local.h> 00028 #include <blackboard/exceptions.h> 00029 #include <blackboard/bbconfig.h> 00030 00031 #include <interfaces/TestInterface.h> 00032 #include <interface/interface_info.h> 00033 00034 #include <core/exceptions/system.h> 00035 00036 #include <signal.h> 00037 #include <cstdlib> 00038 #include <cstring> 00039 #include <cstdio> 00040 00041 #include <iostream> 00042 #include <vector> 00043 00044 using namespace std; 00045 using namespace fawkes; 00046 00047 00048 bool quit = false; 00049 00050 void 00051 signal_handler(int signum) 00052 { 00053 quit = true; 00054 } 00055 00056 00057 #define NUM_CHUNKS 5 00058 00059 int 00060 main(int argc, char **argv) 00061 { 00062 00063 signal(SIGINT, signal_handler); 00064 00065 BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE); 00066 00067 TestInterface *ti_writer; 00068 TestInterface *ti_reader; 00069 00070 try { 00071 cout << "Opening interfaces.. " << flush; 00072 ti_writer = bb->open_for_writing<TestInterface>("SomeID"); 00073 ti_reader = bb->open_for_reading<TestInterface>("SomeID"); 00074 cout << "success, " << 00075 "writer hash=" << ti_writer->hash_printable() << 00076 " reader hash=" << ti_reader->hash_printable() << endl; 00077 } catch (Exception &e) { 00078 cout << "failed! Aborting" << endl; 00079 e.print_trace(); 00080 exit(1); 00081 } 00082 00083 cout << "Listing interfaces.." << endl; 00084 InterfaceInfoList *infl = bb->list_all(); 00085 for (InterfaceInfoList::iterator i = infl->begin(); i != infl->end(); ++i) { 00086 const unsigned char *hash = (*i).hash(); 00087 char phash[__INTERFACE_HASH_SIZE * 2 + 1]; 00088 memset(phash, 0, sizeof(phash)); 00089 for (unsigned int j = 0; j < __INTERFACE_HASH_SIZE; ++j) { 00090 sprintf(&phash[j * 2], "%02x", hash[j]); 00091 } 00092 printf("%s::%s (%s), w:%i r:%u s:%u\n", 00093 (*i).type(), (*i).id(), phash, (*i).has_writer(), 00094 (*i).num_readers(), (*i).serial()); 00095 } 00096 delete infl; 00097 00098 bb->close(ti_reader); 00099 bb->close(ti_writer); 00100 00101 delete bb; 00102 } 00103 00104 00105 /// @endcond