Fawkes API Fawkes Development Version
interface_list_maintainer.h
1
2/***************************************************************************
3 * interface_list_maintainer.h - BlackBoard interface list maintainer
4 *
5 * Created: Mon Mar 16 13:34:00 2015
6 * Copyright 2007-2014 Tim Niemueller [www.niemueller.de]
7 * 2015 Tobias Neumann
8 *
9 ****************************************************************************/
10
11/* This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. A runtime exception applies to
15 * this software (see LICENSE.GPL_WRE file mentioned below for details).
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23 */
24
25#ifndef _BLACKBOARD_INTERFACE_LIST_MAINTAINER_H_
26#define _BLACKBOARD_INTERFACE_LIST_MAINTAINER_H_
27
28#include <blackboard/blackboard.h>
29#include <blackboard/interface_listener.h>
30#include <blackboard/interface_observer.h>
31#include <core/utils/lock_list.h>
32#include <interface/interface.h>
33#include <logging/logger.h>
34#include <utils/uuid.h>
35
36#include <list>
37#include <string>
38
39namespace fawkes {
40
41/** @class BlackBoardInterfaceListMaintainer "interface_list_maintainer.h"
42 * opens and maintains multiple interfaces defined by a pattern
43 * @author Tobias Neumann
44 */
47{
48public:
50 BlackBoard *bb,
51 Logger * l,
52 const char *type,
53 const char *pattern);
55
56 template <class InterfaceType>
57 std::list<InterfaceType *> lock_and_get_list();
58
59 void unlock_list();
60
61private:
62 // for BlackBoardInterfaceObserver
63 virtual void bb_interface_created(const char *type, const char *id) noexcept;
64
65 // for BlackBoardInterfaceListener
66 virtual void bb_interface_writer_removed(fawkes::Interface *interface,
67 fawkes::Uuid instance_serial) noexcept;
68 virtual void bb_interface_reader_removed(fawkes::Interface *interface,
69 fawkes::Uuid instance_serial) noexcept;
70
71 void conditional_close(fawkes::Interface *interface) noexcept;
72
73private:
74 BlackBoard * blackboard_;
75 Logger * logger_;
76 char * name_;
78};
79
80/** Locks the mutex in this class and returns a list of all interfaces defined by the pattern
81 *
82 * after the list is used unlock_list() needs to be called to unlock the mutex in this class
83 *
84 * @return list of interfaces defined by the pattern
85 */
86template <class InterfaceType>
87std::list<InterfaceType *>
89{
90 ifs_.lock();
91 std::list<InterfaceType *> ifs_cpy;
92 for (fawkes::LockList<fawkes::Interface *>::iterator pif = ifs_.begin(); pif != ifs_.end();
93 ++pif) {
94 (*pif)->read();
95 ifs_cpy.push_back(dynamic_cast<InterfaceType *>(*pif));
96 }
97 return ifs_cpy;
98}
99
100} // end namespace fawkes
101
102#endif
opens and maintains multiple interfaces defined by a pattern
BlackBoardInterfaceListMaintainer(const char *n, BlackBoard *bb, Logger *l, const char *type, const char *pattern)
Constructor.
void unlock_list()
unlocks the mutex in this class
std::list< InterfaceType * > lock_and_get_list()
Locks the mutex in this class and returns a list of all interfaces defined by the pattern.
BlackBoard interface listener.
BlackBoard interface observer.
The BlackBoard abstract class.
Definition: blackboard.h:46
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
virtual void lock() const
Lock list.
Definition: lock_list.h:124
Interface for logging.
Definition: logger.h:42
A convenience class for universally unique identifiers (UUIDs).
Definition: uuid.h:29
Fawkes library namespace.