diff options
author | Gergely Risko <gergely+context@risko.hu> | 2009-09-10 14:44:06 +0300 |
---|---|---|
committer | Gergely Risko <gergely+context@risko.hu> | 2009-09-10 14:47:04 +0300 |
commit | 2fcff5cdba4107f9fedd0f5197cda31f9532a3c4 (patch) | |
tree | dc7fd29df74f893e92b23df03bfcb0e6d988335c | |
parent | 131b5f7994360531f688bfe33aff17f4e5a53fcb (diff) |
Getting rid of libcontextsubscriber/src/managerinterface.{cpp,h}
-rw-r--r-- | libcontextsubscriber/src/Makefile.am | 3 | ||||
-rw-r--r-- | libcontextsubscriber/src/contextkitplugin.cpp | 69 | ||||
-rw-r--r-- | libcontextsubscriber/src/contextkitplugin.h | 20 | ||||
-rw-r--r-- | libcontextsubscriber/src/managerinterface.cpp | 98 | ||||
-rw-r--r-- | libcontextsubscriber/src/managerinterface.h | 63 |
5 files changed, 53 insertions, 200 deletions
diff --git a/libcontextsubscriber/src/Makefile.am b/libcontextsubscriber/src/Makefile.am index 7fe707c9..1ae698b6 100644 --- a/libcontextsubscriber/src/Makefile.am +++ b/libcontextsubscriber/src/Makefile.am @@ -1,8 +1,7 @@ lib_LTLIBRARIES = libcontextsubscriber.la libcontextsubscriber_la_SOURCES = contextproperty.cpp \ contextproperty.h propertyhandle.cpp propertyhandle.h \ - provider.cpp provider.h managerinterface.h \ - managerinterface.cpp safedbuspendingcallwatcher.h \ + provider.cpp provider.h safedbuspendingcallwatcher.h \ subscriberinterface.h subscriberinterface.cpp \ contextpropertyinfo.cpp contextpropertyinfo.h \ contextregistryinfo.cpp contextregistryinfo.h infobackend.h \ diff --git a/libcontextsubscriber/src/contextkitplugin.cpp b/libcontextsubscriber/src/contextkitplugin.cpp index ca26b33a..08005933 100644 --- a/libcontextsubscriber/src/contextkitplugin.cpp +++ b/libcontextsubscriber/src/contextkitplugin.cpp @@ -21,7 +21,6 @@ #include "contextkitplugin.h" #include "logging.h" -#include "managerinterface.h" #include "subscriberinterface.h" #include "sconnect.h" #include <QStringList> @@ -51,29 +50,29 @@ namespace ContextSubscriber { \brief Implementation of the ContextKit D-Bus protocol. */ +const QString ContextKitPlugin::managerPath = "/org/freedesktop/ContextKit/Manager"; +const QString ContextKitPlugin::managerIName = "org.freedesktop.ContextKit.Manager"; + /// Creates subscriber and manager interface, tries to get a /// subscriber instance from the manager and starts listening for /// provider appearing and disappearing on D-Bus. ContextKitPlugin::ContextKitPlugin(const QDBusConnection bus, const QString& busName) - : subscriberInterface(0), managerInterface(0), connection(new QDBusConnection(bus)), + : providerListener(new DBusNameListener(bus, busName, this)), + subscriberInterface(0), + managerInterface(new QDBusInterface(busName, managerPath, managerIName, bus, this)), + connection(new QDBusConnection(bus)), busName(busName) { - // Call GetSubscriber asynchronously - managerInterface = new ManagerInterface(*connection, busName, this); - sconnect(managerInterface, SIGNAL(getSubscriberFinished(QString)), this, SLOT(onDBusGetSubscriberFinished(QString))); - // Notice if the provider on the dbus comes and goes - providerListener = new DBusNameListener(bus, busName, this); sconnect(providerListener, SIGNAL(nameAppeared()), this, SLOT(onProviderAppeared())); sconnect(providerListener, SIGNAL(nameDisappeared()), this, SLOT(onProviderDisappeared())); + // Listen to the provider appearing and disappearing, but don't - // perform the initial NameHasOwner check. We will try to connect - // to the provider at startup, whether it's present or not. + // perform the initial NameHasOwner check. We try to connect to + // the provider at startup, whether it's present or not. providerListener->startListening(false); - - // Just try to connect to the provider. onProviderAppeared(); } @@ -84,7 +83,11 @@ void ContextKitPlugin::onProviderAppeared() contextDebug() << "ContextKitPlugin::onProviderAppeared"; delete subscriberInterface; subscriberInterface = 0; - managerInterface->getSubscriber(); + managerInterface->callWithCallback("GetSubscriber", + QList<QVariant>(), + this, + SLOT(onDBusGetSubscriberFinished(QDBusObjectPath)), + SLOT(onDBusGetSubscriberFailed(QDBusError))); } /// Delete our subscriber interface when the provider goes away. @@ -98,27 +101,29 @@ void ContextKitPlugin::onProviderDisappeared() /// Starts using the fresh subscriber interface when it is returned by /// the manager in response to the GetSubscriber call. -void ContextKitPlugin::onDBusGetSubscriberFinished(QString objectPath) +void ContextKitPlugin::onDBusGetSubscriberFinished(QDBusObjectPath objectPath) +{ + delete subscriberInterface; + subscriberInterface = new SubscriberInterface(*connection, busName, objectPath.path(), this); + sconnect(subscriberInterface, + SIGNAL(valuesChanged(QMap<QString, QVariant>)), + this, + SLOT(onDBusValuesChanged(QMap<QString, QVariant>))); + sconnect(subscriberInterface, + SIGNAL(subscribeFinished(QList<QString>)), + this, + SLOT(onDBusSubscribeFinished(QList<QString>))); + sconnect(subscriberInterface, + SIGNAL(subscribeFailed(QList<QString>, QString)), + this, + SLOT(onDBusSubscribeFailed(QList<QString>, QString))); + + emit ready(); +} + +void ContextKitPlugin::onDBusGetSubscriberFailed(QDBusError err) { - if (objectPath != "") { - delete subscriberInterface; - subscriberInterface = new SubscriberInterface(*connection, busName, objectPath, this); - sconnect(subscriberInterface, - SIGNAL(valuesChanged(QMap<QString, QVariant>)), - this, - SLOT(onDBusValuesChanged(QMap<QString, QVariant>))); - sconnect(subscriberInterface, - SIGNAL(subscribeFinished(QList<QString>)), - this, - SLOT(onDBusSubscribeFinished(QList<QString>))); - sconnect(subscriberInterface, - SIGNAL(subscribeFailed(QList<QString>, QString)), - this, - SLOT(onDBusSubscribeFailed(QList<QString>, QString))); - - emit ready(); - } else - emit failed("Was unable to get subscriber object on dbus"); + emit failed("Was unable to get subscriber object on dbus: " + err.message()); } /// Signals the Provider that the subscribe is finished. diff --git a/libcontextsubscriber/src/contextkitplugin.h b/libcontextsubscriber/src/contextkitplugin.h index 25d09d58..586db237 100644 --- a/libcontextsubscriber/src/contextkitplugin.h +++ b/libcontextsubscriber/src/contextkitplugin.h @@ -22,14 +22,17 @@ #ifndef CONTEXTKITPLUGIN_H #define CONTEXTKITPLUGIN_H +#include "dbusnamelistener.h" +#include "subscriberinterface.h" +#include "provider.h" +#include "iproviderplugin.h" #include <QString> #include <QDBusConnection> +#include <QDBusInterface> +#include <QDBusObjectPath> #include <QSet> #include <QVariant> #include <QMap> -#include "dbusnamelistener.h" -#include "provider.h" -#include "iproviderplugin.h" extern "C" { ContextSubscriber::IProviderPlugin* contextKitPluginFactory(QString constructionString); @@ -54,19 +57,26 @@ signals: private slots: void onDBusValuesChanged(QMap<QString, QVariant> values); - void onDBusGetSubscriberFinished(QString objectPath); + void onDBusGetSubscriberFinished(QDBusObjectPath objectPath); + void onDBusGetSubscriberFailed(QDBusError err); void onDBusSubscribeFinished(QList<QString> keys); void onDBusSubscribeFailed(QList<QString> keys, QString error); void onProviderAppeared(); void onProviderDisappeared(); private: + QMap<QString, QVariant>& mergeNullsWithMap(QMap<QString, QVariant> &map, QStringList nulls) const; + DBusNameListener *providerListener; ///< Listens to provider's (dis)appearance over DBus SubscriberInterface *subscriberInterface; ///< The D-Bus interface for the Subscriber object - ManagerInterface *managerInterface; ///< The D-Bus interface for the Manager object + QDBusInterface *managerInterface; ///< The D-Bus interface for the Manager object QDBusConnection *connection; ///< The connection to DBus QString busName; ///< The D-Bus service name of the ContextKit provider connected to + + static const QString managerIName; ///< org.freedesktop.ContextKit.Manager + static const QString subscriberIName; ///< org.freedesktop.ContextKit.Subscriber + static const QString managerPath; ///< /org/freedesktop/ContextKit/Manager }; diff --git a/libcontextsubscriber/src/managerinterface.cpp b/libcontextsubscriber/src/managerinterface.cpp deleted file mode 100644 index 84b330a0..00000000 --- a/libcontextsubscriber/src/managerinterface.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2008, 2009 Nokia Corporation. - * - * Contact: Marius Vollmer <marius.vollmer@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/*! - \class ManagerInterface - - \brief Proxy for calling the GetSubscriber asynchronously on ManagerInterface. -*/ - -#include "managerinterface.h" -#include "safedbuspendingcallwatcher.h" -#include "sconnect.h" -#include "logging.h" - -#include <QDBusInterface> -#include <QDBusPendingReply> -#include <QDBusObjectPath> - -namespace ContextSubscriber { - -const QString ManagerInterface::objectPath = "/org/freedesktop/ContextKit/Manager"; -const char *ManagerInterface::interfaceName = "org.freedesktop.ContextKit.Manager"; - -/// Constructs the ManagerInterface. Connects to the DBus object specified by -/// \a connection and \a busName. -ManagerInterface::ManagerInterface(const QDBusConnection connection, const QString &busName, QObject *parent) - : QDBusAbstractInterface(busName, objectPath, interfaceName, connection, parent), getSubscriberFailed(false) -{ -} - -/// Calls the GetSubscriber function over DBus asynchronously. -void ManagerInterface::getSubscriber() -{ - getSubscriberFailed = false; - - // Construct the asynchronous call - // FIXME: this four lines are repeated everywhere, should have a util function for it - QDBusPendingCall getSubscriberCall = asyncCall("GetSubscriber"); - SafeDBusPendingCallWatcher *watcher = new SafeDBusPendingCallWatcher(getSubscriberCall, this); - sconnect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)), - this, SLOT(onGetSubscriberFinished(QDBusPendingCallWatcher *))); -} - -/// Is called when the asynchronous call to GetSubscriber has finished. Emits -/// the signal getSubscriberFinished if the call finished successfully. -void ManagerInterface::onGetSubscriberFinished(QDBusPendingCallWatcher* watcher) -{ - QDBusPendingReply<QDBusObjectPath> reply = *watcher; - if (reply.isError()) { - // Possible causes of the error: - // The provider is not running - // The provider didn't implement the needed interface + function - // The function resulted in an error - contextWarning() << "Provider error while getting the subscriber object:" << reply.error().message(); - getSubscriberFailed = true; - emit getSubscriberFinished(""); - } else { - QDBusObjectPath path = reply.argumentAt<0>(); - emit getSubscriberFinished(path.path()); - } -} - -bool ManagerInterface::isGetSubscriberFailed() const -{ - return getSubscriberFailed; -} - -void ManagerInterface::connectNotify(const char *signal) -{ - // we don't want to AddMatch any signals on the DBus side - QObject::connectNotify(signal); -} - -void ManagerInterface::disconnectNotify(const char *signal) -{ - // we don't want to AddMatch any signals on the DBus side - QObject::disconnectNotify(signal); -} - -} // end namespace diff --git a/libcontextsubscriber/src/managerinterface.h b/libcontextsubscriber/src/managerinterface.h deleted file mode 100644 index 926f5f2f..00000000 --- a/libcontextsubscriber/src/managerinterface.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2008, 2009 Nokia Corporation. - * - * Contact: Marius Vollmer <marius.vollmer@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef MANAGERINTERFACE_H -#define MANAGERINTERFACE_H - -#include <QObject> -#include <QDBusAbstractInterface> - -class QDBusPendingCallWatcher; -class QDBusConnection; -class QString; - -namespace ContextSubscriber { - -class ManagerInterface : public QDBusAbstractInterface -{ - Q_OBJECT - - static const char *interfaceName; - static const QString objectPath; - -public: - ManagerInterface(const QDBusConnection connection, const QString &busName, QObject *parent = 0); - - void getSubscriber(); - bool isGetSubscriberFailed() const; - -signals: - void getSubscriberFinished(QString objectPath); - -private slots: - void onGetSubscriberFinished(QDBusPendingCallWatcher* watcher); - -private: - bool getSubscriberFailed; ///< Previous async GetSubscriber call failed - -protected: - void connectNotify(const char *signal); - void disconnectNotify(const char *signal); -}; - -} // end namespace - -#endif |