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 
49 {
50 public:
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_;
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
Message handler for FawkesNetworkClient.
BlackBoard instance factory.
Wait until a given condition holds.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for writing.
Definition: remote.cpp:273
Simple Fawkes network client.
Definition: client.h:51
Fawkes library namespace.
Representation of a message that is sent over the network.
Definition: message.h:76
virtual void deregistered(unsigned int id)
We are no longer registered in Fawkes network client.
Definition: remote.cpp:447
virtual void connection_established(unsigned int id)
Client has established a connection.
Definition: remote.cpp:529
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:78
virtual InterfaceInfoList * list(const char *type_pattern, const char *id_pattern)
Get list of interfaces matching type and ID patterns.
Definition: remote.cpp:391
Map with a lock.
Definition: lock_map.h:35
Interface information list.
virtual void close(Interface *interface)
Close interface.
Definition: remote.cpp:319
virtual ~RemoteBlackBoard()
Destructor.
Definition: remote.cpp:112
virtual bool try_aliveness_restore()
Try to restore the aliveness of the BlackBoard instance.
Definition: remote.cpp:157
virtual void inbound_received(FawkesNetworkMessage *msg, unsigned int id)
Called for incoming messages.
Definition: remote.cpp:452
virtual void connection_died(unsigned int id)
Client connection died.
Definition: remote.cpp:515
Remote BlackBoard.
Definition: remote.h:48
RemoteBlackBoard(FawkesNetworkClient *client)
Constructor.
Definition: remote.cpp:56
virtual InterfaceInfoList * list_all()
Get list of all currently existing interfaces.
Definition: remote.cpp:345
The BlackBoard abstract class.
Definition: blackboard.h:45
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual bool is_alive() const
Check if the BlackBoard is still alive.
Definition: remote.cpp:132
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for reading.
Definition: remote.cpp:267