00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __PLUGINS_BBSYNC_SYNC_THREAD_H_
00024 #define __PLUGINS_BBSYNC_SYNC_THREAD_H_
00025
00026 #include "sync_listener.h"
00027 #include "writer_listener.h"
00028
00029 #include <core/threading/thread.h>
00030 #include <core/utils/lock_map.h>
00031 #include <aspect/logging.h>
00032 #include <aspect/configurable.h>
00033 #include <aspect/blackboard.h>
00034 #include <aspect/clock.h>
00035
00036 #include <string>
00037 #include <map>
00038 #include <utility>
00039
00040 namespace fawkes {
00041 class TimeWait;
00042 }
00043
00044 class BlackBoardSynchronizationThread
00045 : public fawkes::Thread,
00046 public fawkes::LoggingAspect,
00047 public fawkes::ConfigurableAspect,
00048 public fawkes::BlackBoardAspect,
00049 public fawkes::ClockAspect
00050 {
00051 public:
00052 BlackBoardSynchronizationThread(std::string &bbsync_cfg_prefix,
00053 std::string &peer_cfg_prefix, std::string &peer);
00054 virtual ~BlackBoardSynchronizationThread();
00055
00056 virtual void init();
00057 virtual void loop();
00058 virtual void finalize();
00059
00060 void writer_added(fawkes::Interface *interface) throw();
00061 void writer_removed(fawkes::Interface *interface) throw();
00062
00063
00064 protected: virtual void run() { Thread::run(); }
00065
00066 private:
00067 typedef struct {
00068 std::string type;
00069 std::string reader_id;
00070 std::string writer_id;
00071 bool remote_writer;
00072 } combo_t;
00073
00074 class InterfaceInfo {
00075 public:
00076 combo_t *combo;
00077 fawkes::Interface *writer;
00078 fawkes::BlackBoard *reader_bb;
00079 fawkes::BlackBoard *writer_bb;
00080
00081 InterfaceInfo()
00082 : combo(NULL), writer(NULL), reader_bb(NULL), writer_bb(NULL)
00083 {}
00084
00085 InterfaceInfo(combo_t *pcombo, fawkes::Interface *pwriter,
00086 fawkes::BlackBoard *preader_bb, fawkes::BlackBoard *pwriter_bb)
00087 : combo(pcombo), writer(pwriter), reader_bb(preader_bb), writer_bb(pwriter_bb)
00088 {}
00089
00090 InterfaceInfo & operator=(const InterfaceInfo &ii)
00091 {
00092 combo=ii.combo; writer=ii.writer; reader_bb=ii.reader_bb; writer_bb=ii.writer_bb;
00093 return *this;
00094 }
00095 };
00096
00097 typedef std::map<std::string, combo_t > ComboMap;
00098 typedef fawkes::LockMap<fawkes::Interface *, InterfaceInfo> InterfaceMap;
00099 typedef fawkes::LockMap<fawkes::Interface *, SyncInterfaceListener *> SyncListenerMap;
00100
00101 bool check_connection();
00102 void read_config_combos(std::string prefix, bool writing);
00103 void open_interfaces();
00104 void close_interfaces();
00105
00106 private:
00107 std::string __bbsync_cfg_prefix;
00108 std::string __peer_cfg_prefix;
00109 std::string __peer;
00110
00111 std::string __host;
00112 unsigned int __port;
00113
00114 fawkes::TimeWait *__timewait;
00115
00116 fawkes::BlackBoard *__remote_bb;
00117
00118 ComboMap __combos;
00119
00120
00121 InterfaceMap __interfaces;
00122
00123 SyncListenerMap __sync_listeners;
00124
00125 SyncWriterInterfaceListener *__wsl_local;
00126 SyncWriterInterfaceListener *__wsl_remote;
00127 };
00128
00129
00130 #endif