2
* Copyright © 2016 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
19
#ifndef MIR_OBSERVER_REGISTRAR_H_
20
#define MIR_OBSERVER_REGISTRAR_H_
29
* Register observers for a subsystem.
31
* \tparam Observer The Observer type to register
33
template<class Observer>
34
class ObserverRegistrar
38
* Add an observer to the set notified of all observations
40
* The ObserverRegistrar does not take any ownership of \p observer, and will
41
* automatically remove it when \p observer expires.
43
* \param [in] observer The observer to register
45
virtual void register_interest(std::weak_ptr<Observer> const& observer) = 0;
48
* Add an observer with specified execution environment
50
* This is threadsafe and can be called in any context.
52
* The ObserverRegistrar does not take any ownership of \p observer, and will
53
* automatically remove it when \p observer expires.
55
* All calls to \p observer methods are performed in the context of
58
* The \p executor should process work in a delayed fashion. Particularly,
59
* executor::spawn(work) is expected to \b not run \p work in the current
60
* stack. Eager execution of work may result in deadlocks if calls to the
61
* observer result in calls into the ObserverRegistrar.
63
* \param [in] observer The observer to register
64
* \param [in] executor Execution environment for calls to \p observer methods.
65
* The caller is responsible for ensuring \p executor outlives
68
virtual void register_interest(
69
std::weak_ptr<Observer> const& observer,
70
Executor& executor) = 0;
73
* Remove an observer from the set notified of all observations.
75
* This is threadsafe and can be called in any context.
76
* It is \b not guaranteed that methods of \p observer will not be called after
79
* \param observer [in] The observer to unregister
81
virtual void unregister_interest(Observer const& observer) = 0;
84
ObserverRegistrar() = default;
85
virtual ~ObserverRegistrar() = default;
86
ObserverRegistrar(ObserverRegistrar const&) = delete;
87
ObserverRegistrar& operator=(ObserverRegistrar const&) = delete;
92
#endif //MIR_OBSERVER_REGISTRAR_H_