Commit graph

1662 commits

Author SHA1 Message Date
Patrick Ohly
88f35083a5 syncevo-dbus-server: fix for handling of active session
The logic for creating a shared_ptr for the active session
was flawed: it assumed that the session must be owned by
a client, which is not true if some other entity (like
a Connection) owns it.

As a result of this flaw, DBusServer::m_syncSession wasn't
set when running a sync via the Connection API, which
crashed when the Connection destructed itself and the
session while some of the session code was still active.

Fixed by keeping both a plain pointer (for the case when
the weak_ptr doesn't provide it anymore while shutting
itself down) and a weak_ptr (which avoids searching for
the shared_ptr).
2009-10-07 18:11:48 +02:00
Patrick Ohly
18a0d2ad3d TransportAgent: added shutdown(), moved HTTP setup out of core engine
This TransportAgent API revision was done in preparation for transport
agents which do not support HTTP. Forcing them to provide HTTP specific
methods is unnecessary, so now setting things like proxy is done when
constructing an HTTP-based agent in the createTransport() call.
So now the result of createTransport() must be ready for sending messages.

setURL() is still part of the API, because it provides message-specific
information. Perhaps it should be renamed when it is clearer what
the corresponding information in other transports is.

For connection oriented agents a new shutdown() call was introduced.
This gives them a chance to close the connection and inform the
engine about errors during that shutdown.

For servers (which send the last message without expecting a reply),
wait(noReply=true) was added.
2009-10-07 18:10:55 +02:00
Patrick Ohly
b080991fd6 SharedBuffer: added the possibility to create a SharedBuffer from const memory
When passing const memory, the constructor copies the memory.
The constructor for non-const memory takes ownership of the memory,
as before.
2009-10-07 18:10:24 +02:00
Patrick Ohly
a3d85c4bba syncevo-dbus-server: implemented Session.Sync() parameter handling
The Session.Sync() parameters are a special case of temporarily
overriding the source properties of all or some sources. This
patch uses the new per-source config filters to transfer the
parameters to the core sync engine.

This patch also introduces Session members for temporary config
changes, which is another way of setting these and other parameters.
These Session members must be set in SetConfig(temporary=true) calls
(not done yet).
2009-10-07 18:10:06 +02:00
Patrick Ohly
d8283ba873 sync source handling: implemented per-source property filtering, Cmdline uses it
Selecting active sources during a sync or status check was done with a
combination of setting a sync mode via a source config filter and
setting a list of active sources. Now the SyncConfig supports a source
filter which is applied to all sources and source filters for each
source. The latter override the former.

This is powerful enough to start syncs with full control over which
sources are active in which mode, as described in the new D-Bus API.
As part of this patch, the command line semantic is implemented
entirely using a combination of different source filters.
2009-10-07 18:10:00 +02:00
Patrick Ohly
4ac0e355c9 syncevo-dbus-server: implemented Session.Sync() and sync status/progress
The Session keeps the sync progress and status in the format expected
by the D-Bus interface. That way it is available without the corresponding
sync engine.

To run a sync, the Session.Sync() method creates a DBusSync, derived
from SyncContext. With an eye towards peer-to-peer sync the
new class and member are named just "sync" instead of using the too
specific "client". When that instance is ready, the g_main_loop_run()
call in DBusServer::run() is stopped and DBusServer::run() hands
over control to Session::run().

That call transfers control to SyncContext::sync(), which
retains control as long as the sync runs. Occassionally (via
progress calls) control is returned temporarily. These calls could be used
to check for D-Bus requests, but currently that is only done when
the sync blocks while transferring messages, by configuring the
SoupTransportAgent to use the same GMainLoop as the D-Bus binding.

The implementation of the D-Bus interface is still very much incomplete.
All of the missing bits and pieces are marked as TODO in the source.
2009-10-07 18:08:35 +02:00
Patrick Ohly
e7af0c9186 SyncContext: added handleException()
This method complements the corresponding method in SyncSource.
At the moment it does not do more than calling the underlying
Exception::handle(). Calling it via SyncContext
is more natural and might be treated differently in the future.
2009-10-07 18:06:07 +02:00
Patrick Ohly
bf2954e5d2 syncevo-dbus-server: added stubs for Server/Session.GetConfig/GetReports()
Both methods are to be implemented inside the ReadOperations
class, which has the server configuration name as sole data item.
The Server methods are provided by glue code which instantiates
a ReadOperations object and calls the real methods.

From a C++ class design perspective the Server glue methods
should be declared static and the ReadOperations methods as const.
However, both qualifiers are not currently supported by the C++
binding.
2009-10-07 18:04:59 +02:00
Patrick Ohly
ec185613ec 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.
2009-10-07 18:03:16 +02:00
Patrick Ohly
41df159fee D-Bus API: added next generation D-Bus UI API
The new API defines two interfaces:
- org.syncevolution.Server for read-only access and starting sessions
- org.syncevolution.Session read/write operations and syncs
- org.syncevolution.Connection for transport stubs

At the moment the new D-Bus interface descriptions are purely for
documentation, they are not used by the GUI yet. Therefore syntax
errors might go unnoticed. Applying xslt to generate the docbook XML
catches some of these.
2009-10-07 17:57:22 +02:00
Patrick Ohly
7b5ae309bf D-Bus C++: added support for structs
Members of structs must be read- and writeable
because the marshaling code accesses them directly.
The dbus_traits then can be defined by deriving
from dbus_struct_traits with template parameters
which describe the struct members.
2009-10-07 16:11:33 +02:00
Patrick Ohly
ecaa53241b D-Bus C++: added support for in-place passing of basic arrays
With V being a basic type, "std::pair<size_t, const V *> &" can
be used to pass an array. The caller owns the array, so this
can be used for method parameters, reply parameters and signals,
but not for return values.

dbus_traits<V> must provide a dbus_type, which is used to
extract and encode the data efficiently via dbus_message_iter_get_fixed_array()
and dbus_message_iter_append_fixed_array().
2009-10-07 16:11:20 +02:00
Patrick Ohly
940383f0b4 D-Bus C++: let app use char and unsigned char for D-BUS BYTE
Strictly speaking, an app has to use uint8_t when it wants
to exchange BYTEs with D-Bus. The extended binding maps both
int8_t and uint8_t to BYTE, so the app can use char and unsigned
char.
2009-10-07 16:11:20 +02:00
Patrick Ohly
b435d87392 D-Bus C++: added the possibility to pass Caller ID string and a watch
Use
    const Caller_t &caller
to get a caller ID string. Caller_t is a class which mimicks a
string, which is necessary to distinguish this parameter
from a std::string parameter passed via D-Bus.

Use
    const boost::shared_ptr<Watch> &watch
to be called with an active watch on the caller.
The callback invoked by the Watch must be set
with setCallback().
2009-10-07 16:11:20 +02:00
Patrick Ohly
0fb5794a21 D-Bus C++: C++ helper classes for libdbus/libgdbus
C++ classes and templates provided by header files simplify
programming in C++ with libdbus and libgdbus. libdbus items are
tracked with Boost shared pointers. Errors are turned into
exceptions. The binding to C++ is done via templates which provide the
C-style callbacks and declarations expected by libgdbus and map to
standard C++ types and STL data structures. Neither code generator nor
library code is required.

Synchronous and asynchronous method implementation are supported.
Asynchronous result deliver is done via a callback object with a
C++ signature that matches the values which have to be returned.

Due to the lack of variadic templates, lots of similar templates have
to be written to cover methods with varying combinations of arguments
and return codes. Not particularly elegant, but the alternative would
be to introduce a code generator, which has its own
drawbacks. Currently up to 10 items per method are supported, where
the number of items include the optional return value, arguments and
retvals.

Setting a Watch (base class) notifies the implementor of an when his
caller disconnects.  This can be used to abort a long-running method
when the consumer of the result goes away.

Callers are identified by their unique Bus ID, represented as Caller_t,
an alias for a plain std::string.

Objects are represented by their path with a DBusObject_t, again a
plain std::string. By default, each path comes with one interface
(DBusObject). It is possible to instantiate multiple DBusObjects with
the same path, which appears on D-Bus as a single object with multiple
interfaces.

The DBusObjectHelper simplifies object handling. It stores the
necessary information and connection reference so that the object can
be unregistered when the DBusObjectHelper is destroyed. The intended
usage is that classes own instances of DBusObjectHelper and activate
those with a method table that points to class methods.

Signals are handled as instances of EmitSignalX templates where X
stands for the number of parameters, pretty much like ResultX
callbacks are handled. The function call operator emits the signal,
with the auxiliary information (D-Bus signal name) set when
instantiating the EmitSignalX object as part of a class. The D-Bus
connection and interface is provided at the time of the signal
emission by the parent DBusObject.

The table entry for the signal is created by a static member function
of the template, which allows building a static table as required by
gdbus. Note that the signal name must be passed into that
function. This slight duplication is necessary because the template
cannot be parameterized with a string constant. Turning
makeSignalEntry() into a normal member function would make it
difficult to build the signal table.

DBusErrorCXX is a helper class for DBusError which automatically
initializes the struct, can be used to check for an error and throws
an exception for it.
2009-10-07 16:11:20 +02:00
Patrick Ohly
914dc8d15e gdbus: fixed segfault in watch disconnect function
If the apps callback function removes the watch that
triggered it, then disconnect_function() used a dangling
data pointer to retrieve the id (first problem) and
g_dbus_remove_watch() used a -1 connection_slot (second
problem, only occurs when the current watch was the
last one).

Fixed by storing the ID in a temporary variable and
adding a connection_slot check to g_dbus_remove_watch(),
similar to the one which was already in g_dbus_remove_all_watches().
2009-10-07 16:11:19 +02:00
Patrick Ohly
962599e5f8 gdbus: allow registering multiple interfaces per object
Apparently this was part of the design (there was a refcount
in ObjectData and a list of interfaces), but the implementation
didn't really use much of that.

Added a check whether there is already an object registered under
a path and reuse that object when adding further interfaces. Only
remove the object when its last interface is gone.
2009-10-07 16:11:19 +02:00
Patrick Ohly
50c7d83636 g_dbus_unregister_object(): fix same invalid memory reuse as for watches
g_dbus_unregister_object() has the same logical flaw as g_dbus_remove_watch():
it left a dangling pointer to its data in the connection slot. This pointer
was found when the slot was reused in the following call sequence:
g_dbus_register_interface()
g_dbus_unregister_interface()
g_dbus_register_interface()

The result was a segfault.
2009-10-07 16:11:19 +02:00
Patrick Ohly
5b71583cd1 g_dbus_create_error(): implemented support for detailed error description
The API had printf-style formatting for a detailed error description,
but that information was ignored. Added a sprintf variant which
allocates the resulting string dynamically, based on vsnprintf().
2009-10-07 16:11:19 +02:00
Patrick Ohly
7e558b23a2 gdbus: compile the gdbus utility library
The library is compiled and installed as a syncevolution utility
library (in other words, as lib/syncevolution/libgdbus), so that
it never conflicts with a copy of the code in another project.
2009-10-07 16:11:02 +02:00
Patrick Ohly
83bf7442d3 watch: call dbus_bus_remove_match() for each dbus_bus_add_match()
Without the remove call the matches would accumulate over time,
which can't be good for the dbus-server.

libgdbus commit ID:
d0084fd7b13b7f4665c223877f77576b08624dbf
2009-10-07 16:07:50 +02:00
Patrick Ohly
b71e1a6fbd fix for ConnectionData handling
g_dbus_remove_watch() decremented the slot ref count and freed
the ConnectionData associated with it if the ref count reached
zero. This left a dangling pointer to the ConnectionData instance
in the slot, which was found and used once the slot got recycled.

The new approach is to clear the data pointer in the slot if
its last user (watch or handler) is gone.

libgdbus commit ID:
3bb0e1e01230f50f66b3004ca385d73c49bff2c6
2009-10-07 16:07:50 +02:00
Marcel Holtmann
55a400b646 Extended GDBusWatchFunction parameter list
libgdbus commit ID:
0ed91c956fb6cf3d94eac17e778c63d5867bcb96
2009-10-07 16:07:49 +02:00
Marcel Holtmann
a8eff07719 Convert all documentation to gtk-doc style
libgdbus commit ID:
a6267460b97efd0ec421e42b88b9ca81a5c9baeb
2009-10-07 16:07:49 +02:00
Marcel Holtmann
53462914bc Protect the interface list with a static mutex
libgdbus commit ID:
9e96781f0e9495ac8efe3b81df968d4ac505e4e8
2009-10-07 16:07:49 +02:00
Marcel Holtmann
8ed69fa134 Use a GSource for message dispatching
libgdbus commit ID:
5b48fc1b816042a9ba8df93f4463fc70f8f259c6
2009-10-07 16:07:49 +02:00
Marcel Holtmann
60ec6188ee Don't add an extra newline in the debug messages
libgdbus commit ID:
8673867875ccc57712ca8bd0aeacc5f43156a32e
2009-10-07 16:07:49 +02:00
Marcel Holtmann
3320a13ea9 Fix typo in debug statement
libgdbus commit ID:
40bc7e6c459548abff92303b770999d2c5e82904
2009-10-07 16:07:49 +02:00
Marcel Holtmann
8d86a083c2 Add watch helper for receiving signals
libgdbus commit ID:
944ca9edbf23fd8d1b5eef4125f18bf26d7257dd
2009-10-07 16:07:48 +02:00
Marcel Holtmann
cf5698f3e7 Use automatic object registration only
libgdbus commit ID:
b0b19a4da72972887580597aadb0b4c86e64134a
2009-10-07 16:07:48 +02:00
Marcel Holtmann
47809b8836 Use common GDBusWatchFunction prototype
libgdbus commit ID:
6605699e3a1ff8275dcc359da7aa73e9d36996f2
2009-10-07 16:07:48 +02:00
Marcel Holtmann
0031027d25 Remove return parameter from disconnect watch callback
libgdbus commit ID:
3dff292ec3e3f9a614e23c8801bccd76e8a052b3
2009-10-07 16:07:48 +02:00
Marcel Holtmann
bd0305aff4 Add more flexible error handling helpers
libgdbus commit ID:
475a7f3b15bc2446f76383e81ed1621ecd6b47e5
2009-10-07 16:07:48 +02:00
Marcel Holtmann
d860fdbec2 Add support for per interface user data
libgdbus commit ID:
5aa0ef05fd3bedef99e1a95ede14e29593cddcdc
2009-10-07 16:07:48 +02:00
Marcel Holtmann
81a28ef5af Add helper functions for creating errors and replies
libgdbus commit ID:
67e0538719f9509ac14843195515e93202f278fe
2009-10-07 16:07:47 +02:00
Marcel Holtmann
2af84d7bbf Add helper functions for sending errors and replies
libgdbus commit ID:
354a36005f34dfab3c23f6a26270e5e266f92475
2009-10-07 16:07:47 +02:00
Marcel Holtmann
874f948b27 Protect the object list with a static mutex
libgdbus commit ID:
b2ee63cb570dd6d8ea58abe9ed3403091cfc389a
2009-10-07 16:07:47 +02:00
Marcel Holtmann
8f16323bfb Update copyright information
libgdbus commit ID:
b0972117a2588631286c677791652b924eaa42ac
2009-10-07 16:07:47 +02:00
Marcel Holtmann
c8d91e35bb Remove option for using dbus-glib's mainloop integration
libgdbus commit ID:
d718c7a6cdef1b2c1345ffda1810fb6e4b4a8573
2009-10-07 16:07:47 +02:00
Marcel Holtmann
816208b434 Add additional checks for error handling
libgdbus commit ID:
17ba2b7bead1c2c37dc33187bdacbaa7bac78b96
2009-10-07 16:07:47 +02:00
Marcel Holtmann
397ba9d4b9 Add option to use dbus-glib's mainloop integration
libgdbus commit ID:
fb91bf75e2704a39f334a403b18cd5a6059fd47b
2009-10-07 16:07:47 +02:00
Marcel Holtmann
12b610ed5e Add error parameter to setup functions
libgdbus commit ID:
159897795a8ec83a03dd2370e2dd800d89d73ddb
2009-10-07 16:07:46 +02:00
Marcel Holtmann
264d47f595 Add annotation for asynchronous methods
libgdbus commit ID:
7fd09a4ca7a95027ff4b877e82049b6f913c1e78
2009-10-07 16:07:46 +02:00
Marcel Holtmann
cbcaa2da7d Add error handling if bus is not available
libgdbus commit ID:
50a20744b2c96f554ad0b7f405c6d0e656aec8fc
2009-10-07 16:07:46 +02:00
Marcel Holtmann
11ab7f4e03 Add function for requesting additional bus names
libgdbus commit ID:
bbd311b2e965c5544980c5f27bd6c4174c0df051
2009-10-07 16:07:46 +02:00
Marcel Holtmann
a9041ca056 Fix naming of object flags
libgdbus commit ID:
69b72cb3af989e75476429fd7b158ea974719fb4
2009-10-07 16:07:46 +02:00
Marcel Holtmann
e2cf82eec9 Fix parent path validation check
libgdbus commit ID:
b3b0e48c03fe9ded112e9dc715c02927484742e5
2009-10-07 16:07:46 +02:00
Marcel Holtmann
f9895cac09 Fix user data in property callbacks
libgdbus commit ID:
08105a42372956495e049571335a6641505dc12d
2009-10-07 16:07:45 +02:00
Marcel Holtmann
027b01f3d0 Fix introspection update for parent objects
libgdbus commit ID:
18f0754ad33e8206d314ad44c01aeed464b05e82
2009-10-07 16:07:45 +02:00
Marcel Holtmann
d16b517c64 Add function for connecting to specific bus addresses
libgdbus commit ID:
750826d3f5250109e8d957f90ed12d1e46e6eda4
2009-10-07 16:07:45 +02:00