aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkos PASZTORY <ext-akos.pasztory@nokia.com>2009-10-27 11:00:50 +0200
committerAkos PASZTORY <ext-akos.pasztory@nokia.com>2009-10-27 11:00:50 +0200
commit455b85adf612f6c851c99265b32648b084fc4d9c (patch)
treecdc037d74739b24062f1cbee1bfc9716999426ec
parentb810435fdbf1fca6440b75101d80cdc043207f47 (diff)
context-provide: info and list commands
-rw-r--r--debian/changelog3
-rw-r--r--libcontextprovider/context-provide/commandwatcher.cpp45
-rw-r--r--libcontextprovider/context-provide/commandwatcher.h1
-rw-r--r--libcontextprovider/context-provide/propertyproxy.cpp13
-rw-r--r--libcontextprovider/context-provide/propertyproxy.h1
-rw-r--r--libcontextprovider/man/context-provide-v2.123
6 files changed, 73 insertions, 13 deletions
diff --git a/debian/changelog b/debian/changelog
index 40704f1b..1930cedc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,8 +6,9 @@ contextkit (0.4~unreleased) unstable; urgency=low
libcontextsubscriber.
* The start command in context-provide is now able to reregister
the service name if needed as advertised in the help.
+ * context-provide supports proxying in Commander mode.
- Implemented: SWP#CntFr-349
+ Implemented: SWP#CntFr-349, SWP#CntFr-353
-- Gergely Risko <gergely+context@risko.hu> Thu, 22 Oct 2009 13:42:27 +0300
diff --git a/libcontextprovider/context-provide/commandwatcher.cpp b/libcontextprovider/context-provide/commandwatcher.cpp
index 7608fa80..9a44de1d 100644
--- a/libcontextprovider/context-provide/commandwatcher.cpp
+++ b/libcontextprovider/context-provide/commandwatcher.cpp
@@ -37,6 +37,7 @@
#include <errno.h>
#include <QMap>
#include <QDir>
+#include <QSet>
const QString CommandWatcher::commanderBusName = "org.freedesktop.ContextKit.Commander";
@@ -49,6 +50,7 @@ CommandWatcher::CommandWatcher(QString bn, QDBusConnection::BusType bt, int comm
sconnect(commandNotifier, SIGNAL(activated(int)), this, SLOT(onActivated()));
if (busName == commanderBusName) {
ContextProperty::ignoreCommander();
+ ContextProperty::setTypeCheck(true);
sconnect(registryInfo, SIGNAL(changed()), this, SLOT(onRegistryChanged()));
onRegistryChanged();
}
@@ -110,6 +112,7 @@ void CommandWatcher::help()
qDebug() << " info KEY - prints the real (proxied) value of KEY";
qDebug() << " unset KEY - sets KEY to unknown";
qDebug() << " del KEY - delete KEY, useful if the tool is commander";
+ qDebug() << " list - same as calling info for all known keys";
qDebug() << " sleep INTERVAL - sleep the INTERVAL amount of seconds";
qDebug() << " dump [FILENAME] - dump the xml content of the defined props";
qDebug() << " start - (re)register everything on D-Bus";
@@ -137,6 +140,8 @@ void CommandWatcher::interpret(const QString& command)
delCommand(args);
} else if (QString("info").startsWith(commandName)) {
infoCommand(args);
+ } else if (QString("list").startsWith(commandName)) {
+ listCommand();
} else if (QString("sleep").startsWith(commandName)) {
sleepCommand(args);
} else if (QString("exit").startsWith(commandName)) {
@@ -188,7 +193,7 @@ void CommandWatcher::addCommand(const QStringList& args)
} else {
types.insert(keyName, keyType);
properties.insert(keyName, new Property(keyName));
- if (busName == commanderBusName)
+ if (busName == commanderBusName && proxies.contains(keyName))
proxies[keyName]->enable(false);
out << "Added key: " << keyName << " with type: " << keyType << endl;
out.flush();
@@ -216,12 +221,20 @@ void CommandWatcher::delCommand(const QStringList &args)
types.remove(keyName);
delete properties.take(keyName);
- if (busName == commanderBusName)
+ if (busName == commanderBusName && proxies.contains(keyName))
proxies[keyName]->enable(true);
out << "Deleted key: " << keyName << endl;
out.flush();
}
+void CommandWatcher::listCommand()
+{
+ foreach (QString key,
+ QSet<QString>::fromList(properties.keys()) +
+ QSet<QString>::fromList(proxies.keys()))
+ infoCommand(QStringList(key));
+}
+
void CommandWatcher::infoCommand(const QStringList &args)
{
if (args.count() < 1) {
@@ -229,15 +242,27 @@ void CommandWatcher::infoCommand(const QStringList &args)
return;
}
QString keyName = args.at(0);
- if (!properties.contains(keyName)) {
- qDebug() << "ERROR:" << keyName << "not known/added";
- return;
+ if (properties.contains(keyName)) {
+ out << types[keyName] << " " << keyName;
+ if (properties[keyName]->value().isNull())
+ out << " is Unknown" << endl;
+ else
+ out << " = " << properties[keyName]->value().toString() << endl;
+ } else if (busName != commanderBusName) {
+ qDebug() << "ERROR:" << keyName << "not addd";
+ }
+ if (busName == commanderBusName) {
+ if (!proxies.contains(keyName))
+ qDebug() << "ERROR:" << keyName << "not known";
+ else {
+ out << "real: " << proxies[keyName]->type() << " "
+ << keyName;
+ if (proxies[keyName]->realValue().isNull())
+ out << " is Unknown" << endl;
+ else
+ out << " = " << proxies[keyName]->realValue().toString() << endl;
+ }
}
- out << types[keyName] << " " << keyName << " "
- << properties[keyName]->value().toString() << endl;
- if (busName == commanderBusName)
- out << "real: " << proxies[keyName]->realValue().typeName() << " "
- << proxies[keyName]->realValue().toString() << endl;
}
void CommandWatcher::sleepCommand(const QStringList& args)
diff --git a/libcontextprovider/context-provide/commandwatcher.h b/libcontextprovider/context-provide/commandwatcher.h
index 614668d7..114fa65b 100644
--- a/libcontextprovider/context-provide/commandwatcher.h
+++ b/libcontextprovider/context-provide/commandwatcher.h
@@ -55,6 +55,7 @@ private:
void dumpCommand(const QStringList& args);
void delCommand(const QStringList& args);
void infoCommand(const QStringList& args);
+ void listCommand();
void startCommand();
QString unquote(const QString& str);
diff --git a/libcontextprovider/context-provide/propertyproxy.cpp b/libcontextprovider/context-provide/propertyproxy.cpp
index 670c647d..9c012a24 100644
--- a/libcontextprovider/context-provide/propertyproxy.cpp
+++ b/libcontextprovider/context-provide/propertyproxy.cpp
@@ -1,6 +1,7 @@
#include "propertyproxy.h"
#include "sconnect.h"
#include "contextproperty.h"
+#include "contextpropertyinfo.h"
#include "property.h"
#include "logging.h"
@@ -28,9 +29,21 @@ QVariant PropertyProxy::realValue() const
return value;
}
+QString PropertyProxy::type() const
+{
+ return subscriber->info()->type();
+}
+
void PropertyProxy::onValueChanged()
{
value = subscriber->value();
if (enabled)
provider->setValue(value);
+ QTextStream out(stdout);
+ out << "real: " << type() << " " << subscriber->key();
+ if (realValue().isNull())
+ out << " is Unknown" << endl;
+ else
+ out << " = " << realValue().toString() << endl;
+ out.flush();
}
diff --git a/libcontextprovider/context-provide/propertyproxy.h b/libcontextprovider/context-provide/propertyproxy.h
index 7c92abc5..f185f2ad 100644
--- a/libcontextprovider/context-provide/propertyproxy.h
+++ b/libcontextprovider/context-provide/propertyproxy.h
@@ -32,6 +32,7 @@ public:
PropertyProxy(QString key, bool enabled = true, QObject *parent = 0);
void enable(bool enable);
QVariant realValue() const;
+ QString type() const;
private slots:
void onValueChanged();
private:
diff --git a/libcontextprovider/man/context-provide-v2.1 b/libcontextprovider/man/context-provide-v2.1
index d913d826..a4bbf63e 100644
--- a/libcontextprovider/man/context-provide-v2.1
+++ b/libcontextprovider/man/context-provide-v2.1
@@ -27,10 +27,16 @@ Properties can also be provided on the command line with \fITYPE\fR
If at least one property is specified on the command line the service
is autostarted and will start providing the properties right away,
-otherwise you have to use the \fBstart\fR command after all of the
-properties have been added by \fBadd\fR invocations. In both cases
+otherwise you have to use the \fB`start'\fR command after all of the
+properties have been added by \fB`add'\fR invocations. In both cases
the service name registered for the service on D-Bus will be \fIBUSNAME\fR.
+If no \fIBUSNAME\fR is given the tool acts as a Commander, taking control of
+all subscribers in the system. This mode by default proxies the real values
+of all properties. To control a property you have to \fB`add'\fR the
+property, which stops forwarding the corresponding property. You can undo
+this via the \fB`del'\fR command.
+
.SH OPTIONS
.TP
\fB--system\fR
@@ -47,6 +53,12 @@ provided properties. The initial value will be \fIINITVALUE\fR if
specified, otherwise unset (null). This has to be called before an
attempt is made to set a key value. \fITYPE\fR can be: STRING, INT,
BOOL, DOUBLE. Example: "add INT Battery.Status 20".
+
+In \fICommander\fR mode it also ceases proxying the real property.
+.TP
+\fBdel\fR \fIKEY\fR
+makes context-provide forget \fIKEY\fR. In \fICommander\fR mode, restores
+proxying of the real property.
.TP
\fIKEY\fB=\fIVALUE\fR
sets the given \fIKEY\fR value to the new \fIVALUE\fR. Example: "Battery.Status=99".
@@ -54,6 +66,13 @@ sets the given \fIKEY\fR value to the new \fIVALUE\fR. Example: "Battery.Status=
\fBunset\fR \fIKEY\fR
sets the given \fIKEY\fR to non specified (null).
.TP
+\fBinfo\fR \fIKEY\fR
+prints the type, name and current value of \fIKEY\fR. In \fICommander\fR
+mode the real value (from the original provider) is printed as well.
+.TP
+\fBlist\fR
+same as calling `info' for all known keys (both proxied and added ones)
+.TP
\fBsleep\fR \fIINTERVAL\fR
sleeps and blocks the main loop for the given amount of seconds. Used
mainly for internal testing purposes. Example: "sleep 10".