12 #include <unordered_map> 14 #include "../handlertable.h" 15 #include "../macros.h" 16 #include "../trackableobject.h" 27 [
this](
const std::string &key) {
28 auto slot = bus_->addMatch(
29 MatchRule(
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
30 "org.freedesktop.DBus",
"NameOwnerChanged",
36 msg >> name >> oldOwner >> newOwner;
37 querySlots_.erase(name);
39 auto view = watcherMap_.view(name);
40 for (
auto &entry : view) {
41 entry(name, oldOwner, newOwner);
45 auto querySlot = bus_->serviceOwnerAsync(
46 key, 0, [
this, key](
Message &msg) {
48 const std::string &pivotKey = key;
49 auto protector = watch();
51 if (msg.
type() != dbus::MessageType::Error) {
55 "org.freedesktop.DBus.Error.NameHasNoOwner") {
59 for (
auto &entry : watcherMap_.view(pivotKey)) {
60 entry(pivotKey,
"", newName);
64 if (
auto *that = protector.get()) {
65 that->querySlots_.erase(pivotKey);
69 if (!slot || !querySlot) {
72 slots_.emplace(std::piecewise_construct,
73 std::forward_as_tuple(key),
74 std::forward_as_tuple(std::move(slot)));
76 std::piecewise_construct, std::forward_as_tuple(key),
77 std::forward_as_tuple(std::move(querySlot)));
80 [
this](
const std::string &key) {
82 querySlots_.erase(key);
87 std::unordered_map<std::string, std::unique_ptr<Slot>> slots_;
88 std::unordered_map<std::string, std::unique_ptr<Slot>> querySlots_;
91 ServiceWatcher::ServiceWatcher(
Bus &bus)
92 : d_ptr(std::make_unique<ServiceWatcherPrivate>(bus)) {}
94 std::unique_ptr<HandlerTableEntry<ServiceWatcherCallback>>
95 ServiceWatcher::watchService(
const std::string &name,
96 ServiceWatcherCallback callback) {
98 return d->watcherMap_.add(name, std::move(callback));
101 ServiceWatcher::~ServiceWatcher() {}
Basic DBus type of a DBus message.
A dbus matching rule to be used with add match.
A class that represents a connection to the Bus.
API for service monitoring.
MessageType type() const
Return the message type.
Helper class to be used with TrackableObjectReference.
API for DBus matching rule.
std::string errorName() const
Return the error name of the message.