2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Pete Woods <pete.woods@canonical.com>
19
#include <core/dbus/dbus.h>
20
#include <core/dbus/match_rule.h>
21
#include <core/dbus/object.h>
22
#include <core/dbus/service_watcher.h>
23
#include <core/dbus/signal.h>
31
struct NameOwnerChanged
33
static const std::string& name()
35
static const std::string s { "NameOwnerChanged" };
39
typedef DBus Interface;
40
typedef std::tuple<std::string, std::string, std::string> ArgumentType;
44
struct dbus::ServiceWatcher::Private
46
void signal_handler(const NameOwnerChanged::ArgumentType& args)
48
const std::string& old_owner(std::get<1>(args));
49
const std::string& new_owner(std::get<2>(args));
51
owner_changed(old_owner, new_owner);
53
if (new_owner.empty())
55
service_unregistered();
63
core::Signal<std::string, std::string> owner_changed;
64
core::Signal<void> service_registered;
65
core::Signal<void> service_unregistered;
66
std::shared_ptr<Object> object;
68
core::dbus::Signal<NameOwnerChanged, NameOwnerChanged::ArgumentType>> signal;
71
dbus::ServiceWatcher::ServiceWatcher(std::shared_ptr<Object> object,
72
const std::string& name, DBus::WatchMode watch_mode) :
77
MatchRule::MatchArgs match_args{ { 0, name } };
81
case DBus::WatchMode::owner_change:
83
case DBus::WatchMode::registration:
84
match_args.push_back({ 1, std::string() });
86
case DBus::WatchMode::unregistration:
87
match_args.push_back({ 2, std::string() });
91
d->signal = d->object->get_signal<NameOwnerChanged>();
93
d->signal->connect_with_match_args(
94
std::bind(&Private::signal_handler, d, std::placeholders::_1), match_args);
97
const core::Signal<std::string, std::string>& dbus::ServiceWatcher::owner_changed() const
99
return d->owner_changed;
102
const core::Signal<void>& dbus::ServiceWatcher::service_registered() const
104
return d->service_registered;
107
const core::Signal<void>& dbus::ServiceWatcher::service_unregistered() const
109
return d->service_unregistered;