D-Bus: added Server.GetCapabilities and Server.GetVersions (BMC #3563)

We are about to extend the D-Bus API. Clients need some way of determining
whether the new features are available. A strict numbering of the API is
inflexible, so let's use "capability" strings instead. Also add flexible
version querying, for debugging.
This commit is contained in:
Patrick Ohly 2010-08-24 21:39:00 +02:00
parent c8b1f3a07d
commit 067397a9f2
3 changed files with 112 additions and 0 deletions

View File

@ -44,6 +44,74 @@
</doc:para>
</doc:doc>
<method name="GetCapabilities">
<doc:doc>
<doc:description>
<doc:para>
Describes which features are implemented by the server. If the method itself
is unavailable, then the features correspond to SyncEvolution 1.0. The following
capabilities are currently defined:
<doc:list>
<doc:item><doc:term>ConfigChanged</doc:term>
<doc:definition>Server.ConfigChange
signal available; if not, reread config after each
session
</doc:definition>
</doc:item>
<doc:item><doc:term>GetConfigName</doc:term>
<doc:definition>Session.GetConfigName()
implemented
</doc:definition>
</doc:item>
<doc:item><doc:term>Notifications</doc:term>
<doc:definition>Server.DisableNotifications()
and Server.EnableNotifications() implemented
</doc:definition>
</doc:item>
<doc:item><doc:term>Version</doc:term>
<doc:definition>Server.GetVersion()
implemented; note that this is not meant to be used to determine supported
features
</doc:definition>
</doc:item>
<doc:item><doc:term>SessionFlags</doc:term>
<doc:definition>Server.StartSessionWithFlags()
and Session.GetFlags() are implemented
</doc:definition>
</doc:item>
</doc:list>
</doc:para>
</doc:description>
</doc:doc>
<arg type="a{s}" name="capabilities" direction="out">
<doc:doc><doc:summary>
set of supported capabilities
</doc:summary></doc:doc>
</arg>
</method>
<method name="GetVersions">
<doc:doc>
<doc:description>
<doc:para>
Returns information about server side implementations.
</doc:para>
</doc:description>
</doc:doc>
<arg type="a{ss}" name="info" direction="out">
<doc:doc><doc:summary>
"version" - main SyncEvolution release name (usually a number,
sometimes also a beta or alpha suffix),
"system" - some plain text information about system libraries,
"backends" - available backend libraries
</doc:summary></doc:doc>
</arg>
</method>
<method name="Attach">
<doc:doc>
<doc:description>

View File

@ -1024,6 +1024,12 @@ class DBusServer : public DBusObjectHelper,
*/
void clientGone(Client *c);
/** Server.GetCapabilities() */
vector<string> getCapabilities();
/** Server.GetVersions() */
StringMap getVersions();
/** Server.Attach() */
void attachClient(const Caller_t &caller,
const boost::shared_ptr<Watch> &watch);
@ -4609,6 +4615,31 @@ std::string DBusServer::getNextSession()
return StringPrintf("%u%u", rand(), m_lastSession);
}
vector<string> DBusServer::getCapabilities()
{
// Note that this is tested by test-dbus.py in
// TestDBusServer.testCapabilities, update the test when adding
// capabilities.
vector<string> capabilities;
// capabilities.push_back("ConfigChanged");
// capabilities.push_back("GetConfigName");
// capabilities.push_back("Notifications");
capabilities.push_back("Version");
// capabilities.push_back("SessionFlags");
return capabilities;
}
StringMap DBusServer::getVersions()
{
StringMap versions;
versions["version"] = VERSION;
versions["system"] = EDSAbiWrapperInfo();
versions["backends"] = SyncSource::backendsInfo();
return versions;
}
void DBusServer::attachClient(const Caller_t &caller,
const boost::shared_ptr<Watch> &watch)
{
@ -4751,6 +4782,8 @@ DBusServer::DBusServer(GMainLoop *loop, const DBusConnectionPtr &conn, int durat
struct timeval tv;
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
add(this, &DBusServer::getCapabilities, "GetCapabilities");
add(this, &DBusServer::getVersions, "GetVersions");
add(this, &DBusServer::attachClient, "Attach");
add(this, &DBusServer::detachClient, "Detach");
add(this, &DBusServer::connect, "Connect");

View File

@ -532,6 +532,17 @@ class TestDBusServer(unittest.TestCase, DBusUtil):
def run(self, result):
self.runTest(result)
def testCapabilities(self):
"""check the Server.GetCapabilities() call"""
self.failUnlessEqual(self.server.GetCapabilities(), ['Version'])
def testVersions(self):
"""check the Server.GetVersions() call"""
versions = self.server.GetVersions()
self.failIfEqual(versions["version"], "")
self.failIfEqual(versions["system"], None)
self.failIfEqual(versions["backends"], None)
def testGetConfigsEmpty(self):
"""GetConfigs() with no configurations available"""
configs = self.server.GetConfigs(False, utf8_strings=True)