Fawkes API Fawkes Development Version
qa_bb_objpos.cpp
1
2/***************************************************************************
3 * qa_bb_objpos.h - BlackBoard QA: open a few ObjectPositionInterfaces
4 *
5 * Created: Mon Jan 12 13:46:16 2009
6 * Copyright 2006-2009 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 <blackboard/remote.h>
30#include <core/exceptions/system.h>
31#include <interfaces/ObjectPositionInterface.h>
32#include <logging/liblogger.h>
33#include <netcomm/fawkes/server_thread.h>
34#include <utils/time/tracker.h>
35
36#include <cstdlib>
37#include <iostream>
38#include <signal.h>
39#include <vector>
40
41using namespace std;
42using namespace fawkes;
43
44bool quit = false;
45
46void
47handle_signal(int signum)
48{
49 quit = true;
50}
51
52int
53main(int argc, char **argv)
54{
55 signal(SIGINT, handle_signal);
56
57 LibLogger::init();
58 //BlackBoard *bb = new RemoteBlackBoard("localhost", 1910);
59 LocalBlackBoard * lbb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
60 BlackBoard * bb = lbb;
62 netthread->start();
63 lbb->start_nethandler(netthread);
64
65 std::list<ObjectPositionInterface *> interfaces;
66
67 cout << "Opening interfaces" << endl;
68 for (int i = 1; i <= 15; ++i) {
69 char tmp[100];
70 sprintf(tmp, "legtracker Leg %i", i);
71 printf(" %s\n", tmp);
73 interfaces.push_back(iface);
74 }
75
76 srand(time(NULL));
77
78 TimeTracker tt;
79 unsigned int ttc_write = tt.add_class("Write");
80
81 int u = 0;
82 while (!quit) {
83 for (std::list<ObjectPositionInterface *>::iterator i = interfaces.begin();
84 i != interfaces.end();
85 ++i) {
86 int r = rand() % 1000000;
87 (*i)->set_world_x((float)r);
88 (*i)->set_world_y((float)r + 1);
89 (*i)->set_world_z((float)r + 2);
90 tt.ping_start(ttc_write);
91 (*i)->write();
92 tt.ping_end(ttc_write);
93 }
94 if (++u > 20000) {
95 tt.print_to_stdout();
96 tt.reset();
97 u = 0;
98 }
99 //sleep(1);
100 }
101
102 for (std::list<ObjectPositionInterface *>::iterator i = interfaces.begin(); i != interfaces.end();
103 ++i) {
104 bb->close(*i);
105 }
106
107 delete bb;
108 LibLogger::finalize();
109}
110
111/// @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 void close(Interface *interface)=0
Close interface.
Fawkes Network Thread.
Definition: server_thread.h:49
Local BlackBoard.
Definition: local.h:45
virtual void start_nethandler(FawkesNetworkHub *hub)
Start network handler.
Definition: local.cpp:194
ObjectPositionInterface Fawkes BlackBoard Interface.
void start(bool wait=true)
Call this method to start the thread.
Definition: thread.cpp:499
Time tracking utility.
Definition: tracker.h:37
Fawkes library namespace.