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 #include <cstdlib>
30 
31 namespace fawkes {
32 
33 class FawkesNetworkClient;
34 class FawkesNetworkMessage;
35 class RefCountRWLock;
36 class BlackBoardNotifier;
37 class Interface;
38 
40 : public InterfaceMediator,
41  public MessageMediator
42 {
43  public:
46  bool readwrite);
48 
51  void reader_added(unsigned int event_serial);
52  void reader_removed(unsigned int event_serial);
53  void writer_added(unsigned int event_serial);
54  void writer_removed(unsigned int event_serial);
55 
56  unsigned int serial() const;
57  unsigned int clid() const;
58  Interface * interface() const;
59 
60  /* InterfaceMediator */
61  virtual bool exists_writer(const Interface *interface) const;
62  virtual unsigned int num_readers(const Interface *interface) const;
63  virtual void notify_of_data_change(const Interface *interface);
64  virtual std::list<std::string> readers(const Interface *interface) const;
65  virtual std::string writer(const Interface *interface) const;
66 
67  /* MessageMediator */
68  virtual void transmit(Message *message);
69 
70  private:
71  inline unsigned int next_msg_id()
72  {
73  return ((__instance_serial << 16) | __next_msg_id++);
74  }
75 
76  private:
77  FawkesNetworkClient *__fnc;
78 
79  RefCountRWLock *__rwlock;
80  BlackBoardNotifier *__notifier;
81  Interface *__interface;
82 
83  void *__mem_chunk;
84  void *__data_chunk;
85  size_t __data_size;
86 
87  unsigned short __instance_serial;
88  unsigned short __next_msg_id;
89  unsigned int __num_readers;
90  bool __has_writer;
91  unsigned int __clid;
92 };
93 
94 } // end namespace fawkes
95 
96 #endif
unsigned int clid() const
Get client ID of assigned client.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
void writer_removed(unsigned int event_serial)
Writer has been removed.
virtual std::string writer(const Interface *interface) const
Get writer of interface.
Simple Fawkes network client.
Definition: client.h:52
Fawkes library namespace.
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
void process_interface_message(FawkesNetworkMessage *msg)
Process MSG_BB_INTERFACE message.
unsigned int serial() const
Get instance serial of interface.
Representation of a message that is sent over the network.
Definition: message.h:75
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
virtual void notify_of_data_change(const Interface *interface)
Notify of data change.
BlackBoard notifier.
Definition: notifier.h:43
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Interface proxy for remote BlackBoard.
void reader_removed(unsigned int event_serial)
Reader has been removed.
Read/write lock with reference counting.
Definition: refc_rwlock.h:33
Interface mediator interface.
void writer_added(unsigned int event_serial)
Writer has been added.
void reader_added(unsigned int event_serial)
Reader has been added.
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
Interface * interface() const
Get instance serial of interface.
virtual void transmit(Message *message)
Transmit message.
void process_data_changed(FawkesNetworkMessage *msg)
Process MSG_BB_DATA_CHANGED message.
Message mediator interface.
BlackBoardInterfaceProxy(FawkesNetworkClient *client, FawkesNetworkMessage *msg, BlackBoardNotifier *notifier, Interface *interface, bool readwrite)
Constructor.