syncevo-dbus-server: implement Server.GetSessions() (MB #8061)

The function was defined, but not part of the server implementation at
all. The order of the returned sessions is now defined in the
specification.

Note that the spec allows for *multiple* running sessions although
currently we only can have at most one.
This commit is contained in:
Patrick Ohly 2009-11-20 09:36:26 +01:00
parent 0bfc0a4bb7
commit d5e58fd0a9
3 changed files with 24 additions and 1 deletions

View File

@ -326,7 +326,8 @@
<method name="GetSessions">
<doc:doc><doc:description>Get currently existing sessions. This includes active and queueing sessions.</doc:description></doc:doc>
<arg type="ao" name="sessions" direction="out">
<doc:doc><doc:summary>array of session D-Bus object paths</doc:summary></doc:doc>
<doc:doc><doc:summary>array of session D-Bus object paths,
in the order in which they will run, running ones first</doc:summary></doc:doc>
</arg>
</method>

View File

@ -328,6 +328,9 @@ class DBusServer : public DBusObjectHelper
std::string &status,
std::vector<std::string> &transports);
/** Server.GetSessions() */
void getSessions(std::vector<std::string> &sessions);
/** Server.SessionChanged */
EmitSignal2<const DBusObject_t &,
bool> sessionChanged;
@ -2675,6 +2678,20 @@ void DBusServer::checkPresence(const std::string &server,
// TODO: implement this, right now always return status = "" = available
}
void DBusServer::getSessions(std::vector<std::string> &sessions)
{
sessions.reserve(m_workQueue.size() + 1);
if (m_activeSession) {
sessions.push_back(m_activeSession->getPath());
}
BOOST_FOREACH(boost::weak_ptr<Session> &session, m_workQueue) {
boost::shared_ptr<Session> s = session.lock();
if (s) {
sessions.push_back(s->getPath());
}
}
}
DBusServer::DBusServer(GMainLoop *loop, const DBusConnectionPtr &conn) :
DBusObjectHelper(conn.get(), "/org/syncevolution/Server", "org.syncevolution.Server"),
m_loop(loop),
@ -2696,6 +2713,7 @@ DBusServer::DBusServer(GMainLoop *loop, const DBusConnectionPtr &conn) :
add(this, &DBusServer::checkSource, "CheckSource");
add(this, &DBusServer::getDatabases, "GetDatabases");
add(this, &DBusServer::checkPresence, "CheckPresence");
add(this, &DBusServer::getSessions, "GetSessions");
add(sessionChanged);
add(presence);
}

View File

@ -515,7 +515,11 @@ class TestDBusSession(unittest.TestCase, DBusUtil):
@timeout(20)
def testSecondSession(self):
"""a second session should not run unless the first one stops"""
sessions = self.server.GetSessions()
self.failUnlessEqual(sessions, [self.sessionpath])
sessionpath = self.server.StartSession("")
sessions = self.server.GetSessions()
self.failUnlessEqual(sessions, [self.sessionpath, sessionpath])
def session_ready(object, ready):
if self.running: