Fawkes API  Fawkes Development Version
ownership.cpp
1 
2 /***************************************************************************
3  * ownership.cpp - BlackBoard with traced ownership
4  *
5  * Created: Thu Jan 22 15:19:03 2015
6  * Copyright 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 #include <blackboard/ownership.h>
24 
25 #include <string>
26 #include <cstring>
27 
28 namespace fawkes {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class BlackBoardWithOwnership <blackboard/ownership.h>
34  * BlackBoard that traces interface ownership.
35  *
36  * @see Interface
37  * @see Message
38  *
39  * @author Tim Niemueller
40  */
41 
42 
43 /** Constructor.
44  * @param parent parent blackboard to use as actual blackboard
45  * @param owner owner name to record in newly created interfaces
46  */
48  : BlackBoard(/* create notifier */ false), blackboard_(parent), owner_(owner)
49 {
50  BlackBoardWithOwnership *bbo = dynamic_cast<BlackBoardWithOwnership *>(blackboard_);
51  if (bbo) {
52  // we are wrapping another ownership, remove indirection and make sure
53  // we do use the outer wrapper's ownership info
54  blackboard_ = bbo->blackboard_;
55  }
56 }
57 
58 
59 /** Destructor. */
61 {
62 }
63 
64 
65 Interface *
66 BlackBoardWithOwnership::open_for_reading(const char *type, const char *identifier, const char *owner)
67 {
68  return blackboard_->open_for_reading(type, identifier,
69  owner ? owner : owner_.c_str());
70 }
71 
72 
73 Interface *
74 BlackBoardWithOwnership::open_for_writing(const char *type, const char *identifier, const char *owner)
75 {
76  return blackboard_->open_for_writing(type, identifier,
77  owner ? owner : owner_.c_str());
78 }
79 
80 
81 std::list<Interface *>
83  const char *id_pattern,
84  const char *owner)
85 {
86  return blackboard_->open_multiple_for_reading(type_pattern, id_pattern,
87  owner ? owner : owner_.c_str());
88 }
89 
90 
91 void
93 {
94  blackboard_->close(interface);
95 }
96 
97 
100 {
101  return blackboard_->list_all();
102 }
103 
104 
106 BlackBoardWithOwnership::list(const char *type_pattern, const char *id_pattern)
107 {
108  return blackboard_->list(type_pattern, id_pattern);
109 }
110 
111 
112 bool
114 {
115  return blackboard_->is_alive();
116 }
117 
118 
119 bool
121 {
122  return blackboard_->try_aliveness_restore();
123 }
124 
125 void
128 {
129  blackboard_->register_listener(listener, flag);
130 }
131 
132 void
135 {
136  if (! listener) return;
137  blackboard_->update_listener(listener, flag);
138 }
139 
140 
141 void
143 {
144  if (! listener) return;
145  blackboard_->unregister_listener(listener);
146 }
147 
148 void
150 {
151  if (! observer) return;
152  blackboard_->register_observer(observer);
153 }
154 
155 
156 void
158 {
159  if (! observer) return;
160  blackboard_->unregister_observer(observer);
161 }
162 
163 
164 } // end namespace fawkes
virtual ~BlackBoardWithOwnership()
Destructor.
Definition: ownership.cpp:60
virtual void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
Definition: blackboard.cpp:230
ListenerRegisterFlag
Flags to constrain listener registration/updates.
Definition: blackboard.h:98
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)
Open multiple interfaces for reading.
Definition: ownership.cpp:82
Fawkes library namespace.
virtual void close(Interface *interface)
Close interface.
Definition: ownership.cpp:92
virtual bool try_aliveness_restore()=0
Try to restore the aliveness of the BlackBoard instance.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for reading.
Definition: ownership.cpp:66
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Definition: blackboard.cpp:218
virtual void update_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Update BB event listener.
Definition: blackboard.cpp:203
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Definition: ownership.cpp:142
virtual InterfaceInfoList * list(const char *type_pattern, const char *id_pattern)=0
Get list of interfaces matching type and ID patterns.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
Definition: blackboard.cpp:190
Interface information list.
virtual bool is_alive() const
Check if the BlackBoard is still alive.
Definition: ownership.cpp:113
virtual bool is_alive() const =0
Check if the BlackBoard is still alive.
virtual void unregister_observer(BlackBoardInterfaceObserver *observer)
Unregister BB interface observer.
Definition: blackboard.cpp:244
BlackBoard that traces interface ownership.
Definition: ownership.h:34
virtual void unregister_observer(BlackBoardInterfaceObserver *observer)
Unregister BB interface observer.
Definition: ownership.cpp:157
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)=0
Open multiple interfaces for reading.
BlackBoard interface observer.
BlackBoardWithOwnership(BlackBoard *parent, const char *owner)
Constructor.
Definition: ownership.cpp:47
virtual InterfaceInfoList * list_all()
Get list of all currently existing interfaces.
Definition: ownership.cpp:99
virtual bool try_aliveness_restore()
Try to restore the aliveness of the BlackBoard instance.
Definition: ownership.cpp:120
virtual InterfaceInfoList * list_all()=0
Get list of all currently existing interfaces.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
Definition: ownership.cpp:149
virtual void update_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Update BB event listener.
Definition: ownership.cpp:133
The BlackBoard abstract class.
Definition: blackboard.h:48
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)
Open interface for writing.
Definition: ownership.cpp:74
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
Definition: ownership.cpp:126
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual InterfaceInfoList * list(const char *type_pattern, const char *id_pattern)
Get list of interfaces matching type and ID patterns.
Definition: ownership.cpp:106
BlackBoard interface listener.
virtual void close(Interface *interface)=0
Close interface.