Fawkes API  Fawkes Development Version
interface_manager.h
1 
2 /***************************************************************************
3  * interface_manager.h - BlackBoard interface manager
4  *
5  * Created: Mon Oct 09 19:05:46 2006
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_INTERFACE_MANAGER_H_
24 #define __BLACKBOARD_INTERFACE_MANAGER_H_
25 
26 #include <interface/mediators/interface_mediator.h>
27 
28 #include <core/utils/lock_map.h>
29 #include <utils/misc/string_compare.h>
30 
31 #include <list>
32 #include <string>
33 
34 namespace fawkes {
35 
36 class Interface;
37 class InterfaceInfoList;
38 class BlackBoardMemoryManager;
39 class BlackBoardMessageManager;
40 class Mutex;
41 class BlackBoardInstanceFactory;
42 class BlackBoardInterfaceListener;
43 class BlackBoardInterfaceObserver;
44 class BlackBoardNotifier;
45 class RefCountRWLock;
46 
48 {
49  friend class BlackBoardMessageManager;
50  public:
51 
53  BlackBoardMessageManager *bb_msgmgr,
54  BlackBoardNotifier *bb_notifier);
56 
57  Interface * open_for_reading(const char *interface_type, const char *identifier,
58  const char *owner = NULL);
59  Interface * open_for_writing(const char *interface_type, const char *identifier,
60  const char *owner = NULL);
61  void close(Interface *interface);
62 
63  InterfaceInfoList * list_all() const;
64  InterfaceInfoList * list(const char *type_pattern,
65  const char *id_pattern) const;
66 
67  std::list<Interface *> open_multiple_for_reading(const char *type_pattern,
68  const char *id_pattern = "*",
69  const char *owner = NULL);
70 
71  /* InterfaceMediator methods */
72  virtual bool exists_writer(const Interface *interface) const;
73  virtual unsigned int num_readers(const Interface *interface) const;
74  virtual void notify_of_data_change(const Interface *interface);
75  virtual std::list<std::string> readers(const Interface *interface) const;
76  virtual std::string writer(const Interface *interface) const;
77 
78  std::list<std::string> readers(const std::string &uid) const;
79  std::string writer(const std::string &uid) const;
80 
81  private:
82  const BlackBoardMemoryManager * memory_manager() const;
83 
84  Interface * new_interface_instance(const char *type, const char *identifier, const char *owner);
85  void delete_interface_instance(Interface *interface);
86 
87  void * find_interface_in_memory(const char *type, const char *identifier);
88  unsigned int next_mem_serial();
89  unsigned int next_instance_serial();
90  void create_interface(const char *type, const char *identifier, const char *owner,
91  Interface* &interface, void* &ptr);
92 
93  Interface * writer_for_mem_serial(unsigned int mem_serial);
94 
95  private:
96  unsigned int instance_serial;
97 
100  Mutex *mutex;
101  BlackBoardInstanceFactory *instance_factory;
102  BlackBoardNotifier *notifier;
103 
104  LockMap< unsigned int, Interface * > writer_interfaces;
106 
107  typedef struct _OwnerInfo {
108  _OwnerInfo() : writer(NULL) {}
109  Interface *writer;
110  std::list<Interface *> readers;
111  } OwnerInfo;
113 };
114 
115 } // end namespace fawkes
116 
117 #endif
BlackBoard instance factory.
void close(Interface *interface)
Close interface.
virtual std::string writer(const Interface *interface) const
Get writer of interface.
Fawkes library namespace.
BlackBoard memory manager.
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
virtual ~BlackBoardInterfaceManager()
Destructor.
InterfaceInfoList * list(const char *type_pattern, const char *id_pattern) const
Get a constrained list of interfaces.
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
Map with a lock.
Definition: lock_map.h:37
Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for writing.
Interface information list.
BlackBoardInterfaceManager(BlackBoardMemoryManager *bb_memmgr, BlackBoardMessageManager *bb_msgmgr, BlackBoardNotifier *bb_notifier)
Constructor.
std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)
Open all interfaces of the given type for reading.
Interface mediator interface.
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
BlackBoard message manager.
Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for reading.
InterfaceInfoList * list_all() const
Get a list of interfaces.
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
BlackBoard interface manager.