Commit Graph

19 Commits

Author SHA1 Message Date
Milan Crha c656bc4a08 build: boost::placeholders
On Fedora, Boost placeholders are now in their own namespace.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2021-01-24 10:33:45 +01:00
Patrick Ohly b8cbd5358f C++: avoid NULL
NULL is ambiguous (can be integer and pointer) and using it as
terminator for vararg list of pointers without explicit casting to a
pointer was downright incorrect. nullptr fixes that.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2020-12-05 21:28:08 +01:00
Patrick Ohly 74f0d01f33 C++: remove more boost headers (tuple, assign, utility)
Several headers were no longer needed resp. could be replaced by more
specific ones like noncopyable.hpp.

boost::assign mostly can be replaced with initialization lists and
boost::tuple with std::tuple.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2020-12-05 21:28:08 +01:00
Patrick Ohly 6217ba0bd1 C++: avoid boost::scope_ptr/array and plain pointers
std::unique_ptr usually can be used instead. std::vector also works
for arrays and even has a data() method as part of the official API in
C++11.

For historic reasons, the functions creating SyncSources returned
plain pointers. We are breaking the API now, so we might as well fix
that.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2020-12-05 21:28:08 +01:00
Patrick Ohly 2fa3c3335a C++: replace boost::shared_ptr, boost::function, boost::bind
We can use std::shared_ptr and std::function instead now.

Lambdas are usually a better alternative to boost/std::bind. The
downside is the need to explicitly specify parameters completely. When
inlining callbacks entirely with lambdas, duplication of that
parameter list can be avoided.

Whenever possible, use std::make_shared to construct objects that are
tracked by std::shared_ptr.

Some objects need a std::weak_ptr during object destruction. For that
we have to use our own implementation of std::enable_shared_from_this,
with a matching creator function. The additional benefit is that we
can get rid of explicit static "create" methods by making that create
function a friend.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2020-12-05 21:28:08 +01:00
Patrick Ohly 3729a239fc C++: variadic templates in D-Bus bindings
Using templates with a varying number of types allows removing
duplicated code for the different cases.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2020-12-05 21:28:08 +01:00
Patrick Ohly 8e333f0a46 glib: avoid deprecated g_type_init and g_thread_init
Calling them triggers warnings with newer glib which are fatal
when compiling with -Werror.
2014-07-23 10:48:19 +02:00
Patrick Ohly de8461f802 code restructing: Exception, throwError()
Raising exceptions via throwError() looses the original source code
location information. Fixing that by explicitly passing that
information as additional parameter, created with the preprocessor
macro SE_HERE.

Several files included the complex SyncContext.h only because needed
throwError(). A better place for the revised implementation is the
Exception class which used to be in util.h, now Exception.h.

Simplifying the include statements exposed indirect include
dependencies and removed "using namespace std" from the compilation of
some source files which happened to rely on it. We want to get rid of
that name space polution, so fix the code instead of adding it back.
2014-05-02 16:43:52 +02:00
Patrick Ohly d89ca72d01 D-Bus: use streams for direct IPC with GIO
When using GIO, it is possible to avoid the DBusServer listening on a
publicly accessible address. Connection setup becomes more reliable,
too, because the D-Bus server side can detect that a child died
because the connection will be closed.

When using libdbus, the traditional server/listen and client/connect
model is still used. GDBus GIO mimicks the same API to minimize
changes in ForkExec. The API gets simplified to support both
approaches:
- Choosing an address is no longer possible (was only used in the
  test example anyway)
- The new connection callback must be specified already when starting
  the server.

The GDBus GIO implementation uses SyncEvolution utility code. Strictly
speaking, this creates a circular dependency
libsyncevolution<->libgdbus. This is solved by not linking libgdbus
against libsyncevolution and expecting executables to do that instead.

The GDBus GIO example no longer linked because of that; it gets removed
because it was of little value.

Now that we started using CLOEXEC, we might as well use it for the
permanent file descriptors created for each ForkExec instance.
2014-04-01 16:45:09 +02:00
Patrick Ohly d3eee8a039 glib: stricter ref counting
Following the boost::instrusive_ptr example and making "add_ref =
true" the default in our CXX GLib and GObject wrappers led to some
memory leaks because it didn't enforce thinking about whether the
plain pointer is already owned by us or not.

It is better to use a mandatory enum value, ADD_REF and TRANSFER_REF,
and force explicit construction. Doing that revealed that the
assignment operator was implemented as constructing a CXX instance
with increased ref count and/or that in some places, a real leak was
caused by increasing the ref count unnecessarily.

Running under valgrind gave a false sense of security. Some of the
real leaks only showed up randomly in tests.
2013-05-16 11:19:32 +02:00
Patrick Ohly 6ac33ec077 dbus-client-server: added test code for client or server dying
The test covers waiting for a reply that never comes because the peer
dies. GIO D-Bus returns a "connection lost" error in this case. Still
need to test what happens when a process isn't currently waiting for a
response to its own call, but rather a method invocation from its peer
- it seems that it'll simply get stuck waiting forever when the peer
dies.
2012-05-10 22:08:45 +02:00
Patrick Ohly 605161de86 ForkExec: fix race condition
Delay message processing in the child until m_onConnect is done.

Fixes the following problem with GIO D-Bus:
- client connects, starts helper thread
- parent sends method call
- helper thread processes method calls, discards it
  (doesn't match anything)
- client calls m_onConnect (too late)

The introduction of delayed message processing broke the
dbus-client-server, because it does its main work in the onConnect
signal, where replies by the server where not processed after the
change.

The solution is to explicitly allow message processing inside the
signal slot.
2012-05-08 09:13:47 +02:00
Chris Kühl 2eeea6af5c test: Fix cli arguments in test/dbus-client-server.cpp 2012-05-08 09:13:47 +02:00
Krzesimir Nowak 58f3a95fb5 GDBus libdbus+GIO: support blocking D-Bus calls
The call operator on DBusClientCall[0123] is now blocking. It will
return result values as single value, std::pair or boost::tuple,
respectively. If an error is encountered either locally or in the
peer, a runtime_error is thrown.

This is an API change. The traditional implementation was to start an
asynchronous call. That is still possible, but has to be requested
explicitly with the new start() method.

This distinction is necessary because C++ cannot guess (easily)
whether the callback parameter is a callback type or another parameter
for the D-Bus peer. It's also a bit cleaner in the source code because
now the call operator really acts like a normal, synchronous call.

The downside of the synchronous calls is that complex return values
have to be copied more often. If that is too expensive, then use the
asynchronous start() + callback approach.
2012-02-17 15:34:15 +01:00
Patrick Ohly 9a78c5e6bd D-Bus client/server: authentication
Checking authentication needs to be abstraced and cannot be done with
a libdbus-only method. At the moment the assumption is that the
connecting client is at least from the same user.
2012-01-17 11:04:38 +01:00
Patrick Ohly 3fa4d9c528 fork/exec: added onFailure
Methods called from glib C code must not throw exceptions. If that
happens, the problem will be reported via onFailure.

The more likely problem is that the child quits prematurely or with an
error code. Both is reported via onFailure now, so the user of
ForkExecParent no longer has to watch the child itself.
2012-01-17 11:04:37 +01:00
Patrick Ohly 3536b30c3b fork/exec: removed loop parameter
The parameter wasn't really needed for anything. Everything happens
inside the main context and the caller is responsible for creating and
running a loop.
2012-01-17 11:04:37 +01:00
Patrick Ohly 6b9d10a769 DBus client/server test: added usage of fork/exec
Run with --forkexec to let dbus-client-server restart itself as child.
2012-01-17 11:04:37 +01:00
Patrick Ohly f88fe5acac GDBus: test program for client/server setup
Can run as both client and server. Linked against libsyncevolution
only because it needs some utility methods in it.

Logs authentication state when a new connection is created.  Currently
such connections are unauthenticated at first. If the client has the
same user ID as the server, it is allowed to proceed (tested
empirically). If not, authentication fails and handle_message() is
not called (but the connection remains open!?).

Disconnects are not properly detected because GDBus for libdbus
doesn't support reporting disconnects on a connection (not
implemented). Instead of relying on it, better watch child or parent
via some other means. In this example, the server side just keeps
the connection open until the next client connects. The client
lets GDBus exit() the process on disconnect.
2012-01-17 11:04:37 +01:00