0fb5794a21
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.
21 lines
547 B
Makefile
21 lines
547 B
Makefile
include_HEADERS = gdbus.h
|
|
|
|
if ENABLE_MODULES
|
|
pkglib_LTLIBRARIES = libgdbus.la
|
|
else
|
|
noinst_LTLIBRARIES = libgdbus.la
|
|
endif
|
|
|
|
libgdbus_la_SOURCES = debug.h debug.c mainloop.c object.c watch.c
|
|
libgdbus_la_LDFLAGS = -version-info 0:0:0 -export-symbols-regex g_dbus_.*
|
|
|
|
libgdbus_la_LIBADD = @GLIB_LIBS@ @DBUS_LIBS@
|
|
|
|
AM_CFLAGS = @GLIB_CFLAGS@ @DBUS_CFLAGS@
|
|
|
|
MAINTAINERCLEANFILES = Makefile.in
|
|
|
|
noinst_PROGRAMS = example
|
|
example_SOURCES = test/example.cpp
|
|
example_CXXFLAGS = @GLIB_CFLAGS@ @DBUS_CFLAGS@
|
|
example_LDADD = libgdbus.la @GLIB_LIBS@ @DBUS_LIBS@
|