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/// @cond QA
25
26#include <blackboard/bbconfig.h>
27#include <blackboard/exceptions.h>
28#include <blackboard/local.h>
29#include <core/exceptions/system.h>
30#include <interface/interface_info.h>
31#include <interfaces/TestInterface.h>
32
33#include <cstdio>
34#include <cstdlib>
35#include <cstring>
36#include <iostream>
37#include <signal.h>
38#include <vector>
39
40using namespace std;
41using namespace fawkes;
42
43bool quit = false;
44
45void
46signal_handler(int signum)
47{
48 quit = true;
49}
50
51#define NUM_CHUNKS 5
52
53int
54main(int argc, char **argv)
55{
56 signal(SIGINT, signal_handler);
57
58 BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
59
60 TestInterface *ti_writer;
61 TestInterface *ti_reader;
62
63 try {
64 cout << "Opening interfaces.. " << flush;
65 ti_writer = bb->open_for_writing<TestInterface>("SomeID");
66 ti_reader = bb->open_for_reading<TestInterface>("SomeID");
67 cout << "success, "
68 << "writer hash=" << ti_writer->hash_printable()
69 << " reader hash=" << ti_reader->hash_printable() << endl;
70 } catch (Exception &e) {
71 cout << "failed! Aborting" << endl;
72 e.print_trace();
73 exit(1);
74 }
75
76 cout << "Listing interfaces.." << endl;
77 InterfaceInfoList *infl = bb->list_all();
78 for (InterfaceInfoList::iterator i = infl->begin(); i != infl->end(); ++i) {
79 const unsigned char *hash = (*i).hash();
80 char phash[INTERFACE_HASH_SIZE_ * 2 + 1];
81 memset(phash, 0, sizeof(phash));
82 for (unsigned int j = 0; j < INTERFACE_HASH_SIZE_; ++j) {
83 sprintf(&phash[j * 2], "%02x", hash[j]);
84 }
85 printf("%s::%s (%s), w:%i r:%u s:%u\n",
86 (*i).type(),
87 (*i).id(),
88 phash,
89 (*i).has_writer(),
90 (*i).num_readers(),
91 (*i).serial());
92 }
93 delete infl;
94
95 bb->close(ti_reader);
96 bb->close(ti_writer);
97
98 delete bb;
99}
100
101/// @endcond
The BlackBoard abstract class.
Definition: blackboard.h:46
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual InterfaceInfoList * list_all()=0
Get list of all currently existing interfaces.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual void close(Interface *interface)=0
Close interface.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void print_trace() noexcept
Prints trace to stderr.
Definition: exception.cpp:601
Interface information list.
const char * hash_printable() const
Get printable interface hash.
Definition: interface.cpp:314
Local BlackBoard.
Definition: local.h:45
TestInterface Fawkes BlackBoard Interface.
Definition: TestInterface.h:34
Fawkes library namespace.