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 #include "sync_thread.h"
25 
26 #include <set>
27 
28 using namespace fawkes;
29 
30 /** @class BlackBoardSynchronizationPlugin "bbsync_plugin.h"
31  * BlackBoard synchronization plugin.
32  * This plugin synchronizes one or more (or even all) interfaces of two or
33  * more Fawkes instances over the network.
34  *
35  * @author Tim Niemueller
36  */
37 
38 /** Constructor.
39  * @param config Fawkes configuration
40  */
42  : Plugin(config)
43 {
44  std::set<std::string> peers;
45  std::set<std::string> ignored_peers;
46 
47  std::string prefix = "/fawkes/bbsync/";
48  std::string peers_prefix = prefix + "peers/";
49 
50  Configuration::ValueIterator *i = config->search(peers_prefix.c_str());
51  while (i->next()) {
52  std::string peer = std::string(i->path()).substr(peers_prefix.length());
53  peer = peer.substr(0, peer.find("/"));
54 
55  if ( (peers.find(peer) == peers.end()) &&
56  (ignored_peers.find(peer) == ignored_peers.end()) ) {
57 
58  std::string peer_prefix = peers_prefix + peer + "/";
59 
60  bool active = true;
61  try {
62  active = config->get_bool((peer_prefix + "active").c_str());
63  } catch (Exception &e) {} // 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  } else {
82  }
83 }
84 
85 PLUGIN_DESCRIPTION("Synchronize with remote Fawkes BlackBoards")
Plugin interface class.
Definition: plugin.h:33
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
BlackBoardSynchronizationPlugin(fawkes::Configuration *config)
Constructor.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual bool next()=0
Check if there is another element and advance to this if possible.
BlackBoard synchronization plugin.
Definition: bbsync_plugin.h:28
Base class for exceptions in Fawkes.
Definition: exception.h:36
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
virtual const char * path() const =0
Path of value.
Thread to synchronize two BlackBoards.
Definition: sync_thread.h:44
void push_back(Thread *thread)
Add thread to the end.
Iterator interface to iterate over config values.
Definition: config.h:72
Interface for configuration handling.
Definition: config.h:67