From dc9a8f9fd449088f798a0be13db44f656b44e2b1 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 10:32:25 +0300 Subject: bluez plugin: Initial draft of the plugin. --- libcontextsubscriber/Makefile.am | 2 +- libcontextsubscriber/plugins/Makefile.am | 1 + libcontextsubscriber/plugins/bluez/Makefile.am | 21 ++++ .../plugins/bluez/bluezinterface.cpp | 112 +++++++++++++++++++++ .../plugins/bluez/bluezinterface.h | 63 ++++++++++++ libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 32 ++++++ libcontextsubscriber/plugins/bluez/bluezplugin.h | 42 ++++++++ .../plugins/bluez/loggingfeatures.h | 27 +++++ libcontextsubscriber/src/Makefile.am | 3 +- libcontextsubscriber/src/bluezinterface.cpp | 110 -------------------- libcontextsubscriber/src/bluezinterface.h | 63 ------------ 11 files changed, 300 insertions(+), 176 deletions(-) create mode 100644 libcontextsubscriber/plugins/Makefile.am create mode 100644 libcontextsubscriber/plugins/bluez/Makefile.am create mode 100644 libcontextsubscriber/plugins/bluez/bluezinterface.cpp create mode 100644 libcontextsubscriber/plugins/bluez/bluezinterface.h create mode 100644 libcontextsubscriber/plugins/bluez/bluezplugin.cpp create mode 100644 libcontextsubscriber/plugins/bluez/bluezplugin.h create mode 100644 libcontextsubscriber/plugins/bluez/loggingfeatures.h delete mode 100644 libcontextsubscriber/src/bluezinterface.cpp delete mode 100644 libcontextsubscriber/src/bluezinterface.h (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/Makefile.am b/libcontextsubscriber/Makefile.am index 1a1294b0..b19f837c 100644 --- a/libcontextsubscriber/Makefile.am +++ b/libcontextsubscriber/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = src unit-tests customer-tests multithreading-tests cli reg-cli update-contextkit-providers doc man +SUBDIRS = src plugins unit-tests customer-tests multithreading-tests cli reg-cli update-contextkit-providers doc man pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = contextsubscriber-1.0.pc diff --git a/libcontextsubscriber/plugins/Makefile.am b/libcontextsubscriber/plugins/Makefile.am new file mode 100644 index 00000000..a05dd1e9 --- /dev/null +++ b/libcontextsubscriber/plugins/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = bluez diff --git a/libcontextsubscriber/plugins/bluez/Makefile.am b/libcontextsubscriber/plugins/bluez/Makefile.am new file mode 100644 index 00000000..98ee0c98 --- /dev/null +++ b/libcontextsubscriber/plugins/bluez/Makefile.am @@ -0,0 +1,21 @@ +lib_LTLIBRARIES = libcontextsubscriberbluez.la +libcontextsubscriberbluez_la_SOURCES = bluezinterface.cpp \ + bluezinterface.h bluezplugin.cpp bluezplugin.h \ + loggingfeatures.h + +AM_CXXFLAGS = -I$(top_srcdir)/common -I$(srcdir)/../../src \ + $(QtCore_CFLAGS) $(QtDBus_CFLAGS) \ + '-DCONTEXT_LOG_MODULE_NAME="bluezplugin"' + +$(top_builddir)/common/libcommon.a: + $(MAKE) -C $(top_builddir)/common libcommon.a + +LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) +libcontextsubscriberbluez_la_LIBADD=$(top_builddir)/common/libcommon.la + +.PHONY: $(top_builddir)/common/libcommon.la + +# moccing +nodist_libcontextsubscriberbluez_la_SOURCES = mocs.cpp +QT_TOMOC = $(filter %.h, $(libcontextsubscriberbluez_la_SOURCES)) +include $(top_srcdir)/am/qt.am diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp new file mode 100644 index 00000000..416b641c --- /dev/null +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 + * + */ + +#include "bluezinterface.h" +#include "logging.h" + +#include +#include +#include +#include + +const QString BluezInterface::serviceName = "org.bluez"; +const QString BluezInterface::managerPath = "/"; +const QString BluezInterface::managerInterface = "org.bluez.Manager"; +const QString BluezInterface::adapterInterface = "org.bluez.Adapter"; +QDBusConnection BluezInterface::busConnection = QDBusConnection::systemBus(); + +BluezInterface::BluezInterface() : manager(0), adapter(0) +{ + busConnection.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", + "org.freedesktop.DBus", "NameOwnerChanged", + this, SLOT(onNameOwnerChanged(QString, QString, QString))); + properties["Powered"] = "Bluetooth.Enabled"; + properties["Discoverable"] = "Bluetooth.Visible"; + connectToBluez(); +} + +void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QString newOwner) +{ + if (name == serviceName && newOwner != "") { + connectToBluez(); + } +} + +void BluezInterface::connectToBluez() +{ + if (adapter) { + busConnection.disconnect(serviceName, + adapterPath, + adapterInterface, + "PropertyChanged", + this, SLOT(onPropertyChanged(QString, QDBusVariant))); + delete adapter; + adapter = 0; + } + if (manager) { + delete manager; + manager = 0; + } + + manager = new QDBusInterface(serviceName, managerPath, managerInterface, busConnection, this); + manager->callWithCallback("DefaultAdapter", QList(), this, + SLOT(replyDefaultAdapter(QDBusObjectPath)), + SLOT(replyDBusError(QDBusError))); +} + +void BluezInterface::replyDBusError(QDBusError err) +{ + contextWarning() << "DBus error occured:" << err.message(); +} + +void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) +{ + adapterPath = path.path(); + adapter = new QDBusInterface(serviceName, adapterPath, adapterInterface, busConnection, this); + busConnection.connect(serviceName, + path.path(), + adapterInterface, + "PropertyChanged", + this, SLOT(onPropertyChanged(QString, QDBusVariant))); + adapter->callWithCallback("GetProperties", QList(), this, + SLOT(replyGetProperties(QMap)), + SLOT(replyDBusError(QDBusError))); +} + +void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) +{ + onPropertyChanged(key, value.variant()); +} + +void BluezInterface::onPropertyChanged(QString key, QVariant value) +{ + if (properties.contains(key) && values[key] != value) { + values[key] = value; + // TODO: emit here + contextDebug() << "Prop changed:" << key << value.toString(); + } +} + +void BluezInterface::replyGetProperties(QMap map) +{ + foreach(QString key, map.keys()) + onPropertyChanged(key, map[key]); +} diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.h b/libcontextsubscriber/plugins/bluez/bluezinterface.h new file mode 100644 index 00000000..538047a3 --- /dev/null +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 BLUEZINTERFACE_H +#define BLUEZINTERFACE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// FIXME: Doxygen +class BluezInterface : public QObject +{ + Q_OBJECT +public: + BluezInterface(); +private slots: + void replyDBusError(QDBusError err); + void replyDefaultAdapter(QDBusObjectPath path); + void replyGetProperties(QMap map); + void onPropertyChanged(QString key, QDBusVariant value); + void onNameOwnerChanged(QString name, QString oldOwner, QString newOwner); +private: + void onPropertyChanged(QString key, QVariant value); + void connectToBluez(); + + QDBusInterface* manager; + QDBusInterface* adapter; + QString adapterPath; + QMap values; + QMap properties; + static const QString serviceName; + static const QString managerPath; + static const QString managerInterface; + static const QString adapterInterface; + static QDBusConnection busConnection; +}; + +#endif diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp new file mode 100644 index 00000000..5e22a623 --- /dev/null +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 + * + */ + +#include "bluezplugin.h" + +void BluezPlugin::subscribe(QSet keys) +{ +} + +void BluezPlugin::unsubscribe(QSet keys) +{ +} + + diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h new file mode 100644 index 00000000..bd19976a --- /dev/null +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 BLUEZPLUGIN_H +#define BLUEZPLUGIN_H + +#include "propertyprovider.h" + +using ContextSubscriber::IProviderPlugin; + +extern "C" { + IProviderPlugin* contextKitPluginFactory(const QString& constructionString); +} + + +class BluezPlugin : public IProviderPlugin +{ + Q_OBJECT +public: + virtual void subscribe(QSet keys); + virtual void unsubscribe(QSet keys); +}; + +#endif diff --git a/libcontextsubscriber/plugins/bluez/loggingfeatures.h b/libcontextsubscriber/plugins/bluez/loggingfeatures.h new file mode 100644 index 00000000..9e4008d8 --- /dev/null +++ b/libcontextsubscriber/plugins/bluez/loggingfeatures.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 BLUEZPLUGIN_LOGGINGFEATURES_H +#define BLUEZPLUGIN_LOGGINGFEATURES_H + +#define F_BLUEZPLUGIN (ContextFeature("bluezplugin")) + +#endif diff --git a/libcontextsubscriber/src/Makefile.am b/libcontextsubscriber/src/Makefile.am index 0ea4f627..34cb2f3e 100644 --- a/libcontextsubscriber/src/Makefile.am +++ b/libcontextsubscriber/src/Makefile.am @@ -12,8 +12,7 @@ libcontextsubscriber_la_SOURCES = contextproperty.cpp \ infocdbbackend.cpp infocdbbackend.h dbusnamelistener.h \ dbusnamelistener.cpp handlesignalrouter.cpp \ handlesignalrouter.h queuedinvoker.cpp queuedinvoker.h \ - loggingfeatures.h bluezinterface.h bluezinterface.cpp \ - contextkitplugin.h contextkitplugin.cpp + loggingfeatures.h contextkitplugin.h contextkitplugin.cpp includecontextsubscriberdir=$(includedir)/contextsubscriber includecontextsubscriber_HEADERS = contextproperty.h contextpropertyinfo.h contextregistryinfo.h diff --git a/libcontextsubscriber/src/bluezinterface.cpp b/libcontextsubscriber/src/bluezinterface.cpp deleted file mode 100644 index a114c844..00000000 --- a/libcontextsubscriber/src/bluezinterface.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2008 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 - * - */ - -#include "bluezinterface.h" -#include -#include -#include -#include -#include "logging.h" - -const QString BluezInterface::serviceName = "org.bluez"; -const QString BluezInterface::managerPath = "/"; -const QString BluezInterface::managerInterface = "org.bluez.Manager"; -const QString BluezInterface::adapterInterface = "org.bluez.Adapter"; -QDBusConnection BluezInterface::busConnection = QDBusConnection::systemBus(); - -BluezInterface::BluezInterface() : manager(0), adapter(0) -{ - busConnection.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "NameOwnerChanged", - this, SLOT(onNameOwnerChanged(QString, QString, QString))); - properties["Powered"] = "Bluetooth.Enabled"; - properties["Discoverable"] = "Bluetooth.Visible"; - connectToBluez(); -} - -void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QString newOwner) -{ - if (name == serviceName && newOwner != "") { - connectToBluez(); - } -} - -void BluezInterface::connectToBluez() -{ - if (adapter) { - busConnection.disconnect(serviceName, - adapterPath, - adapterInterface, - "PropertyChanged", - this, SLOT(onPropertyChanged(QString, QDBusVariant))); - delete adapter; - adapter = 0; - } - if (manager) { - delete manager; - manager = 0; - } - - manager = new QDBusInterface(serviceName, managerPath, managerInterface, busConnection, this); - manager->callWithCallback("DefaultAdapter", QList(), this, - SLOT(replyDefaultAdapter(QDBusObjectPath)), - SLOT(replyDBusError(QDBusError))); -} - -void BluezInterface::replyDBusError(QDBusError err) -{ - contextWarning() << "DBus error occured:" << err.message(); -} - -void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) -{ - adapterPath = path.path(); - adapter = new QDBusInterface(serviceName, adapterPath, adapterInterface, busConnection, this); - busConnection.connect(serviceName, - path.path(), - adapterInterface, - "PropertyChanged", - this, SLOT(onPropertyChanged(QString, QDBusVariant))); - adapter->callWithCallback("GetProperties", QList(), this, - SLOT(replyGetProperties(QMap)), - SLOT(replyDBusError(QDBusError))); -} - -void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) -{ - onPropertyChanged(key, value.variant()); -} - -void BluezInterface::onPropertyChanged(QString key, QVariant value) -{ - if (properties.contains(key) && values[key] != value) { - values[key] = value; - // TODO: emit here - } -} - -void BluezInterface::replyGetProperties(QMap map) -{ - foreach(QString key, map.keys()) - onPropertyChanged(key, map[key]); -} diff --git a/libcontextsubscriber/src/bluezinterface.h b/libcontextsubscriber/src/bluezinterface.h deleted file mode 100644 index cbe21a91..00000000 --- a/libcontextsubscriber/src/bluezinterface.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2008 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 BLUEZINTERFACE_H -#define BLUEZINTERFACE_H - -#include -#include -#include -#include -#include - -class QDBusError; -class QDBusInterface; -class QDBusObjectPath; -class QDBusVariant; - -class BluezInterface : public QObject -{ - Q_OBJECT -public: - BluezInterface(); -private slots: - void replyDBusError(QDBusError err); - void replyDefaultAdapter(QDBusObjectPath path); - void replyGetProperties(QMap map); - void onPropertyChanged(QString key, QDBusVariant value); - void onNameOwnerChanged(QString name, QString oldOwner, QString newOwner); -private: - void onPropertyChanged(QString key, QVariant value); - void connectToBluez(); - - QDBusInterface* manager; - QDBusInterface* adapter; - QString adapterPath; - QMap values; - QMap properties; - static const QString serviceName; - static const QString managerPath; - static const QString managerInterface; - static const QString adapterInterface; - static QDBusConnection busConnection; -}; - -#endif -- cgit v1.2.3 From c62858de891e28a720baf2799d331402b4fbb906 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 11:18:57 +0300 Subject: bluez plugin: Drafting the implementation some more: division of work between Plugin and Interface. --- .../plugins/bluez/bluezinterface.cpp | 17 +++------ .../plugins/bluez/bluezinterface.h | 16 +++++++-- libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 40 ++++++++++++++++++++++ libcontextsubscriber/plugins/bluez/bluezplugin.h | 17 +++++++-- 4 files changed, 72 insertions(+), 18 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp index 416b641c..519ea2fc 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp @@ -38,8 +38,6 @@ BluezInterface::BluezInterface() : manager(0), adapter(0) busConnection.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", this, SLOT(onNameOwnerChanged(QString, QString, QString))); - properties["Powered"] = "Bluetooth.Enabled"; - properties["Discoverable"] = "Bluetooth.Visible"; connectToBluez(); } @@ -75,6 +73,7 @@ void BluezInterface::connectToBluez() void BluezInterface::replyDBusError(QDBusError err) { contextWarning() << "DBus error occured:" << err.message(); + emit failed(); } void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) @@ -89,24 +88,16 @@ void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) adapter->callWithCallback("GetProperties", QList(), this, SLOT(replyGetProperties(QMap)), SLOT(replyDBusError(QDBusError))); + emit ready(); } void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) { - onPropertyChanged(key, value.variant()); -} - -void BluezInterface::onPropertyChanged(QString key, QVariant value) -{ - if (properties.contains(key) && values[key] != value) { - values[key] = value; - // TODO: emit here - contextDebug() << "Prop changed:" << key << value.toString(); - } + emit propertyChanged(key, value.variant()); } void BluezInterface::replyGetProperties(QMap map) { foreach(QString key, map.keys()) - onPropertyChanged(key, map[key]); + emit propertyChanged(key, map[key]); } diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.h b/libcontextsubscriber/plugins/bluez/bluezinterface.h index 538047a3..2e80731c 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.h +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.h @@ -32,12 +32,24 @@ #include #include -// FIXME: Doxygen +/*! + + \class BluezInterface + + \brief Communicates with bluetoothd over D-Bus and signals the + changes in Bluez properties. + + */ class BluezInterface : public QObject { Q_OBJECT public: BluezInterface(); +signals: + void propertyChanged(QString key, QVariant value); + void ready(); + void failed(); + private slots: void replyDBusError(QDBusError err); void replyDefaultAdapter(QDBusObjectPath path); @@ -51,8 +63,6 @@ private: QDBusInterface* manager; QDBusInterface* adapter; QString adapterPath; - QMap values; - QMap properties; static const QString serviceName; static const QString managerPath; static const QString managerInterface; diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp index 5e22a623..ac99302e 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp @@ -20,6 +20,34 @@ */ #include "bluezplugin.h" +#include "sconnect.h" +#include "logging.h" + +IProviderPlugin* bluezPluginFactory(const QString& /*constructionString*/) +{ + // Note: it's the caller's responsibility to delete the plugin if + // needed. + return new BluezPlugin(); +} + +BluezPlugin::BluezPlugin() +{ + // Connect signals from the Bluez interface. The events we listen to are: + // - interface getting connected to Bluez + // - interface failing to connect to Bluez + // - interface losing connection to Bluez TODO: implement + // - Bluez property changing + sconnect(&bluezInterface, SIGNAL(ready()), + this, SIGNAL(ready())); + sconnect(&bluezInterface, SIGNAL(failed()), + this, SIGNAL(failed())); + sconnect(&bluezInterface, SIGNAL(propertyChanged(QString, QVariant)), + this, SLOT(onPropertyChanged(QString, QVariant))); + + // Create a mapping from Bluez properties to Context Properties + properties["Powered"] = "Bluetooth.Enabled"; + properties["Discoverable"] = "Bluetooth.Visible"; +} void BluezPlugin::subscribe(QSet keys) { @@ -29,4 +57,16 @@ void BluezPlugin::unsubscribe(QSet keys) { } +/// Called when a Bluez property changes. Check if the change is +/// relevant, and if so, signal the value change of the corresponding +/// context property. +void BluezPlugin::onPropertyChanged(QString key, QVariant value) +{ + if (properties.contains(key)) { + contextDebug() << "Prop changed:" << properties[key] << value.toString(); + emit valueChanged(properties[key], value); + // Note: the upper layer is responsible for checking if the + // value was a different one. + } +} diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h index bd19976a..8f82c0a5 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -22,21 +22,34 @@ #ifndef BLUEZPLUGIN_H #define BLUEZPLUGIN_H -#include "propertyprovider.h" +#include "bluezinterface.h" +#include "propertyprovider.h" // For IProviderPlugin definition using ContextSubscriber::IProviderPlugin; extern "C" { - IProviderPlugin* contextKitPluginFactory(const QString& constructionString); + IProviderPlugin* bluezPluginFactory(const QString& constructionString); } +// FIXME: doxygen + class BluezPlugin : public IProviderPlugin { Q_OBJECT + public: + explicit BluezPlugin(); virtual void subscribe(QSet keys); virtual void unsubscribe(QSet keys); + +private slots: + void onPropertyChanged(QString key, QVariant variant); + +private: + BluezInterface bluezInterface; + QMap properties; ///< Mapping of Bluez properties to Context FW properties + }; #endif -- cgit v1.2.3 From 7059c0041746998227674444188a184183db612d Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 12:05:59 +0300 Subject: bluez plugin: Still drafting. --- libcontextsubscriber/plugins/bluez/bluezinterface.cpp | 9 ++++++--- libcontextsubscriber/plugins/bluez/bluezinterface.h | 5 +++-- libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 14 ++++++++++---- libcontextsubscriber/plugins/bluez/bluezplugin.h | 9 ++++++++- 4 files changed, 27 insertions(+), 10 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp index 519ea2fc..c5a7a7a2 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp @@ -38,7 +38,7 @@ BluezInterface::BluezInterface() : manager(0), adapter(0) busConnection.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", this, SLOT(onNameOwnerChanged(QString, QString, QString))); - connectToBluez(); + //connectToBluez(); } void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QString newOwner) @@ -73,11 +73,12 @@ void BluezInterface::connectToBluez() void BluezInterface::replyDBusError(QDBusError err) { contextWarning() << "DBus error occured:" << err.message(); - emit failed(); + emit failed("Cannot connect to BlueZ:" + err.message()); } void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) { + contextDebug(); adapterPath = path.path(); adapter = new QDBusInterface(serviceName, adapterPath, adapterInterface, busConnection, this); busConnection.connect(serviceName, @@ -93,11 +94,13 @@ void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) { + contextDebug() << key << value.variant().toString(); emit propertyChanged(key, value.variant()); } void BluezInterface::replyGetProperties(QMap map) { - foreach(QString key, map.keys()) + contextDebug(); + foreach(const QString& key, map.keys()) emit propertyChanged(key, map[key]); } diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.h b/libcontextsubscriber/plugins/bluez/bluezinterface.h index 2e80731c..6079a69c 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.h +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.h @@ -45,10 +45,12 @@ class BluezInterface : public QObject Q_OBJECT public: BluezInterface(); + void connectToBluez(); + signals: void propertyChanged(QString key, QVariant value); void ready(); - void failed(); + void failed(QString error); private slots: void replyDBusError(QDBusError err); @@ -58,7 +60,6 @@ private slots: void onNameOwnerChanged(QString name, QString oldOwner, QString newOwner); private: void onPropertyChanged(QString key, QVariant value); - void connectToBluez(); QDBusInterface* manager; QDBusInterface* adapter; diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp index ac99302e..48db7d1c 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp @@ -37,12 +37,14 @@ BluezPlugin::BluezPlugin() // - interface failing to connect to Bluez // - interface losing connection to Bluez TODO: implement // - Bluez property changing - sconnect(&bluezInterface, SIGNAL(ready()), + bluezInterface = new BluezInterface(); + sconnect(bluezInterface, SIGNAL(ready()), this, SIGNAL(ready())); - sconnect(&bluezInterface, SIGNAL(failed()), - this, SIGNAL(failed())); - sconnect(&bluezInterface, SIGNAL(propertyChanged(QString, QVariant)), + sconnect(bluezInterface, SIGNAL(failed(QString)), + this, SIGNAL(failed(QString))); + sconnect(bluezInterface, SIGNAL(propertyChanged(QString, QVariant)), this, SLOT(onPropertyChanged(QString, QVariant))); + bluezInterface->connectToBluez(); // Create a mapping from Bluez properties to Context Properties properties["Powered"] = "Bluetooth.Enabled"; @@ -51,6 +53,10 @@ BluezPlugin::BluezPlugin() void BluezPlugin::subscribe(QSet keys) { + contextDebug() << keys; + foreach(const QString& key, keys) { + emit subscribeFinished(key); + } } void BluezPlugin::unsubscribe(QSet keys) diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h index 8f82c0a5..f18e590b 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -43,11 +43,18 @@ public: virtual void subscribe(QSet keys); virtual void unsubscribe(QSet keys); +signals: + void ready(); + void failed(QString error); + void subscribeFinished(QString key); + void subscribeFailed(QString failedKey, QString error); + void valueChanged(QString key, QVariant value); + private slots: void onPropertyChanged(QString key, QVariant variant); private: - BluezInterface bluezInterface; + BluezInterface* bluezInterface; QMap properties; ///< Mapping of Bluez properties to Context FW properties }; -- cgit v1.2.3 From 58e9229cfba43f42a237a81dc61b28250fb633e5 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 13:08:34 +0300 Subject: bluez plugin: A temporary fix; the plugin seems to work now. --- libcontextsubscriber/plugins/bluez/bluezinterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp index c5a7a7a2..9e891f6b 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp @@ -89,7 +89,7 @@ void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) adapter->callWithCallback("GetProperties", QList(), this, SLOT(replyGetProperties(QMap)), SLOT(replyDBusError(QDBusError))); - emit ready(); + //emit ready(); // FIXME: this seems to break the plugin! } void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) -- cgit v1.2.3 From 289d97400c0e5fe213b598542959a288c913c254 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 13:12:56 +0300 Subject: bluez plugin: Simplifying. --- libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 10 +++++----- libcontextsubscriber/plugins/bluez/bluezplugin.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp index 48db7d1c..0728dd75 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp @@ -37,14 +37,13 @@ BluezPlugin::BluezPlugin() // - interface failing to connect to Bluez // - interface losing connection to Bluez TODO: implement // - Bluez property changing - bluezInterface = new BluezInterface(); - sconnect(bluezInterface, SIGNAL(ready()), + sconnect(&bluezInterface, SIGNAL(ready()), this, SIGNAL(ready())); - sconnect(bluezInterface, SIGNAL(failed(QString)), + sconnect(&bluezInterface, SIGNAL(failed(QString)), this, SIGNAL(failed(QString))); - sconnect(bluezInterface, SIGNAL(propertyChanged(QString, QVariant)), + sconnect(&bluezInterface, SIGNAL(propertyChanged(QString, QVariant)), this, SLOT(onPropertyChanged(QString, QVariant))); - bluezInterface->connectToBluez(); + bluezInterface.connectToBluez(); // Create a mapping from Bluez properties to Context Properties properties["Powered"] = "Bluetooth.Enabled"; @@ -68,6 +67,7 @@ void BluezPlugin::unsubscribe(QSet keys) /// context property. void BluezPlugin::onPropertyChanged(QString key, QVariant value) { + contextDebug() << key << value.toString(); if (properties.contains(key)) { contextDebug() << "Prop changed:" << properties[key] << value.toString(); emit valueChanged(properties[key], value); diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h index f18e590b..a9b20b74 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -54,7 +54,7 @@ private slots: void onPropertyChanged(QString key, QVariant variant); private: - BluezInterface* bluezInterface; + BluezInterface bluezInterface; QMap properties; ///< Mapping of Bluez properties to Context FW properties }; -- cgit v1.2.3 From b04aca32ccc8ab512e7174a8dd9f31ff25be4d3c Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 13:35:29 +0300 Subject: libcontextsubscriber plugins: A fix: Handle the signals from plugins queued, so that we don't end up in a deadlock (of one thread) when the plugin e.g. emits subscribeFinished() inside subscribe(). --- libcontextsubscriber/src/propertyprovider.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/propertyprovider.cpp b/libcontextsubscriber/src/propertyprovider.cpp index 752d78aa..3c615d6e 100644 --- a/libcontextsubscriber/src/propertyprovider.cpp +++ b/libcontextsubscriber/src/propertyprovider.cpp @@ -63,15 +63,15 @@ void Provider::constructPlugin() handleSignalRouter, SLOT(onValueChanged(QString, QVariant))); sconnect(plugin, SIGNAL(ready()), - this, SLOT(onPluginReady())); + this, SLOT(onPluginReady()), Qt::QueuedConnection); sconnect(plugin, SIGNAL(failed(QString)), - this, SLOT(onPluginFailed(QString))); + this, SLOT(onPluginFailed(QString)), Qt::QueuedConnection); // FIXME: signal these things through the handlesignalrouter sconnect(plugin, SIGNAL(subscribeFinished(QString)), - this, SLOT(onPluginSubscribeFinished(QString))); + this, SLOT(onPluginSubscribeFinished(QString)), Qt::QueuedConnection); sconnect(plugin, SIGNAL(subscribeFailed(QString, QString)), - this, SLOT(onPluginSubscribeFailed(QString, QString))); + this, SLOT(onPluginSubscribeFailed(QString, QString)), Qt::QueuedConnection); } void Provider::onPluginReady() -- cgit v1.2.3 From b6a1fb1db8e5da42d34230ff64cc648b43be2fb7 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 13:38:57 +0300 Subject: bluez plugin: We can emit ready() and subscribeFinished() when we want, now that the deadlock is fixed on libcontextsubscriber side. --- libcontextsubscriber/plugins/bluez/bluezinterface.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp index 9e891f6b..91c52601 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp @@ -38,7 +38,6 @@ BluezInterface::BluezInterface() : manager(0), adapter(0) busConnection.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", this, SLOT(onNameOwnerChanged(QString, QString, QString))); - //connectToBluez(); } void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QString newOwner) @@ -89,7 +88,7 @@ void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) adapter->callWithCallback("GetProperties", QList(), this, SLOT(replyGetProperties(QMap)), SLOT(replyDBusError(QDBusError))); - //emit ready(); // FIXME: this seems to break the plugin! + emit ready(); } void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) -- cgit v1.2.3 From e9bf8fc2a8bea54df4dfa10244f9280cae7f323d Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 15:00:14 +0300 Subject: bluez plugin: Emitting failed() when BlueZ disappears from D-Bus. --- libcontextsubscriber/plugins/bluez/bluezinterface.cpp | 12 ++++++++++-- libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp index 91c52601..96637cd0 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp @@ -42,8 +42,16 @@ BluezInterface::BluezInterface() : manager(0), adapter(0) void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QString newOwner) { - if (name == serviceName && newOwner != "") { - connectToBluez(); + if (name == serviceName) { + if (newOwner != "") { + // BlueZ appeared -> connect to it. If successful, ready() + // will be emitted when the connection is established. + connectToBluez(); + } + else { + // BlueZ disappeared + emit failed("BlueZ left D-Bus"); + } } } diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp index 0728dd75..f18f5007 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp @@ -35,7 +35,7 @@ BluezPlugin::BluezPlugin() // Connect signals from the Bluez interface. The events we listen to are: // - interface getting connected to Bluez // - interface failing to connect to Bluez - // - interface losing connection to Bluez TODO: implement + // - interface losing connection to Bluez // - Bluez property changing sconnect(&bluezInterface, SIGNAL(ready()), this, SIGNAL(ready())); -- cgit v1.2.3 From be8ae742d71fe47d7658b82684873412497c773f Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 15:19:31 +0300 Subject: Bluez plugin: Namespacing and doxygen. --- libcontextsubscriber/plugins/bluez/bluezinterface.cpp | 12 ++++++++++++ libcontextsubscriber/plugins/bluez/bluezinterface.h | 4 ++++ libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 14 +++++++++++++- libcontextsubscriber/plugins/bluez/bluezplugin.h | 13 ++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp index 96637cd0..799e252c 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp @@ -27,6 +27,8 @@ #include #include +namespace ContextSubscriberBluez { + const QString BluezInterface::serviceName = "org.bluez"; const QString BluezInterface::managerPath = "/"; const QString BluezInterface::managerInterface = "org.bluez.Manager"; @@ -40,6 +42,7 @@ BluezInterface::BluezInterface() : manager(0), adapter(0) this, SLOT(onNameOwnerChanged(QString, QString, QString))); } +/// Called when the nameOwnerChanged signal is received over D-Bus. void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QString newOwner) { if (name == serviceName) { @@ -55,6 +58,7 @@ void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QStr } } +/// Try to establish the connection to BlueZ. void BluezInterface::connectToBluez() { if (adapter) { @@ -77,12 +81,15 @@ void BluezInterface::connectToBluez() SLOT(replyDBusError(QDBusError))); } +/// Called when a D-Bus error occurs when processing our +/// callWithCallback. void BluezInterface::replyDBusError(QDBusError err) { contextWarning() << "DBus error occured:" << err.message(); emit failed("Cannot connect to BlueZ:" + err.message()); } +/// Called when the DefaultAdapter D-Bus call is done. void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) { contextDebug(); @@ -99,15 +106,20 @@ void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) emit ready(); } +/// Connected to the D-Bus signal PropertyChanged from BlueZ / adaptor. void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) { contextDebug() << key << value.variant().toString(); emit propertyChanged(key, value.variant()); } +/// Called when the GetProperties D-Bus call is done. void BluezInterface::replyGetProperties(QMap map) { contextDebug(); foreach(const QString& key, map.keys()) emit propertyChanged(key, map[key]); } + +} // end namespace + diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.h b/libcontextsubscriber/plugins/bluez/bluezinterface.h index 6079a69c..204d3449 100644 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.h +++ b/libcontextsubscriber/plugins/bluez/bluezinterface.h @@ -32,6 +32,9 @@ #include #include +namespace ContextSubscriberBluez +{ + /*! \class BluezInterface @@ -71,4 +74,5 @@ private: static QDBusConnection busConnection; }; +} #endif diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp index f18f5007..816c3396 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp @@ -23,13 +23,18 @@ #include "sconnect.h" #include "logging.h" +/// The factory method for constructing the IPropertyProvider instance. IProviderPlugin* bluezPluginFactory(const QString& /*constructionString*/) { // Note: it's the caller's responsibility to delete the plugin if // needed. - return new BluezPlugin(); + return new ContextSubscriberBluez::BluezPlugin(); } +namespace ContextSubscriberBluez { + +/// Constructor. Construct the BluezInterface which handles the D-Bus +/// connection, and tell it to try to connect to Bluez right away. BluezPlugin::BluezPlugin() { // Connect signals from the Bluez interface. The events we listen to are: @@ -50,6 +55,9 @@ BluezPlugin::BluezPlugin() properties["Discoverable"] = "Bluetooth.Visible"; } +/// Implementation of the IPropertyProvider::subscribe. We don't need +/// any extra work for subscribing to keys, thus subscribe is finished +/// right away. void BluezPlugin::subscribe(QSet keys) { contextDebug() << keys; @@ -58,6 +66,8 @@ void BluezPlugin::subscribe(QSet keys) } } +/// Implementation of the IPropertyProvider::unsubscribe. We're not +/// keeping track on subscriptions, so we don't need to do anything. void BluezPlugin::unsubscribe(QSet keys) { } @@ -76,3 +86,5 @@ void BluezPlugin::onPropertyChanged(QString key, QVariant value) } } +} // end namespace + diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h index a9b20b74..64f9664a 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -31,7 +31,17 @@ extern "C" { IProviderPlugin* bluezPluginFactory(const QString& constructionString); } -// FIXME: doxygen +namespace ContextSubscriberBluez +{ + +/*! + \class BluezPlugin + + \brief A libcontextsubscriber plugin for communicating with Bluez + over D-Bus. Provides context properties Bluetooth.Enabled and + Bluetooth.Visible. + + */ class BluezPlugin : public IProviderPlugin @@ -58,5 +68,6 @@ private: QMap properties; ///< Mapping of Bluez properties to Context FW properties }; +} #endif -- cgit v1.2.3 From c41dab9d0aa7feff05123946e9ca0462ce4da5d5 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 15:25:08 +0300 Subject: Bluez plugin: .context declaration file. --- libcontextsubscriber/plugins/bluez/bluez.context | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 libcontextsubscriber/plugins/bluez/bluez.context (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluez.context b/libcontextsubscriber/plugins/bluez/bluez.context new file mode 100644 index 00000000..5760b156 --- /dev/null +++ b/libcontextsubscriber/plugins/bluez/bluez.context @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file -- cgit v1.2.3 From 374e72d9db14e102f09dba42a060f5964ecf24eb Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Tue, 8 Sep 2009 15:34:02 +0300 Subject: Bluez plugin: Removing inherited signals from header file; apparently we don't need them. --- libcontextsubscriber/plugins/bluez/bluezplugin.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h index 64f9664a..3a72dae7 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -53,13 +53,6 @@ public: virtual void subscribe(QSet keys); virtual void unsubscribe(QSet keys); -signals: - void ready(); - void failed(QString error); - void subscribeFinished(QString key); - void subscribeFailed(QString failedKey, QString error); - void valueChanged(QString key, QVariant value); - private slots: void onPropertyChanged(QString key, QVariant variant); -- cgit v1.2.3 From 16e8eb73f43cfa286d0a1a66ef5fabb64e2e08d5 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Wed, 9 Sep 2009 10:48:59 +0300 Subject: bluez plugin: Fixing a header file renamed in the prev. merge. --- libcontextsubscriber/plugins/bluez/bluezplugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h index 3a72dae7..2c7699fd 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -23,7 +23,7 @@ #define BLUEZPLUGIN_H #include "bluezinterface.h" -#include "propertyprovider.h" // For IProviderPlugin definition +#include "provider.h" // For IProviderPlugin definition using ContextSubscriber::IProviderPlugin; -- cgit v1.2.3 From 6b222da65f2250d19d07dae3f1ca909ae6c33554 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Wed, 9 Sep 2009 16:16:15 +0300 Subject: Infrastructure for bluez plugin test. --- .../customer-tests/bluez-plugin/Makefile.am | 25 ++++++++ .../bluez-plugin/testbluezplugin.cpp | 73 ++++++++++++++++++++++ .../customer-tests/bluez-plugin/testbluezplugin.h | 45 +++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am create mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp create mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am b/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am new file mode 100644 index 00000000..d0b2c85a --- /dev/null +++ b/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am @@ -0,0 +1,25 @@ +bin_PROGRAMS = test-bluez-plugin + +# test's sources +test_bluez_plugin_SOURCES = testbluezplugin.cpp testbluezplugin.h + +# only include these files in the coverage +COVERAGE_FILES = bluezplugin.cpp bluezinterface.cpp +# FIXME: how to tell where the coverage files are? + +# do the testing, coverage, etc. stuff +# tests.am is using +=, so we have to set a value here for these four always +AM_CXXFLAGS = $(QtDBus_CFLAGS) '-I$(srcdir)/../util/' '-I$(srcdir)/../../src/' +AM_LDFLAGS = $(QtDBus_LIBS) +FROM_SOURCE = # copy these files from the real source +FROM_SOURCE_DIR = $(srcdir)/../../src +LDADD = +include $(top_srcdir)/am/tests.am + +nodist_test_bluez_plugin_SOURCES = mocs.cpp +QT_TOMOC = $(filter %.h, $(test_bluez_plugin_SOURCES)) #$(FROM_SOURCE)) +include $(top_srcdir)/am/qt.am + +# Running the customer test +check-customer: + LD_LIBRARY_PATH=$(builddir)/../../plugins/bluez/.libs/ ./test-bluez-plugin \ No newline at end of file diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp new file mode 100644 index 00000000..e51efaad --- /dev/null +++ b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 + * + */ + +// Header file of the tests +#include "testbluezplugin.h" + +// Plugin interface definition +#include "provider.h" // FIXME: change header file name + +#include +#include + +typedef ContextSubscriber::IProviderPlugin* (*PluginFactoryFunc)(const QString& constructionString); + +// +// Definition of testcases +// + +// Before all tests +void BluezPluginTests::initTestCase() +{ +} + +// After all tests +void BluezPluginTests::cleanupTestCase() +{ +} + +// Before each test +void BluezPluginTests::init() +{ + library = new QLibrary("libcontextsubscriberbluez"); +} + +// After each test +void BluezPluginTests::cleanup() +{ + delete library; + library = 0; +} + +// Test cases + +void BluezPluginTests::loading() +{ + /*library->load(); + qDebug() << library->errorString(); + QVERIFY(library->isLoaded()); + PluginFactoryFunc f = (PluginFactoryFunc) library->resolve("bluezPluginFactory"); + QVERIFY(f); + */ + // FIXME: implement the test when plugin loading / building is more clear +} + +QTEST_MAIN(BluezPluginTests); diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h new file mode 100644 index 00000000..acba0574 --- /dev/null +++ b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 + * + */ + +#include + +class QLibrary; + +class BluezPluginTests : public QObject +{ + Q_OBJECT + + // Tests +private slots: + // Init and cleanup helper functions + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + + // Test cases + void loading(); + //void normalOperation(); + //void bluezNotPresent(); + //void bluezDisappearsAndAppears(); +private: + QLibrary* library; +}; -- cgit v1.2.3 From 4deee8b5eb918f5c4afbfc47b5004785d61e6491 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 10 Sep 2009 09:15:57 +0300 Subject: bluez plugin: .gitignore additions. --- libcontextsubscriber/customer-tests/bluez-plugin/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/.gitignore (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/.gitignore b/libcontextsubscriber/customer-tests/bluez-plugin/.gitignore new file mode 100644 index 00000000..a05fc209 --- /dev/null +++ b/libcontextsubscriber/customer-tests/bluez-plugin/.gitignore @@ -0,0 +1 @@ +test-bluez-plugin -- cgit v1.2.3 From 5d08ac9ece5b0e8a71b7910e59a02a3383eb2a85 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 10 Sep 2009 10:01:34 +0300 Subject: bluez plugin: Drafting customer tests. --- .../customer-tests/bluez-plugin/bluez_stub.py | 645 +++++++++++++++++++++ .../bluez-plugin/testbluezplugin.cpp | 86 +++ .../customer-tests/bluez-plugin/testbluezplugin.h | 5 +- 3 files changed, 735 insertions(+), 1 deletion(-) create mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py b/libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py new file mode 100644 index 00000000..52c89a3b --- /dev/null +++ b/libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py @@ -0,0 +1,645 @@ +#!/usr/bin/env python2.5 +## +## @file bluez_stub.py +## +## Copyright (C) 2008 Nokia. All rights reserved. +## +## @author Aapo Makela +## +## This python file export a DBUS server, which emulates the +## objects/interfaces provided by bluez-utils daemon(s). +## It is used for testing conbtui API. +## +## Requires python2.5-gobject and python2.5-dbus +## +## Implements also some testing API: +## +## org.bluez +## / +## org.bluez.Manager.Testing +## +## AddAdapter (string bt_address): objpath +## +## RemoveAdapter (object adapter) +## +## SetDefaultAdapter (object adapter) +## +## SetError (string error) +## +## org.bluez +## /hci{0, 1, ...} +## org.bluez.Adapter.Testing +## +## AddDeviceAround (string bt_address, string name, Uint32 cod, array{string} UUIDs) +## +## TestAgentRequest (string what ("PinCode", "Passkey", "Confirmation")) +## +## SetError (string error) +## +## org.bluez +## /hci{0, 1, ...}/dev_XX_XX_XX_XX_XX_XX +## org.bluez.Device.Testing +## +## Connect () +## +## SetError (string error) +## + +import time +import dbus +import dbus.service +from dbus.mainloop.glib import DBusGMainLoop +import gobject + +class BluezException(dbus.DBusException): + def __init__(self, error_name): + dbus.DBusException.__init__(self) + self._dbus_error_name = "org.bluez.Error." + error_name + +class BluetoothDevice: + + def __init__(self, bt_address, name = "", cod = 0, + uuids = dbus.Array(signature="s")): + # Set properties + self.properties = {} + self.properties["Address"] = bt_address + self.properties["Name"] = name + self.properties["Class"] = dbus.UInt32(cod) + self.properties["Paired"] = dbus.Boolean(False) + self.properties["Connected"] = dbus.Boolean(False) + self.properties["Trusted"] = dbus.Boolean(False) + self.properties["Alias"] = self.properties["Name"] + self.properties["UUIDs"] = uuids + + def __cmp__(self, other): + return cmp(self.properties["Address"], other.properties["Address"]) + +# Device stuff +class BluezDevice(BluetoothDevice, dbus.service.Object): + name = "" + path = "" + error = "" + + def __init__(self, main_loop, adapter, bt_address, properties = {}): + # Here the object path + self.path = adapter + "/dev_" + bt_address.replace(":", "_") + + BluetoothDevice.__init__(self, bt_address) + dbus.service.Object.__init__(self, dbus.SystemBus(), self.path) + + self.properties = {} + if properties: + self.properties = properties + self.properties["Adapter"] = dbus.ObjectPath(adapter) + self.main_loop = main_loop + self.stopped = False + + @dbus.service.method(dbus_interface='org.bluez.Device', + in_signature='', out_signature='a{sv}') + def GetProperties(self): + if self.error: + raise BluezException(self.error) + + return self.properties + + @dbus.service.method(dbus_interface='org.bluez.Device', + in_signature='sv', out_signature='') + def SetProperty(self, name, value): + if self.error: + raise BluezException(self.error) + + if name not in self.properties.keys(): + raise BluezException("DoesNotExist") + if name in ("Address", "Name", "UUIDs", "Paired", "Connected", "Adapter"): + raise BluezException("InvalidArguments") + + if name == "Alias" and value == "": + self.properties[name] = self.properties["Name"] + self.PropertyChanged(name, self.properties["Name"]) + else: + self.properties[name] = value + self.PropertyChanged(name, value) + + @dbus.service.method(dbus_interface='org.bluez.Device', + in_signature='', out_signature='') + def Disconnect(self): + if self.error: + raise BluezException(self.error) + + if self.properties["Connected"] == False: + raise BluezException("NotConnected") + + self.DisconnectRequested() + time.sleep(2) + self.properties["Connected"] = False + self.PropertyChanged("Connected", False) + + # + # DBUS signals + # + + @dbus.service.signal(dbus_interface='org.bluez.Device', + signature='') + def DisconnectRequested(self): + print "device DisconnectedRequested signal" + + @dbus.service.signal(dbus_interface='org.bluez.Device', + signature='sv') + def PropertyChanged(self, name, value): + print "device PropertyChanged(%s, %s) signal" % (str(name), str(value)) + + # + # DBUS test methods + # + + @dbus.service.method(dbus_interface='org.bluez.Device.Testing', + in_signature='', out_signature='') + def Connect(self): + self.properties["Connected"] = True + self.PropertyChanged("Connected", True) + + @dbus.service.method(dbus_interface='org.bluez.Device.Testing', + in_signature='s', out_signature='') + def SetError(self, error): + self.error = error + + +# Adapter stuff +class BluezAdapter(dbus.service.Object): + + properties = {} + name = "" + global_agent = None + devices_around = [BluetoothDevice("11:22:33:44:55:66", "Phone", 5898764), + BluetoothDevice("22:33:44:55:66:77", "Tablet", 1048852)] + devices = {} + stopped = True + error = "" + + def __init__(self, main_loop, path, bt_address): + # Here the object path + self.path = path + dbus.service.Object.__init__(self, dbus.SystemBus(), self.path) + + self.main_loop = main_loop + self.stopped = False + + # Set properties + self.properties["Address"] = bt_address + self.properties["Name"] = "Test" + self.properties["Powered"] = False + self.properties["Discoverable"] = False + self.properties["DiscoverableTimeout"] = dbus.UInt32(180) + self.properties["Discovering"] = dbus.Boolean(False) + + self.pairing_return_cb = None + self.pairing_error_cb = None + self.new_device = None + self.agent = None + self.timeout = 0 + self.sessions = 0 + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='', out_signature='a{sv}') + def GetProperties(self): + if self.error: + raise BluezException(self.error) + + return self.properties + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='sv', out_signature='') + def SetProperty(self, name, value): + if self.error: + raise BluezException(self.error) + + if name not in self.properties.keys(): + raise BluezException("DoesNotExist") + if name in ("Address"): + raise BluezException("InvalidArguments") + self.properties[name] = value + self.PropertyChanged(name, value) + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='', out_signature='') + def RequestSession(self): + if self.sessions == 0 and not self.properties["Powered"]: + if self.global_agent: + try: + if self.properties["Discoverable"]: + self.global_agent.ConfirmModeChange("discoverable") + else: + self.global_agent.ConfirmModeChange("connectable") + except dbus.DBusException: + raise BluezException("Rejected") + self.properties["Powered"] = True + self.PropertyChanged("Powered", True) + self.sessions += 1 + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='', out_signature='') + def ReleaseSession(self): + self.sessions -= 1 + if self.sessions == 0: + self.properties["Powered"] = False + self.PropertyChanged("Powered", False) + if self.sessions < 0: + self.sessions = 0 + + def discover_device_timeout(self): + if self.stopped == True or self.idx >= len(self.devices_around): + self.timeout = gobject.timeout_add(30000, self.discover_device_timeout) + return False + + properties = self.devices_around[self.idx].properties.copy() + properties["RSSI"] = dbus.Int16(-60) + if properties.has_key("UUIDs"): + del properties["UUIDs"] + self.DeviceFound(properties["Address"], properties) + self.idx += 1 + return True + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='', out_signature='') + def StartDiscovery(self): + if self.error: + raise BluezException(self.error) + + self.idx = 0 + self.stopped = False + self.timeout = gobject.timeout_add(3000, self.discover_device_timeout) + self.SetProperty("Discovering", dbus.Boolean(True)) + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='', out_signature='') + def StopDiscovery(self): + if self.error: + raise BluezException(self.error) + + self.stopped = True + if self.timeout: + self.SetProperty("Discovering", dbus.Boolean(False)) + gobject.source_remove(self.timeout) + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='s', out_signature='o') + def FindDevice(self, address): + if self.error: + raise BluezException(self.error) + + for path, device in self.devices.items(): + if device.properties["Address"] == address: + return path + raise BluezException("DoesNotExist") + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='', out_signature='ao') + def ListDevices(self): + if self.error: + raise BluezException(self.error) + + keys = self.devices.keys() + keys.sort() + return keys + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='s', out_signature='') + def CancelDeviceCreation(self, address): + pass + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='s', out_signature='o') + def CreateDevice(self, address): + if self.error: + raise BluezException(self.error) + + for device in self.devices_around: + if device.properties["Address"] == address: + new_device = BluezDevice(self.main_loop, self.path, + device.properties["Address"], + device.properties) + self.devices[new_device.path] = new_device + self.DeviceCreated(new_device.path) + # TODO: add UUIDs + return new_device.path + raise BluezException("Failed") + + def pincode_reply(self, passkey): + print "pincode_reply %s" % str(passkey) + self.passkey = passkey + self.stopped = True + + if self.passkey != "1234": + self.pairing_error_cb(BluezException("Failed")) + else: + self.new_device.properties["Paired"] = True + self.pairing_return_cb(self.new_device.path) + + if self.timeout: + gobject.source_remove(self.timeout) + self.pairing_error_cb = None + self.pairing_return_cb = None + + def passkey_error(self, error): + print "passkey_error" + self.stopped = True + if self.timeout: + gobject.source_remove(self.timeout) + if self.pairing_error_cb: + self.pairing_error_cb (error) + self.pairing_error_cb = None + self.pairing_return_cb = None + + def passkey_timeout(self): + print "passkey_timeout" + if not self.pairing_error_cb: + return + + self.pairing_error_cb(BluezException("Failed")) + self.agent.Cancel(dbus_interface="org.bluez.Agent") + self.RemoveDevice(self.new_device.path) + self.pairing_error_cb = None + self.pairing_return_cb = None + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='sos', out_signature='o', + sender_keyword='sender', + async_callbacks=("return_cb", "error_cb")) + def CreatePairedDevice(self, address, agent_name, capability, return_cb, error_cb, sender): + if self.error: + raise BluezException(self.error) + + self.agent = dbus.SystemBus().get_object(sender, agent_name, introspect = False) + new_device = None + device_found = False + + for obj_path, device in self.devices.items(): + if device.properties["Address"] == address: + if device.properties["Paired"] == True: + raise BluezException("Failed") + new_device = device + device_found = True + break + + if new_device is None: + for device in self.devices_around: + if device.properties["Address"] == address: + new_device = BluezDevice(self.main_loop, self.path, + device.properties["Address"], + device.properties) + # TODO: add UUIDs + self.devices[new_device.path] = new_device + self.DeviceCreated(new_device.path) + break + + if new_device is None: + raise BluezException("Failed") + + self.pairing_return_cb = return_cb + self.pairing_error_cb = error_cb + + self.new_device = new_device + self.agent.RequestPinCode(dbus.ObjectPath(new_device.path), + dbus_interface="org.bluez.Agent", + reply_handler=self.pincode_reply, + error_handler=self.passkey_error) + + self.timeout = gobject.timeout_add(10000, self.passkey_timeout) + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='o', out_signature='') + def RemoveDevice(self, device_path): + if self.error: + raise BluezException(self.error) + + if not self.devices.has_key(device_path): + raise BluezException("Failed") + + del self.devices[device_path] + self.DeviceRemoved(device_path) + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='os', out_signature='', + sender_keyword='sender') + def RegisterAgent(self, agent_name, capability, sender = None): + if self.error: + raise BluezException(self.error) + + bus = dbus.SystemBus() + self.global_agent = bus.get_object(sender, agent_name, introspect = False) + + @dbus.service.method(dbus_interface='org.bluez.Adapter', + in_signature='o', out_signature='') + def UnregisterAgent(self, agent_name): + if self.error: + raise BluezException(self.error) + + #self.agents[agent_name].Release() + del self.global_agent + + # + # DBUS signals + # + + @dbus.service.signal(dbus_interface='org.bluez.Adapter', + signature='sv') + def PropertyChanged(self, name, value): + print "adapter PropertyChanged (%s, %s) signal" % (str(name), str(value)) + + @dbus.service.signal(dbus_interface='org.bluez.Adapter', + signature='sa{sv}') + def DeviceFound(self, address, values): + print "adapter DeviceFound signal" + + @dbus.service.signal(dbus_interface='org.bluez.Adapter', + signature='s') + def DeviceDisappeared(self, address): + print "adapter DeviceDisappeared signal" + + @dbus.service.signal(dbus_interface='org.bluez.Adapter', + signature='o') + def DeviceCreated(self, device): + print "adapter DeviceCreated signal" + + @dbus.service.signal(dbus_interface='org.bluez.Adapter', + signature='o') + def DeviceRemoved(self, device): + print "adapter DeviceRemoved signal" + + # + # DBUS test methods + # + + @dbus.service.method(dbus_interface='org.bluez.Adapter.Testing', + in_signature='ssuas', out_signature='') + def AddDeviceAround(self, bt_address, name, cod, uuids): + self.devices_around.append(BluetoothDevice(bt_address, name, cod, uuids)) + + def null_reply(self, passkey = None): + pass + + @dbus.service.method(dbus_interface='org.bluez.Adapter.Testing', + in_signature='s', out_signature='') + def TestAgentRequest(self, what): + if what not in ("PinCode", "Passkey", "Confirmation"): + raise BluezException("WrongMethod") + + new_device = BluezDevice(self.main_loop, self.path, + self.devices_around[0].properties["Address"], + self.devices_around[0].properties) + self.devices[new_device.path] = new_device + self.DeviceCreated(new_device.path) + + agent_obj = self.global_agent + if what == "PinCode": + agent_obj.RequestPinCode(dbus.ObjectPath(new_device.path), + dbus_interface="org.bluez.Agent", + reply_handler=self.null_reply, + error_handler=self.null_reply) + elif what == "Passkey": + agent_obj.RequestPasskey(dbus.ObjectPath(new_device.path), + dbus_interface="org.bluez.Agent", + reply_handler=self.null_reply, + error_handler=self.null_reply) + elif what == "Confirmation": + agent_obj.RequestConfirmation(dbus.ObjectPath(new_device.path), + dbus.UInt32(111111), + dbus_interface="org.bluez.Agent", + reply_handler=self.null_reply, + error_handler=self.null_reply) + + @dbus.service.method(dbus_interface='org.bluez.Adapter.Testing', + in_signature='s', out_signature='') + def SetError(self, error): + self.error = error + + +# Manager stuff +class BluezManager(dbus.service.Object): + + adapters = [] + default_adapter = 0 + error = "" + + def __init__(self, main_loop): + # Here the object path + dbus.service.Object.__init__(self, + dbus.service.BusName("org.bluez", bus=dbus.SystemBus()), + "/") + + self.main_loop = main_loop + self.stopped = False + + # + # DBUS methods + # + + @dbus.service.method(dbus_interface='org.bluez.Manager', + in_signature='', out_signature='o') + def DefaultAdapter(self): + if self.error: + raise BluezException(self.error) + + if not self.adapters: + raise BluezException("NoSuchAdapter") + + return (self.adapters[self.default_adapter]) + + @dbus.service.method(dbus_interface='org.bluez.Manager', + in_signature='s', out_signature='o') + def FindAdapter(self, pattern): + if self.error: + raise BluezException(self.error) + + adapter_idx = 0 + for adapter in self.adapters: + if adapter.name.find(pattern) != -1: + return (adapter) + if adapter.properties["Address"].find(pattern) != -1: + return (adapter) + raise BluezException("NoSuchAdapter") + + @dbus.service.method(dbus_interface='org.bluez.Manager', + in_signature='', out_signature='ao') + def ListAdapters(self): + if self.error: + raise BluezException(self.error) + + return (self.adapters) + + # + # DBUS signals + # + + @dbus.service.signal(dbus_interface='org.bluez.Manager', + signature='o') + def AdapterAdded(self, adapter): + print "manager AdapterAdded signal" + + @dbus.service.signal(dbus_interface='org.bluez.Manager', + signature='o') + def AdapterRemoved(self, adapter): + print "manager AdapterRemoved signal" + + @dbus.service.signal(dbus_interface='org.bluez.Manager', + signature='o') + def DefaultAdapterChanged(self, adapter): + print "manager DefaultAdapterChanged signal" + + # + # DBUS test methods + # + + @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', + in_signature='s', out_signature='o') + def AddAdapter(self, bt_address): + new_path = "/org/bluez/hci%d" % (len(self.adapters)) + adapter = BluezAdapter(self.main_loop, new_path, bt_address) + self.adapters.append(adapter) + self.AdapterAdded(adapter) + + # Set default adapter, if this is the only one + if len(self.adapters) == 1: + self.default_adapter = 0 + self.DefaultAdapterChanged(self.adapters[self.default_adapter]) + return adapter + + @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', + in_signature='o', out_signature='') + def RemoveAdapter(self, adapter_name): + for adapter in self.adapters: + if adapter.name == adapter_name[1:]: + self.AdapterRemoved(adapter) + if self.default_adapter == self.adapters.index(adapter): + self.default_adapter = 0 + if len(self.adapters) > 1: + self.DefaultAdapterChanged(self.adapters[self.default_adapter]) + self.adapters.remove(adapter) + return + raise BluezException("NoSuchAdapter") + + @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', + in_signature='o', out_signature='') + def SetDefaultAdapter(self, adapter_name): + for adapter in self.adapters: + if adapter.name == adapter_name[1:]: + self.default_adapter = self.adapters.index(adapter) + self.DefaultAdapterChanged(self.adapters[self.default_adapter]) + return + raise BluezException("NoSuchAdapter") + + @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', + in_signature='s', out_signature='') + def SetError(self, error): + self.error = error + + +# Main stuff +if __name__ == "__main__": + DBusGMainLoop(set_as_default=True) + + # Here register the service name + loop = gobject.MainLoop() + manager_server = BluezManager(loop) + loop.run() + diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp index 2bbe0cd5..73b1c68a 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp +++ b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp @@ -25,8 +25,17 @@ // Plugin interface definition #include "iproviderplugin.h" +// Temporary: plugin header files +#include "bluezplugin.h" + #include #include +#include +#include +#include +#include +#include +#include typedef ContextSubscriber::IProviderPlugin* (*PluginFactoryFunc)(const QString& constructionString); @@ -48,15 +57,57 @@ void BluezPluginTests::cleanupTestCase() void BluezPluginTests::init() { library = new QLibrary("libcontextsubscriberbluez"); + bluezProcess = new QProcess(); } // After each test void BluezPluginTests::cleanup() { + if (bluezProcess) { + bluezProcess->kill(); + bluezProcess->waitForFinished(); + } delete library; library = 0; + delete bluezProcess; + bluezProcess = 0; +} + +// Helpers +bool BluezPluginTests::startBluez() +{ + // Run the bluez stub + bluezProcess->start("python bluez_stub.py"); // FIXME: srcdir! + bool ok = bluezProcess->waitForStarted(); + + if (!ok) { + qDebug() << "Cannot start process"; + return false; + } + sleep(3); + // Unfortunately, we cannot guarantee that the stub process gets + // enough time to start its D-Bus operations before the test + // proceeds. + + // Make it create a default adapter + QDBusConnection connection = QDBusConnection::systemBus(); + QDBusMessage message = QDBusMessage::createMethodCall ("org.bluez", "/", "org.bluez.Manager.Testing", "AddAdapter"); + + QList argumentList; + QVariant s("dummy-bt-address"); + argumentList.append(s); + message.setArguments(argumentList); + + QDBusMessage reply = connection.call(message); + if (reply.type() == QDBusMessage::ReplyMessage) { + return true; + } + qDebug() << "Invalid reply:" << reply.errorMessage(); + + return false; } + // Test cases void BluezPluginTests::loading() @@ -70,4 +121,39 @@ void BluezPluginTests::loading() // FIXME: implement the test when plugin loading / building is more clear } +void BluezPluginTests::normalOperation() +{ + // Start BlueZ stub + QVERIFY(startBluez()); + + // Test: Create plugin + ContextSubscriberBluez::BluezPlugin* bluezPlugin = new ContextSubscriberBluez::BluezPlugin(); + // FIXME: use the same way to create the plugin than libcontextsubscriber does + QSignalSpy readySpy(bluezPlugin, SIGNAL(ready())); + QSignalSpy subscribeFinishedSpy(bluezPlugin, SIGNAL(subscribeFinished(QString))); + QSignalSpy subscribeFailedSpy(bluezPlugin, SIGNAL(subscribeFailed(QString, QString))); + + // Expected result: the plugin emits ready() at some point. + QDateTime start = QDateTime::currentDateTime(); + while (readySpy.count() != 1 && start.secsTo(QDateTime::currentDateTime()) < 3) { + QCoreApplication::processEvents(); + } + QCOMPARE(readySpy.count(), 1); + + // Test: subscribe to keys + QSet keys; + keys << "Bluetooth.Visible"; + keys << "Bluetooth.Enabled"; + bluezPlugin->subscribe(keys); + + // Expected result: the plugin emits subscribeFinished for those keys + start = QDateTime::currentDateTime(); + while (subscribeFinishedSpy.count() < 2 && start.secsTo(QDateTime::currentDateTime()) < 3) { + QCoreApplication::processEvents(); + } + QCOMPARE(subscribeFinishedSpy.count(), 2); + QCOMPARE(subscribeFailedSpy.count(), 0); +} + + QTEST_MAIN(BluezPluginTests); diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h index acba0574..6387f887 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h +++ b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h @@ -22,6 +22,7 @@ #include class QLibrary; +class QProcess; class BluezPluginTests : public QObject { @@ -37,9 +38,11 @@ private slots: // Test cases void loading(); - //void normalOperation(); + void normalOperation(); //void bluezNotPresent(); //void bluezDisappearsAndAppears(); private: + bool startBluez(); QLibrary* library; + QProcess* bluezProcess; }; -- cgit v1.2.3 From 9c594138e38962ed691c4cd546b6445c66549d47 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 10 Sep 2009 12:06:29 +0300 Subject: bluez plugin: An easier customer test for bluez plugin. --- .../customer-tests/bluez-plugin2/bluez.context | 7 ++ .../bluez-plugin2/test-bluez-plugin.py | 110 +++++++++++++++++++++ libcontextsubscriber/customer-tests/runTests.sh | 2 +- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context create mode 100644 libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context new file mode 100644 index 00000000..37616c83 --- /dev/null +++ b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context @@ -0,0 +1,7 @@ + + + TRUTH + TRUTH + diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py b/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py new file mode 100644 index 00000000..e1d70bec --- /dev/null +++ b/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python +## +## This file is part of ContextKit. +## +## Copyright (C) 2009 Nokia. All rights reserved. +## +## Contact: Marius Vollmer +## +## 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 +## +## +## Requires python2.5-gobject and python2.5-dbus +## +import sys +import unittest +import os +import string +from subprocess import Popen, PIPE +import time +import signal +from time import sleep + +def proc_kill(pid): + os.system('../common/rec-kill.sh %d' % pid) + +def timeoutHandler(signum, frame): + raise Exception('Tests have been running for too long') + +def stdoutRead (object,lines): + list = [] + for i in range(lines): + list.append(object.stdout.readline().rstrip()) + return list + +def set_bluez_property(property, value): + os.system('dbus-send --system --dest=org.bluez --print-reply --type=method_call /org/bluez/`pidof bluetoothd`/hci0 org.bluez.Adapter.SetProperty string:%s variant:boolean:%s' % (property, value)) + time.sleep(1) + + +class BluezPlugin(unittest.TestCase): + + def setUp(self): + os.environ["CONTEXT_PROVIDERS"] = "." + + # Make Bluetooth invisible and un-enabled + # Note: This test will alter the bluetooth settings of the system! + + set_bluez_property("Discoverable", "false") + set_bluez_property("Powered", "false") + + self.context_client = Popen(["context-listen","Bluetooth.Enabled","Bluetooth.Visible"],stdin=PIPE,stdout=PIPE,stderr=PIPE) + self.initial_output = stdoutRead(self.context_client, 2) + self.initial_output.sort() + + def tearDown(self): + + # Restore some default values for Bluez + set_bluez_property("Powered", "true") + set_bluez_property("Discoverable", "false") + + proc_kill(self.context_client.pid) + + def testInitial(self): + self.assertEqual(self.initial_output[0].strip(), "Bluetooth.Enabled = bool:false") + self.assertEqual(self.initial_output[1].strip(), "Bluetooth.Visible = bool:false") + + def testEnabledAndVisible(self): + + # Enable + set_bluez_property("Powered", "true") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Enabled = bool:true"] + self.assertEqual(actual, expected) + + # Set visible + set_bluez_property("Discoverable", "true") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Visible = bool:true"] + self.assertEqual(actual, expected) + + # Set invisible + set_bluez_property("Discoverable", "false") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Visible = bool:false"] + self.assertEqual(actual, expected) + + # Disable + set_bluez_property("Powered", "false") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Enabled = bool:false"] + self.assertEqual(actual, expected) + + +if __name__ == "__main__": + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) + signal.signal(signal.SIGALRM, timeoutHandler) + signal.alarm(30) + unittest.main() diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index 82efc04f..8ce5dd78 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIRS="commander subscription asynchronicity registry" +DIRS="commander subscription asynchronicity registry bluez-plugin2" if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] then -- cgit v1.2.3 From 3c2707f61baf6e97f0fc5757f6c52673eb958b82 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 10 Sep 2009 13:07:41 +0300 Subject: Fixing my bad "Queue all signal from plugin" fix in this branch, too. --- libcontextsubscriber/src/provider.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index a968f08a..c5e8b931 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -127,9 +127,9 @@ void Provider::constructPlugin() handleSignalRouter, SLOT(onValueChanged(QString, QVariant))); sconnect(plugin, SIGNAL(ready()), - this, SLOT(onPluginReady()), Qt::QueuedConnection); + this, SLOT(onPluginReady())); sconnect(plugin, SIGNAL(failed(QString)), - this, SLOT(onPluginFailed(QString)), Qt::QueuedConnection); + this, SLOT(onPluginFailed(QString))); sconnect(plugin, SIGNAL(subscribeFinished(QString)), this, SLOT(onPluginSubscribeFinished(QString)), Qt::QueuedConnection); -- cgit v1.2.3 From 5cc2564bd4360d38e21eead4aca08167972eeb0f Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 10 Sep 2009 15:59:26 +0300 Subject: bluez plugin: Renaming the factory function. Declaring the plugin .so name in the .context file. --- libcontextsubscriber/plugins/bluez/bluez.context | 4 ++-- libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 3 ++- libcontextsubscriber/plugins/bluez/bluezplugin.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/plugins/bluez/bluez.context b/libcontextsubscriber/plugins/bluez/bluez.context index 5760b156..fc8ca0d6 100644 --- a/libcontextsubscriber/plugins/bluez/bluez.context +++ b/libcontextsubscriber/plugins/bluez/bluez.context @@ -1,5 +1,5 @@ - + - \ No newline at end of file + diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp index 816c3396..59bd6ad6 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp @@ -21,10 +21,11 @@ #include "bluezplugin.h" #include "sconnect.h" + #include "logging.h" /// The factory method for constructing the IPropertyProvider instance. -IProviderPlugin* bluezPluginFactory(const QString& /*constructionString*/) +IProviderPlugin* pluginFactory(const QString& /*constructionString*/) { // Note: it's the caller's responsibility to delete the plugin if // needed. diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h index b1311492..6fa9f9dc 100644 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ b/libcontextsubscriber/plugins/bluez/bluezplugin.h @@ -28,7 +28,7 @@ using ContextSubscriber::IProviderPlugin; extern "C" { - IProviderPlugin* bluezPluginFactory(const QString& constructionString); + IProviderPlugin* pluginFactory(const QString& constructionString); } namespace ContextSubscriberBluez -- cgit v1.2.3 From fb4078667c37cb66a459209fb2b5837ce5128770 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 10 Sep 2009 16:00:14 +0300 Subject: libcontextsubscriber plugins: Draft implementation of the plugin loading system. --- libcontextsubscriber/src/provider.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index c5e8b931..c39963bd 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace ContextSubscriber { @@ -91,6 +92,8 @@ namespace ContextSubscriber { \brief Emitted when the subscription procedure for \c keys finished (either succeeded, either failed) */ +typedef IProviderPlugin* (*PluginFactoryFunc)(const QString& constructionString); + /// Stores the passed plugin name and construction paramater, then /// moves into the main thread and queues a constructPlugin call. Provider::Provider(const QString &plugin, const QString &constructionString) @@ -111,7 +114,23 @@ void Provider::constructPlugin() { if (pluginName == "contextkit-dbus") { plugin = contextKitPluginFactory(constructionString); - } else ; // FIXME: implement plugin system in the else branch + } + else { + QLibrary library(pluginName); + library.load(); + if (library.isLoaded() == false) { + contextCritical() << "Error loading library:" << library.errorString(); + } + else { + PluginFactoryFunc factory = (PluginFactoryFunc) library.resolve("pluginFactory"); + if (factory) { + contextDebug() << "Resolved factory function"; + plugin = factory(constructionString); + } else { + contextCritical() << "Cannot resolve factory function pluginFactory"; + } + } + } if (plugin == 0) { pluginState = FAILED; -- cgit v1.2.3 From 37df5d352538d300585866c0aa5d9da40401c78c Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Thu, 10 Sep 2009 16:10:31 +0300 Subject: libcontextsubscriber/cli: added flush support --- libcontextsubscriber/cli/commandwatcher.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/cli/commandwatcher.cpp b/libcontextsubscriber/cli/commandwatcher.cpp index a4841d96..c4b8d11e 100644 --- a/libcontextsubscriber/cli/commandwatcher.cpp +++ b/libcontextsubscriber/cli/commandwatcher.cpp @@ -17,7 +17,6 @@ CommandWatcher::CommandWatcher(int commandfd, QMap *properties, QObject *parent) : QObject(parent), commandfd(commandfd), properties(properties) { - fcntl(commandfd, F_SETFL, O_NONBLOCK); commandNotifier = new QSocketNotifier(commandfd, QSocketNotifier::Read, this); sconnect(commandNotifier, SIGNAL(activated(int)), this, SLOT(onActivated())); help(); @@ -29,6 +28,7 @@ void CommandWatcher::onActivated() static QByteArray commandBuffer = ""; static char buf[1024]; int readSize; + fcntl(commandfd, F_SETFL, O_NONBLOCK); while ((readSize = read(commandfd, &buf, 1024)) > 0) commandBuffer += QByteArray(buf, readSize); @@ -61,12 +61,14 @@ void CommandWatcher::help() qDebug() << " type KEY - get the info()->type for a key"; qDebug() << " plugin KEY - get the info()->plugin for a key"; qDebug() << " constructionstring KEY - get the info()->constructionstring for a key"; + qDebug() << " flush - write FLUSHED to stderr and stdout"; qDebug() << "Any prefix of a command can be used as an abbreviation"; } void CommandWatcher::interpret(const QString& command) const { QTextStream out(stdout); + QTextStream err(stderr); if (command == "") { help(); } else { @@ -74,7 +76,7 @@ void CommandWatcher::interpret(const QString& command) const QString commandName = args[0]; args.pop_front(); - if (args.size() == 0) { + if (args.size() == 0 && !QString("flush").startsWith(commandName)) { help(); return; } @@ -163,6 +165,11 @@ void CommandWatcher::interpret(const QString& command) const out << "constructionstring: " << properties->value(key)->info()->constructionString() << endl; else qDebug() << "no such key:" << key; + } else if (QString("flush").startsWith(commandName)) { + out << "FLUSHED" << endl; + out.flush(); + err << "FLUSHED" << endl; + err.flush(); } else help(); } -- cgit v1.2.3 From 5bbb1ded3cbdae493fd9e7f3f39bfb01ba360836 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 10 Sep 2009 16:26:17 +0300 Subject: bluez plugin: Fixing the customer tests after plugin-loading modifications. --- libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context | 2 +- libcontextsubscriber/customer-tests/runTests.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context index 37616c83..91e31e77 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context +++ b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context @@ -1,7 +1,7 @@ +plugin="libcontextsubscriberbluez" constructionString="bluez"> TRUTH TRUTH diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index 8ce5dd78..a901888b 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -5,7 +5,7 @@ DIRS="commander subscription asynchronicity registry bluez-plugin2" if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] then export CONTEXT_PROVIDERS=. - export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs + export LD_LIBRARY_PATH=../../src/.libs:../../plugins/bluez/.libs:../../../libcontextprovider/src/.libs export PATH=$PATH:../../../python:../../cli:../../reg-cli for dir in $DIRS; do -- cgit v1.2.3 From b68f1101692bf09778b608c25a9398900ed0b2db Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Thu, 10 Sep 2009 17:18:03 +0300 Subject: libcontextsubscriber/customer-tests: flush support for the customer tests. --- .../asynchronicity/asynchronicity.py | 41 +++-------- .../customer-tests/common/cltool.py | 80 ++++++++++++++++++++++ libcontextsubscriber/customer-tests/runTests.sh | 2 + 3 files changed, 93 insertions(+), 30 deletions(-) create mode 100644 libcontextsubscriber/customer-tests/common/cltool.py (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py index 11180b58..d1de94af 100755 --- a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py +++ b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py @@ -32,16 +32,9 @@ import os import signal import re import time - import unittest from subprocess import Popen, PIPE - -def timeoutHandler(signum, frame): - raise Exception('tests has been running for too long') - -class Callable: - def __init__(self, anycallable): - self.__call__ = anycallable +from cltool import CLTool class Asynchronous(unittest.TestCase): def startProvider(busname, args): @@ -51,15 +44,7 @@ class Asynchronous(unittest.TestCase): print >>ret.stdin, "info()" ret.stdout.readline().rstrip() return ret - startProvider = Callable(startProvider) - - def wanted(name, type, value): - return "%s = %s:%s" % (name, type, value) - wanted = Callable(wanted) - - def wantedUnknown(name): - return "%s is Unknown" % (name) - wantedUnknown = Callable(wantedUnknown) + startProvider = staticmethod(startProvider) #SetUp def setUp(self): @@ -97,20 +82,19 @@ class Asynchronous(unittest.TestCase): """ # check the fast property - self.context_client = Popen(["context-listen", "test.fast", "test.slow"], - stdin=PIPE, stdout=PIPE, stderr=PIPE) + self.context_client = CLTool("context-listen", "test.fast", "test.slow") - got = self.context_client.stdout.readline().rstrip() - self.assertEqual(got, - self.wanted("test.fast", "int", "42"), - "Bad value for the fast property") + self.assert_(self.context_client.expect(CLTool.STDOUT, + CLTool.wanted("test.fast", "int", "42"), + 1), # timeout == 1 second + "Bad value for the fast property, wanted 42, communication:") fast_time = time.time() # check the slow property - got = self.context_client.stdout.readline().rstrip() - self.assertEqual(got, - self.wanted("test.slow", "int", "42"), - "Bad value for the slow property") + self.assert_(self.context_client.expect(CLTool.STDOUT, + CLTool.wanted("test.slow", "int", "42"), + 10), # timeout == 10 second max, but 3 is enough usually + "Bad value for the slow property, wanted 42, communication:") slow_time = time.time() self.assert_(slow_time - fast_time > 2.0, @@ -129,9 +113,6 @@ def runTests(): result = unittest.TextTestRunner(verbosity=2).run(suiteInstallation) return len(result.errors + result.failures) - if __name__ == "__main__": sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) - signal.signal(signal.SIGALRM, timeoutHandler) - signal.alarm(10) sys.exit(runTests()) diff --git a/libcontextsubscriber/customer-tests/common/cltool.py b/libcontextsubscriber/customer-tests/common/cltool.py new file mode 100644 index 00000000..c80ce355 --- /dev/null +++ b/libcontextsubscriber/customer-tests/common/cltool.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +## +## Copyright (C) 2008, 2009 Nokia. All rights reserved. +## +## Contact: Marius Vollmer +## +## 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 + +import re +import time +from subprocess import Popen, PIPE + +class CLTool: + STDOUT = 1 + STDERR = 2 + def __init__(self, *cline): + self.__process = Popen(cline, stdin=PIPE, stdout=PIPE, stderr=PIPE) + self.__io = [] + + def send(self, string): + self.__io.append((0, string)) + print >>self.__process.stdin, string + + def expect(self, fileno, exp_str, timeout): + stream = 0 + if fileno == self.STDOUT: stream = self.__process.stdout + if fileno == self.STDERR: stream = self.__process.stderr + if stream == 0: return False + + print >>self.__process.stdin, "flush" + cur_str = "" + start_time = time.time() + while True: + line = stream.readline().rstrip() + if line == "FLUSHED": + if re.match(exp_str, cur_str): + return True + else: + time.sleep(0.1) + if time.time() - start_time > timeout: + self.printio() + print "Expected:", exp_str + print "Received before the timeout:\n", cur_str + return False + print >>self.__process.stdin, "flush" + else: + cur_str += line + "\n" + self.__io.append((fileno, line)) + + def printio(self): + print + print '----------------------------------------------------' + for line in self.__io: + if line[0] == 0: + print "[IN] <<<", line[1] + if line[0] == 1: + print "[OU] >>>", line[1] + if line[0] == 2: + print "[ER] >>>", line[1] + print '----------------------------------------------------' + + def wanted(name, type, value): + return "%s = %s:%s$" % (name, type, value) + wanted = staticmethod(wanted) + + def wantedUnknown(name): + return "%s is Unknown" % (name) + wantedUnknown = staticmethod(wantedUnknown) diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index 82efc04f..ae24a623 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -1,6 +1,8 @@ #!/bin/bash +cd $(dirname $0) DIRS="commander subscription asynchronicity registry" +export PYTHONPATH="`pwd`/common/" if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] then -- cgit v1.2.3 From 1c0fde79f0d7d25f0fffc525a6c1292d56f51a34 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 11:32:56 +0300 Subject: libcontextsubscriber, plugins: Building test plugins. --- libcontextsubscriber/customer-tests/Makefile.am | 2 +- .../customer-tests/testplugins/Makefile.am | 2 + .../customer-tests/testplugins/timeplugin.cpp | 76 ++++++++++++++++++++++ .../customer-tests/testplugins/timeplugin.h | 63 ++++++++++++++++++ .../testplugins/timeplugin1/Makefile.am | 30 +++++++++ .../testplugins/timeplugin1/time1.context | 4 ++ .../testplugins/timeplugin2/Makefile.am | 30 +++++++++ .../testplugins/timeplugin2/time2.context | 4 ++ 8 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 libcontextsubscriber/customer-tests/testplugins/Makefile.am create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin.h create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/Makefile.am b/libcontextsubscriber/customer-tests/Makefile.am index 8eed733d..07495c1a 100644 --- a/libcontextsubscriber/customer-tests/Makefile.am +++ b/libcontextsubscriber/customer-tests/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = update-contextkit-providers +SUBDIRS = update-contextkit-providers testplugins libcontextsubscribertestsdir = $(datadir)/libcontextsubscriber-tests libcontextsubscribertests_DATA = tests.xml diff --git a/libcontextsubscriber/customer-tests/testplugins/Makefile.am b/libcontextsubscriber/customer-tests/testplugins/Makefile.am new file mode 100644 index 00000000..38b401c6 --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = timeplugin1 timeplugin2 +EXTRA_DIST = timeplugin.cpp timeplugin.h diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp new file mode 100644 index 00000000..f7b748de --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 + * + */ + +#include "timeplugin.h" +#include "sconnect.h" + +#include "logging.h" + +#include + +/// The factory method for constructing the IPropertyProvider instance. +IProviderPlugin* pluginFactory(const QString& /*constructionString*/) +{ + // Note: it's the caller's responsibility to delete the plugin if + // needed. + return new ContextSubscriberTime::TimePlugin(); +} + +namespace ContextSubscriberTime { + +TimePlugin::TimePlugin() +{ + contextDebug(); + prefix = TIME_PLUGIN_PREFIX; + timer.setInterval(2000); + sconnect(&timer, SIGNAL(timeout()), this, SLOT(onTimeout())); + sconnect(this, SIGNAL(emitReady()), this, SLOT(onEmitReady()), Qt::QueuedConnection); + emit emitReady(); +} + +void TimePlugin::subscribe(QSet keys) +{ + contextDebug() << keys; + foreach(const QString& key, keys) { + emit subscribeFinished(key); + } + timer.start(); +} + +void TimePlugin::unsubscribe(QSet keys) +{ + timer.stop(); +} + +void TimePlugin::onEmitReady() +{ + contextDebug(); + emit ready(); +} + +void TimePlugin::onTimeout() +{ + contextDebug() << "Timeout"; + emit valueChanged("Test.Time", QDateTime::currentDateTime().toString().prepend(prefix)); +} + +} // end namespace + diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin.h b/libcontextsubscriber/customer-tests/testplugins/timeplugin.h new file mode 100644 index 00000000..508be886 --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2009 Nokia Corporation. + * + * Contact: Marius Vollmer + * + * 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 + * + */ + +/* +This is a test plugin for customer tests. +*/ + +#ifndef TIMEPLUGIN_H +#define TIMEPLUGIN_H + +#include "iproviderplugin.h" // For IProviderPlugin definition +#include + +using ContextSubscriber::IProviderPlugin; + +extern "C" { + IProviderPlugin* pluginFactory(const QString& constructionString); +} + +namespace ContextSubscriberTime +{ + +class TimePlugin : public IProviderPlugin +{ + Q_OBJECT + +public: + explicit TimePlugin(); + virtual void subscribe(QSet keys); + virtual void unsubscribe(QSet keys); + +signals: + void emitReady(); + +private slots: + void onEmitReady(); + void onTimeout(); + +private: + QTimer timer; + QString prefix; +}; +} + +#endif diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am new file mode 100644 index 00000000..a7903652 --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am @@ -0,0 +1,30 @@ +lib_LTLIBRARIES = libcontextsubscribertime1.la +libcontextsubscribertime1_la_SOURCES = timeplugin.cpp timeplugin.h + +BUILT_SOURCES = $(libcontextsubscribertime1_la_SOURCES) +timeplugin.cpp: ../timeplugin.cpp + ln -sf $< $@ +timeplugin.h: ../timeplugin.h + ln -sf $< $@ + +clean-local: + rm -f timeplugin.cpp timeplugin.h + +AM_CXXFLAGS = -I$(top_srcdir)/common \ + -I$(srcdir)/../../../src $(QtCore_CFLAGS) \ + $(QtDBus_CFLAGS) \ + '-DCONTEXT_LOG_MODULE_NAME="time1plugin"' \ + '-DTIME_PLUGIN_PREFIX="Time1: "' + +$(top_builddir)/common/libcommon.a: + $(MAKE) -C $(top_builddir)/common libcommon.a + +LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) +libcontextsubscribertime1_la_LIBADD=$(top_builddir)/common/libcommon.la + +.PHONY: $(top_builddir)/common/libcommon.la + +# moccing +nodist_libcontextsubscribertime1_la_SOURCES = mocs.cpp +QT_TOMOC = $(filter %.h, $(libcontextsubscribertime1_la_SOURCES)) +include $(top_srcdir)/am/qt.am diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context new file mode 100644 index 00000000..33c9d20d --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context @@ -0,0 +1,4 @@ + + + STRING + diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am new file mode 100644 index 00000000..060efcad --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am @@ -0,0 +1,30 @@ +lib_LTLIBRARIES = libcontextsubscribertime2.la +libcontextsubscribertime2_la_SOURCES = timeplugin.cpp timeplugin.h + +BUILT_SOURCES = $(libcontextsubscribertime2_la_SOURCES) +timeplugin.cpp: ../timeplugin.cpp + ln -sf $< $@ +timeplugin.h: ../timeplugin.h + ln -sf $< $@ + +clean-local: + rm -f timeplugin.cpp timeplugin.h + +AM_CXXFLAGS = -I$(top_srcdir)/common \ + -I$(srcdir)/../../../src $(QtCore_CFLAGS) \ + $(QtDBus_CFLAGS) \ + '-DCONTEXT_LOG_MODULE_NAME="time2plugin"' \ + '-DTIME_PLUGIN_PREFIX="Time2: "' + +$(top_builddir)/common/libcommon.a: + $(MAKE) -C $(top_builddir)/common libcommon.a + +LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) +libcontextsubscribertime2_la_LIBADD=$(top_builddir)/common/libcommon.la + +.PHONY: $(top_builddir)/common/libcommon.la + +# moccing +nodist_libcontextsubscribertime2_la_SOURCES = mocs.cpp +QT_TOMOC = $(filter %.h, $(libcontextsubscribertime2_la_SOURCES)) +include $(top_srcdir)/am/qt.am diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context new file mode 100644 index 00000000..ac170272 --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context @@ -0,0 +1,4 @@ + + + STRING + -- cgit v1.2.3 From 74a6a6c40b9f91b38e01519926275098ab3cf75d Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 11:41:18 +0300 Subject: libcontextsubscriber, plugins: Oops, fixing previous commit: testplugins dir needs building but we shouldn't do make-customer there. --- libcontextsubscriber/customer-tests/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/Makefile.am b/libcontextsubscriber/customer-tests/Makefile.am index 07495c1a..8ec2e565 100644 --- a/libcontextsubscriber/customer-tests/Makefile.am +++ b/libcontextsubscriber/customer-tests/Makefile.am @@ -1,4 +1,5 @@ SUBDIRS = update-contextkit-providers testplugins +CHECKSUBDIRS = update-contextkit-providers libcontextsubscribertestsdir = $(datadir)/libcontextsubscriber-tests libcontextsubscribertests_DATA = tests.xml @@ -6,7 +7,7 @@ libcontextsubscribertests_DATA = tests.xml check-customer: $(MAKE) -C $(top_srcdir) all ./runTests.sh - for i in $(SUBDIRS); do $(MAKE) -C $$i $@; done + for i in $(CHECKSUBDIRS); do $(MAKE) -C $$i $@; done CLEANFILES = *.pyc -- cgit v1.2.3 From 6bdcf91ddc348448d060d4ae680f4175cbca549d Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Fri, 11 Sep 2009 11:48:31 +0300 Subject: Cleanups. --- libcontextsubscriber/src/Makefile.am | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/Makefile.am b/libcontextsubscriber/src/Makefile.am index 1ae698b6..9cc161a3 100644 --- a/libcontextsubscriber/src/Makefile.am +++ b/libcontextsubscriber/src/Makefile.am @@ -1,21 +1,22 @@ lib_LTLIBRARIES = libcontextsubscriber.la libcontextsubscriber_la_SOURCES = contextproperty.cpp \ - contextproperty.h propertyhandle.cpp propertyhandle.h \ - provider.cpp provider.h safedbuspendingcallwatcher.h \ - subscriberinterface.h subscriberinterface.cpp \ - contextpropertyinfo.cpp contextpropertyinfo.h \ - contextregistryinfo.cpp contextregistryinfo.h infobackend.h \ - infobackend.cpp infoxmlbackend.h infoxmlbackend.cpp \ - infoxmlkeysfinder.h infoxmlkeysfinder.cpp infokeydata.h \ - cdbwriter.h cdbwriter.cpp cdbreader.cpp cdbreader.h \ - infocdbbackend.cpp infocdbbackend.h dbusnamelistener.h \ - dbusnamelistener.cpp handlesignalrouter.cpp \ - handlesignalrouter.h queuedinvoker.cpp queuedinvoker.h \ - loggingfeatures.h bluezinterface.h bluezinterface.cpp \ - contextkitplugin.h contextkitplugin.cpp iproviderplugin.h + contextproperty.h propertyhandle.cpp propertyhandle.h \ + provider.cpp provider.h safedbuspendingcallwatcher.h \ + subscriberinterface.h subscriberinterface.cpp \ + contextpropertyinfo.cpp contextpropertyinfo.h \ + contextregistryinfo.cpp contextregistryinfo.h infobackend.h \ + infobackend.cpp infoxmlbackend.h infoxmlbackend.cpp \ + infoxmlkeysfinder.h infoxmlkeysfinder.cpp infokeydata.h \ + cdbwriter.h cdbwriter.cpp cdbreader.cpp cdbreader.h \ + infocdbbackend.cpp infocdbbackend.h dbusnamelistener.h \ + dbusnamelistener.cpp handlesignalrouter.cpp \ + handlesignalrouter.h queuedinvoker.cpp queuedinvoker.h \ + loggingfeatures.h bluezinterface.h bluezinterface.cpp \ + contextkitplugin.h contextkitplugin.cpp iproviderplugin.h includecontextsubscriberdir=$(includedir)/contextsubscriber -includecontextsubscriber_HEADERS = contextproperty.h contextpropertyinfo.h contextregistryinfo.h +includecontextsubscriber_HEADERS = contextproperty.h \ + contextpropertyinfo.h contextregistryinfo.h iproviderplugin.h AM_CXXFLAGS = -I$(top_srcdir)/common \ $(QtCore_CFLAGS) $(QtXml_CFLAGS) $(QtDBus_CFLAGS) \ -- cgit v1.2.3 From b63a404897f33891ba3968c17393bf11f72ccd82 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 13:40:37 +0300 Subject: libcontextsubscriber plugins: Move declaration files to test directory. --- libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp | 4 ++++ libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp | 4 ++++ .../customer-tests/testplugins/timeplugin1/time1.context | 4 ---- .../customer-tests/testplugins/timeplugin2/time2.context | 4 ---- 4 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp create mode 100644 libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp delete mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context delete mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp b/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp new file mode 100644 index 00000000..33c9d20d --- /dev/null +++ b/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp @@ -0,0 +1,4 @@ + + + STRING + diff --git a/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp b/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp new file mode 100644 index 00000000..ac170272 --- /dev/null +++ b/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp @@ -0,0 +1,4 @@ + + + STRING + diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context deleted file mode 100644 index 33c9d20d..00000000 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin1/time1.context +++ /dev/null @@ -1,4 +0,0 @@ - - - STRING - diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context deleted file mode 100644 index ac170272..00000000 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin2/time2.context +++ /dev/null @@ -1,4 +0,0 @@ - - - STRING - -- cgit v1.2.3 From 97d436aca10ce605678a85924321cba2bf68b489 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 13:41:57 +0300 Subject: .gitignore --- libcontextsubscriber/customer-tests/testplugins/timeplugin1/.gitignore | 2 ++ libcontextsubscriber/customer-tests/testplugins/timeplugin2/.gitignore | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin1/.gitignore create mode 100644 libcontextsubscriber/customer-tests/testplugins/timeplugin2/.gitignore (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin1/.gitignore b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/.gitignore new file mode 100644 index 00000000..d79521dc --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/.gitignore @@ -0,0 +1,2 @@ +timeplugin.cpp +timeplugin.h diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin2/.gitignore b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/.gitignore new file mode 100644 index 00000000..d79521dc --- /dev/null +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/.gitignore @@ -0,0 +1,2 @@ +timeplugin.cpp +timeplugin.h -- cgit v1.2.3 From d6acc231d31ca1f7321d6ed11e932b825b168126 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 13:48:35 +0300 Subject: libcontextsubscriber: Modifying the locking in ContextPropertyInfo so that emitting signals and listeners accessing cached values doesn't create a deadlock. Adding a pluginChanged signal. --- libcontextsubscriber/src/contextpropertyinfo.cpp | 47 +++++++++++++++++------- libcontextsubscriber/src/contextpropertyinfo.h | 8 ++++ 2 files changed, 41 insertions(+), 14 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/contextpropertyinfo.cpp b/libcontextsubscriber/src/contextpropertyinfo.cpp index 1e23f2db..30cfd8b7 100644 --- a/libcontextsubscriber/src/contextpropertyinfo.cpp +++ b/libcontextsubscriber/src/contextpropertyinfo.cpp @@ -303,29 +303,48 @@ void ContextPropertyInfo::onKeyDataChanged(const QString& key) if (key != keyName) return; + // Update caches and store old values + QString oldType = cachedType; QString newType = InfoBackend::instance()->typeForKey(keyName); - if (cachedType != newType) { + cachedType = newType; - if (cachedType == "") + cachedDoc = InfoBackend::instance()->docForKey(keyName); + + QString oldPlugin = cachedPlugin; + QString oldConstructionString = cachedConstructionString; + QString newPlugin = InfoBackend::instance()->pluginForKey(keyName); + QString newConstructionString = InfoBackend::instance()->constructionStringForKey(keyName); + cachedPlugin = newPlugin; + cachedConstructionString = newConstructionString; + + // Release the lock before emitting the signals; otherwise + // listeners trying to access cached values would create a + // deadlock. + lock.unlock(); + + // Emit the needed signals + if (oldType != newType) { + + if (oldType == "") emit existsChanged(true); if (newType == "") emit existsChanged(false); - cachedType = newType; emit typeChanged(cachedType); } - cachedDoc = InfoBackend::instance()->docForKey(keyName); - - // TBD: obsolete the providerChanged signal and add pluginChanged or sth? - QString newPlugin = InfoBackend::instance()->pluginForKey(keyName); - if (cachedPlugin == "contextkit-dbus" || newPlugin == "contextkit-dbus") { - cachedPlugin = newPlugin; - cachedConstructionString = InfoBackend::instance()->constructionStringForKey(keyName); - QString newProvider = ""; - if (newPlugin == "contextkit-dbus") { - newProvider = cachedConstructionString.split(":").last(); + // TBD: obsolete the providerChanged & providerDBusTypeChanged signals? + if (oldPlugin != newPlugin || oldConstructionString != newConstructionString) { + if (oldPlugin == "contextkit-dbus" || newPlugin == "contextkit-dbus") { + QString newProvider = ""; + if (newPlugin == "contextkit-dbus") { + newProvider = cachedConstructionString.split(":").last(); + } + emit providerChanged(newProvider); + // Note: we don't emit providerDBusTypeChanged any + // more. It would be cumbersome, and there's no real use + // case for listening to it. } - emit providerChanged(newProvider); + emit pluginChanged(newPlugin, newConstructionString); } } diff --git a/libcontextsubscriber/src/contextpropertyinfo.h b/libcontextsubscriber/src/contextpropertyinfo.h index 3ba6b255..e83aebb9 100644 --- a/libcontextsubscriber/src/contextpropertyinfo.h +++ b/libcontextsubscriber/src/contextpropertyinfo.h @@ -85,6 +85,14 @@ signals: /// signal you can wait (watch) for various keys to become available. /// \param exists The new state of the key. void existsChanged(bool exists); + + /// Emitted when the libcontextsubscriber plugin providing the key + /// changes, or the construction parameter to give to the plugin + /// changes.. The \a plugin is the name of the new plugin + /// providing the key and the \a constructionString is the new + /// construction parameter to give to the plugin. + void pluginChanged(QString plugin, QString constructionString); + }; #endif // CONTEXTPROPERTYINFO_H -- cgit v1.2.3 From 317756832757a87dc0ee85b3ea1c040a83648c47 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 13:50:05 +0300 Subject: libcontextsubscriber: logging additions --- libcontextsubscriber/src/loggingfeatures.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/loggingfeatures.h b/libcontextsubscriber/src/loggingfeatures.h index 86f71c25..05a0d276 100644 --- a/libcontextsubscriber/src/loggingfeatures.h +++ b/libcontextsubscriber/src/loggingfeatures.h @@ -26,5 +26,6 @@ #define F_XML (ContextFeature("xml")) #define F_CDB (ContextFeature("cdb")) #define F_DESTROY (ContextFeature("destroy")) +#define F_PLUGINS (ContextFeature("plugins")) #endif -- cgit v1.2.3 From ddfa69b8e9fdc8256025d08e1e4cd197884c9e7d Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 13:58:56 +0300 Subject: libcontextsubscriber: PropertyHandle listening to ContextPropertyInfo signals to determine when it needs to update its provider information. This way the caches of ContextPropertyInfo are up to date when PropertyHandle is notified. --- libcontextsubscriber/src/propertyhandle.cpp | 13 ++++++++++--- .../unit-tests/propertyhandle/contextpropertyinfo.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/propertyhandle.cpp b/libcontextsubscriber/src/propertyhandle.cpp index f1592659..cef5c406 100644 --- a/libcontextsubscriber/src/propertyhandle.cpp +++ b/libcontextsubscriber/src/propertyhandle.cpp @@ -83,6 +83,12 @@ PropertyHandle::PropertyHandle(const QString& key) // done before calling updateProvider. myInfo = new ContextPropertyInfo(myKey, this); + // Start listening to changes in property introspection (e.g., added to registry, plugin changes) + sconnect(myInfo, SIGNAL(existsChanged(bool)), + this, SLOT(updateProvider())); + sconnect(myInfo, SIGNAL(pluginChanged(QString, QString)), + this, SLOT(updateProvider())); + // Start listening for the context commander, and also initiate a // NameHasOwner check. @@ -103,9 +109,6 @@ PropertyHandle::PropertyHandle(const QString& key) // Otherwise, delay connecting to the provider until we know // whether commander is present. - // Start listening to changes in property registry (e.g., new keys, keys removed) - sconnect(ContextRegistryInfo::instance(), SIGNAL(keysChanged(const QStringList&)), - this, SLOT(updateProvider())); // Move the PropertyHandle (and all children) to main thread. moveToThread(QCoreApplication::instance()->thread()); @@ -127,6 +130,7 @@ void PropertyHandle::setTypeCheck(bool typeCheck) void PropertyHandle::updateProvider() { Provider *newProvider; + contextDebug() << F_PLUGINS; if (commandingEnabled && commanderListener->isServicePresent() == DBusNameListener::Present) { // If commander is present it should be able to override the @@ -139,6 +143,7 @@ void PropertyHandle::updateProvider() if (myInfo->exists()) { // If myInfo knows the current provider which should be // connected to, connect to it. + contextDebug() << F_PLUGINS << "Key exists"; newProvider = Provider::instance(myInfo->plugin(), myInfo->constructionString()); } else { @@ -146,6 +151,8 @@ void PropertyHandle::updateProvider() // This way, we can still continue communicating with the // provider even though the key is no longer in the // registry. + contextDebug() << F_PLUGINS << "Key doesn't exist -> keep old provider info"; + newProvider = myProvider; if (newProvider == 0) { diff --git a/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h b/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h index a53f6d46..61cdcb45 100644 --- a/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h +++ b/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h @@ -50,6 +50,7 @@ signals: void providerDBusTypeChanged(QDBusConnection::BusType newBusType); void typeChanged(QString newType); void existsChanged(bool exists); + void pluginChanged(QString, QString); public: // For the test program -- cgit v1.2.3 From a7b641122cae7077de844c9831111ff784304c2e Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 14:24:47 +0300 Subject: libcontextsubscriber plugins: Adding a customer test for plugins: changing the plugin which provides a property. --- .../pluginchanging/pluginchanging.py | 82 ++++++++++++++++++++++ libcontextsubscriber/customer-tests/runTests.sh | 4 +- 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py new file mode 100644 index 00000000..b564db52 --- /dev/null +++ b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +## +## This file is part of ContextKit. +## +## Copyright (C) 2009 Nokia. All rights reserved. +## +## Contact: Marius Vollmer +## +## 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 +## +## +## Requires python2.5-gobject and python2.5-dbus +## +import sys +import unittest +import os +import string +from subprocess import Popen, PIPE +import time +import signal + +def proc_kill(pid): + os.system('../common/rec-kill.sh %d' % pid) + +def timeoutHandler(signum, frame): + raise Exception('tests has been running for too long') + +def stdoutRead (object,lines): + list = [] + for i in range(lines): + list.append(object.stdout.readline().rstrip()) + return list + +class Subscription(unittest.TestCase): + + def setUp(self): + os.environ["CONTEXT_PROVIDERS"] = "." + + self.context_client = Popen(["context-listen","Test.Time"],stdin=PIPE,stdout=PIPE,stderr=PIPE) + + def tearDown(self): + proc_kill(self.context_client.pid) + os.remove('time.context') + + def testChangingPlugin(self): + + # Copy the declaration file, declaring libcontextsubscribertime1 plugin. + os.system('cp time1.context.temp time.context.temp') + os.system('mv time.context.temp time.context') + actual = self.context_client.stdout.readline().rstrip() + + # The client got a value provided by the libcontextsubscribertime1 + self.assertEqual(actual.startswith("Test.Time = QString:Time1: "), True, "Got: %s" % actual) + + # Modify the registry so that the key is now provided by libcontextsubscribertime2 + os.system('cp time2.context.temp time.context.temp') + os.system('mv time.context.temp time.context') + + # Assert that the client starts getting the value from the correct plugin + # (not necessarily the first one) + actual = self.context_client.stdout.readline().rstrip() + actual = self.context_client.stdout.readline().rstrip() + + self.assertEqual(actual.startswith("Test.Time = QString:Time2: "), True, "Got: %s" % actual) + +if __name__ == "__main__": + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) + signal.signal(signal.SIGALRM, timeoutHandler) + signal.alarm(30) + unittest.main() diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index a901888b..f0ba2042 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -1,11 +1,11 @@ #!/bin/bash -DIRS="commander subscription asynchronicity registry bluez-plugin2" +DIRS="commander subscription asynchronicity registry bluez-plugin2 pluginchanging" if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] then export CONTEXT_PROVIDERS=. - export LD_LIBRARY_PATH=../../src/.libs:../../plugins/bluez/.libs:../../../libcontextprovider/src/.libs + export LD_LIBRARY_PATH=../../src/.libs:../../plugins/bluez/.libs:../../../libcontextprovider/src/.libs:../testplugins/timeplugin1/.libs:../testplugins/timeplugin2/.libs export PATH=$PATH:../../../python:../../cli:../../reg-cli for dir in $DIRS; do -- cgit v1.2.3 From 1e90445d3293699df4160d9d1820144422d795be Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Fri, 11 Sep 2009 15:01:06 +0300 Subject: Libcontextsubscriber/plugin loading review. --- .../customer-tests/bluez-plugin/Makefile.am | 2 +- .../customer-tests/bluez-plugin2/bluez.context | 8 +- .../bluez-plugin2/test-bluez-plugin.py | 102 ++++++++++----------- .../customer-tests/testplugins/timeplugin.cpp | 11 ++- .../customer-tests/testplugins/timeplugin.h | 7 +- libcontextsubscriber/src/Makefile.am | 2 +- libcontextsubscriber/src/iproviderplugin.h | 2 + libcontextsubscriber/src/provider.cpp | 2 - 8 files changed, 66 insertions(+), 70 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am b/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am index d0b2c85a..93d69310 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am +++ b/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am @@ -22,4 +22,4 @@ include $(top_srcdir)/am/qt.am # Running the customer test check-customer: - LD_LIBRARY_PATH=$(builddir)/../../plugins/bluez/.libs/ ./test-bluez-plugin \ No newline at end of file + LD_LIBRARY_PATH=$(builddir)/../../plugins/bluez/.libs/ ./test-bluez-plugin diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context index 91e31e77..5472f1a7 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context +++ b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context @@ -1,7 +1,7 @@ - TRUTH - TRUTH + xmlns="http://contextkit.freedesktop.org/Provider" + plugin="libcontextsubscriberbluez" constructionString="bluez"> + TRUTH + TRUTH diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py b/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py index e1d70bec..338124ea 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py +++ b/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py @@ -33,78 +33,76 @@ import signal from time import sleep def proc_kill(pid): - os.system('../common/rec-kill.sh %d' % pid) + os.system('../common/rec-kill.sh %d' % pid) def timeoutHandler(signum, frame): - raise Exception('Tests have been running for too long') + raise Exception('Tests have been running for too long') def stdoutRead (object,lines): - list = [] - for i in range(lines): - list.append(object.stdout.readline().rstrip()) - return list + list = [] + for i in range(lines): + list.append(object.stdout.readline().rstrip()) + return list def set_bluez_property(property, value): - os.system('dbus-send --system --dest=org.bluez --print-reply --type=method_call /org/bluez/`pidof bluetoothd`/hci0 org.bluez.Adapter.SetProperty string:%s variant:boolean:%s' % (property, value)) - time.sleep(1) + os.system('dbus-send --system --dest=org.bluez --print-reply --type=method_call /org/bluez/`pidof bluetoothd`/hci0 org.bluez.Adapter.SetProperty string:%s variant:boolean:%s' % (property, value)) + time.sleep(1) class BluezPlugin(unittest.TestCase): - def setUp(self): - os.environ["CONTEXT_PROVIDERS"] = "." + def setUp(self): + os.environ["CONTEXT_PROVIDERS"] = "." - # Make Bluetooth invisible and un-enabled - # Note: This test will alter the bluetooth settings of the system! + # Make Bluetooth invisible and un-enabled + # Note: This test will alter the bluetooth settings of the system! - set_bluez_property("Discoverable", "false") - set_bluez_property("Powered", "false") + set_bluez_property("Discoverable", "false") + set_bluez_property("Powered", "false") - self.context_client = Popen(["context-listen","Bluetooth.Enabled","Bluetooth.Visible"],stdin=PIPE,stdout=PIPE,stderr=PIPE) - self.initial_output = stdoutRead(self.context_client, 2) - self.initial_output.sort() + self.context_client = Popen(["context-listen","Bluetooth.Enabled","Bluetooth.Visible"],stdin=PIPE,stdout=PIPE,stderr=PIPE) + self.initial_output = stdoutRead(self.context_client, 2) + self.initial_output.sort() - def tearDown(self): + def tearDown(self): - # Restore some default values for Bluez - set_bluez_property("Powered", "true") - set_bluez_property("Discoverable", "false") + # Restore some default values for Bluez + set_bluez_property("Powered", "true") + set_bluez_property("Discoverable", "false") - proc_kill(self.context_client.pid) + proc_kill(self.context_client.pid) - def testInitial(self): - self.assertEqual(self.initial_output[0].strip(), "Bluetooth.Enabled = bool:false") - self.assertEqual(self.initial_output[1].strip(), "Bluetooth.Visible = bool:false") + def testInitial(self): + self.assertEqual(self.initial_output[0].strip(), "Bluetooth.Enabled = bool:false") + self.assertEqual(self.initial_output[1].strip(), "Bluetooth.Visible = bool:false") - def testEnabledAndVisible(self): - - # Enable - set_bluez_property("Powered", "true") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Enabled = bool:true"] - self.assertEqual(actual, expected) + def testEnabledAndVisible(self): + # Enable + set_bluez_property("Powered", "true") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Enabled = bool:true"] + self.assertEqual(actual, expected) - # Set visible - set_bluez_property("Discoverable", "true") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Visible = bool:true"] - self.assertEqual(actual, expected) + # Set visible + set_bluez_property("Discoverable", "true") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Visible = bool:true"] + self.assertEqual(actual, expected) - # Set invisible - set_bluez_property("Discoverable", "false") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Visible = bool:false"] - self.assertEqual(actual, expected) - - # Disable - set_bluez_property("Powered", "false") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Enabled = bool:false"] - self.assertEqual(actual, expected) + # Set invisible + set_bluez_property("Discoverable", "false") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Visible = bool:false"] + self.assertEqual(actual, expected) + # Disable + set_bluez_property("Powered", "false") + actual = stdoutRead(self.context_client,1) + expected = ["Bluetooth.Enabled = bool:false"] + self.assertEqual(actual, expected) if __name__ == "__main__": - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) - signal.signal(signal.SIGALRM, timeoutHandler) - signal.alarm(30) - unittest.main() + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) + signal.signal(signal.SIGALRM, timeoutHandler) + signal.alarm(30) + unittest.main() diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp index f7b748de..8cc08e3b 100644 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp @@ -27,7 +27,7 @@ #include /// The factory method for constructing the IPropertyProvider instance. -IProviderPlugin* pluginFactory(const QString& /*constructionString*/) +IProviderPlugin* pluginFactory(QString /*constructionString*/) { // Note: it's the caller's responsibility to delete the plugin if // needed. @@ -42,8 +42,10 @@ TimePlugin::TimePlugin() prefix = TIME_PLUGIN_PREFIX; timer.setInterval(2000); sconnect(&timer, SIGNAL(timeout()), this, SLOT(onTimeout())); - sconnect(this, SIGNAL(emitReady()), this, SLOT(onEmitReady()), Qt::QueuedConnection); - emit emitReady(); + QTimer *t = new QTimer(this); + sconnect(t, SIGNAL(timeout()), this, SLOT(emitReady()), Qt::QueuedConnection); + t.setSingleShot(true); + t.setInterval(0); } void TimePlugin::subscribe(QSet keys) @@ -60,7 +62,7 @@ void TimePlugin::unsubscribe(QSet keys) timer.stop(); } -void TimePlugin::onEmitReady() +void TimePlugin::emitReady() { contextDebug(); emit ready(); @@ -73,4 +75,3 @@ void TimePlugin::onTimeout() } } // end namespace - diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin.h b/libcontextsubscriber/customer-tests/testplugins/timeplugin.h index 508be886..78f1ccc2 100644 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin.h +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin.h @@ -32,7 +32,7 @@ This is a test plugin for customer tests. using ContextSubscriber::IProviderPlugin; extern "C" { - IProviderPlugin* pluginFactory(const QString& constructionString); + IProviderPlugin* pluginFactory(QString constructionString); } namespace ContextSubscriberTime @@ -47,11 +47,8 @@ public: virtual void subscribe(QSet keys); virtual void unsubscribe(QSet keys); -signals: - void emitReady(); - private slots: - void onEmitReady(); + void emitReady(); void onTimeout(); private: diff --git a/libcontextsubscriber/src/Makefile.am b/libcontextsubscriber/src/Makefile.am index b00f11a8..986fdec1 100644 --- a/libcontextsubscriber/src/Makefile.am +++ b/libcontextsubscriber/src/Makefile.am @@ -12,7 +12,7 @@ libcontextsubscriber_la_SOURCES = contextproperty.cpp \ dbusnamelistener.cpp handlesignalrouter.cpp \ handlesignalrouter.h queuedinvoker.cpp queuedinvoker.h \ loggingfeatures.h contextkitplugin.h contextkitplugin.cpp \ - iproviderplugin.h bluezinterface.h bluezinterface.cpp + iproviderplugin.h includecontextsubscriberdir=$(includedir)/contextsubscriber includecontextsubscriber_HEADERS = contextproperty.h \ diff --git a/libcontextsubscriber/src/iproviderplugin.h b/libcontextsubscriber/src/iproviderplugin.h index 2cfef845..e03900ed 100644 --- a/libcontextsubscriber/src/iproviderplugin.h +++ b/libcontextsubscriber/src/iproviderplugin.h @@ -42,6 +42,8 @@ signals: void valueChanged(QString key, QVariant value); }; +typedef IProviderPlugin* (*PluginFactoryFunc)(QString constructionString); + } #endif diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index c39963bd..511568b5 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -92,8 +92,6 @@ namespace ContextSubscriber { \brief Emitted when the subscription procedure for \c keys finished (either succeeded, either failed) */ -typedef IProviderPlugin* (*PluginFactoryFunc)(const QString& constructionString); - /// Stores the passed plugin name and construction paramater, then /// moves into the main thread and queues a constructPlugin call. Provider::Provider(const QString &plugin, const QString &constructionString) -- cgit v1.2.3 From e6f867d422722e66b4172d06b9de2f7a411ef8e5 Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Fri, 11 Sep 2009 15:06:11 +0300 Subject: libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py +x --- libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py old mode 100644 new mode 100755 -- cgit v1.2.3 From 08112b9b3987061f3cd4d652002ebab055d88dbe Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 15:44:38 +0300 Subject: libcontextsubscriber plugins: Specifying the place where the plugins are build-time or run time. Requiring non-built-in plugin names to have a trailing /. --- .../customer-tests/bluez-plugin2/bluez.context | 6 +-- libcontextsubscriber/customer-tests/runTests.sh | 3 +- libcontextsubscriber/src/Makefile.am | 4 ++ libcontextsubscriber/src/provider.cpp | 45 ++++++++++++++++------ .../unit-tests/provider/Makefile.am | 4 +- 5 files changed, 46 insertions(+), 16 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context index 5472f1a7..36b8a68b 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context +++ b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context @@ -1,7 +1,7 @@ - TRUTH - TRUTH + plugin="/libcontextsubscriberbluez" constructionString="bluez"> + TRUTH + TRUTH diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index aa620a91..cba8076c 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -7,8 +7,9 @@ export PYTHONPATH="`pwd`/common/" if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] then export CONTEXT_PROVIDERS=. - export LD_LIBRARY_PATH=../../src/.libs:../../plugins/bluez/.libs:../../../libcontextprovider/src/.libs:../testplugins/timeplugin1/.libs:../testplugins/timeplugin2/.libs + export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs:../testplugins/timeplugin1/.libs:../testplugins/timeplugin2/.libs export PATH=$PATH:../../../python:../../cli:../../reg-cli + export CONTEXT_SUBSCRIBER_PLUGINS=../../plugins/bluez/.libs/ for dir in $DIRS; do cd $dir diff --git a/libcontextsubscriber/src/Makefile.am b/libcontextsubscriber/src/Makefile.am index 986fdec1..b790c4dd 100644 --- a/libcontextsubscriber/src/Makefile.am +++ b/libcontextsubscriber/src/Makefile.am @@ -20,6 +20,7 @@ includecontextsubscriber_HEADERS = contextproperty.h \ AM_CXXFLAGS = -I$(top_srcdir)/common \ $(QtCore_CFLAGS) $(QtXml_CFLAGS) $(QtDBus_CFLAGS) \ + '-DDEFAULT_CONTEXT_SUBSCRIBER_PLUGINS="@libdir@/contextkit/subscriber-plugins"' \ '-DDEFAULT_CONTEXT_PROVIDERS="@datadir@/contextkit/providers/"' \ '-DDEFAULT_CONTEXT_CORE_DECLARATIONS="@datadir@/contextkit/core.context"' \ '-DCONTEXT_LOG_MODULE_NAME="libcontextsubscriber"' @@ -40,3 +41,6 @@ include $(top_srcdir)/am/qt.am # because if you change configure parameter DEFAULT_CONTEXT_PROVIDERS, # you should do a recompile infocdbbackend.lo infoxmlbackend.lo: Makefile + +# and the same for DEFAULT_CONTEXT_SUBSCRIBER_PLUGINS +provider.lo: Makefile diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index 511568b5..2f8e008f 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -25,6 +25,7 @@ #include "sconnect.h" #include "contextkitplugin.h" #include "logging.h" +#include "loggingfeatures.h" #include #include #include @@ -110,23 +111,45 @@ Provider::Provider(const QString &plugin, const QString &constructionString) /// up with the name of the function). void Provider::constructPlugin() { + contextDebug() << F_PLUGINS; if (pluginName == "contextkit-dbus") { plugin = contextKitPluginFactory(constructionString); } else { - QLibrary library(pluginName); - library.load(); - if (library.isLoaded() == false) { - contextCritical() << "Error loading library:" << library.errorString(); + // Require the plugin name to start with / + if (pluginName.startsWith("/")) { + + // Enable overriding the plugin location with an environment variable + const char *pluginPath = getenv("CONTEXT_SUBSCRIBER_PLUGINS"); + if (! pluginPath) + pluginPath = DEFAULT_CONTEXT_SUBSCRIBER_PLUGINS; + + QString pluginFilename(pluginPath); + // Allow pluginPath to have a trailing / or not + if (pluginFilename.endsWith("/")) { + pluginFilename.chop(1); + } + + pluginFilename.append(pluginName); + + QLibrary library(pluginFilename); + library.load(); + + if (library.isLoaded()) { + PluginFactoryFunc factory = (PluginFactoryFunc) library.resolve("pluginFactory"); + if (factory) { + contextDebug() << "Resolved factory function"; + plugin = factory(constructionString); + } else { + contextCritical() << "Error resolving function pluginFactory from plugin" << pluginFilename; + } + } + else { + contextCritical() << "Error loading plugin" << pluginFilename << ":" << library.errorString(); + } } else { - PluginFactoryFunc factory = (PluginFactoryFunc) library.resolve("pluginFactory"); - if (factory) { - contextDebug() << "Resolved factory function"; - plugin = factory(constructionString); - } else { - contextCritical() << "Cannot resolve factory function pluginFactory"; - } + contextCritical() << "Illegal plugin name" << pluginName << ", doesn't start with /"; } } diff --git a/libcontextsubscriber/unit-tests/provider/Makefile.am b/libcontextsubscriber/unit-tests/provider/Makefile.am index 8d28ea53..936b9a92 100644 --- a/libcontextsubscriber/unit-tests/provider/Makefile.am +++ b/libcontextsubscriber/unit-tests/provider/Makefile.am @@ -9,7 +9,9 @@ COVERAGE_FILES = provider.cpp # do the testing, coverage, etc. stuff # tests.am is using +=, so we have to set a value here for these four always -AM_CXXFLAGS = $(QtDBus_CFLAGS) +AM_CXXFLAGS = $(QtDBus_CFLAGS) \ + '-DDEFAULT_CONTEXT_SUBSCRIBER_PLUGINS="@libdir@/contextkit/subscriber-plugins"' + AM_LDFLAGS = $(QtDBus_LIBS) # copy these files from the real source FROM_SOURCE = provider.cpp provider.h iproviderplugin.h \ -- cgit v1.2.3 From 8d10f65d247d4a98bbac288b0e67125e490b0bd4 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 15:46:11 +0300 Subject: libcontextsubscriber plugins: some more trailing /'s. --- libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp | 2 +- libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp b/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp index 33c9d20d..da09ce66 100644 --- a/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp +++ b/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp @@ -1,4 +1,4 @@ - + STRING diff --git a/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp b/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp index ac170272..1cc5b656 100644 --- a/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp +++ b/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp @@ -1,4 +1,4 @@ - + STRING -- cgit v1.2.3 From 0372cee8a5990f744a017cb405d2d4ffd2ff01cf Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 16:12:55 +0300 Subject: libcontextsubscriber plugins: Now the customer tests must also specify where the plugins are via CONTEXT_SUBSCRIBER_PLUGINS, not via LD_LIBRARY_PATH. --- .../customer-tests/bluez-plugin2/test-bluez-plugin.py | 2 ++ .../customer-tests/pluginchanging/pluginchanging.py | 9 +++++++++ libcontextsubscriber/customer-tests/runTests.sh | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py b/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py index 338124ea..7bb58080 100644 --- a/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py +++ b/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py @@ -53,6 +53,8 @@ class BluezPlugin(unittest.TestCase): def setUp(self): os.environ["CONTEXT_PROVIDERS"] = "." + os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] = "../../plugins/bluez/.libs/" + # FIXME: this won't work in the test package... # Make Bluetooth invisible and un-enabled # Note: This test will alter the bluetooth settings of the system! diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py index b564db52..1d703d03 100755 --- a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py +++ b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py @@ -46,13 +46,22 @@ def stdoutRead (object,lines): class Subscription(unittest.TestCase): def setUp(self): + print "set up" os.environ["CONTEXT_PROVIDERS"] = "." + # We need 2 plugins which are in separate directories. + os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] = "." + os.system('cp ../testplugins/timeplugin1/.libs/libcontextsubscribertime1.so.* .') + os.system('cp ../testplugins/timeplugin2/.libs/libcontextsubscribertime2.so.* .') + self.context_client = Popen(["context-listen","Test.Time"],stdin=PIPE,stdout=PIPE,stderr=PIPE) def tearDown(self): + print "tear down" + proc_kill(self.context_client.pid) os.remove('time.context') + os.remove('libcontextsubscribertime*.so.*') def testChangingPlugin(self): diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index cba8076c..d933341a 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -7,9 +7,8 @@ export PYTHONPATH="`pwd`/common/" if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] then export CONTEXT_PROVIDERS=. - export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs:../testplugins/timeplugin1/.libs:../testplugins/timeplugin2/.libs + export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs export PATH=$PATH:../../../python:../../cli:../../reg-cli - export CONTEXT_SUBSCRIBER_PLUGINS=../../plugins/bluez/.libs/ for dir in $DIRS; do cd $dir -- cgit v1.2.3 From 3678e675bf09c0e2798f16cafefaed2e3dab02e4 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 11 Sep 2009 16:34:55 +0300 Subject: libcontextsubscriber plugins: Fix test plugin. --- libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp index 8cc08e3b..39b61016 100644 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp @@ -44,8 +44,9 @@ TimePlugin::TimePlugin() sconnect(&timer, SIGNAL(timeout()), this, SLOT(onTimeout())); QTimer *t = new QTimer(this); sconnect(t, SIGNAL(timeout()), this, SLOT(emitReady()), Qt::QueuedConnection); - t.setSingleShot(true); - t.setInterval(0); + t->setSingleShot(true); + t->setInterval(0); + t->start(); } void TimePlugin::subscribe(QSet keys) -- cgit v1.2.3 From c45e3fca5c59f1949ebf8befbff1bf6b8a4d5f44 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Mon, 14 Sep 2009 09:11:58 +0300 Subject: libcontextsubscriber plugins: Fixing the plugin-loading customer test. --- .../customer-tests/pluginchanging/pluginchanging.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py index 1d703d03..e2da172b 100755 --- a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py +++ b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py @@ -35,7 +35,7 @@ def proc_kill(pid): os.system('../common/rec-kill.sh %d' % pid) def timeoutHandler(signum, frame): - raise Exception('tests has been running for too long') + raise Exception('tests have been running for too long') def stdoutRead (object,lines): list = [] @@ -46,12 +46,11 @@ def stdoutRead (object,lines): class Subscription(unittest.TestCase): def setUp(self): - print "set up" os.environ["CONTEXT_PROVIDERS"] = "." # We need 2 plugins which are in separate directories. os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] = "." - os.system('cp ../testplugins/timeplugin1/.libs/libcontextsubscribertime1.so.* .') - os.system('cp ../testplugins/timeplugin2/.libs/libcontextsubscribertime2.so.* .') + os.system('cp ../testplugins/timeplugin1/.libs/libcontextsubscribertime1.so* .') + os.system('cp ../testplugins/timeplugin2/.libs/libcontextsubscribertime2.so* .') self.context_client = Popen(["context-listen","Test.Time"],stdin=PIPE,stdout=PIPE,stderr=PIPE) @@ -61,14 +60,16 @@ class Subscription(unittest.TestCase): proc_kill(self.context_client.pid) os.remove('time.context') - os.remove('libcontextsubscribertime*.so.*') + os.system('rm libcontextsubscribertime*.so*') def testChangingPlugin(self): # Copy the declaration file, declaring libcontextsubscribertime1 plugin. os.system('cp time1.context.temp time.context.temp') os.system('mv time.context.temp time.context') + #print "now reading" actual = self.context_client.stdout.readline().rstrip() + #print actual # The client got a value provided by the libcontextsubscribertime1 self.assertEqual(actual.startswith("Test.Time = QString:Time1: "), True, "Got: %s" % actual) -- cgit v1.2.3 From b0a42cb695b7da69545ce8ffe596740b7bab7a92 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Mon, 14 Sep 2009 13:47:24 +0300 Subject: Removing the bluez plugin; now it lives in contextkit-maemo. --- libcontextsubscriber/Makefile.am | 2 +- .../customer-tests/bluez-plugin/.gitignore | 1 - .../customer-tests/bluez-plugin/Makefile.am | 25 - .../customer-tests/bluez-plugin/bluez_stub.py | 645 --------------------- .../bluez-plugin/testbluezplugin.cpp | 159 ----- .../customer-tests/bluez-plugin/testbluezplugin.h | 48 -- .../customer-tests/bluez-plugin2/bluez.context | 7 - .../bluez-plugin2/test-bluez-plugin.py | 110 ---- libcontextsubscriber/customer-tests/runTests.sh | 2 +- libcontextsubscriber/plugins/Makefile.am | 1 - libcontextsubscriber/plugins/bluez/Makefile.am | 21 - libcontextsubscriber/plugins/bluez/bluez.context | 5 - .../plugins/bluez/bluezinterface.cpp | 125 ---- .../plugins/bluez/bluezinterface.h | 78 --- libcontextsubscriber/plugins/bluez/bluezplugin.cpp | 91 --- libcontextsubscriber/plugins/bluez/bluezplugin.h | 66 --- .../plugins/bluez/loggingfeatures.h | 27 - 17 files changed, 2 insertions(+), 1411 deletions(-) delete mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/.gitignore delete mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am delete mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py delete mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp delete mode 100644 libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h delete mode 100644 libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context delete mode 100644 libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py delete mode 100644 libcontextsubscriber/plugins/Makefile.am delete mode 100644 libcontextsubscriber/plugins/bluez/Makefile.am delete mode 100644 libcontextsubscriber/plugins/bluez/bluez.context delete mode 100644 libcontextsubscriber/plugins/bluez/bluezinterface.cpp delete mode 100644 libcontextsubscriber/plugins/bluez/bluezinterface.h delete mode 100644 libcontextsubscriber/plugins/bluez/bluezplugin.cpp delete mode 100644 libcontextsubscriber/plugins/bluez/bluezplugin.h delete mode 100644 libcontextsubscriber/plugins/bluez/loggingfeatures.h (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/Makefile.am b/libcontextsubscriber/Makefile.am index b19f837c..1a1294b0 100644 --- a/libcontextsubscriber/Makefile.am +++ b/libcontextsubscriber/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = src plugins unit-tests customer-tests multithreading-tests cli reg-cli update-contextkit-providers doc man +SUBDIRS = src unit-tests customer-tests multithreading-tests cli reg-cli update-contextkit-providers doc man pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = contextsubscriber-1.0.pc diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/.gitignore b/libcontextsubscriber/customer-tests/bluez-plugin/.gitignore deleted file mode 100644 index a05fc209..00000000 --- a/libcontextsubscriber/customer-tests/bluez-plugin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test-bluez-plugin diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am b/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am deleted file mode 100644 index 93d69310..00000000 --- a/libcontextsubscriber/customer-tests/bluez-plugin/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -bin_PROGRAMS = test-bluez-plugin - -# test's sources -test_bluez_plugin_SOURCES = testbluezplugin.cpp testbluezplugin.h - -# only include these files in the coverage -COVERAGE_FILES = bluezplugin.cpp bluezinterface.cpp -# FIXME: how to tell where the coverage files are? - -# do the testing, coverage, etc. stuff -# tests.am is using +=, so we have to set a value here for these four always -AM_CXXFLAGS = $(QtDBus_CFLAGS) '-I$(srcdir)/../util/' '-I$(srcdir)/../../src/' -AM_LDFLAGS = $(QtDBus_LIBS) -FROM_SOURCE = # copy these files from the real source -FROM_SOURCE_DIR = $(srcdir)/../../src -LDADD = -include $(top_srcdir)/am/tests.am - -nodist_test_bluez_plugin_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(test_bluez_plugin_SOURCES)) #$(FROM_SOURCE)) -include $(top_srcdir)/am/qt.am - -# Running the customer test -check-customer: - LD_LIBRARY_PATH=$(builddir)/../../plugins/bluez/.libs/ ./test-bluez-plugin diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py b/libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py deleted file mode 100644 index 52c89a3b..00000000 --- a/libcontextsubscriber/customer-tests/bluez-plugin/bluez_stub.py +++ /dev/null @@ -1,645 +0,0 @@ -#!/usr/bin/env python2.5 -## -## @file bluez_stub.py -## -## Copyright (C) 2008 Nokia. All rights reserved. -## -## @author Aapo Makela -## -## This python file export a DBUS server, which emulates the -## objects/interfaces provided by bluez-utils daemon(s). -## It is used for testing conbtui API. -## -## Requires python2.5-gobject and python2.5-dbus -## -## Implements also some testing API: -## -## org.bluez -## / -## org.bluez.Manager.Testing -## -## AddAdapter (string bt_address): objpath -## -## RemoveAdapter (object adapter) -## -## SetDefaultAdapter (object adapter) -## -## SetError (string error) -## -## org.bluez -## /hci{0, 1, ...} -## org.bluez.Adapter.Testing -## -## AddDeviceAround (string bt_address, string name, Uint32 cod, array{string} UUIDs) -## -## TestAgentRequest (string what ("PinCode", "Passkey", "Confirmation")) -## -## SetError (string error) -## -## org.bluez -## /hci{0, 1, ...}/dev_XX_XX_XX_XX_XX_XX -## org.bluez.Device.Testing -## -## Connect () -## -## SetError (string error) -## - -import time -import dbus -import dbus.service -from dbus.mainloop.glib import DBusGMainLoop -import gobject - -class BluezException(dbus.DBusException): - def __init__(self, error_name): - dbus.DBusException.__init__(self) - self._dbus_error_name = "org.bluez.Error." + error_name - -class BluetoothDevice: - - def __init__(self, bt_address, name = "", cod = 0, - uuids = dbus.Array(signature="s")): - # Set properties - self.properties = {} - self.properties["Address"] = bt_address - self.properties["Name"] = name - self.properties["Class"] = dbus.UInt32(cod) - self.properties["Paired"] = dbus.Boolean(False) - self.properties["Connected"] = dbus.Boolean(False) - self.properties["Trusted"] = dbus.Boolean(False) - self.properties["Alias"] = self.properties["Name"] - self.properties["UUIDs"] = uuids - - def __cmp__(self, other): - return cmp(self.properties["Address"], other.properties["Address"]) - -# Device stuff -class BluezDevice(BluetoothDevice, dbus.service.Object): - name = "" - path = "" - error = "" - - def __init__(self, main_loop, adapter, bt_address, properties = {}): - # Here the object path - self.path = adapter + "/dev_" + bt_address.replace(":", "_") - - BluetoothDevice.__init__(self, bt_address) - dbus.service.Object.__init__(self, dbus.SystemBus(), self.path) - - self.properties = {} - if properties: - self.properties = properties - self.properties["Adapter"] = dbus.ObjectPath(adapter) - self.main_loop = main_loop - self.stopped = False - - @dbus.service.method(dbus_interface='org.bluez.Device', - in_signature='', out_signature='a{sv}') - def GetProperties(self): - if self.error: - raise BluezException(self.error) - - return self.properties - - @dbus.service.method(dbus_interface='org.bluez.Device', - in_signature='sv', out_signature='') - def SetProperty(self, name, value): - if self.error: - raise BluezException(self.error) - - if name not in self.properties.keys(): - raise BluezException("DoesNotExist") - if name in ("Address", "Name", "UUIDs", "Paired", "Connected", "Adapter"): - raise BluezException("InvalidArguments") - - if name == "Alias" and value == "": - self.properties[name] = self.properties["Name"] - self.PropertyChanged(name, self.properties["Name"]) - else: - self.properties[name] = value - self.PropertyChanged(name, value) - - @dbus.service.method(dbus_interface='org.bluez.Device', - in_signature='', out_signature='') - def Disconnect(self): - if self.error: - raise BluezException(self.error) - - if self.properties["Connected"] == False: - raise BluezException("NotConnected") - - self.DisconnectRequested() - time.sleep(2) - self.properties["Connected"] = False - self.PropertyChanged("Connected", False) - - # - # DBUS signals - # - - @dbus.service.signal(dbus_interface='org.bluez.Device', - signature='') - def DisconnectRequested(self): - print "device DisconnectedRequested signal" - - @dbus.service.signal(dbus_interface='org.bluez.Device', - signature='sv') - def PropertyChanged(self, name, value): - print "device PropertyChanged(%s, %s) signal" % (str(name), str(value)) - - # - # DBUS test methods - # - - @dbus.service.method(dbus_interface='org.bluez.Device.Testing', - in_signature='', out_signature='') - def Connect(self): - self.properties["Connected"] = True - self.PropertyChanged("Connected", True) - - @dbus.service.method(dbus_interface='org.bluez.Device.Testing', - in_signature='s', out_signature='') - def SetError(self, error): - self.error = error - - -# Adapter stuff -class BluezAdapter(dbus.service.Object): - - properties = {} - name = "" - global_agent = None - devices_around = [BluetoothDevice("11:22:33:44:55:66", "Phone", 5898764), - BluetoothDevice("22:33:44:55:66:77", "Tablet", 1048852)] - devices = {} - stopped = True - error = "" - - def __init__(self, main_loop, path, bt_address): - # Here the object path - self.path = path - dbus.service.Object.__init__(self, dbus.SystemBus(), self.path) - - self.main_loop = main_loop - self.stopped = False - - # Set properties - self.properties["Address"] = bt_address - self.properties["Name"] = "Test" - self.properties["Powered"] = False - self.properties["Discoverable"] = False - self.properties["DiscoverableTimeout"] = dbus.UInt32(180) - self.properties["Discovering"] = dbus.Boolean(False) - - self.pairing_return_cb = None - self.pairing_error_cb = None - self.new_device = None - self.agent = None - self.timeout = 0 - self.sessions = 0 - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='', out_signature='a{sv}') - def GetProperties(self): - if self.error: - raise BluezException(self.error) - - return self.properties - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='sv', out_signature='') - def SetProperty(self, name, value): - if self.error: - raise BluezException(self.error) - - if name not in self.properties.keys(): - raise BluezException("DoesNotExist") - if name in ("Address"): - raise BluezException("InvalidArguments") - self.properties[name] = value - self.PropertyChanged(name, value) - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='', out_signature='') - def RequestSession(self): - if self.sessions == 0 and not self.properties["Powered"]: - if self.global_agent: - try: - if self.properties["Discoverable"]: - self.global_agent.ConfirmModeChange("discoverable") - else: - self.global_agent.ConfirmModeChange("connectable") - except dbus.DBusException: - raise BluezException("Rejected") - self.properties["Powered"] = True - self.PropertyChanged("Powered", True) - self.sessions += 1 - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='', out_signature='') - def ReleaseSession(self): - self.sessions -= 1 - if self.sessions == 0: - self.properties["Powered"] = False - self.PropertyChanged("Powered", False) - if self.sessions < 0: - self.sessions = 0 - - def discover_device_timeout(self): - if self.stopped == True or self.idx >= len(self.devices_around): - self.timeout = gobject.timeout_add(30000, self.discover_device_timeout) - return False - - properties = self.devices_around[self.idx].properties.copy() - properties["RSSI"] = dbus.Int16(-60) - if properties.has_key("UUIDs"): - del properties["UUIDs"] - self.DeviceFound(properties["Address"], properties) - self.idx += 1 - return True - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='', out_signature='') - def StartDiscovery(self): - if self.error: - raise BluezException(self.error) - - self.idx = 0 - self.stopped = False - self.timeout = gobject.timeout_add(3000, self.discover_device_timeout) - self.SetProperty("Discovering", dbus.Boolean(True)) - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='', out_signature='') - def StopDiscovery(self): - if self.error: - raise BluezException(self.error) - - self.stopped = True - if self.timeout: - self.SetProperty("Discovering", dbus.Boolean(False)) - gobject.source_remove(self.timeout) - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='s', out_signature='o') - def FindDevice(self, address): - if self.error: - raise BluezException(self.error) - - for path, device in self.devices.items(): - if device.properties["Address"] == address: - return path - raise BluezException("DoesNotExist") - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='', out_signature='ao') - def ListDevices(self): - if self.error: - raise BluezException(self.error) - - keys = self.devices.keys() - keys.sort() - return keys - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='s', out_signature='') - def CancelDeviceCreation(self, address): - pass - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='s', out_signature='o') - def CreateDevice(self, address): - if self.error: - raise BluezException(self.error) - - for device in self.devices_around: - if device.properties["Address"] == address: - new_device = BluezDevice(self.main_loop, self.path, - device.properties["Address"], - device.properties) - self.devices[new_device.path] = new_device - self.DeviceCreated(new_device.path) - # TODO: add UUIDs - return new_device.path - raise BluezException("Failed") - - def pincode_reply(self, passkey): - print "pincode_reply %s" % str(passkey) - self.passkey = passkey - self.stopped = True - - if self.passkey != "1234": - self.pairing_error_cb(BluezException("Failed")) - else: - self.new_device.properties["Paired"] = True - self.pairing_return_cb(self.new_device.path) - - if self.timeout: - gobject.source_remove(self.timeout) - self.pairing_error_cb = None - self.pairing_return_cb = None - - def passkey_error(self, error): - print "passkey_error" - self.stopped = True - if self.timeout: - gobject.source_remove(self.timeout) - if self.pairing_error_cb: - self.pairing_error_cb (error) - self.pairing_error_cb = None - self.pairing_return_cb = None - - def passkey_timeout(self): - print "passkey_timeout" - if not self.pairing_error_cb: - return - - self.pairing_error_cb(BluezException("Failed")) - self.agent.Cancel(dbus_interface="org.bluez.Agent") - self.RemoveDevice(self.new_device.path) - self.pairing_error_cb = None - self.pairing_return_cb = None - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='sos', out_signature='o', - sender_keyword='sender', - async_callbacks=("return_cb", "error_cb")) - def CreatePairedDevice(self, address, agent_name, capability, return_cb, error_cb, sender): - if self.error: - raise BluezException(self.error) - - self.agent = dbus.SystemBus().get_object(sender, agent_name, introspect = False) - new_device = None - device_found = False - - for obj_path, device in self.devices.items(): - if device.properties["Address"] == address: - if device.properties["Paired"] == True: - raise BluezException("Failed") - new_device = device - device_found = True - break - - if new_device is None: - for device in self.devices_around: - if device.properties["Address"] == address: - new_device = BluezDevice(self.main_loop, self.path, - device.properties["Address"], - device.properties) - # TODO: add UUIDs - self.devices[new_device.path] = new_device - self.DeviceCreated(new_device.path) - break - - if new_device is None: - raise BluezException("Failed") - - self.pairing_return_cb = return_cb - self.pairing_error_cb = error_cb - - self.new_device = new_device - self.agent.RequestPinCode(dbus.ObjectPath(new_device.path), - dbus_interface="org.bluez.Agent", - reply_handler=self.pincode_reply, - error_handler=self.passkey_error) - - self.timeout = gobject.timeout_add(10000, self.passkey_timeout) - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='o', out_signature='') - def RemoveDevice(self, device_path): - if self.error: - raise BluezException(self.error) - - if not self.devices.has_key(device_path): - raise BluezException("Failed") - - del self.devices[device_path] - self.DeviceRemoved(device_path) - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='os', out_signature='', - sender_keyword='sender') - def RegisterAgent(self, agent_name, capability, sender = None): - if self.error: - raise BluezException(self.error) - - bus = dbus.SystemBus() - self.global_agent = bus.get_object(sender, agent_name, introspect = False) - - @dbus.service.method(dbus_interface='org.bluez.Adapter', - in_signature='o', out_signature='') - def UnregisterAgent(self, agent_name): - if self.error: - raise BluezException(self.error) - - #self.agents[agent_name].Release() - del self.global_agent - - # - # DBUS signals - # - - @dbus.service.signal(dbus_interface='org.bluez.Adapter', - signature='sv') - def PropertyChanged(self, name, value): - print "adapter PropertyChanged (%s, %s) signal" % (str(name), str(value)) - - @dbus.service.signal(dbus_interface='org.bluez.Adapter', - signature='sa{sv}') - def DeviceFound(self, address, values): - print "adapter DeviceFound signal" - - @dbus.service.signal(dbus_interface='org.bluez.Adapter', - signature='s') - def DeviceDisappeared(self, address): - print "adapter DeviceDisappeared signal" - - @dbus.service.signal(dbus_interface='org.bluez.Adapter', - signature='o') - def DeviceCreated(self, device): - print "adapter DeviceCreated signal" - - @dbus.service.signal(dbus_interface='org.bluez.Adapter', - signature='o') - def DeviceRemoved(self, device): - print "adapter DeviceRemoved signal" - - # - # DBUS test methods - # - - @dbus.service.method(dbus_interface='org.bluez.Adapter.Testing', - in_signature='ssuas', out_signature='') - def AddDeviceAround(self, bt_address, name, cod, uuids): - self.devices_around.append(BluetoothDevice(bt_address, name, cod, uuids)) - - def null_reply(self, passkey = None): - pass - - @dbus.service.method(dbus_interface='org.bluez.Adapter.Testing', - in_signature='s', out_signature='') - def TestAgentRequest(self, what): - if what not in ("PinCode", "Passkey", "Confirmation"): - raise BluezException("WrongMethod") - - new_device = BluezDevice(self.main_loop, self.path, - self.devices_around[0].properties["Address"], - self.devices_around[0].properties) - self.devices[new_device.path] = new_device - self.DeviceCreated(new_device.path) - - agent_obj = self.global_agent - if what == "PinCode": - agent_obj.RequestPinCode(dbus.ObjectPath(new_device.path), - dbus_interface="org.bluez.Agent", - reply_handler=self.null_reply, - error_handler=self.null_reply) - elif what == "Passkey": - agent_obj.RequestPasskey(dbus.ObjectPath(new_device.path), - dbus_interface="org.bluez.Agent", - reply_handler=self.null_reply, - error_handler=self.null_reply) - elif what == "Confirmation": - agent_obj.RequestConfirmation(dbus.ObjectPath(new_device.path), - dbus.UInt32(111111), - dbus_interface="org.bluez.Agent", - reply_handler=self.null_reply, - error_handler=self.null_reply) - - @dbus.service.method(dbus_interface='org.bluez.Adapter.Testing', - in_signature='s', out_signature='') - def SetError(self, error): - self.error = error - - -# Manager stuff -class BluezManager(dbus.service.Object): - - adapters = [] - default_adapter = 0 - error = "" - - def __init__(self, main_loop): - # Here the object path - dbus.service.Object.__init__(self, - dbus.service.BusName("org.bluez", bus=dbus.SystemBus()), - "/") - - self.main_loop = main_loop - self.stopped = False - - # - # DBUS methods - # - - @dbus.service.method(dbus_interface='org.bluez.Manager', - in_signature='', out_signature='o') - def DefaultAdapter(self): - if self.error: - raise BluezException(self.error) - - if not self.adapters: - raise BluezException("NoSuchAdapter") - - return (self.adapters[self.default_adapter]) - - @dbus.service.method(dbus_interface='org.bluez.Manager', - in_signature='s', out_signature='o') - def FindAdapter(self, pattern): - if self.error: - raise BluezException(self.error) - - adapter_idx = 0 - for adapter in self.adapters: - if adapter.name.find(pattern) != -1: - return (adapter) - if adapter.properties["Address"].find(pattern) != -1: - return (adapter) - raise BluezException("NoSuchAdapter") - - @dbus.service.method(dbus_interface='org.bluez.Manager', - in_signature='', out_signature='ao') - def ListAdapters(self): - if self.error: - raise BluezException(self.error) - - return (self.adapters) - - # - # DBUS signals - # - - @dbus.service.signal(dbus_interface='org.bluez.Manager', - signature='o') - def AdapterAdded(self, adapter): - print "manager AdapterAdded signal" - - @dbus.service.signal(dbus_interface='org.bluez.Manager', - signature='o') - def AdapterRemoved(self, adapter): - print "manager AdapterRemoved signal" - - @dbus.service.signal(dbus_interface='org.bluez.Manager', - signature='o') - def DefaultAdapterChanged(self, adapter): - print "manager DefaultAdapterChanged signal" - - # - # DBUS test methods - # - - @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', - in_signature='s', out_signature='o') - def AddAdapter(self, bt_address): - new_path = "/org/bluez/hci%d" % (len(self.adapters)) - adapter = BluezAdapter(self.main_loop, new_path, bt_address) - self.adapters.append(adapter) - self.AdapterAdded(adapter) - - # Set default adapter, if this is the only one - if len(self.adapters) == 1: - self.default_adapter = 0 - self.DefaultAdapterChanged(self.adapters[self.default_adapter]) - return adapter - - @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', - in_signature='o', out_signature='') - def RemoveAdapter(self, adapter_name): - for adapter in self.adapters: - if adapter.name == adapter_name[1:]: - self.AdapterRemoved(adapter) - if self.default_adapter == self.adapters.index(adapter): - self.default_adapter = 0 - if len(self.adapters) > 1: - self.DefaultAdapterChanged(self.adapters[self.default_adapter]) - self.adapters.remove(adapter) - return - raise BluezException("NoSuchAdapter") - - @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', - in_signature='o', out_signature='') - def SetDefaultAdapter(self, adapter_name): - for adapter in self.adapters: - if adapter.name == adapter_name[1:]: - self.default_adapter = self.adapters.index(adapter) - self.DefaultAdapterChanged(self.adapters[self.default_adapter]) - return - raise BluezException("NoSuchAdapter") - - @dbus.service.method(dbus_interface='org.bluez.Manager.Testing', - in_signature='s', out_signature='') - def SetError(self, error): - self.error = error - - -# Main stuff -if __name__ == "__main__": - DBusGMainLoop(set_as_default=True) - - # Here register the service name - loop = gobject.MainLoop() - manager_server = BluezManager(loop) - loop.run() - diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp deleted file mode 100644 index 73b1c68a..00000000 --- a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 - * - */ - -// Header file of the tests -#include "testbluezplugin.h" - -// Plugin interface definition -#include "iproviderplugin.h" - -// Temporary: plugin header files -#include "bluezplugin.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -typedef ContextSubscriber::IProviderPlugin* (*PluginFactoryFunc)(const QString& constructionString); - -// -// Definition of testcases -// - -// Before all tests -void BluezPluginTests::initTestCase() -{ -} - -// After all tests -void BluezPluginTests::cleanupTestCase() -{ -} - -// Before each test -void BluezPluginTests::init() -{ - library = new QLibrary("libcontextsubscriberbluez"); - bluezProcess = new QProcess(); -} - -// After each test -void BluezPluginTests::cleanup() -{ - if (bluezProcess) { - bluezProcess->kill(); - bluezProcess->waitForFinished(); - } - delete library; - library = 0; - delete bluezProcess; - bluezProcess = 0; -} - -// Helpers -bool BluezPluginTests::startBluez() -{ - // Run the bluez stub - bluezProcess->start("python bluez_stub.py"); // FIXME: srcdir! - bool ok = bluezProcess->waitForStarted(); - - if (!ok) { - qDebug() << "Cannot start process"; - return false; - } - sleep(3); - // Unfortunately, we cannot guarantee that the stub process gets - // enough time to start its D-Bus operations before the test - // proceeds. - - // Make it create a default adapter - QDBusConnection connection = QDBusConnection::systemBus(); - QDBusMessage message = QDBusMessage::createMethodCall ("org.bluez", "/", "org.bluez.Manager.Testing", "AddAdapter"); - - QList argumentList; - QVariant s("dummy-bt-address"); - argumentList.append(s); - message.setArguments(argumentList); - - QDBusMessage reply = connection.call(message); - if (reply.type() == QDBusMessage::ReplyMessage) { - return true; - } - qDebug() << "Invalid reply:" << reply.errorMessage(); - - return false; -} - - -// Test cases - -void BluezPluginTests::loading() -{ - /*library->load(); - qDebug() << library->errorString(); - QVERIFY(library->isLoaded()); - PluginFactoryFunc f = (PluginFactoryFunc) library->resolve("bluezPluginFactory"); - QVERIFY(f); - */ - // FIXME: implement the test when plugin loading / building is more clear -} - -void BluezPluginTests::normalOperation() -{ - // Start BlueZ stub - QVERIFY(startBluez()); - - // Test: Create plugin - ContextSubscriberBluez::BluezPlugin* bluezPlugin = new ContextSubscriberBluez::BluezPlugin(); - // FIXME: use the same way to create the plugin than libcontextsubscriber does - QSignalSpy readySpy(bluezPlugin, SIGNAL(ready())); - QSignalSpy subscribeFinishedSpy(bluezPlugin, SIGNAL(subscribeFinished(QString))); - QSignalSpy subscribeFailedSpy(bluezPlugin, SIGNAL(subscribeFailed(QString, QString))); - - // Expected result: the plugin emits ready() at some point. - QDateTime start = QDateTime::currentDateTime(); - while (readySpy.count() != 1 && start.secsTo(QDateTime::currentDateTime()) < 3) { - QCoreApplication::processEvents(); - } - QCOMPARE(readySpy.count(), 1); - - // Test: subscribe to keys - QSet keys; - keys << "Bluetooth.Visible"; - keys << "Bluetooth.Enabled"; - bluezPlugin->subscribe(keys); - - // Expected result: the plugin emits subscribeFinished for those keys - start = QDateTime::currentDateTime(); - while (subscribeFinishedSpy.count() < 2 && start.secsTo(QDateTime::currentDateTime()) < 3) { - QCoreApplication::processEvents(); - } - QCOMPARE(subscribeFinishedSpy.count(), 2); - QCOMPARE(subscribeFailedSpy.count(), 0); -} - - -QTEST_MAIN(BluezPluginTests); diff --git a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h b/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h deleted file mode 100644 index 6387f887..00000000 --- a/libcontextsubscriber/customer-tests/bluez-plugin/testbluezplugin.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 - * - */ - -#include - -class QLibrary; -class QProcess; - -class BluezPluginTests : public QObject -{ - Q_OBJECT - - // Tests -private slots: - // Init and cleanup helper functions - void initTestCase(); - void cleanupTestCase(); - void init(); - void cleanup(); - - // Test cases - void loading(); - void normalOperation(); - //void bluezNotPresent(); - //void bluezDisappearsAndAppears(); -private: - bool startBluez(); - QLibrary* library; - QProcess* bluezProcess; -}; diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context b/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context deleted file mode 100644 index 36b8a68b..00000000 --- a/libcontextsubscriber/customer-tests/bluez-plugin2/bluez.context +++ /dev/null @@ -1,7 +0,0 @@ - - - TRUTH - TRUTH - diff --git a/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py b/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py deleted file mode 100644 index 7bb58080..00000000 --- a/libcontextsubscriber/customer-tests/bluez-plugin2/test-bluez-plugin.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python -## -## This file is part of ContextKit. -## -## Copyright (C) 2009 Nokia. All rights reserved. -## -## Contact: Marius Vollmer -## -## 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 -## -## -## Requires python2.5-gobject and python2.5-dbus -## -import sys -import unittest -import os -import string -from subprocess import Popen, PIPE -import time -import signal -from time import sleep - -def proc_kill(pid): - os.system('../common/rec-kill.sh %d' % pid) - -def timeoutHandler(signum, frame): - raise Exception('Tests have been running for too long') - -def stdoutRead (object,lines): - list = [] - for i in range(lines): - list.append(object.stdout.readline().rstrip()) - return list - -def set_bluez_property(property, value): - os.system('dbus-send --system --dest=org.bluez --print-reply --type=method_call /org/bluez/`pidof bluetoothd`/hci0 org.bluez.Adapter.SetProperty string:%s variant:boolean:%s' % (property, value)) - time.sleep(1) - - -class BluezPlugin(unittest.TestCase): - - def setUp(self): - os.environ["CONTEXT_PROVIDERS"] = "." - os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] = "../../plugins/bluez/.libs/" - # FIXME: this won't work in the test package... - - # Make Bluetooth invisible and un-enabled - # Note: This test will alter the bluetooth settings of the system! - - set_bluez_property("Discoverable", "false") - set_bluez_property("Powered", "false") - - self.context_client = Popen(["context-listen","Bluetooth.Enabled","Bluetooth.Visible"],stdin=PIPE,stdout=PIPE,stderr=PIPE) - self.initial_output = stdoutRead(self.context_client, 2) - self.initial_output.sort() - - def tearDown(self): - - # Restore some default values for Bluez - set_bluez_property("Powered", "true") - set_bluez_property("Discoverable", "false") - - proc_kill(self.context_client.pid) - - def testInitial(self): - self.assertEqual(self.initial_output[0].strip(), "Bluetooth.Enabled = bool:false") - self.assertEqual(self.initial_output[1].strip(), "Bluetooth.Visible = bool:false") - - def testEnabledAndVisible(self): - # Enable - set_bluez_property("Powered", "true") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Enabled = bool:true"] - self.assertEqual(actual, expected) - - # Set visible - set_bluez_property("Discoverable", "true") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Visible = bool:true"] - self.assertEqual(actual, expected) - - # Set invisible - set_bluez_property("Discoverable", "false") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Visible = bool:false"] - self.assertEqual(actual, expected) - - # Disable - set_bluez_property("Powered", "false") - actual = stdoutRead(self.context_client,1) - expected = ["Bluetooth.Enabled = bool:false"] - self.assertEqual(actual, expected) - -if __name__ == "__main__": - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) - signal.signal(signal.SIGALRM, timeoutHandler) - signal.alarm(30) - unittest.main() diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index d933341a..2015357b 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -1,7 +1,7 @@ #!/bin/bash cd $(dirname $0) -DIRS="commander subscription asynchronicity registry bluez-plugin2 pluginchanging" +DIRS="commander subscription asynchronicity registry pluginchanging" export PYTHONPATH="`pwd`/common/" if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] diff --git a/libcontextsubscriber/plugins/Makefile.am b/libcontextsubscriber/plugins/Makefile.am deleted file mode 100644 index a05dd1e9..00000000 --- a/libcontextsubscriber/plugins/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = bluez diff --git a/libcontextsubscriber/plugins/bluez/Makefile.am b/libcontextsubscriber/plugins/bluez/Makefile.am deleted file mode 100644 index 98ee0c98..00000000 --- a/libcontextsubscriber/plugins/bluez/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -lib_LTLIBRARIES = libcontextsubscriberbluez.la -libcontextsubscriberbluez_la_SOURCES = bluezinterface.cpp \ - bluezinterface.h bluezplugin.cpp bluezplugin.h \ - loggingfeatures.h - -AM_CXXFLAGS = -I$(top_srcdir)/common -I$(srcdir)/../../src \ - $(QtCore_CFLAGS) $(QtDBus_CFLAGS) \ - '-DCONTEXT_LOG_MODULE_NAME="bluezplugin"' - -$(top_builddir)/common/libcommon.a: - $(MAKE) -C $(top_builddir)/common libcommon.a - -LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) -libcontextsubscriberbluez_la_LIBADD=$(top_builddir)/common/libcommon.la - -.PHONY: $(top_builddir)/common/libcommon.la - -# moccing -nodist_libcontextsubscriberbluez_la_SOURCES = mocs.cpp -QT_TOMOC = $(filter %.h, $(libcontextsubscriberbluez_la_SOURCES)) -include $(top_srcdir)/am/qt.am diff --git a/libcontextsubscriber/plugins/bluez/bluez.context b/libcontextsubscriber/plugins/bluez/bluez.context deleted file mode 100644 index fc8ca0d6..00000000 --- a/libcontextsubscriber/plugins/bluez/bluez.context +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp b/libcontextsubscriber/plugins/bluez/bluezinterface.cpp deleted file mode 100644 index 799e252c..00000000 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 - * - */ - -#include "bluezinterface.h" -#include "logging.h" - -#include -#include -#include -#include - -namespace ContextSubscriberBluez { - -const QString BluezInterface::serviceName = "org.bluez"; -const QString BluezInterface::managerPath = "/"; -const QString BluezInterface::managerInterface = "org.bluez.Manager"; -const QString BluezInterface::adapterInterface = "org.bluez.Adapter"; -QDBusConnection BluezInterface::busConnection = QDBusConnection::systemBus(); - -BluezInterface::BluezInterface() : manager(0), adapter(0) -{ - busConnection.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "NameOwnerChanged", - this, SLOT(onNameOwnerChanged(QString, QString, QString))); -} - -/// Called when the nameOwnerChanged signal is received over D-Bus. -void BluezInterface::onNameOwnerChanged(QString name, QString /*oldOwner*/, QString newOwner) -{ - if (name == serviceName) { - if (newOwner != "") { - // BlueZ appeared -> connect to it. If successful, ready() - // will be emitted when the connection is established. - connectToBluez(); - } - else { - // BlueZ disappeared - emit failed("BlueZ left D-Bus"); - } - } -} - -/// Try to establish the connection to BlueZ. -void BluezInterface::connectToBluez() -{ - if (adapter) { - busConnection.disconnect(serviceName, - adapterPath, - adapterInterface, - "PropertyChanged", - this, SLOT(onPropertyChanged(QString, QDBusVariant))); - delete adapter; - adapter = 0; - } - if (manager) { - delete manager; - manager = 0; - } - - manager = new QDBusInterface(serviceName, managerPath, managerInterface, busConnection, this); - manager->callWithCallback("DefaultAdapter", QList(), this, - SLOT(replyDefaultAdapter(QDBusObjectPath)), - SLOT(replyDBusError(QDBusError))); -} - -/// Called when a D-Bus error occurs when processing our -/// callWithCallback. -void BluezInterface::replyDBusError(QDBusError err) -{ - contextWarning() << "DBus error occured:" << err.message(); - emit failed("Cannot connect to BlueZ:" + err.message()); -} - -/// Called when the DefaultAdapter D-Bus call is done. -void BluezInterface::replyDefaultAdapter(QDBusObjectPath path) -{ - contextDebug(); - adapterPath = path.path(); - adapter = new QDBusInterface(serviceName, adapterPath, adapterInterface, busConnection, this); - busConnection.connect(serviceName, - path.path(), - adapterInterface, - "PropertyChanged", - this, SLOT(onPropertyChanged(QString, QDBusVariant))); - adapter->callWithCallback("GetProperties", QList(), this, - SLOT(replyGetProperties(QMap)), - SLOT(replyDBusError(QDBusError))); - emit ready(); -} - -/// Connected to the D-Bus signal PropertyChanged from BlueZ / adaptor. -void BluezInterface::onPropertyChanged(QString key, QDBusVariant value) -{ - contextDebug() << key << value.variant().toString(); - emit propertyChanged(key, value.variant()); -} - -/// Called when the GetProperties D-Bus call is done. -void BluezInterface::replyGetProperties(QMap map) -{ - contextDebug(); - foreach(const QString& key, map.keys()) - emit propertyChanged(key, map[key]); -} - -} // end namespace - diff --git a/libcontextsubscriber/plugins/bluez/bluezinterface.h b/libcontextsubscriber/plugins/bluez/bluezinterface.h deleted file mode 100644 index 204d3449..00000000 --- a/libcontextsubscriber/plugins/bluez/bluezinterface.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 BLUEZINTERFACE_H -#define BLUEZINTERFACE_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ContextSubscriberBluez -{ - -/*! - - \class BluezInterface - - \brief Communicates with bluetoothd over D-Bus and signals the - changes in Bluez properties. - - */ -class BluezInterface : public QObject -{ - Q_OBJECT -public: - BluezInterface(); - void connectToBluez(); - -signals: - void propertyChanged(QString key, QVariant value); - void ready(); - void failed(QString error); - -private slots: - void replyDBusError(QDBusError err); - void replyDefaultAdapter(QDBusObjectPath path); - void replyGetProperties(QMap map); - void onPropertyChanged(QString key, QDBusVariant value); - void onNameOwnerChanged(QString name, QString oldOwner, QString newOwner); -private: - void onPropertyChanged(QString key, QVariant value); - - QDBusInterface* manager; - QDBusInterface* adapter; - QString adapterPath; - static const QString serviceName; - static const QString managerPath; - static const QString managerInterface; - static const QString adapterInterface; - static QDBusConnection busConnection; -}; - -} -#endif diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp b/libcontextsubscriber/plugins/bluez/bluezplugin.cpp deleted file mode 100644 index 59bd6ad6..00000000 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 - * - */ - -#include "bluezplugin.h" -#include "sconnect.h" - -#include "logging.h" - -/// The factory method for constructing the IPropertyProvider instance. -IProviderPlugin* pluginFactory(const QString& /*constructionString*/) -{ - // Note: it's the caller's responsibility to delete the plugin if - // needed. - return new ContextSubscriberBluez::BluezPlugin(); -} - -namespace ContextSubscriberBluez { - -/// Constructor. Construct the BluezInterface which handles the D-Bus -/// connection, and tell it to try to connect to Bluez right away. -BluezPlugin::BluezPlugin() -{ - // Connect signals from the Bluez interface. The events we listen to are: - // - interface getting connected to Bluez - // - interface failing to connect to Bluez - // - interface losing connection to Bluez - // - Bluez property changing - sconnect(&bluezInterface, SIGNAL(ready()), - this, SIGNAL(ready())); - sconnect(&bluezInterface, SIGNAL(failed(QString)), - this, SIGNAL(failed(QString))); - sconnect(&bluezInterface, SIGNAL(propertyChanged(QString, QVariant)), - this, SLOT(onPropertyChanged(QString, QVariant))); - bluezInterface.connectToBluez(); - - // Create a mapping from Bluez properties to Context Properties - properties["Powered"] = "Bluetooth.Enabled"; - properties["Discoverable"] = "Bluetooth.Visible"; -} - -/// Implementation of the IPropertyProvider::subscribe. We don't need -/// any extra work for subscribing to keys, thus subscribe is finished -/// right away. -void BluezPlugin::subscribe(QSet keys) -{ - contextDebug() << keys; - foreach(const QString& key, keys) { - emit subscribeFinished(key); - } -} - -/// Implementation of the IPropertyProvider::unsubscribe. We're not -/// keeping track on subscriptions, so we don't need to do anything. -void BluezPlugin::unsubscribe(QSet keys) -{ -} - -/// Called when a Bluez property changes. Check if the change is -/// relevant, and if so, signal the value change of the corresponding -/// context property. -void BluezPlugin::onPropertyChanged(QString key, QVariant value) -{ - contextDebug() << key << value.toString(); - if (properties.contains(key)) { - contextDebug() << "Prop changed:" << properties[key] << value.toString(); - emit valueChanged(properties[key], value); - // Note: the upper layer is responsible for checking if the - // value was a different one. - } -} - -} // end namespace - diff --git a/libcontextsubscriber/plugins/bluez/bluezplugin.h b/libcontextsubscriber/plugins/bluez/bluezplugin.h deleted file mode 100644 index 6fa9f9dc..00000000 --- a/libcontextsubscriber/plugins/bluez/bluezplugin.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 BLUEZPLUGIN_H -#define BLUEZPLUGIN_H - -#include "bluezinterface.h" -#include "iproviderplugin.h" // For IProviderPlugin definition - -using ContextSubscriber::IProviderPlugin; - -extern "C" { - IProviderPlugin* pluginFactory(const QString& constructionString); -} - -namespace ContextSubscriberBluez -{ - -/*! - \class BluezPlugin - - \brief A libcontextsubscriber plugin for communicating with Bluez - over D-Bus. Provides context properties Bluetooth.Enabled and - Bluetooth.Visible. - - */ - - -class BluezPlugin : public IProviderPlugin -{ - Q_OBJECT - -public: - explicit BluezPlugin(); - virtual void subscribe(QSet keys); - virtual void unsubscribe(QSet keys); - -private slots: - void onPropertyChanged(QString key, QVariant variant); - -private: - BluezInterface bluezInterface; - QMap properties; ///< Mapping of Bluez properties to Context FW properties - -}; -} - -#endif diff --git a/libcontextsubscriber/plugins/bluez/loggingfeatures.h b/libcontextsubscriber/plugins/bluez/loggingfeatures.h deleted file mode 100644 index 9e4008d8..00000000 --- a/libcontextsubscriber/plugins/bluez/loggingfeatures.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Contact: Marius Vollmer - * - * 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 BLUEZPLUGIN_LOGGINGFEATURES_H -#define BLUEZPLUGIN_LOGGINGFEATURES_H - -#define F_BLUEZPLUGIN (ContextFeature("bluezplugin")) - -#endif -- cgit v1.2.3 From 6e05fcef9d902caa54d048fb7355fff9086b3277 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Wed, 16 Sep 2009 11:14:35 +0300 Subject: Whitespace fixes. --- .../customer-tests/pluginchanging/time1.context.temp | 2 +- .../customer-tests/pluginchanging/time2.context.temp | 2 +- .../customer-tests/testplugins/timeplugin1/Makefile.am | 6 +++--- .../customer-tests/testplugins/timeplugin2/Makefile.am | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp b/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp index da09ce66..d29592fe 100644 --- a/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp +++ b/libcontextsubscriber/customer-tests/pluginchanging/time1.context.temp @@ -1,4 +1,4 @@ - STRING + STRING diff --git a/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp b/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp index 1cc5b656..c8a2757c 100644 --- a/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp +++ b/libcontextsubscriber/customer-tests/pluginchanging/time2.context.temp @@ -1,4 +1,4 @@ - STRING + STRING diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am index a7903652..723dfd06 100644 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin1/Makefile.am @@ -1,5 +1,5 @@ -lib_LTLIBRARIES = libcontextsubscribertime1.la -libcontextsubscribertime1_la_SOURCES = timeplugin.cpp timeplugin.h +lib_LTLIBRARIES = libcontextsubscribertime1.la +libcontextsubscribertime1_la_SOURCES = timeplugin.cpp timeplugin.h BUILT_SOURCES = $(libcontextsubscribertime1_la_SOURCES) timeplugin.cpp: ../timeplugin.cpp @@ -19,7 +19,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/common \ $(top_builddir)/common/libcommon.a: $(MAKE) -C $(top_builddir)/common libcommon.a -LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) +LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) libcontextsubscribertime1_la_LIBADD=$(top_builddir)/common/libcommon.la .PHONY: $(top_builddir)/common/libcommon.la diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am index 060efcad..6e1f27bc 100644 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin2/Makefile.am @@ -1,5 +1,5 @@ -lib_LTLIBRARIES = libcontextsubscribertime2.la -libcontextsubscribertime2_la_SOURCES = timeplugin.cpp timeplugin.h +lib_LTLIBRARIES = libcontextsubscribertime2.la +libcontextsubscribertime2_la_SOURCES = timeplugin.cpp timeplugin.h BUILT_SOURCES = $(libcontextsubscribertime2_la_SOURCES) timeplugin.cpp: ../timeplugin.cpp @@ -19,7 +19,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/common \ $(top_builddir)/common/libcommon.a: $(MAKE) -C $(top_builddir)/common libcommon.a -LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) +LIBS += $(CDB_LIBS) $(QtCore_LIBS) $(QtDBus_LIBS) libcontextsubscribertime2_la_LIBADD=$(top_builddir)/common/libcommon.la .PHONY: $(top_builddir)/common/libcommon.la -- cgit v1.2.3 From 1c3c8b563759d2ef2761124651e2a7979c619a25 Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Wed, 16 Sep 2009 11:56:04 +0300 Subject: libcontextsubscriber/customer-tests/testplugins: use invokeMethod instead of timer --- .../customer-tests/testplugins/timeplugin.cpp | 12 +----------- libcontextsubscriber/customer-tests/testplugins/timeplugin.h | 1 - 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp index 39b61016..6e3c4df0 100644 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin.cpp @@ -42,11 +42,7 @@ TimePlugin::TimePlugin() prefix = TIME_PLUGIN_PREFIX; timer.setInterval(2000); sconnect(&timer, SIGNAL(timeout()), this, SLOT(onTimeout())); - QTimer *t = new QTimer(this); - sconnect(t, SIGNAL(timeout()), this, SLOT(emitReady()), Qt::QueuedConnection); - t->setSingleShot(true); - t->setInterval(0); - t->start(); + QMetaObject::invokeMethod(this, "ready", Qt::QueuedConnection); } void TimePlugin::subscribe(QSet keys) @@ -63,12 +59,6 @@ void TimePlugin::unsubscribe(QSet keys) timer.stop(); } -void TimePlugin::emitReady() -{ - contextDebug(); - emit ready(); -} - void TimePlugin::onTimeout() { contextDebug() << "Timeout"; diff --git a/libcontextsubscriber/customer-tests/testplugins/timeplugin.h b/libcontextsubscriber/customer-tests/testplugins/timeplugin.h index 78f1ccc2..3a51fb5a 100644 --- a/libcontextsubscriber/customer-tests/testplugins/timeplugin.h +++ b/libcontextsubscriber/customer-tests/testplugins/timeplugin.h @@ -48,7 +48,6 @@ public: virtual void unsubscribe(QSet keys); private slots: - void emitReady(); void onTimeout(); private: -- cgit v1.2.3 From 34f6c51234261a8c88b56d99c07e18fa75b47764 Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Wed, 16 Sep 2009 11:56:23 +0300 Subject: libcontextsubscriber/src/provider.cpp: make the elseif block more like a switch --- libcontextsubscriber/src/provider.cpp | 54 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index 2f8e008f..aa110a08 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -115,43 +115,39 @@ void Provider::constructPlugin() if (pluginName == "contextkit-dbus") { plugin = contextKitPluginFactory(constructionString); } - else { - // Require the plugin name to start with / - if (pluginName.startsWith("/")) { - - // Enable overriding the plugin location with an environment variable - const char *pluginPath = getenv("CONTEXT_SUBSCRIBER_PLUGINS"); - if (! pluginPath) - pluginPath = DEFAULT_CONTEXT_SUBSCRIBER_PLUGINS; - - QString pluginFilename(pluginPath); - // Allow pluginPath to have a trailing / or not - if (pluginFilename.endsWith("/")) { - pluginFilename.chop(1); - } + else if (pluginName.startsWith("/")) { // Require the plugin name to start with / + // Enable overriding the plugin location with an environment variable + const char *pluginPath = getenv("CONTEXT_SUBSCRIBER_PLUGINS"); + if (! pluginPath) + pluginPath = DEFAULT_CONTEXT_SUBSCRIBER_PLUGINS; + + QString pluginFilename(pluginPath); + // Allow pluginPath to have a trailing / or not + if (pluginFilename.endsWith("/")) { + pluginFilename.chop(1); + } - pluginFilename.append(pluginName); + pluginFilename.append(pluginName); - QLibrary library(pluginFilename); - library.load(); + QLibrary library(pluginFilename); + library.load(); - if (library.isLoaded()) { - PluginFactoryFunc factory = (PluginFactoryFunc) library.resolve("pluginFactory"); - if (factory) { - contextDebug() << "Resolved factory function"; - plugin = factory(constructionString); - } else { - contextCritical() << "Error resolving function pluginFactory from plugin" << pluginFilename; - } - } - else { - contextCritical() << "Error loading plugin" << pluginFilename << ":" << library.errorString(); + if (library.isLoaded()) { + PluginFactoryFunc factory = (PluginFactoryFunc) library.resolve("pluginFactory"); + if (factory) { + contextDebug() << "Resolved factory function"; + plugin = factory(constructionString); + } else { + contextCritical() << "Error resolving function pluginFactory from plugin" << pluginFilename; } } else { - contextCritical() << "Illegal plugin name" << pluginName << ", doesn't start with /"; + contextCritical() << "Error loading plugin" << pluginFilename << ":" << library.errorString(); } } + else { + contextCritical() << "Illegal plugin name" << pluginName << ", doesn't start with /"; + } if (plugin == 0) { pluginState = FAILED; -- cgit v1.2.3 From cc47f435176bf7c1dd74b6b7bee5f299cd178f1a Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Wed, 16 Sep 2009 11:58:22 +0300 Subject: libcontextsubscriber/customer-tests: separated environment from runTests.sh So it can be easily sourced from your shell for debugging. --- libcontextsubscriber/customer-tests/env.sh | 6 ++++++ libcontextsubscriber/customer-tests/runTests.sh | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 libcontextsubscriber/customer-tests/env.sh (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/env.sh b/libcontextsubscriber/customer-tests/env.sh new file mode 100644 index 00000000..31a65d57 --- /dev/null +++ b/libcontextsubscriber/customer-tests/env.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +export PYTHONPATH="`pwd`/common/" +export CONTEXT_PROVIDERS=. +export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs +export PATH=$PATH:../../../python:../../cli:../../reg-cli diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh index 2015357b..c723a495 100755 --- a/libcontextsubscriber/customer-tests/runTests.sh +++ b/libcontextsubscriber/customer-tests/runTests.sh @@ -2,13 +2,10 @@ cd $(dirname $0) DIRS="commander subscription asynchronicity registry pluginchanging" -export PYTHONPATH="`pwd`/common/" +. ./env.sh if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ] then - export CONTEXT_PROVIDERS=. - export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs - export PATH=$PATH:../../../python:../../cli:../../reg-cli for dir in $DIRS; do cd $dir -- cgit v1.2.3 From b0332b81416440d754d736ac898a7d2d3e7d4d7b Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Wed, 16 Sep 2009 11:58:26 +0300 Subject: Cleanup. --- libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py index e2da172b..70a04149 100755 --- a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py +++ b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py @@ -56,8 +56,6 @@ class Subscription(unittest.TestCase): self.context_client = Popen(["context-listen","Test.Time"],stdin=PIPE,stdout=PIPE,stderr=PIPE) def tearDown(self): - print "tear down" - proc_kill(self.context_client.pid) os.remove('time.context') os.system('rm libcontextsubscribertime*.so*') -- cgit v1.2.3 From 8dacd338ebaa02ac02ec31f0611d445a28f1a88c Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Wed, 16 Sep 2009 12:02:02 +0300 Subject: libcontextsubscriber/src: added warnings about the privateness of the plugin interface --- libcontextsubscriber/src/iproviderplugin.h | 5 +++++ libcontextsubscriber/src/provider.cpp | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/iproviderplugin.h b/libcontextsubscriber/src/iproviderplugin.h index e03900ed..dcd4342c 100644 --- a/libcontextsubscriber/src/iproviderplugin.h +++ b/libcontextsubscriber/src/iproviderplugin.h @@ -27,6 +27,11 @@ namespace ContextSubscriber { +/* This is not a public API of ContextKit, please do not write third + * party plugins for the ContextKit client library without first + * contacting us. + */ + class IProviderPlugin : public QObject { Q_OBJECT diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index aa110a08..86e0a96d 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -38,6 +38,11 @@ namespace ContextSubscriber { \class IProviderPlugin \brief Interface for provider plugins. + Note: this interface is private, currently it is not advised to use + it and create ContextKit subscriber plugins on your own, we can and + will change this interface anytime in the future even between small + bugfix releases. + Every Provider instance contains exactly one plugin (pointer) with this interface which is constructed on initialization time and never change after that. This way the concrete protocol (dbus, shared -- cgit v1.2.3 From a09dccfaca5c88025d3a792bd9878a442516be9d Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Wed, 16 Sep 2009 13:03:54 +0300 Subject: libcontextsubscriber documentation: Small clarification to the plugin documentation. --- libcontextsubscriber/src/provider.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libcontextsubscriber') diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index 86e0a96d..dcf745fc 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -52,7 +52,14 @@ namespace ContextSubscriber { unsubscribe calls (on the wire) using the \c subscribe and \c unsubscribe methods. - The plugin can fail or became ready anytime because of things + When the plugin is constructed, it should emit the signal ready() + when it is ready to take in subscriptions. However, the signal + ready() should not be emitted in the plugin constructor. If the + plugin is able to take in subscriptions immediately, you can use + QMetaObject::invokeMethod with QueuedConnection to emit the signal + when the main loop is entered the next time. + + The plugin can fail or became ready again anytime because of things happening on the wire inside the plugin (socket closed, dbus service appears/disappears). Whenever the plugin has new information about this it should emit the signal \c ready or \c failed accordingly. -- cgit v1.2.3