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