qa_bb_listall.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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