Fawkes API Fawkes Development Version
bbsync_plugin.cpp
1
2/***************************************************************************
3 * bbsync_plugin.cpp - Fawkes BlackBoardSynchronization Plugin
4 *
5 * Created: Fri Jun 29 11:47:53 2007 (on flight to RoboCup 2007, Atlanta)
6 * Copyright 2006 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.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#include "bbsync_plugin.h"
24
25#include "sync_thread.h"
26
27#include <set>
28
29using namespace fawkes;
30
31/** @class BlackBoardSynchronizationPlugin "bbsync_plugin.h"
32 * BlackBoard synchronization plugin.
33 * This plugin synchronizes one or more (or even all) interfaces of two or
34 * more Fawkes instances over the network.
35 *
36 * @author Tim Niemueller
37 */
38
39/** Constructor.
40 * @param config Fawkes configuration
41 */
43: Plugin(config)
44{
45 std::set<std::string> peers;
46 std::set<std::string> ignored_peers;
47
48 std::string prefix = "/fawkes/bbsync/";
49 std::string peers_prefix = prefix + "peers/";
50
51 Configuration::ValueIterator *i = config->search(peers_prefix.c_str());
52 while (i->next()) {
53 std::string peer = std::string(i->path()).substr(peers_prefix.length());
54 peer = peer.substr(0, peer.find("/"));
55
56 if ((peers.find(peer) == peers.end()) && (ignored_peers.find(peer) == ignored_peers.end())) {
57 std::string peer_prefix = peers_prefix + peer + "/";
58
59 bool active = true;
60 try {
61 active = config->get_bool((peer_prefix + "active").c_str());
62 } catch (Exception &e) {
63 } // ignored, assume enabled
64
65 if (active) {
66 //printf("Adding sync thread for peer %s\n", peer.c_str());
68 sync_thread = new BlackBoardSynchronizationThread(prefix, peer_prefix, peer);
69 peers.insert(peer);
70 thread_list.push_back(sync_thread);
71 } else {
72 //printf("Ignoring sync peer %s\n", peer.c_str());
73 ignored_peers.insert(peer);
74 }
75 }
76 }
77 delete i;
78
79 if (thread_list.empty()) {
80 throw Exception("No synchronization peers configured, aborting");
81 }
82}
83
84PLUGIN_DESCRIPTION("Synchronize with remote Fawkes BlackBoards")
BlackBoard synchronization plugin.
Definition: bbsync_plugin.h:29
BlackBoardSynchronizationPlugin(fawkes::Configuration *config)
Constructor.
Thread to synchronize two BlackBoards.
Definition: sync_thread.h:49
Iterator interface to iterate over config values.
Definition: config.h:75
virtual const char * path() const =0
Path of value.
virtual bool next()=0
Check if there is another element and advance to this if possible.
Interface for configuration handling.
Definition: config.h:68
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
Base class for exceptions in Fawkes.
Definition: exception.h:36
Plugin interface class.
Definition: plugin.h:34
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
Configuration * config
Fawkes configuration.
Definition: plugin.h:58
void push_back(Thread *thread)
Add thread to the end.
Fawkes library namespace.