aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarja Hassinen <marja.hassinen@nokia.com>2010-10-13 10:30:49 +0300
committerMarja Hassinen <marja.hassinen@nokia.com>2010-10-13 10:30:49 +0300
commitcb7e394414f7b0365a208e1da335f89e80a3be34 (patch)
treec4e162b311c09390607d1cd8e39f2dac7af84cd0
parent6d17e887e7a7bffe00d10040788a4be50886c187 (diff)
Connecting to commander only if CONTEXT_COMMANDING is set.
This avoids one extra D-Bus connection if the session bus is not otherwise needed. Also, waitForSubscription is quicker if the value is available: we don't need to wait for the "is commander present" check to complete.
-rw-r--r--debian/changelog4
-rwxr-xr-xlibcontextsubscriber/customer-tests/commander/commander_appearing.py3
-rwxr-xr-xlibcontextsubscriber/customer-tests/commander/commander_disabled.py23
-rwxr-xr-xlibcontextsubscriber/customer-tests/commander/commander_nonexistent.py3
-rw-r--r--libcontextsubscriber/src/propertyhandle.cpp60
-rw-r--r--libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp5
6 files changed, 74 insertions, 24 deletions
diff --git a/debian/changelog b/debian/changelog
index 26486630..f72c4dba 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,8 @@
contextkit (0.5.20~unreleased) unstable; urgency=low
- *
+ * Commanding is only allowed if the env var CONTEXT_COMMANDING is set.
- -- Marja Hassinen <marja.hassinen@nokia.com> Tue, 21 Sep 2010 09:28:44 +0300
+ -- Marja Hassinen <marja.hassinen@nokia.com> Wed, 13 Oct 2010 10:14:11 +0300
contextkit (0.5.19) unstable; urgency=low
diff --git a/libcontextsubscriber/customer-tests/commander/commander_appearing.py b/libcontextsubscriber/customer-tests/commander/commander_appearing.py
index 1a87c124..40519ae7 100755
--- a/libcontextsubscriber/customer-tests/commander/commander_appearing.py
+++ b/libcontextsubscriber/customer-tests/commander/commander_appearing.py
@@ -38,6 +38,9 @@ import unittest
from ContextKit.cltool import CLTool, wanted, wantedUnknown
class CommanderAppearing(unittest.TestCase):
+ def setUp(self):
+ os.environ['CONTEXT_COMMANDING'] = '1'
+
def tearDown(self):
os.unlink('context-provide.context')
diff --git a/libcontextsubscriber/customer-tests/commander/commander_disabled.py b/libcontextsubscriber/customer-tests/commander/commander_disabled.py
index 661a6752..94830447 100755
--- a/libcontextsubscriber/customer-tests/commander/commander_disabled.py
+++ b/libcontextsubscriber/customer-tests/commander/commander_disabled.py
@@ -36,7 +36,28 @@ class CommanderDisabled(unittest.TestCase):
def tearDown(self):
os.unlink('context-provide.context')
- def testCommanderFunctionality(self):
+ def testIgnoreCommander(self):
+ # CONTEXT_COMMANDING is set but ContextProperty::ignoreCommander is
+ # called
+ os.environ['CONTEXT_COMMANDING'] = '1'
+ provider = CLTool("context-provide", "--v2", "contextkit.test", "int", "test.int", "42")
+ provider.send("dump")
+ provider.expect("Wrote") # wait for it
+ commander = CLTool("context-provide", "--v2")
+ commander.send("add int test.int 4242")
+ commander.send("start")
+ commander.expect("Added") # wait for it
+ os.environ["CONTEXT_CLI_IGNORE_COMMANDER"] = ""
+ listen = CLTool("context-listen", "test.int")
+ self.assert_(listen.expect(wanted("test.int", "int", "42")),
+ "Provider provided value is wrong")
+ listen.wait()
+ commander.wait()
+ provider.wait()
+
+ def testNoCommanding(self):
+ # CONTEXT_COMMANDING is not set
+ del os.environ['CONTEXT_COMMANDING']
provider = CLTool("context-provide", "--v2", "contextkit.test", "int", "test.int", "42")
provider.send("dump")
provider.expect("Wrote") # wait for it
diff --git a/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py b/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py
index d595961b..c0d470c9 100755
--- a/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py
+++ b/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py
@@ -36,6 +36,9 @@ import unittest
from ContextKit.cltool import CLTool, wanted
class CommanderNonExistent(unittest.TestCase):
+ def setUp(self):
+ os.environ['CONTEXT_COMMANDING'] = '1'
+
def tearDown(self):
os.unlink('context-provide.context')
diff --git a/libcontextsubscriber/src/propertyhandle.cpp b/libcontextsubscriber/src/propertyhandle.cpp
index a5289d5a..3289d897 100644
--- a/libcontextsubscriber/src/propertyhandle.cpp
+++ b/libcontextsubscriber/src/propertyhandle.cpp
@@ -38,6 +38,8 @@
#include <QReadLocker>
#include <QWriteLocker>
+#include <stdlib.h>
+
namespace ContextSubscriber {
static const QDBusConnection::BusType commanderDBusType = QDBusConnection::SessionBus;
@@ -87,29 +89,44 @@ PropertyHandle::PropertyHandle(const QString& key)
sconnect(myInfo, SIGNAL(changed(QString)),
this, SLOT(updateProvider()));
- // Start listening for the context commander, and also initiate a
- // NameHasOwner check.
-
- // Because of the waitForSubscription() feature, we immediately need to
- // subscribe to the real providers when the commander presence becomes
- // known. So, these connect()s need to be synchronous (not queued).
- sconnect(commanderListener, SIGNAL(nameAppeared()),
- this, SLOT(updateProvider()));
- sconnect(commanderListener, SIGNAL(nameDisappeared()),
- this, SLOT(updateProvider()));
-
- commanderListener->startListening(true);
+ // Check whether we should listen to commander at all. This extra if just
+ // optimizes away getenv in case we've already checked it and noticed
+ // commanding is not enabled.
+ if (commandingEnabled) {
+ const char *commanding = getenv("CONTEXT_COMMANDING");
+ if (!commanding)
+ commandingEnabled = false;
+ }
- // Check if commander is already there:
- DBusNameListener::ServicePresence commanderPresence = commanderListener->isServicePresent();
- if (commanderPresence != DBusNameListener::Unknown) {
- // The status of the commander is known, so we can connect to
- // the provider (or commander) immediately.
+ if (commandingEnabled) {
+ // Start listening for the context commander, and also initiate a
+ // NameHasOwner check.
+
+ // Because of the waitForSubscription() feature, we immediately need to
+ // subscribe to the real providers when the commander presence becomes
+ // known. So, these connect()s need to be synchronous (not queued).
+ sconnect(commanderListener, SIGNAL(nameAppeared()),
+ this, SLOT(updateProvider()));
+ sconnect(commanderListener, SIGNAL(nameDisappeared()),
+ this, SLOT(updateProvider()));
+
+ commanderListener->startListening(true);
+
+ // Check if commander is already there:
+ DBusNameListener::ServicePresence commanderPresence = commanderListener->isServicePresent();
+ if (commanderPresence != DBusNameListener::Unknown) {
+ // The status of the commander is known, so we can connect to
+ // the provider (or commander) immediately.
+ updateProvider();
+ }
+ // Otherwise, delay connecting to the provider until we know
+ // whether commander is present.
+ }
+ else {
+ // Don't wait for the commander; just connect to the real provider
+ // immediately.
updateProvider();
}
- // Otherwise, delay connecting to the provider until we know
- // whether commander is present.
-
// Move the PropertyHandle (and all children) to main thread.
moveToThread(QCoreApplication::instance()->thread());
@@ -213,7 +230,8 @@ QVariant PropertyHandle::value() const
bool PropertyHandle::isSubscribePending() const
{
// We wait until commander presence is unknown ...
- if (commanderListener->isServicePresent() == DBusNameListener::Unknown)
+ if (commandingEnabled &&
+ commanderListener->isServicePresent() == DBusNameListener::Unknown)
return true;
// ... or until we get some value ...
if (!myValue.isNull())
diff --git a/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp b/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp
index a59b34d5..d9627776 100644
--- a/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp
+++ b/libcontextsubscriber/unit-tests/propertyhandle/testpropertyhandle.cpp
@@ -35,6 +35,8 @@
#include <QDebug>
#include <QDBusConnection>
+#include <stdlib.h>
+
ContextRegistryInfo* mockContextRegistryInfo;
ContextPropertyInfo* mockContextPropertyInfo;
@@ -221,6 +223,9 @@ void DBusNameListener::startListening(bool nameHasOwnerCheck)
void PropertyHandleUnitTests::initTestCase()
{
qInstallMsgHandler(myMessageOutput);
+ // Either all PropertyHandle objects are commandable or none of them is;
+ // this needs to be set before creating the first PropertyHandle object.
+ setenv("CONTEXT_COMMANDING", "1", 0);
}
// After all tests