Fawkes API  Fawkes Development Version
remote.h
1 
2 /***************************************************************************
3  * remote.h - Remote BlackBoard using the Fawkes network protocol
4  *
5  * Created: Mon Mar 03 10:52:28 2008
6  * Copyright 2006-2015 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
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_WRE file in the doc directory.
21  */
22 
23 #ifndef _BLACKBOARD_REMOTE_H_
24 #define _BLACKBOARD_REMOTE_H_
25 
26 #include <blackboard/blackboard.h>
27 #include <core/exceptions/software.h>
28 #include <core/utils/lock_map.h>
29 #include <netcomm/fawkes/client_handler.h>
30 
31 #include <list>
32 
33 namespace fawkes {
34 
35 class FawkesNetworkClient;
36 class FawkesNetworkMessage;
37 class Mutex;
38 class WaitCondition;
39 class Interface;
40 class InterfaceInfoList;
41 
42 class BlackBoardInstanceFactory;
43 class BlackBoardNotifier;
44 class BlackBoardInterfaceProxy;
45 class BlackBoardInterfaceListener;
46 class BlackBoardInterfaceObserver;
47 
48 class RemoteBlackBoard : public BlackBoard, public FawkesNetworkClientHandler
49 {
50 public:
51  RemoteBlackBoard(FawkesNetworkClient *client);
52  RemoteBlackBoard(const char *hostname, unsigned short int port);
53  virtual ~RemoteBlackBoard();
54 
55  virtual Interface *
56  open_for_reading(const char *interface_type, const char *identifier, const char *owner = NULL);
57  virtual Interface *
58  open_for_writing(const char *interface_type, const char *identifier, const char *owner = NULL);
59  virtual void close(Interface *interface);
60 
61  virtual InterfaceInfoList *list_all();
62  virtual InterfaceInfoList *list(const char *type_pattern, const char *id_pattern);
63  virtual bool is_alive() const throw();
64  virtual bool try_aliveness_restore() throw();
65 
66  std::list<Interface *> open_multiple_for_reading(const char *interface_type,
67  const char *id_pattern = "*",
68  const char *owner = NULL);
69 
70  /* for FawkesNetworkClientHandler */
71  virtual void deregistered(unsigned int id) throw();
72  virtual void inbound_received(FawkesNetworkMessage *msg, unsigned int id) throw();
73  virtual void connection_died(unsigned int id) throw();
74  virtual void connection_established(unsigned int id) throw();
75 
76  /* extensions for RemoteBlackBoard */
77 
78 private: /* methods */
79  void open_interface(const char *type,
80  const char *identifier,
81  const char *owner,
82  bool writer,
83  Interface * iface);
84  Interface *
85  open_interface(const char *type, const char *identifier, const char *owner, bool writer);
86  void reopen_interfaces();
87 
88 private: /* members */
89  Mutex * mutex_;
90  FawkesNetworkClient * fnc_;
91  bool fnc_owner_;
93  BlackBoardInstanceFactory * instance_factory_;
94  LockMap<unsigned int, BlackBoardInterfaceProxy *> proxies_;
95  LockMap<unsigned int, BlackBoardInterfaceProxy *>::iterator pit_;
96  std::list<BlackBoardInterfaceProxy *> invalid_proxies_;
97  std::list<BlackBoardInterfaceProxy *>::iterator ipit_;
98 
99  Mutex * wait_mutex_;
100  WaitCondition *wait_cond_;
101 
102  const char *inbound_thread_;
103 };
104 
105 } // end namespace fawkes
106 
107 #endif
fawkes::RemoteBlackBoard::open_for_writing
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)
Definition: remote.cpp:278
fawkes::LockMap
Definition: lock_map.h:41
fawkes::RemoteBlackBoard::open_multiple_for_reading
std::list< Interface * > open_multiple_for_reading(const char *interface_type, const char *id_pattern="*", const char *owner=NULL)
Definition: remote.cpp:284
fawkes::RemoteBlackBoard::try_aliveness_restore
virtual bool try_aliveness_restore()
Definition: remote.cpp:162
fawkes::RemoteBlackBoard::is_alive
virtual bool is_alive() const
Definition: remote.cpp:137
fawkes::Mutex
Definition: mutex.h:38
fawkes::WaitCondition
Definition: wait_condition.h:42
fawkes::RemoteBlackBoard::connection_established
virtual void connection_established(unsigned int id)
Definition: remote.cpp:534
fawkes::RemoteBlackBoard::RemoteBlackBoard
RemoteBlackBoard(FawkesNetworkClient *client)
Constructor.
Definition: remote.cpp:61
fawkes::BlackBoardInterfaceProxy
Definition: interface_proxy.h:46
fawkes
fawkes::RemoteBlackBoard::list
virtual InterfaceInfoList * list(const char *type_pattern, const char *id_pattern)
Definition: remote.cpp:396
fawkes::RemoteBlackBoard::list_all
virtual InterfaceInfoList * list_all()
Definition: remote.cpp:350
fawkes::InterfaceInfoList
Definition: interface_info.h:81
fawkes::RemoteBlackBoard::~RemoteBlackBoard
virtual ~RemoteBlackBoard()
Destructor.
Definition: remote.cpp:117
fawkes::Interface
Definition: interface.h:78
fawkes::RemoteBlackBoard::inbound_received
virtual void inbound_received(FawkesNetworkMessage *msg, unsigned int id)
Definition: remote.cpp:457
fawkes::RemoteBlackBoard::close
virtual void close(Interface *interface)
Close interface.
Definition: remote.cpp:324
fawkes::RemoteBlackBoard::connection_died
virtual void connection_died(unsigned int id)
Definition: remote.cpp:520
fawkes::BlackBoardInstanceFactory
Definition: instance_factory.h:39
fawkes::RemoteBlackBoard::deregistered
virtual void deregistered(unsigned int id)
We are no longer registered in Fawkes network client.
Definition: remote.cpp:452
fawkes::FawkesNetworkMessage
Definition: message.h:82
fawkes::FawkesNetworkClient
Definition: client.h:57
fawkes::RemoteBlackBoard::open_for_reading
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Definition: remote.cpp:272