D-Bus API: added Server.StartSessionWithFlags() and Session.GetFlags()
Clients like Genesis would like to know for which purpose a session was created. If it was for changing the configuration, they can ignore the session. If it was for sync, then progress and result should be displayed. Starting a session with the new "no-sync" flag in the new StartSessionWithFlags() achieves that. Note that it is up to the clients to provide that hint; currently none of the clients do that.
This commit is contained in:
parent
c7be6f1c49
commit
5e219fedef
|
@ -382,10 +382,36 @@ sometimes also a beta or alpha suffix),
|
|||
<doc:doc><doc:description>
|
||||
Start a session. The object is created instantly but will not be
|
||||
ready for method calls until status changes from "queueing" to "idle".
|
||||
The Detach() method can be called before that.
|
||||
The Detach() method can be called before that. Same as StartSessionWithFlags()
|
||||
without any flags set.
|
||||
</doc:description></doc:doc>
|
||||
<arg type="s" name="server" direction="in">
|
||||
<doc:doc><doc:summary>server name</doc:summary></doc:doc>
|
||||
<arg type="s" name="config" direction="in">
|
||||
<doc:doc><doc:summary>name of configuration to be created or used in session</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<arg type="o" name="session" direction="out">
|
||||
<doc:doc><doc:summary>session D-Bus object path</doc:summary></doc:doc>
|
||||
</arg>
|
||||
</method>
|
||||
|
||||
<method name="StartSessionWithFlags">
|
||||
<doc:doc><doc:description>
|
||||
Start a session. The object is created instantly but will not be
|
||||
ready for method calls until status changes from "queueing" to "idle".
|
||||
The Detach() method can be called before that. Additional flags,
|
||||
identified by strings, can be passed to control the session creation.
|
||||
They can be retrieved with Session.GetFlags(). The following flags are
|
||||
currently defined:
|
||||
<doc:list>
|
||||
<doc:item><doc:term>no-sync</doc:term>
|
||||
<doc:definition>session will not be used for running a synchronization</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
</doc:description></doc:doc>
|
||||
<arg type="s" name="config" direction="in">
|
||||
<doc:doc><doc:summary>name of configuration to be created or used in session</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<arg type="a{s}" name="flags" direction="in">
|
||||
<doc:doc><doc:summary>optional flags</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<arg type="o" name="session" direction="out">
|
||||
<doc:doc><doc:summary>session D-Bus object path</doc:summary></doc:doc>
|
||||
|
|
|
@ -6,6 +6,17 @@
|
|||
<doc:para>Commands (other than Detach()) cannot be used before the status changes to "idle" (see GetStatus() and StatusChanged).</doc:para>
|
||||
</doc:description></doc:doc>
|
||||
|
||||
<method name="GetFlags">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
Get the session flags set with Server.StartSessionWithFlags().
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
<arg type="a{s}" name="flags" direction="out">
|
||||
<doc:doc><doc:summary>session flags</doc:summary></doc:doc>
|
||||
</arg>
|
||||
</method>
|
||||
|
||||
<method name="GetConfig">
|
||||
<doc:doc><doc:description>Get the configuration of the server</doc:description></doc:doc>
|
||||
<arg type="b" name="tmplate" direction="in">
|
||||
|
|
|
@ -1049,7 +1049,16 @@ class DBusServer : public DBusObjectHelper,
|
|||
void startSession(const Caller_t &caller,
|
||||
const boost::shared_ptr<Watch> &watch,
|
||||
const std::string &server,
|
||||
DBusObject_t &object);
|
||||
DBusObject_t &object) {
|
||||
startSessionWithFlags(caller, watch, server, std::vector<std::string>(), object);
|
||||
}
|
||||
|
||||
/** Server.StartSessionWithFlags() */
|
||||
void startSessionWithFlags(const Caller_t &caller,
|
||||
const boost::shared_ptr<Watch> &watch,
|
||||
const std::string &server,
|
||||
const std::vector<std::string> &flags,
|
||||
DBusObject_t &object);
|
||||
|
||||
/** Server.GetConfig() */
|
||||
void getConfig(const std::string &config_name,
|
||||
|
@ -1671,6 +1680,7 @@ class Session : public DBusObjectHelper,
|
|||
private boost::noncopyable
|
||||
{
|
||||
DBusServer &m_server;
|
||||
std::vector<std::string> m_flags;
|
||||
const std::string m_sessionID;
|
||||
std::string m_peerDeviceID;
|
||||
|
||||
|
@ -1827,7 +1837,8 @@ public:
|
|||
Session(DBusServer &server,
|
||||
const std::string &peerDeviceID,
|
||||
const std::string &config_name,
|
||||
const std::string &session);
|
||||
const std::string &session,
|
||||
const std::vector<std::string> &flags = std::vector<std::string>());
|
||||
~Session();
|
||||
|
||||
enum {
|
||||
|
@ -1897,6 +1908,9 @@ public:
|
|||
const string &descr,
|
||||
const ConfigPasswordKey &key);
|
||||
|
||||
/** Session.GetFlags() */
|
||||
std::vector<std::string> getFlags() { return m_flags; }
|
||||
|
||||
/** Session.SetConfig() */
|
||||
void setConfig(bool update, bool temporary,
|
||||
const ReadOperations::Config_t &config);
|
||||
|
@ -3112,13 +3126,15 @@ string Session::syncStatusToString(SyncStatus state)
|
|||
Session::Session(DBusServer &server,
|
||||
const std::string &peerDeviceID,
|
||||
const std::string &config_name,
|
||||
const std::string &session) :
|
||||
const std::string &session,
|
||||
const std::vector<std::string> &flags) :
|
||||
DBusObjectHelper(server.getConnection(),
|
||||
std::string("/org/syncevolution/Session/") + session,
|
||||
"org.syncevolution.Session",
|
||||
boost::bind(&DBusServer::autoTermCallback, &server)),
|
||||
ReadOperations(config_name, server),
|
||||
m_server(server),
|
||||
m_flags(flags),
|
||||
m_sessionID(session),
|
||||
m_peerDeviceID(peerDeviceID),
|
||||
m_serverMode(false),
|
||||
|
@ -3144,6 +3160,7 @@ Session::Session(DBusServer &server,
|
|||
emitProgress(*this, "ProgressChanged")
|
||||
{
|
||||
add(this, &Session::detach, "Detach");
|
||||
add(this, &Session::getFlags, "GetFlags");
|
||||
add(static_cast<ReadOperations *>(this), &ReadOperations::getConfigs, "GetConfigs");
|
||||
add(static_cast<ReadOperations *>(this), &ReadOperations::getConfig, "GetConfig");
|
||||
add(this, &Session::setConfig, "SetConfig");
|
||||
|
@ -4626,7 +4643,7 @@ vector<string> DBusServer::getCapabilities()
|
|||
// capabilities.push_back("GetConfigName");
|
||||
// capabilities.push_back("Notifications");
|
||||
capabilities.push_back("Version");
|
||||
// capabilities.push_back("SessionFlags");
|
||||
capabilities.push_back("SessionFlags");
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
|
@ -4718,10 +4735,11 @@ void DBusServer::connect(const Caller_t &caller,
|
|||
object = c->getPath();
|
||||
}
|
||||
|
||||
void DBusServer::startSession(const Caller_t &caller,
|
||||
const boost::shared_ptr<Watch> &watch,
|
||||
const std::string &server,
|
||||
DBusObject_t &object)
|
||||
void DBusServer::startSessionWithFlags(const Caller_t &caller,
|
||||
const boost::shared_ptr<Watch> &watch,
|
||||
const std::string &server,
|
||||
const std::vector<std::string> &flags,
|
||||
DBusObject_t &object)
|
||||
{
|
||||
boost::shared_ptr<Client> client = addClient(getConnection(),
|
||||
caller,
|
||||
|
@ -4730,7 +4748,8 @@ void DBusServer::startSession(const Caller_t &caller,
|
|||
boost::shared_ptr<Session> session(new Session(*this,
|
||||
"is this a client or server session?",
|
||||
server,
|
||||
new_session));
|
||||
new_session,
|
||||
flags));
|
||||
client->attach(session);
|
||||
session->activate();
|
||||
enqueue(session);
|
||||
|
@ -4788,6 +4807,7 @@ DBusServer::DBusServer(GMainLoop *loop, const DBusConnectionPtr &conn, int durat
|
|||
add(this, &DBusServer::detachClient, "Detach");
|
||||
add(this, &DBusServer::connect, "Connect");
|
||||
add(this, &DBusServer::startSession, "StartSession");
|
||||
add(this, &DBusServer::startSessionWithFlags, "StartSessionWithFlags");
|
||||
add(this, &DBusServer::getConfigs, "GetConfigs");
|
||||
add(this, &DBusServer::getConfig, "GetConfig");
|
||||
add(this, &DBusServer::getReports, "GetReports");
|
||||
|
|
|
@ -353,12 +353,15 @@ class DBusUtil(Timeout):
|
|||
'/org/syncevolution/Server'),
|
||||
'org.syncevolution.Server')
|
||||
|
||||
def createSession(self, config, wait):
|
||||
def createSession(self, config, wait, flags=[]):
|
||||
"""Return sessionpath and session object for session using 'config'.
|
||||
A signal handler calls loop.quit() when this session becomes ready.
|
||||
If wait=True, then this call blocks until the session is ready.
|
||||
"""
|
||||
sessionpath = self.server.StartSession(config)
|
||||
if flags:
|
||||
sessionpath = self.server.StartSessionWithFlags(config, flags)
|
||||
else:
|
||||
sessionpath = self.server.StartSession(config)
|
||||
|
||||
def session_ready(object, ready):
|
||||
if self.running and ready and object == sessionpath:
|
||||
|
@ -534,7 +537,9 @@ class TestDBusServer(unittest.TestCase, DBusUtil):
|
|||
|
||||
def testCapabilities(self):
|
||||
"""check the Server.GetCapabilities() call"""
|
||||
self.failUnlessEqual(self.server.GetCapabilities(), ['Version'])
|
||||
capabilities = self.server.GetCapabilities()
|
||||
capabilities.sort()
|
||||
self.failUnlessEqual(capabilities, ['SessionFlags', 'Version'])
|
||||
|
||||
def testVersions(self):
|
||||
"""check the Server.GetVersions() call"""
|
||||
|
@ -887,7 +892,13 @@ class TestDBusSession(unittest.TestCase, DBusUtil):
|
|||
|
||||
def testCreateSession(self):
|
||||
"""ask for session"""
|
||||
pass
|
||||
self.failUnlessEqual(self.session.GetFlags(), [])
|
||||
|
||||
def testCreateSessionWithFlags(self):
|
||||
"""ask for session with some specific flags"""
|
||||
self.session.Detach()
|
||||
self.sessionpath, self.session = self.createSession("", True, ["foo", "bar"])
|
||||
self.failUnlessEqual(self.session.GetFlags(), ["foo", "bar"])
|
||||
|
||||
@timeout(20)
|
||||
def testSecondSession(self):
|
||||
|
|
Loading…
Reference in New Issue