syncevo-dbus-server: moved to gdbus with C++ bridge
This is basically a rewrite from scratch, targeting the revised D-Bus API. The core infrastructure for handling client requests is in place, including the work queue for sessions and unexpected disconnects. Many of the related D-Bus methods (Server.Connect(), Server.StartSession(), Connection.Close(), Session.Close()) are implemented. Rudimentary testing is done with the test/dbus-server-connect.py script.
This commit is contained in:
parent
41df159fee
commit
ec185613ec
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Intel Corporation
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) version 3.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "DBusSyncClient.h"
|
||||
#include <syncevo/SyncSource.h>
|
||||
|
||||
|
||||
DBusSyncClient::DBusSyncClient(const string &server,
|
||||
const map<string, int> &source_map,
|
||||
void (*progress) (const char *source,int type,int extra1,int extra2,int extra3,gpointer data),
|
||||
void (*server_message) (const char *message,gpointer data),
|
||||
char* (*need_password) (const char *username, const char *server_url, gpointer data),
|
||||
gboolean (*check_for_suspend)(gpointer data),
|
||||
gpointer userdata) :
|
||||
SyncContext(server, true, getSyncSources (source_map)),
|
||||
m_source_map (source_map),
|
||||
m_userdata (userdata),
|
||||
m_progress (progress),
|
||||
m_server_message (server_message),
|
||||
m_need_password (need_password),
|
||||
m_check_for_suspend (check_for_suspend)
|
||||
{
|
||||
}
|
||||
|
||||
DBusSyncClient::~DBusSyncClient()
|
||||
{
|
||||
}
|
||||
|
||||
void DBusSyncClient::prepare(const std::vector<SyncSource *> &sources)
|
||||
{
|
||||
SyncModes modes (SYNC_NONE);
|
||||
|
||||
map<string,int>::const_iterator iter;
|
||||
for (iter = m_source_map.begin (); iter != m_source_map.end (); iter++) {
|
||||
modes.setSyncMode (iter->first, (SyncMode)iter->second);
|
||||
}
|
||||
setSyncModes (sources, modes);
|
||||
|
||||
}
|
||||
|
||||
bool DBusSyncClient::getPrintChanges() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string DBusSyncClient::askPassword(const string &passwordName, const string &descr, const ConfigPasswordKey &key)
|
||||
{
|
||||
string retval;
|
||||
char *password = NULL;
|
||||
if (!m_need_password)
|
||||
throwError(string("Password query not supported"));
|
||||
|
||||
password = m_need_password (getUsername (), getSyncURL(), m_userdata);
|
||||
if (password)
|
||||
retval = string (password);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void DBusSyncClient::displayServerMessage(const string &message)
|
||||
{
|
||||
m_server_message (message.c_str(), m_userdata);
|
||||
}
|
||||
|
||||
void DBusSyncClient::displaySyncProgress(sysync::TProgressEventEnum type,
|
||||
int32_t extra1, int32_t extra2, int32_t extra3)
|
||||
{
|
||||
m_progress (NULL, type, extra1, extra2, extra3, m_userdata);
|
||||
SyncContext::displaySyncProgress(type, extra1, extra2, extra3);
|
||||
}
|
||||
|
||||
void DBusSyncClient::displaySourceProgress(sysync::TProgressEventEnum type,
|
||||
SyncSource &source,
|
||||
int32_t extra1, int32_t extra2, int32_t extra3)
|
||||
{
|
||||
m_progress (g_strdup (source.getName()), type, extra1, extra2,
|
||||
// Synthesis engine doesn't count locally
|
||||
// deleted items during
|
||||
// refresh-from-server. That's a matter of
|
||||
// taste. In SyncEvolution we'd like these
|
||||
// items to show up, so add it here.
|
||||
(type == sysync::PEV_DSSTATS_L &&
|
||||
source.getFinalSyncMode() == SYNC_REFRESH_FROM_SERVER) ?
|
||||
source.getNumDeleted() :
|
||||
extra3,
|
||||
m_userdata);
|
||||
SyncContext::displaySourceProgress(type, source, extra1, extra2, extra3);
|
||||
}
|
||||
|
||||
bool DBusSyncClient::checkForSuspend()
|
||||
{
|
||||
return m_check_for_suspend (m_userdata);
|
||||
}
|
||||
|
||||
int DBusSyncClient::sleep (int intervals)
|
||||
{
|
||||
time_t start = time(NULL);
|
||||
while (true) {
|
||||
g_main_context_iteration(NULL, FALSE);
|
||||
time_t now = time(NULL);
|
||||
if (m_check_for_suspend(m_userdata)) {
|
||||
return (intervals - now + start);
|
||||
}
|
||||
if (intervals - now + start <=0) {
|
||||
return intervals - now +start;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Intel Corporation
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) version 3.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* This is an implementation of SyncContext
|
||||
* that is a DBus service. Internally it uses a
|
||||
* SyncevoDBusServer GObject to handle the DBus side
|
||||
* of things.
|
||||
* */
|
||||
|
||||
|
||||
#ifndef INCL_DBUSSYNCCLIENT
|
||||
#define INCL_DBUSSYNCCLIENT
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <synthesis/sync_declarations.h>
|
||||
#include <syncevo/SyncContext.h>
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
using namespace SyncEvo;
|
||||
|
||||
class DBusSyncClient : public SyncContext {
|
||||
|
||||
public:
|
||||
DBusSyncClient(const string &server,
|
||||
const map<string, int> &source_map,
|
||||
void (*progress) (const char *source,int type,int extra1,int extra2,int extra3,gpointer data) = NULL,
|
||||
void (*server_message) (const char *message,gpointer data) = NULL,
|
||||
char* (*need_password) (const char *username, const char *server_url, gpointer data) = NULL,
|
||||
gboolean (*check_for_suspend)(gpointer data) = NULL,
|
||||
gpointer userdata = NULL);
|
||||
|
||||
~DBusSyncClient();
|
||||
|
||||
protected:
|
||||
virtual void prepare(const std::vector<SyncSource *> &sources);
|
||||
|
||||
virtual bool getPrintChanges() const;
|
||||
|
||||
virtual string askPassword(const string &passwordName, const string &descr, const ConfigPasswordKey &key);
|
||||
|
||||
virtual void displayServerMessage(const string &message);
|
||||
|
||||
virtual void displaySyncProgress(sysync::TProgressEventEnum type,
|
||||
int32_t extra1, int32_t extra2, int32_t extra3);
|
||||
|
||||
virtual void displaySourceProgress(sysync::TProgressEventEnum type,
|
||||
SyncSource &source,
|
||||
int32_t extra1, int32_t extra2, int32_t extra3);
|
||||
|
||||
virtual bool checkForSuspend();
|
||||
|
||||
virtual int sleep (int intervals);
|
||||
|
||||
private:
|
||||
map<string, int> m_source_map;
|
||||
gpointer m_userdata;
|
||||
|
||||
void (*m_progress) (const char *source,int type,int extra1,int extra2,int extra3,gpointer data);
|
||||
void (*m_server_message) (const char *message, gpointer data);
|
||||
char* (*m_need_password) (const char *username, const char *server_url, gpointer data);
|
||||
gboolean (*m_check_for_suspend) (gpointer data);
|
||||
|
||||
static set<string> getSyncSources (const map<string, int> &source_map)
|
||||
{
|
||||
set<string> sources;
|
||||
map<string,int>::const_iterator iter;
|
||||
|
||||
for (iter = source_map.begin (); iter != source_map.end (); iter++)
|
||||
sources.insert (iter->first);
|
||||
|
||||
return sources;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -140,18 +140,16 @@ distclean-local:
|
|||
|
||||
if COND_DBUS
|
||||
syncevo_dbus_server_SOURCES = \
|
||||
syncevo-dbus-server.cpp syncevo-dbus-server.h \
|
||||
DBusSyncClient.cpp DBusSyncClient.h \
|
||||
syncevo-dbus-server.cpp \
|
||||
$(CORE_SOURCES)
|
||||
nodist_syncevo_dbus_server_SOURCES = \
|
||||
dbus/interfaces/syncevo-marshal.c \
|
||||
../test/test.cpp
|
||||
|
||||
syncevo_dbus_server_LDADD = $(DBUS_GLIB_LIBS) $(KEYRING_LIBS) $(CORE_LDADD)
|
||||
syncevo_dbus_server_CPPFLAGS = -DHAVE_CONFIG_H -Idbus/interfaces $(DBUS_GLIB_CFLAGS) $(KEYRING_CFLAGS) $(AM_CPPFLAGS)
|
||||
syncevo_dbus_server_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS)
|
||||
syncevo_dbus_server_LDADD = gdbus/libgdbus.la $(CORE_LDADD)
|
||||
syncevo_dbus_server_CPPFLAGS = -DHAVE_CONFIG_H -I$(srcdir)/gdbus $(AM_CPPFLAGS)
|
||||
syncevo_dbus_server_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS)
|
||||
syncevo_dbus_server_LDFLAGS = $(CORE_LD_FLAGS)
|
||||
syncevo_dbus_server_DEPENDENCIES = $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)
|
||||
syncevo_dbus_server_DEPENDENCIES = gdbus/libgdbus.la $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)
|
||||
endif
|
||||
|
||||
# With --disable-shared autotools links against libfunambol.a which does not
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Intel Corporation
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) version 3.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __SYNCEVO_DBUS_SERVER_H
|
||||
#define __SYNCEVO_DBUS_SERVER_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
typedef struct _SyncevoDBusServer SyncevoDBusServer;
|
||||
#include "DBusSyncClient.h"
|
||||
|
||||
#define SYNCEVO_TYPE_DBUS_SERVER (syncevo_dbus_server_get_type ())
|
||||
#define SYNCEVO_DBUS_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYNCEVO_TYPE_DBUS_SERVER, SyncevoDBusServerClass))
|
||||
|
||||
typedef struct _SyncevoDBusServer {
|
||||
GObject parent_object;
|
||||
|
||||
DBusSyncClient *client;
|
||||
char *server;
|
||||
GPtrArray *sources;
|
||||
|
||||
gboolean aborted;
|
||||
|
||||
guint shutdown_timeout_src;
|
||||
} SyncevoDBusServer;
|
||||
|
||||
typedef struct _SyncevoDBusServerClass {
|
||||
GObjectClass parent_class;
|
||||
DBusGConnection *connection;
|
||||
|
||||
/* DBus signals*/
|
||||
void (*progress) (SyncevoDBusServer *service,
|
||||
char *server,
|
||||
char *source,
|
||||
int type,
|
||||
int extra1, int extra2, int extra3);
|
||||
void (*server_message) (SyncevoDBusServer *service,
|
||||
char *server,
|
||||
char *message);
|
||||
} SyncevoDBusServerClass;
|
||||
|
||||
GType syncevo_dbus_server_get_type (void);
|
||||
|
||||
void
|
||||
emit_progress (const char *source,
|
||||
int type,
|
||||
int extra1,
|
||||
int extra2,
|
||||
int extra3,
|
||||
gpointer data);
|
||||
|
||||
void
|
||||
emit_server_message (const char *message,
|
||||
gpointer data);
|
||||
|
||||
gboolean
|
||||
check_for_suspend (gpointer data);
|
||||
|
||||
#endif // __SYNCEVO_DBUS_SERVER_H
|
|
@ -0,0 +1,70 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
import dbus
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
import gobject
|
||||
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
|
||||
object = dbus.Interface(bus.get_object('org.syncevolution',
|
||||
'/org/syncevolution/Server'),
|
||||
'org.syncevolution.Server')
|
||||
|
||||
conpath = object.Connect({'description': 'dbus-server-connection.py',
|
||||
'transport': 'dummy'},
|
||||
False,
|
||||
0)
|
||||
print conpath
|
||||
|
||||
connection = dbus.Interface(bus.get_object('org.syncevolution',
|
||||
conpath),
|
||||
'org.syncevolution.Connection')
|
||||
connection.Close(False, 'die, connection, die')
|
||||
|
||||
|
||||
loop = gobject.MainLoop()
|
||||
|
||||
conpath = object.Connect({'description': 'dbus-server-connection.py',
|
||||
'transport': 'dummy'},
|
||||
False,
|
||||
0)
|
||||
connection = dbus.Interface(bus.get_object('org.syncevolution',
|
||||
conpath),
|
||||
'org.syncevolution.Connection')
|
||||
|
||||
def Reply(data, type, meta, final, session):
|
||||
print "Reply:", data, type, meta, final, session
|
||||
connection.Close(True, '')
|
||||
|
||||
sessionpath = None
|
||||
def SessionChanged(object, ready):
|
||||
print "SessionChanged:", object, ready
|
||||
if not ready or sessionpath == object:
|
||||
loop.quit()
|
||||
|
||||
bus.add_signal_receiver(Reply,
|
||||
'Reply',
|
||||
'org.syncevolution.Connection',
|
||||
'org.syncevolution',
|
||||
conpath,
|
||||
byte_arrays=True)
|
||||
bus.add_signal_receiver(SessionChanged,
|
||||
'SessionChanged',
|
||||
'org.syncevolution.Server',
|
||||
'org.syncevolution',
|
||||
None,
|
||||
byte_arrays=True)
|
||||
connection.Process([ 1, 2, 3, 4 ], "dummy message type")
|
||||
loop.run()
|
||||
|
||||
sessionpath = object.StartSession('no_such_server')
|
||||
session = dbus.Interface(bus.get_object('org.syncevolution',
|
||||
sessionpath),
|
||||
'org.syncevolution.Session')
|
||||
# wait for session ready
|
||||
loop.run()
|
||||
session.Close()
|
||||
# wait for session gone
|
||||
loop.run()
|
Loading…
Reference in New Issue