aboutsummaryrefslogtreecommitdiff
path: root/libcontextsubscriber
diff options
context:
space:
mode:
authorGergely Risko <gergely+context@risko.hu>2009-09-21 11:38:24 +0300
committerGergely Risko <gergely+context@risko.hu>2009-09-21 11:38:24 +0300
commit3b3b57d231521e939352229fb995420795a3cb24 (patch)
tree575d8abf598fc4e3d0b2ba79a4fc540f46a264c1 /libcontextsubscriber
parent7cf44bded328c27c6cbe18300ed379c4d706bc16 (diff)
parentb0109b02d8222f1063fa83b89b246766aa855244 (diff)
Merge branch 'master' into cdbqvariant
Diffstat (limited to 'libcontextsubscriber')
-rw-r--r--libcontextsubscriber/customer-tests/Makefile.am2
-rwxr-xr-xlibcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py26
-rwxr-xr-xlibcontextsubscriber/customer-tests/runTests.sh8
-rw-r--r--libcontextsubscriber/customer-tests/tests.xml7
-rw-r--r--libcontextsubscriber/src/contextpropertyinfo.cpp33
-rw-r--r--libcontextsubscriber/src/contextpropertyinfo.h10
-rw-r--r--libcontextsubscriber/src/infobackend.h7
-rw-r--r--libcontextsubscriber/src/infocdbbackend.cpp17
-rw-r--r--libcontextsubscriber/src/infocdbbackend.h2
-rw-r--r--libcontextsubscriber/src/infoxmlbackend.cpp25
-rw-r--r--libcontextsubscriber/src/infoxmlbackend.h2
-rw-r--r--libcontextsubscriber/src/propertyhandle.cpp4
-rw-r--r--libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h2
-rw-r--r--libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp5
14 files changed, 111 insertions, 39 deletions
diff --git a/libcontextsubscriber/customer-tests/Makefile.am b/libcontextsubscriber/customer-tests/Makefile.am
index 8ec2e565..05b328d4 100644
--- a/libcontextsubscriber/customer-tests/Makefile.am
+++ b/libcontextsubscriber/customer-tests/Makefile.am
@@ -12,4 +12,4 @@ check-customer:
CLEANFILES = *.pyc
EXTRA_DIST = asynchronicity commander subscription runTests.sh \
- tests.xml common registry
+ tests.xml common registry pluginchanging
diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py
index 70a04149..3645d847 100755
--- a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py
+++ b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py
@@ -30,9 +30,7 @@ import string
from subprocess import Popen, PIPE
import time
import signal
-
-def proc_kill(pid):
- os.system('../common/rec-kill.sh %d' % pid)
+from cltool import CLTool
def timeoutHandler(signum, frame):
raise Exception('tests have been running for too long')
@@ -49,14 +47,12 @@ class Subscription(unittest.TestCase):
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/libcontextsubscribertime1.so.0.0.0 ./libcontextsubscribertime1.so')
+ os.system('cp ../testplugins/libcontextsubscribertime2.so.0.0.0 ./libcontextsubscribertime2.so')
- self.context_client = Popen(["context-listen","Test.Time"],stdin=PIPE,stdout=PIPE,stderr=PIPE)
+ self.context_client = CLTool("context-listen", "Test.Time")
def tearDown(self):
- proc_kill(self.context_client.pid)
os.remove('time.context')
os.system('rm libcontextsubscribertime*.so*')
@@ -66,22 +62,16 @@ class Subscription(unittest.TestCase):
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)
+ # Expect value coming from plugin libcontextsubscribertime1
+ self.assert_(self.context_client.expect(CLTool.STDOUT, "Test.Time = QString:Time1:", 3))
# 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)
+ # Expect value coming from plugin libcontextsubscribertime2
+ self.assert_(self.context_client.expect(CLTool.STDOUT, "Test.Time = QString:Time2:", 3))
if __name__ == "__main__":
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1)
diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh
index c723a495..885311fb 100755
--- a/libcontextsubscriber/customer-tests/runTests.sh
+++ b/libcontextsubscriber/customer-tests/runTests.sh
@@ -4,16 +4,24 @@ cd $(dirname $0)
DIRS="commander subscription asynchronicity registry pluginchanging"
. ./env.sh
+
if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ]
then
+ # Copy built test plugin .so's closer to the test program
+ cp testplugins/timeplugin1/.libs/libcontextsubscribertime1.so.0.0.0 testplugins/
+ cp testplugins/timeplugin2/.libs/libcontextsubscribertime2.so.0.0.0 testplugins/
for dir in $DIRS; do
+ echo "Running tests in $dir"
cd $dir
for file in *.py; do
python2.5 $file || exit 1
done
cd ..
done
+ rm testplugins/libcontextsubscribertime1.so.0.0.0
+ rm testplugins/libcontextsubscribertime2.so.0.0.0
+
else
echo "libcontextprovider is not installed nor built"
exit 1
diff --git a/libcontextsubscriber/customer-tests/tests.xml b/libcontextsubscriber/customer-tests/tests.xml
index 50dfbab7..bbfd5354 100644
--- a/libcontextsubscriber/customer-tests/tests.xml
+++ b/libcontextsubscriber/customer-tests/tests.xml
@@ -10,8 +10,7 @@
<!-- At least one case per set, name mandatory, description mandatory, other optional -->
<case name="libsub001" description="This test verifies that the asynchronicity of the subscriber library" requirement="" timeout="20">
<!-- At least one step per test, expected_result optional - tells which return code is considered passed -->
- <step expected_result="0">. /tmp/session_bus_address.user;export CONTEXT_PROVIDERS=.;cd
- /usr/share/libcontextsubscriber-tests/asynchronicity;python /usr/share/libcontextsubscriber-tests/asynchronicity/asynchronicity.py</step>
+ <step expected_result="0">. /tmp/session_bus_address.user;export PYTHONPATH=$PYTHONPATH:/usr/share/libcontextsubscriber-tests/common ; export CONTEXT_PROVIDERS=.;cd /usr/share/libcontextsubscriber-tests/asynchronicity;python /usr/share/libcontextsubscriber-tests/asynchronicity/asynchronicity.py</step>
</case>
<!-- At least one case per set, name mandatory, description mandatory, other optional -->
<case name="libsub002" description="This test verifies that properties are overriden by commander" requirement="" timeout="20">
@@ -74,6 +73,10 @@
<!-- At least one step per test, expected_result optional - tells which return code is considered passed -->
<step expected_result="0">. /tmp/session_bus_address.user;export CONTEXT_PROVIDERS=.;cd /usr/share/libcontextsubscriber-tests/subscription;python /usr/share/libcontextsubscriber-tests/subscription/subscription.py SubscriptionPause.testWaitForSubscribe</step>
</case>
+ <case name="libsub016" description="Plugin loading of libcontextsubscriber" requirement="" timeout="20">
+ <step expected_result="0">. /tmp/session_bus_address.user;export CONTEXT_PROVIDERS=.;export PYTHONPATH=$PYTHONPATH:/usr/share/libcontextsubscriber-tests/common ;cd /usr/share/libcontextsubscriber-tests/pluginchanging;python /usr/share/libcontextsubscriber-tests/pluginchanging/pluginchanging.py</step>
+ </case>
+
<environments>
<scratchbox>false</scratchbox>
<hardware>true</hardware>
diff --git a/libcontextsubscriber/src/contextpropertyinfo.cpp b/libcontextsubscriber/src/contextpropertyinfo.cpp
index 30cfd8b7..e3b81dc7 100644
--- a/libcontextsubscriber/src/contextpropertyinfo.cpp
+++ b/libcontextsubscriber/src/contextpropertyinfo.cpp
@@ -211,6 +211,8 @@ ContextPropertyInfo::ContextPropertyInfo(const QString &key, QObject *parent)
cachedDoc = infoBackend->docForKey(keyName);
cachedPlugin = infoBackend->pluginForKey(keyName);
cachedConstructionString = infoBackend->constructionStringForKey(keyName);
+ cachedExists = infoBackend->keyExists(keyName);
+ cachedProvided = infoBackend->keyProvided(keyName);
}
}
@@ -239,11 +241,14 @@ QString ContextPropertyInfo::type() const
bool ContextPropertyInfo::exists() const
{
QMutexLocker lock(&cacheLock);
- // A key is assumed to exist if it's type != "".
- if (cachedType != "")
- return true;
- else
- return false;
+ return cachedExists;
+}
+
+/// Returns true if the key is provided by someone.
+bool ContextPropertyInfo::provided() const
+{
+ QMutexLocker lock(&cacheLock);
+ return cachedProvided;
}
/// Returns the name of the plugin supplying this property
@@ -312,10 +317,15 @@ void ContextPropertyInfo::onKeyDataChanged(const QString& key)
QString oldPlugin = cachedPlugin;
QString oldConstructionString = cachedConstructionString;
+ bool oldExists = cachedExists;
+ bool oldProvided = cachedProvided;
+
QString newPlugin = InfoBackend::instance()->pluginForKey(keyName);
QString newConstructionString = InfoBackend::instance()->constructionStringForKey(keyName);
cachedPlugin = newPlugin;
cachedConstructionString = newConstructionString;
+ cachedExists = InfoBackend::instance()->keyExists(keyName);
+ cachedProvided = InfoBackend::instance()->keyProvided(keyName);
// Release the lock before emitting the signals; otherwise
// listeners trying to access cached values would create a
@@ -323,15 +333,12 @@ void ContextPropertyInfo::onKeyDataChanged(const QString& key)
lock.unlock();
// Emit the needed signals
- if (oldType != newType) {
-
- if (oldType == "")
- emit existsChanged(true);
- if (newType == "")
- emit existsChanged(false);
-
+ if (oldType != newType)
emit typeChanged(cachedType);
- }
+ if (oldExists != cachedExists)
+ emit existsChanged(cachedExists);
+ if (oldProvided != cachedProvided)
+ emit existsChanged(cachedProvided);
// TBD: obsolete the providerChanged & providerDBusTypeChanged signals?
if (oldPlugin != newPlugin || oldConstructionString != newConstructionString) {
diff --git a/libcontextsubscriber/src/contextpropertyinfo.h b/libcontextsubscriber/src/contextpropertyinfo.h
index e83aebb9..2a988f90 100644
--- a/libcontextsubscriber/src/contextpropertyinfo.h
+++ b/libcontextsubscriber/src/contextpropertyinfo.h
@@ -42,6 +42,7 @@ public:
QString doc() const;
QString type() const;
bool exists() const;
+ bool provided() const;
QString providerDBusName() const;
QDBusConnection::BusType providerDBusType() const;
@@ -55,6 +56,8 @@ private:
QString cachedType; ///< Cached (stored) type of the key.
QString cachedPlugin; ///< Cached name of the plugin providing the key
QString cachedConstructionString; ///< Cached construction string for the Provider
+ bool cachedExists; ///< Cached state of the key (existance).
+ bool cachedProvided; ///< Cached state of the key (whether someone provides it).
mutable QMutex cacheLock; ///< Lock for the cache.
private slots:
@@ -86,6 +89,13 @@ signals:
/// \param exists The new state of the key.
void existsChanged(bool exists);
+ /// Emitted when the key gets a provider or loses a provider. The \a provided
+ /// is the new state of the introspected key. This is a strict signal - it's
+ /// emitted only when there was an actual change in the state. Using this
+ /// signal you can wait (watch) for various keys to become available.
+ /// \param provided The new state of the key.
+ void providedChanged(bool provided);
+
/// 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
diff --git a/libcontextsubscriber/src/infobackend.h b/libcontextsubscriber/src/infobackend.h
index 5e8d04fc..afd719b5 100644
--- a/libcontextsubscriber/src/infobackend.h
+++ b/libcontextsubscriber/src/infobackend.h
@@ -59,6 +59,13 @@ public:
/// Returns the constructor plugin parameter for the given \a key name.
virtual QString constructionStringForKey(QString key) const = 0;
+ /// Returns true if the given key exists.
+ virtual bool keyExists(QString key) const = 0;
+
+ /// Returns true if the given key is provided (i.e., not a core
+ /// property which nobody provides currently)
+ virtual bool keyProvided(QString key) const = 0;
+
signals:
/// Emitted when key list changes. ContextRegistryInfo listens on that.
void keysChanged(const QStringList& currentKeys);
diff --git a/libcontextsubscriber/src/infocdbbackend.cpp b/libcontextsubscriber/src/infocdbbackend.cpp
index ebb28783..217f11c5 100644
--- a/libcontextsubscriber/src/infocdbbackend.cpp
+++ b/libcontextsubscriber/src/infocdbbackend.cpp
@@ -104,6 +104,23 @@ QString InfoCdbBackend::constructionStringForKey(QString key) const
return reader.valueForKey(key + ":KEYCONSTRUCTIONSTRING").toString();
}
+bool InfoCdbBackend::keyExists(QString key) const
+{
+ if (reader.valuesForKey("KEYS").contains(key))
+ return true;
+ else
+ return false;
+}
+
+bool InfoCdbBackend::keyProvided(QString key) const
+{
+ QString plugin = reader.valueForKey(key + ":KEYPLUGIN");
+ if (plugin == "")
+ return false;
+
+ return true;
+}
+
/// Returns true if the database file is present.
bool InfoCdbBackend::databaseExists()
{
diff --git a/libcontextsubscriber/src/infocdbbackend.h b/libcontextsubscriber/src/infocdbbackend.h
index f9f17c06..c56827df 100644
--- a/libcontextsubscriber/src/infocdbbackend.h
+++ b/libcontextsubscriber/src/infocdbbackend.h
@@ -44,6 +44,8 @@ public:
virtual QString docForKey(QString key) const;
virtual QString pluginForKey(QString key) const;
virtual QString constructionStringForKey(QString key) const;
+ virtual bool keyExists(QString key) const;
+ virtual bool keyProvided(QString key) const;
static QString databaseDirectory();
static QString databasePath();
diff --git a/libcontextsubscriber/src/infoxmlbackend.cpp b/libcontextsubscriber/src/infoxmlbackend.cpp
index 435b35bc..2018e431 100644
--- a/libcontextsubscriber/src/infoxmlbackend.cpp
+++ b/libcontextsubscriber/src/infoxmlbackend.cpp
@@ -54,7 +54,7 @@ InfoXmlBackend::InfoXmlBackend(QObject *parent)
QDir dir = QDir(InfoXmlBackend::registryPath());
if (! dir.exists() || ! dir.isReadable()) {
- contextWarning() << "Registry path" << InfoXmlBackend::registryPath()
+ contextWarning() << "Registry path" << InfoXmlBackend::registryPath()
<< "is not a directory or is not readable!";
return;
}
@@ -146,6 +146,25 @@ QString InfoXmlBackend::constructionStringForKey(QString key) const
return keyDataHash.value(key).constructionString;
}
+bool InfoXmlBackend::keyExists(QString key) const
+{
+ if (keyDataHash.contains(key))
+ return true;
+ else
+ return false;
+}
+
+bool InfoXmlBackend::keyProvided(QString key) const
+{
+ if (keyDataHash.contains(key) == false)
+ return false;
+
+ if (keyDataHash.value(key).plugin != "")
+ return true;
+
+ return false;
+}
+
/// Returns the full path to the registry directory. Takes the
/// \c CONTEXT_PROVIDERS env variable into account.
QString InfoXmlBackend::registryPath()
@@ -178,7 +197,7 @@ void InfoXmlBackend::onFileChanged(const QString &path)
// an unconditional reload message for us.
contextDebug() << F_XML << path << "changed.";
-
+
QStringList oldKeys = listKeys();
regenerateKeyDataList();
QStringList currentKeys = listKeys();
@@ -213,7 +232,7 @@ void InfoXmlBackend::onDirectoryChanged(const QString &path)
return;
contextDebug() << F_XML << registryPath() << "directory changed.";
-
+
QStringList oldKeys = listKeys();
regenerateKeyDataList();
QStringList currentKeys = listKeys();
diff --git a/libcontextsubscriber/src/infoxmlbackend.h b/libcontextsubscriber/src/infoxmlbackend.h
index 061e702a..4c95b67f 100644
--- a/libcontextsubscriber/src/infoxmlbackend.h
+++ b/libcontextsubscriber/src/infoxmlbackend.h
@@ -46,6 +46,8 @@ public:
virtual QString docForKey(QString key) const;
virtual QString pluginForKey(QString key) const;
virtual QString constructionStringForKey(QString key) const;
+ virtual bool keyExists(QString key) const;
+ virtual bool keyProvided(QString key) const;
static QString registryPath();
static QString coreDeclPath();
diff --git a/libcontextsubscriber/src/propertyhandle.cpp b/libcontextsubscriber/src/propertyhandle.cpp
index cef5c406..3290d080 100644
--- a/libcontextsubscriber/src/propertyhandle.cpp
+++ b/libcontextsubscriber/src/propertyhandle.cpp
@@ -84,7 +84,7 @@ PropertyHandle::PropertyHandle(const QString& key)
myInfo = new ContextPropertyInfo(myKey, this);
// Start listening to changes in property introspection (e.g., added to registry, plugin changes)
- sconnect(myInfo, SIGNAL(existsChanged(bool)),
+ sconnect(myInfo, SIGNAL(providedChanged(bool)),
this, SLOT(updateProvider()));
sconnect(myInfo, SIGNAL(pluginChanged(QString, QString)),
this, SLOT(updateProvider()));
@@ -140,7 +140,7 @@ void PropertyHandle::updateProvider()
// The myInfo object doesn't have to be re-created, because it
// just routes the function calls to a registry backend.
- if (myInfo->exists()) {
+ if (myInfo->provided()) {
// If myInfo knows the current provider which should be
// connected to, connect to it.
contextDebug() << F_PLUGINS << "Key exists";
diff --git a/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h b/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h
index 61cdcb45..5558659c 100644
--- a/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h
+++ b/libcontextsubscriber/unit-tests/propertyhandle/contextpropertyinfo.h
@@ -39,6 +39,7 @@ public:
QString type() const;
bool exists() const;
+ bool provided() const;
QString plugin() const;
QString constructionString() const;
@@ -50,6 +51,7 @@ signals:
void providerDBusTypeChanged(QDBusConnection::BusType newBusType);
void typeChanged(QString newType);
void existsChanged(bool exists);
+ void providedChanged(bool provided);
void pluginChanged(QString, QString);
public:
diff --git a/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp b/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp
index 8c8f4c57..2144b197 100644
--- a/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp
+++ b/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp
@@ -57,6 +57,11 @@ bool ContextPropertyInfo::exists() const
return myType != "";
}
+bool ContextPropertyInfo::provided() const
+{
+ return true;
+}
+
QString ContextPropertyInfo::plugin() const
{
return "fakeplugin";