From 6f43bb64e180083aff726a5be2c5122e97e54819 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 8 Feb 2016 19:29:58 +0100 Subject: Listen for notifications from specific resources. --- common/clientapi.cpp | 13 +++++++++++++ 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) d->resourceAccess << resourceAccess; } +Notifier::Notifier(const QByteArray &instanceIdentifier) + : d(new Sink::Notifier::Private) +{ + auto resourceAccess = Sink::ResourceAccess::Ptr::create(instanceIdentifier); + resourceAccess->open(); + QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { + for (const auto &handler : d->handler) { + handler(notification); + } + }); + d->resourceAccess << resourceAccess; +} + void Notifier::registerHandler(std::function handler) { 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 { class SINKCOMMON_EXPORT Notifier { public: Notifier(const QSharedPointer &resourceAccess); - // Notifier(const QByteArray &resource); + Notifier(const QByteArray &resourceInstanceIdentifier); // Notifier(const QByteArrayList &resource); void registerHandler(std::function); private: class Private; - QScopedPointer d; + QSharedPointer d; }; } -- cgit v1.2.3