Fawkes API Fawkes Development Version
qa_bb_openall.cpp
1
2/***************************************************************************
3 * qa_bb_openall.h - BlackBoard interface QA
4 *
5 * Created: Fri Jun 29 13:44:04 2007 (on flight to RoboCup 2007, Atlanta)
6 * Copyright 2006-2007 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 <interfaces/TestInterface.h>
31#include <logging/liblogger.h>
32
33#include <cstdio>
34#include <cstdlib>
35#include <iostream>
36#include <signal.h>
37#include <vector>
38
39using namespace std;
40using namespace fawkes;
41
42int
43main(int argc, char **argv)
44{
45 LibLogger::init();
46 BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
47
48 TestInterface *ti_writer_1;
49 TestInterface *ti_writer_2;
50 TestInterface *ti_writer_3;
51 TestInterface *ti_writer_4;
52 TestInterface *ti_writer_5;
53 TestInterface *ti_writer_6;
54
55 try {
56 cout << "Opening interfaces.. " << flush;
57 ti_writer_1 = bb->open_for_writing<TestInterface>("SomeID 1");
58 ti_writer_2 = bb->open_for_writing<TestInterface>("SomeID 2");
59 ti_writer_3 = bb->open_for_writing<TestInterface>("SomeID 3");
60 ti_writer_4 = bb->open_for_writing<TestInterface>("AnotherID 1");
61 ti_writer_5 = bb->open_for_writing<TestInterface>("AnotherID 2");
62 ti_writer_6 = bb->open_for_writing<TestInterface>("AnotherID 3");
63 cout << "success" << endl;
64 } catch (Exception &e) {
65 cout << "failed! Aborting" << endl;
66 e.print_trace();
67 exit(1);
68 }
69
70 std::list<Interface *> readers = bb->open_multiple_for_reading("TestInterface");
71 for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
72 printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
73 bb->close(*i);
74 }
75
76 const char *pattern = "AnotherID *";
77 readers = bb->open_multiple_for_reading("TestInterface", pattern);
78 printf("Found %zu interfaces with pattern \"%s\"\n", readers.size(), pattern);
79 for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
80 printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
81 bb->close(*i);
82 }
83
84 bb->close(ti_writer_1);
85 bb->close(ti_writer_2);
86 bb->close(ti_writer_3);
87 bb->close(ti_writer_4);
88 bb->close(ti_writer_5);
89 bb->close(ti_writer_6);
90
91 delete bb;
92 LibLogger::finalize();
93}
94
95/// @endcond
The BlackBoard abstract class.
Definition: blackboard.h:46
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)=0
Open multiple interfaces for reading.
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
Local BlackBoard.
Definition: local.h:45
TestInterface Fawkes BlackBoard Interface.
Definition: TestInterface.h:34
Fawkes library namespace.