Fawkes API  Fawkes Development Version
interface_proxy.h
1 
2 /***************************************************************************
3  * interface_proxy.h - BlackBoard interface proxy for RemoteBlackBoard
4  *
5  * Created: Tue Mar 04 10:52:28 2008
6  * Copyright 2006-2008 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. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _BLACKBOARD_INTERFACE_PROXY_H_
25 #define _BLACKBOARD_INTERFACE_PROXY_H_
26 
27 #include <interface/mediators/interface_mediator.h>
28 #include <interface/mediators/message_mediator.h>
29 
30 #include <cstdlib>
31 
32 namespace fawkes {
33 
34 class FawkesNetworkClient;
35 class FawkesNetworkMessage;
36 class RefCountRWLock;
37 class BlackBoardNotifier;
38 class Interface;
39 
40 class BlackBoardInterfaceProxy : public InterfaceMediator, public MessageMediator
41 {
42 public:
43  BlackBoardInterfaceProxy(FawkesNetworkClient * client,
45  BlackBoardNotifier * notifier,
47  bool readwrite);
49 
52  void reader_added(unsigned int event_serial);
53  void reader_removed(unsigned int event_serial);
54  void writer_added(unsigned int event_serial);
55  void writer_removed(unsigned int event_serial);
56 
57  unsigned int serial() const;
58  unsigned int clid() const;
59  Interface * interface() const;
60 
61  /* InterfaceMediator */
62  virtual bool exists_writer(const Interface *interface) const;
63  virtual unsigned int num_readers(const Interface *interface) const;
64  virtual void notify_of_data_change(const Interface *interface);
65  virtual std::list<std::string> readers(const Interface *interface) const;
66  virtual std::string writer(const Interface *interface) const;
67 
68  /* MessageMediator */
69  virtual void transmit(Message *message);
70 
71 private:
72  inline unsigned int
73  next_msg_id()
74  {
75  return ((instance_serial_ << 16) | next_msg_id_++);
76  }
77 
78 private:
79  FawkesNetworkClient *fnc_;
80 
81  RefCountRWLock * rwlock_;
82  BlackBoardNotifier *notifier_;
83  Interface * interface_;
84 
85  void * mem_chunk_;
86  void * data_chunk_;
87  size_t data_size_;
88 
89  unsigned short instance_serial_;
90  unsigned short next_msg_id_;
91  unsigned int num_readers_;
92  bool has_writer_;
93  unsigned int clid_;
94 };
95 
96 } // end namespace fawkes
97 
98 #endif
fawkes::BlackBoardInterfaceProxy::num_readers
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
Definition: interface_proxy.cpp:299
fawkes::BlackBoardInterfaceProxy::notify_of_data_change
virtual void notify_of_data_change(const Interface *interface)
Notify of data change.
Definition: interface_proxy.cpp:317
fawkes::BlackBoardInterfaceProxy::BlackBoardInterfaceProxy
BlackBoardInterfaceProxy(FawkesNetworkClient *client, FawkesNetworkMessage *msg, BlackBoardNotifier *notifier, Interface *interface, bool readwrite)
Constructor.
Definition: interface_proxy.cpp:59
fawkes::BlackBoardInterfaceProxy::reader_added
void reader_added(unsigned int event_serial)
Reader has been added.
Definition: interface_proxy.cpp:226
fawkes::BlackBoardInterfaceProxy::exists_writer
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
Definition: interface_proxy.cpp:293
fawkes::BlackBoardInterfaceProxy::writer
virtual std::string writer(const Interface *interface) const
Get writer of interface.
Definition: interface_proxy.cpp:311
fawkes::BlackBoardInterfaceProxy::transmit
virtual void transmit(Message *message)
Transmit message.
Definition: interface_proxy.cpp:334
fawkes::RefCountRWLock
Definition: refc_rwlock.h:36
fawkes::Message
Definition: message.h:40
fawkes::BlackBoardInterfaceProxy::serial
unsigned int serial() const
Get instance serial of interface.
Definition: interface_proxy.cpp:268
fawkes::BlackBoardInterfaceProxy::reader_removed
void reader_removed(unsigned int event_serial)
Reader has been removed.
Definition: interface_proxy.cpp:236
fawkes
fawkes::BlackBoardInterfaceProxy::process_interface_message
void process_interface_message(FawkesNetworkMessage *msg)
Process MSG_BB_INTERFACE message.
Definition: interface_proxy.cpp:157
fawkes::BlackBoardInterfaceProxy::process_data_changed
void process_data_changed(FawkesNetworkMessage *msg)
Process MSG_BB_DATA_CHANGED message.
Definition: interface_proxy.cpp:118
fawkes::Interface
Definition: interface.h:77
fawkes::BlackBoardInterfaceProxy::~BlackBoardInterfaceProxy
~BlackBoardInterfaceProxy()
Destructor.
Definition: interface_proxy.cpp:109
fawkes::BlackBoardInterfaceProxy::clid
unsigned int clid() const
Get client ID of assigned client.
Definition: interface_proxy.cpp:277
fawkes::BlackBoardInterfaceProxy::writer_added
void writer_added(unsigned int event_serial)
Writer has been added.
Definition: interface_proxy.cpp:248
fawkes::BlackBoardNotifier
Definition: notifier.h:46
fawkes::FawkesNetworkMessage
Definition: message.h:80
fawkes::BlackBoardInterfaceProxy::writer_removed
void writer_removed(unsigned int event_serial)
Writer has been removed.
Definition: interface_proxy.cpp:258
fawkes::FawkesNetworkClient
Definition: client.h:55
fawkes::BlackBoardInterfaceProxy::readers
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
Definition: interface_proxy.cpp:305
fawkes::BlackBoardInterfaceProxy::interface
Interface * interface() const
Get instance serial of interface.
Definition: interface_proxy.cpp:286