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 
35 #include <list>
36 #include <string>
37 
38 namespace fawkes {
39 
40 /** @class BlackBoardInterfaceListMaintainer "interface_list_maintainer.h"
41  * opens and maintains multiple interfaces defined by a pattern
42  * @author Tobias Neumann
43  */
46 {
47 public:
49  BlackBoard *bb,
50  Logger * l,
51  const char *type,
52  const char *pattern);
54 
55  template <class InterfaceType>
56  std::list<InterfaceType *> lock_and_get_list();
57 
58  void unlock_list();
59 
60 private:
61  // for BlackBoardInterfaceObserver
62  virtual void bb_interface_created(const char *type, const char *id) throw();
63 
64  // for BlackBoardInterfaceListener
65  virtual void bb_interface_writer_removed(fawkes::Interface *interface,
66  unsigned int instance_serial) throw();
67  virtual void bb_interface_reader_removed(fawkes::Interface *interface,
68  unsigned int instance_serial) throw();
69 
70  void conditional_close(fawkes::Interface *interface) throw();
71 
72 private:
73  BlackBoard * blackboard_;
74  Logger * logger_;
75  char * name_;
77 };
78 
79 /** Locks the mutex in this class and returns a list of all interfaces defined by the pattern
80  *
81  * after the list is used unlock_list() needs to be called to unlock the mutex in this class
82  *
83  * @return list of interfaces defined by the pattern
84  */
85 template <class InterfaceType>
86 std::list<InterfaceType *>
88 {
89  ifs_.lock();
90  std::list<InterfaceType *> ifs_cpy;
91  for (fawkes::LockList<fawkes::Interface *>::iterator pif = ifs_.begin(); pif != ifs_.end();
92  ++pif) {
93  (*pif)->read();
94  ifs_cpy.push_back(dynamic_cast<InterfaceType *>(*pif));
95  }
96  return ifs_cpy;
97 }
98 
99 } // end namespace fawkes
100 
101 #endif
std::list< InterfaceType * > lock_and_get_list()
Locks the mutex in this class and returns a list of all interfaces defined by the pattern.
virtual void lock() const
Lock list.
Definition: lock_list.h:124
Fawkes library namespace.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:78
BlackBoardInterfaceListMaintainer(const char *n, BlackBoard *bb, Logger *l, const char *type, const char *pattern)
Constructor.
BlackBoard interface observer.
opens and maintains multiple interfaces defined by a pattern
The BlackBoard abstract class.
Definition: blackboard.h:45
void unlock_list()
unlocks the mutex in this class
BlackBoard interface listener.
Interface for logging.
Definition: logger.h:41