syncevolution/src
Patrick Ohly a009f28520 D-Bus server: fork/exec for sync, command line and restore operations
This commit moves the blocking syncing, database restore and command
line execution into a separate, short-lived process executing the
syncevo-dbus-helper. The advantage is that the main
syncevo-dbus-server remains responsive under all circumstances (fully
asynchronous now) and suffers less from memory leaks and/or crashes
during a sync.

The core idea behind the new architecture is that Session remains the
D-Bus facing side of a session. It continues to run inside
syncevo-dbus-server and uses the syncevo-dbus-helper transparently via
a custom D-Bus interface between the two processes. State changes of
the helper are mirrored in the server.

Later the helper might also be used multiple times in a Session. For
example, anything related to loading backends should be moved into the
helper (currently the "is config usable" check still runs in the
syncevo-dbus-server and needs to load/initialize backends). The
startup code of the helper already handles that (see boolean result of
operation callback), but it is not used yet in practice.

At the moment, only the helper provides a D-Bus API. It sends out
signals when it needs information from the server. The server watches
those and replies when ready. The helper monitors the connection to
the parent and detects that it won't get an answer if that connection
goes down.

The problem of "helper died unexpectedly" is also handled, by not
returning a D-Bus method reply until the requested operation is
completed (different from the way how the public D-Bus API is
defined!).

The Connection class continues to use such a Session, as before. It's
now fully asynchronous and exchanges messages with the helper via the
Session class.

Inside syncevo-dbus-server, boost::signals2 and the dbus-callbacks
infrastructure for asynchronous methods execution are used heavily
now. The glib event loop is entered exactly once and only left to shut
down.

Inside syncevo-dbus-helper, the event loop is entered only as
needed. Password requests sent from syncevo-local-sync to
syncevo-dbus-helper are handled asynchronously inside the event loop
driven by the local transport.

syncevo-dbus-helper and syncevo-local-sync are conceptually very
similar. Should investigate whether a single executable can serve both
functions.

The AutoSyncManager was completely rewritten. The data structure is a
lot simpler now (basically just a cache of transient information about
a sync config and the relevant config properties that define auto
syncing). The main work happens inside the schedule() call, which
verifies whether a session can run and, if not possible for some
reasons, ensures that it gets invoked again when that blocker is
gone (timeout over, server idle, etc.). The new code also uses
signals/slots instead of explicit coupling between the different
classes.

All code still lives inside the src/dbus/server directory. This
simplifies checking differences in partly modified files like
dbus-sync.cpp. A future commit will move the helper files.

The syslog logger code is referenced by the server, but never used.
This functionality needs further thought:
- Make usage depend on command line option? Beware that test-dbus.py
  looks for the "ready to run" output and thus startup breaks when
  all output goes to syslog instead of stdout.
- Redirect glib messages into syslog (done by LogRedirect, disabled when
  using LoggerSyslog)?

The syncevo-dbus-server now sends the final "Session.StatusChanged
done" signal immediately. The old implementation accidentally delayed
sending that for 100 seconds. The revised test-dbus.py checks for
more "session done" quit events to cover this fix.

Only user-visible messages should have the INFO level in any of the
helpers. Messages about starting and stopping processes are related to
implementation details and thus should only have DEBUG level.

The user also doesn't care about where the operation eventually
runs. All messages related to it should be in INFO/DEBUG/ERROR
messages without a process name. Therefore now syncevo-dbus-server
logs with a process name (also makes some explicit argv[0] logging
redundant; requires changes in test-dbus.py) and syncevo-dbus-helper
doesn't.

syncevo-local-sync is different from syncevo-dbus-helper: it produces
user-relevant output (the other half of the local sync). It's output
is carefully chosen so that the process name is something the user
understands (target context) and output can be clearly related to one
side or the other (for example, context names are included in the sync
table).

Output handling is based on the same idea as output handling in the
syncevo-dbus-server:
- Session registers itself as the top-most logger and sends
  SyncEvolution logging via D-Bus to the parent, which re-sends
  it with the right D-Bus object path as output of the session.
- Output redirection catches all other output and feeds it back
  to the Session log handler, from where it goes via D-Bus
  to the parent.

The advantage of this approach is that level information is made
available directly to the parent and that message boundaries are
preserved properly.

stderr and stdout are redirected into the parent and logged there as
error. Normally the child should not print anything. While it runs,
LogRedirect inside it will capture output and log it
internally. Anything reaching the parent thus must be from early
process startup or shutdown.

Almost all communication from syncevo-dbus-helper to
syncevo-dbus-server is purely information for the syncevo-dbus-server;
syncevo-dbus-helper doesn't care whether the signal can be
delivered. The only exception is the information request, which must
succeed.

Instead of catching exceptions everywhere, the optional signals are
declared as such in the EmitSignal template parameterization and
no longer throw exceptions when something goes wrong. They also don't
log anything, because that could lead to quite a lof of output.
2012-05-10 22:08:49 +02:00
..
backends local + remote sync: negotiate UID support via SyncCap (BMC #22783) 2012-05-03 09:45:36 +02:00
dbus D-Bus server: fork/exec for sync, command line and restore operations 2012-05-10 22:08:49 +02:00
gdbus GDBus libdbus: signal delivery optional 2012-05-10 22:08:47 +02:00
gdbusxx GDBus GIO: abort when D-Bus name cannot be obtained 2012-05-10 22:08:48 +02:00
gnome-bluetooth Merge remote-tracking branch 'origin/syncevolution-1-2-branch' 2011-11-28 10:16:57 +01:00
gtk-ui GTK-2/3 UI: avoid g_strcasecmp 2012-04-24 15:42:09 +02:00
gtk3-ui GTK-2/3 UI: avoid g_strcasecmp 2012-04-24 15:42:09 +02:00
syncevo sync aborting: check while starting sync, avoid killing process during testing 2012-05-10 22:08:48 +02:00
synthesis-includes autotools: --disable-core --enable-gui => build only sync-ui and its D-Bus lib 2010-03-23 19:04:06 +01:00
templates Merge remote-tracking branch 'origin/syncevolution-1-2-branch' 2011-11-28 10:16:57 +01:00
async.patch patch switches to async version of the Evolution API 2007-02-22 19:33:21 +00:00
client-test-app.cpp testing: enhanced DAV source testing + infrastructure 2012-04-23 11:03:32 +00:00
client-test-buteo.cpp buteo-test: update tracker database file name 2010-12-15 15:45:23 +01:00
client-test-buteo.h buteo-test: update tracker database file name 2010-12-15 15:45:23 +01:00
CmdlineSyncClient.cpp SyncContext + ConfigUserInterface: code refactoring 2012-03-09 07:25:11 +00:00
CmdlineSyncClient.h SyncContext + ConfigUserInterface: code refactoring 2012-03-09 07:25:11 +00:00
README.h added missing copyright and license headers 2009-05-11 16:31:17 +02:00
README.templates Merge remote branch 'origin/syncevolution-0-9-branch' 2009-11-30 21:41:53 +01:00
shlibs.local reverted to 0.7 packaging 2008-07-03 19:56:15 +00:00
src.am D-Bus server: fork/exec for sync, command line and restore operations 2012-05-10 22:08:49 +02:00
syncevo-local-sync.cpp local sync: execute 'syncevo-local-sync' on child side, communicate via D-Bus 2012-01-20 13:38:49 +01:00
syncevolution.cpp command line: cleaned up output 2012-04-11 12:54:28 +02:00
testcases.am Port build system to non-recursive Automake. 2011-08-30 16:38:34 +02:00
valgrind.supp ObexTransportAgent: Fix valgrind warnings (MB#10091) 2010-03-12 06:33:13 -08:00

The configuration templates in "templates" get installed into
$(datadir)/syncevolution/templates.

When adding/changing a new server, then only enter the properties
which need to be changed here so that the default values can
be used for the remaining properties.

An icon can be added here for servers. The file name must start with
"icon".

Server configurations must be kept in sync in three different places:
- here (if a server is installed as files)
- in SyncEvolutionConfig.cpp's EvolutionSyncConfig::createServerTemplate()
- in SyncEvolutionCmdline.cpp's test server configs
- in test/test-dbus.py testGetConfigsTemplates()

Note that server icons must come with a suitable license that allows
redistribution.