Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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-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_MANAGER_H_
25 #define __BLACKBOARD_INTERFACE_MANAGER_H_
26 
27 #include <interface/mediators/interface_mediator.h>
28 
29 #include <core/utils/lock_map.h>
30 #include <utils/misc/string_compare.h>
31 
32 #include <list>
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  Interface * open_for_writing(const char *interface_type, const char *identifier);
59  void close(Interface *interface);
60 
61  InterfaceInfoList * list_all() const;
62  InterfaceInfoList * list(const char *type_pattern,
63  const char *id_pattern) const;
64 
65  std::list<Interface *> open_multiple_for_reading(const char *type_pattern,
66  const char *id_pattern = "*");
67 
68  /* InterfaceMediator methods */
69  virtual bool exists_writer(const Interface *interface) const;
70  virtual unsigned int num_readers(const Interface *interface) const;
71  virtual void notify_of_data_change(const Interface *interface);
72 
73  private:
74  const BlackBoardMemoryManager * memory_manager() const;
75 
76  Interface * new_interface_instance(const char *type, const char *identifier);
77  void delete_interface_instance(Interface *interface);
78 
79  void * find_interface_in_memory(const char *type, const char *identifier);
80  unsigned int next_mem_serial();
81  unsigned int next_instance_serial();
82  void create_interface(const char *type, const char *identifier,
83  Interface* &interface, void* &ptr);
84 
85  Interface * writer_for_mem_serial(unsigned int mem_serial);
86 
87  private:
88  unsigned int instance_serial;
89 
92  Mutex *mutex;
93  BlackBoardInstanceFactory *instance_factory;
94  BlackBoardNotifier *notifier;
95 
96  LockMap< unsigned int, Interface * > writer_interfaces;
98 };
99 
100 } // end namespace fawkes
101 
102 #endif
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
BlackBoard instance factory.
void close(Interface *interface)
Close interface.
Interface * open_for_reading(const char *interface_type, const char *identifier)
Open interface for reading.
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:80
virtual ~BlackBoardInterfaceManager()
Destructor.
Map with a lock.
Definition: lock_map.h:37
std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*")
Open all interfaces of the given type for reading.
InterfaceInfoList * list(const char *type_pattern, const char *id_pattern) const
Get a constrained list of interfaces.
InterfaceInfoList * list_all() const
Get a list of interfaces.
Interface information list.
BlackBoardInterfaceManager(BlackBoardMemoryManager *bb_memmgr, BlackBoardMessageManager *bb_msgmgr, BlackBoardNotifier *bb_notifier)
Constructor.
Interface mediator interface.
Interface * open_for_writing(const char *interface_type, const char *identifier)
Open interface for writing.
BlackBoard message manager.
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.