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 <core/utils/lock_map.h>
27 #include <interface/mediators/interface_mediator.h>
28 #include <utils/misc/string_compare.h>
29 
30 #include <list>
31 #include <string>
32 
33 namespace fawkes {
34 
35 class Interface;
36 class InterfaceInfoList;
37 class BlackBoardMemoryManager;
38 class BlackBoardMessageManager;
39 class Mutex;
40 class BlackBoardInstanceFactory;
41 class BlackBoardInterfaceListener;
42 class BlackBoardInterfaceObserver;
43 class BlackBoardNotifier;
44 class RefCountRWLock;
45 
47 {
49 
50 public:
52  BlackBoardMessageManager *bb_msgmgr,
53  BlackBoardNotifier * bb_notifier);
55 
56  Interface *
57  open_for_reading(const char *interface_type, const char *identifier, const char *owner = NULL);
58  Interface *
59  open_for_writing(const char *interface_type, const char *identifier, const char *owner = NULL);
60  void close(Interface *interface);
61 
62  InterfaceInfoList *list_all() const;
63  InterfaceInfoList *list(const char *type_pattern, const char *id_pattern) const;
64 
65  std::list<Interface *> open_multiple_for_reading(const char *type_pattern,
66  const char *id_pattern = "*",
67  const char *owner = NULL);
68 
69  /* InterfaceMediator methods */
70  virtual bool exists_writer(const Interface *interface) const;
71  virtual unsigned int num_readers(const Interface *interface) const;
72  virtual void notify_of_data_change(const Interface *interface);
73  virtual std::list<std::string> readers(const Interface *interface) const;
74  virtual std::string writer(const Interface *interface) const;
75 
76  std::list<std::string> readers(const std::string &uid) const;
77  std::string writer(const std::string &uid) const;
78 
79 private:
80  const BlackBoardMemoryManager *memory_manager() const;
81 
82  Interface *new_interface_instance(const char *type, const char *identifier, const char *owner);
83  void delete_interface_instance(Interface *interface);
84 
85  void * find_interface_in_memory(const char *type, const char *identifier);
86  unsigned int next_mem_serial();
87  unsigned int next_instance_serial();
88  void create_interface(const char *type,
89  const char *identifier,
90  const char *owner,
91  Interface *&interface,
92  void *& ptr);
93 
94  Interface *writer_for_mem_serial(unsigned int mem_serial);
95 
96 private:
97  unsigned int instance_serial;
98 
99  BlackBoardMemoryManager * memmgr;
100  BlackBoardMessageManager * msgmgr;
101  Mutex * mutex;
102  BlackBoardInstanceFactory *instance_factory;
103  BlackBoardNotifier * notifier;
104 
105  LockMap<unsigned int, Interface *> writer_interfaces;
107 
108  typedef struct _OwnerInfo
109  {
110  _OwnerInfo() : writer(NULL)
111  {
112  }
113  Interface * writer;
114  std::list<Interface *> readers;
115  } OwnerInfo;
117 };
118 
119 } // end namespace fawkes
120 
121 #endif
fawkes::BlackBoardInterfaceManager::BlackBoardInterfaceManager
BlackBoardInterfaceManager(BlackBoardMemoryManager *bb_memmgr, BlackBoardMessageManager *bb_msgmgr, BlackBoardNotifier *bb_notifier)
Constructor.
Definition: interface_manager.cpp:63
fawkes::LockMap
Map with a lock.
Definition: lock_map.h:36
fawkes::Mutex
Mutex mutual exclusion lock.
Definition: mutex.h:33
fawkes::BlackBoardInterfaceManager::writer
virtual std::string writer(const Interface *interface) const
Get writer of interface.
Definition: interface_manager.cpp:682
fawkes::BlackBoardInterfaceManager::list
InterfaceInfoList * list(const char *type_pattern, const char *id_pattern) const
Get a constrained list of interfaces.
Definition: interface_manager.cpp:575
fawkes::BlackBoardInterfaceManager::open_for_reading
Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for reading.
Definition: interface_manager.cpp:247
fawkes::BlackBoardInterfaceManager::~BlackBoardInterfaceManager
virtual ~BlackBoardInterfaceManager()
Destructor.
Definition: interface_manager.cpp:80
fawkes::BlackBoardInterfaceManager::open_for_writing
Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for writing.
Definition: interface_manager.cpp:412
fawkes::BlackBoardMemoryManager
BlackBoard memory manager.
Definition: memory_manager.h:59
fawkes::BlackBoardInterfaceManager::num_readers
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
Definition: interface_manager.cpp:659
fawkes::BlackBoardInterfaceManager
BlackBoard interface manager.
Definition: interface_manager.h:47
fawkes::InterfaceMediator
Interface mediator interface.
Definition: interface_mediator.h:40
fawkes
Fawkes library namespace.
fawkes::BlackBoardInterfaceManager::close
void close(Interface *interface)
Close interface.
Definition: interface_manager.cpp:485
fawkes::BlackBoardInterfaceManager::open_multiple_for_reading
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.
Definition: interface_manager.cpp:325
fawkes::InterfaceInfoList
Interface information list.
Definition: interface_info.h:76
fawkes::Interface
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
fawkes::BlackBoardInterfaceManager::list_all
InterfaceInfoList * list_all() const
Get a list of interfaces.
Definition: interface_manager.cpp:530
fawkes::BlackBoardMessageManager
BlackBoard message manager.
Definition: message_manager.h:37
fawkes::BlackBoardInstanceFactory
BlackBoard instance factory.
Definition: instance_factory.h:34
fawkes::BlackBoardInterfaceManager::notify_of_data_change
virtual void notify_of_data_change(const Interface *interface)
Notify of data change.
Definition: interface_manager.cpp:647
fawkes::BlackBoardNotifier
BlackBoard notifier.
Definition: notifier.h:43
fawkes::BlackBoardInterfaceManager::exists_writer
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
Definition: interface_manager.cpp:653
fawkes::BlackBoardInterfaceManager::readers
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
Definition: interface_manager.cpp:666