diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-08 19:29:58 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-08 19:29:58 +0100 |
commit | 6f43bb64e180083aff726a5be2c5122e97e54819 (patch) | |
tree | ab6427486e26ccbeb190200cb0ade54a99ec6604 | |
parent | ed9f2ce38e11c907c8b801736bebc6923e9dbb2b (diff) | |
download | sink-6f43bb64e180083aff726a5be2c5122e97e54819.tar.gz sink-6f43bb64e180083aff726a5be2c5122e97e54819.zip |
Listen for notifications from specific resources.
-rw-r--r-- | common/clientapi.cpp | 13 | ||||
-rw-r--r-- | common/clientapi.h | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 413abd3..5eb4b55 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp | |||
@@ -353,6 +353,19 @@ Notifier::Notifier(const QSharedPointer<ResourceAccess> &resourceAccess) | |||
353 | d->resourceAccess << resourceAccess; | 353 | d->resourceAccess << resourceAccess; |
354 | } | 354 | } |
355 | 355 | ||
356 | Notifier::Notifier(const QByteArray &instanceIdentifier) | ||
357 | : d(new Sink::Notifier::Private) | ||
358 | { | ||
359 | auto resourceAccess = Sink::ResourceAccess::Ptr::create(instanceIdentifier); | ||
360 | resourceAccess->open(); | ||
361 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { | ||
362 | for (const auto &handler : d->handler) { | ||
363 | handler(notification); | ||
364 | } | ||
365 | }); | ||
366 | d->resourceAccess << resourceAccess; | ||
367 | } | ||
368 | |||
356 | void Notifier::registerHandler(std::function<void(const Notification &)> handler) | 369 | void Notifier::registerHandler(std::function<void(const Notification &)> handler) |
357 | { | 370 | { |
358 | d->handler << handler; | 371 | d->handler << handler; |
diff --git a/common/clientapi.h b/common/clientapi.h index 8697003..d0910df 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -128,13 +128,13 @@ namespace Resources { | |||
128 | class SINKCOMMON_EXPORT Notifier { | 128 | class SINKCOMMON_EXPORT Notifier { |
129 | public: | 129 | public: |
130 | Notifier(const QSharedPointer<ResourceAccess> &resourceAccess); | 130 | Notifier(const QSharedPointer<ResourceAccess> &resourceAccess); |
131 | // Notifier(const QByteArray &resource); | 131 | Notifier(const QByteArray &resourceInstanceIdentifier); |
132 | // Notifier(const QByteArrayList &resource); | 132 | // Notifier(const QByteArrayList &resource); |
133 | void registerHandler(std::function<void(const Notification &)>); | 133 | void registerHandler(std::function<void(const Notification &)>); |
134 | 134 | ||
135 | private: | 135 | private: |
136 | class Private; | 136 | class Private; |
137 | QScopedPointer<Private> d; | 137 | QSharedPointer<Private> d; |
138 | }; | 138 | }; |
139 | 139 | ||
140 | } | 140 | } |