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
33namespace fawkes {
34
35class Interface;
36class InterfaceInfoList;
37class BlackBoardMemoryManager;
38class BlackBoardMessageManager;
39class Mutex;
40class BlackBoardInstanceFactory;
41class BlackBoardInterfaceListener;
42class BlackBoardInterfaceObserver;
43class BlackBoardNotifier;
44class RefCountRWLock;
45
47{
49
50public:
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
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_refresh(const Interface *interface, bool has_changed);
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
79private:
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 void create_interface(const char *type,
88 const char *identifier,
89 const char *owner,
90 Interface *&interface,
91 void *& ptr);
92
93 Interface *writer_for_mem_serial(unsigned int mem_serial);
94
95private:
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 {
109 _OwnerInfo() : writer(NULL)
110 {
111 }
113 std::list<Interface *> readers;
114 } OwnerInfo;
116};
117
118} // end namespace fawkes
119
120#endif
BlackBoard instance factory.
BlackBoard interface manager.
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
BlackBoardInterfaceManager(BlackBoardMemoryManager *bb_memmgr, BlackBoardMessageManager *bb_msgmgr, BlackBoardNotifier *bb_notifier)
Constructor.
InterfaceInfoList * list_all() const
Get a list of interfaces.
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.
InterfaceInfoList * list(const char *type_pattern, const char *id_pattern) const
Get a constrained list of interfaces.
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for writing.
virtual std::string writer(const Interface *interface) const
Get writer of interface.
virtual void notify_of_data_refresh(const Interface *interface, bool has_changed)
Notify of data change.
virtual ~BlackBoardInterfaceManager()
Destructor.
void close(Interface *interface)
Close interface.
Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for reading.
BlackBoard memory manager.
BlackBoard message manager.
BlackBoard notifier.
Definition: notifier.h:44
Interface information list.
Interface mediator interface.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Map with a lock.
Definition: lock_map.h:36
Mutex mutual exclusion lock.
Definition: mutex.h:33
Fawkes library namespace.