Fawkes API  Fawkes Development Version
qa_bb_listall.cpp
1 
2 /***************************************************************************
3  * qa_bb_listall.cpp - BlackBoard interface QA: list all
4  *
5  * Created: Mon Mar 03 16:27:23 2008
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 
25 /// @cond QA
26 
27 #include <blackboard/local.h>
28 #include <blackboard/exceptions.h>
29 #include <blackboard/bbconfig.h>
30 
31 #include <interfaces/TestInterface.h>
32 #include <interface/interface_info.h>
33 
34 #include <core/exceptions/system.h>
35 
36 #include <signal.h>
37 #include <cstdlib>
38 #include <cstring>
39 #include <cstdio>
40 
41 #include <iostream>
42 #include <vector>
43 
44 using namespace std;
45 using namespace fawkes;
46 
47 
48 bool quit = false;
49 
50 void
51 signal_handler(int signum)
52 {
53  quit = true;
54 }
55 
56 
57 #define NUM_CHUNKS 5
58 
59 int
60 main(int argc, char **argv)
61 {
62 
63  signal(SIGINT, signal_handler);
64 
65  BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
66 
67  TestInterface *ti_writer;
68  TestInterface *ti_reader;
69 
70  try {
71  cout << "Opening interfaces.. " << flush;
72  ti_writer = bb->open_for_writing<TestInterface>("SomeID");
73  ti_reader = bb->open_for_reading<TestInterface>("SomeID");
74  cout << "success, " <<
75  "writer hash=" << ti_writer->hash_printable() <<
76  " reader hash=" << ti_reader->hash_printable() << endl;
77  } catch (Exception &e) {
78  cout << "failed! Aborting" << endl;
79  e.print_trace();
80  exit(1);
81  }
82 
83  cout << "Listing interfaces.." << endl;
84  InterfaceInfoList *infl = bb->list_all();
85  for (InterfaceInfoList::iterator i = infl->begin(); i != infl->end(); ++i) {
86  const unsigned char *hash = (*i).hash();
87  char phash[__INTERFACE_HASH_SIZE * 2 + 1];
88  memset(phash, 0, sizeof(phash));
89  for (unsigned int j = 0; j < __INTERFACE_HASH_SIZE; ++j) {
90  sprintf(&phash[j * 2], "%02x", hash[j]);
91  }
92  printf("%s::%s (%s), w:%i r:%u s:%u\n",
93  (*i).type(), (*i).id(), phash, (*i).has_writer(),
94  (*i).num_readers(), (*i).serial());
95  }
96  delete infl;
97 
98  bb->close(ti_reader);
99  bb->close(ti_writer);
100 
101  delete bb;
102 }
103 
104 
105 /// @endcond
Fawkes library namespace.
STL namespace.
Local BlackBoard.
Definition: local.h:44
Interface information list.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:619
virtual InterfaceInfoList * list_all()=0
Get list of all currently existing interfaces.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
The BlackBoard abstract class.
Definition: blackboard.h:48
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
TestInterface Fawkes BlackBoard Interface.
Definition: TestInterface.h:33
const char * hash_printable() const
Get printable interface hash.
Definition: interface.cpp:304
virtual void close(Interface *interface)=0
Close interface.