build: Enable configure switch to build with GIO GDBus
syncEvolution has used an in-tree copy of Bluez's gdbus dbus implentation. With this patch there is now a configure switch which enables the use of the GLib's GDBus dbus implmentation if the --with-gio-gdbus configure flag is use or, if no flag is used, an adequate glib version (2.26) is found. This commit does *not* actually implement the use of GIO's GDBus. The implmentation is coming soon. Thus only --without-gio-gdbus will currently result in a working build.
This commit is contained in:
parent
29fee7a2bc
commit
103dfe4f73
12
configure.ac
12
configure.ac
|
@ -440,6 +440,17 @@ AC_ARG_ENABLE(dbus-service,
|
|||
fi])
|
||||
AM_CONDITIONAL([COND_DBUS], [test "$enable_dbus_service" = "yes"])
|
||||
|
||||
AC_ARG_WITH(gio-gdbus,
|
||||
AS_HELP_STRING([--with-gio-gdbus],
|
||||
[enables use of GIO's GDBus instead of the in-tree, Bluez gdbus.]),
|
||||
with_gio_gdbus="$withval",
|
||||
PKG_CHECK_EXISTS([gio-2.0 >= 2.26],
|
||||
[with_gio_gdbus="yes"],
|
||||
[with_gio_gdbus="no"]))
|
||||
AM_CONDITIONAL([COND_GIO_GDBUS], [test "x$with_gio_gdbus" = "xyes"])
|
||||
AS_IF([test "x$with_gio_gdbus" = "xyes"], [need_glib=yes
|
||||
PKG_CHECK_MODULES([GIO_GDBUS], [gio-2.0 >= 2.26])] )
|
||||
|
||||
PKG_CHECK_MODULES(KEYRING, [gnome-keyring-1], HAVE_KEYRING=yes, HAVE_KEYRING=no)
|
||||
AC_ARG_ENABLE(gnome-keyring,
|
||||
AS_HELP_STRING([--enable-gnome-keyring],
|
||||
|
@ -1070,6 +1081,7 @@ for backend in $BACKENDS; do
|
|||
eval echo $backend: \${enable_${backend}}
|
||||
done
|
||||
echo "DBus service: $enable_dbus_service"
|
||||
echo "GIO GDBus: $with_gio_gdbus"
|
||||
echo "GNOME keyring: $enable_gnome_keyring"
|
||||
echo "UI (DBus client): $enable_gui"
|
||||
echo "Bluetooth transport: $have_bluetooth"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <list>
|
||||
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
|
|
@ -28,7 +28,7 @@ DBusMessage *SyncEvoHandleException(DBusMessage *msg);
|
|||
SE_END_CXX
|
||||
// This needs to be defined before including gdbus-cxx-bridge.h!
|
||||
#define DBUS_CXX_EXCEPTION_HANDLER SyncEvo::SyncEvoHandleException
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "timer.h"
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
SE_BEGIN_CXX
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <syncevo/SyncSource.h>
|
||||
#include <syncevo/SmartPtr.h>
|
||||
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
SE_BEGIN_CXX
|
||||
|
||||
|
|
|
@ -46,8 +46,14 @@ src_dbus_server_libsyncevodbusserver_la_SOURCES = \
|
|||
|
||||
dist_pkgdata_DATA += src/dbus/server/bluetooth_products.ini
|
||||
|
||||
if COND_GIO_GDBUS
|
||||
gdbus_dir = $(top_srcdir)/src/gdbusxx
|
||||
else
|
||||
gdbus_dir = $(top_srcdir)/src/gdbus
|
||||
endif
|
||||
|
||||
src_dbus_server_libsyncevodbusserver_la_LIBADD = $(KEYRING_LIBS) $(LIBNOTIFY_LIBS) $(MLITE_LIBS) $(KDE_KWALLET_LIBS) $(DBUS_LIBS) $(LIBSOUP_LIBS)
|
||||
src_dbus_server_libsyncevodbusserver_la_CPPFLAGS = -DHAVE_CONFIG_H -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\" -I$(top_srcdir)/src -I$(top_srcdir)/test -I$(top_srcdir) $(BACKEND_CPPFLAGS)
|
||||
src_dbus_server_libsyncevodbusserver_la_CPPFLAGS = -DHAVE_CONFIG_H -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\" -I$(top_srcdir)/src -I$(top_srcdir)/test -I$(top_srcdir) -I$(gdbus_dir) $(BACKEND_CPPFLAGS)
|
||||
src_dbus_server_libsyncevodbusserver_la_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(SYNTHESIS_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBSOUP_CFLAGS) $(KEYRING_CFLAGS) $(LIBNOTIFY_CFLAGS) $(MLITE_CFLAGS) $(KDE_KWALLET_CFLAGS) $(SYNCEVO_WFLAGS)
|
||||
|
||||
# Deal with .service, .desktop and startup script files.
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef SOURCE_PROGRESS_H
|
||||
#define SOURCE_PROGRESS_H
|
||||
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef SOURCE_STATUS_H
|
||||
#define SOURCE_STATUS_H
|
||||
|
||||
#include "gdbus/gdbus-cxx-bridge.h"
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/example
|
|
@ -0,0 +1,14 @@
|
|||
This is a C++ wrapper for the GLib GDBus d-bus implementation.
|
||||
|
||||
SyncEvolution also includes a wrapper for another library named gdbus
|
||||
which originated in the Bluez project. This implementation has been
|
||||
included in-tree and getting and sending patches is a somewhat
|
||||
automated process.
|
||||
|
||||
The plan is to drop the in-tree, Bluez gdbus as soon as Debian stable
|
||||
and Ubuntu LTS both support a GLib >= 2.26 (the version first to
|
||||
include GDBus). Until this happens we'll have to keep the in-tree one
|
||||
around.
|
||||
|
||||
In order to make our lives easier, both implementation should have the
|
||||
same interface.
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (C) 2011 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 "gdbus-cxx-bridge.h"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
void intrusive_ptr_add_ref(GDBusConnection *con) { g_object_ref(con); }
|
||||
void intrusive_ptr_release(GDBusConnection *con) { g_object_unref(con); }
|
||||
void intrusive_ptr_add_ref(GDBusMessage *msg) { g_object_ref(msg); }
|
||||
void intrusive_ptr_release(GDBusMessage *msg) { g_object_unref(msg); }
|
||||
void intrusive_ptr_add_ref(GDBusPendingCall *call) { g_object_ref(call); }
|
||||
void intrusive_ptr_release(GDBusPendingCall *call) { g_object_unref(call); }
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* 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 INCL_GDBUS_CXX
|
||||
#define INCL_GDBUS_CXX
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
namespace GDBusCXX {
|
||||
|
||||
/**
|
||||
* An exception class which can be thrown to create
|
||||
* specific D-Bus exception on the bus.
|
||||
*/
|
||||
class dbus_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param dbus_name the D-Bus error name, like "org.example.error.Invalid"
|
||||
* @param what a more detailed description
|
||||
*/
|
||||
dbus_error(const std::string &dbus_name, const std::string &what) :
|
||||
std::runtime_error(what),
|
||||
m_dbus_name(dbus_name)
|
||||
{}
|
||||
~dbus_error() throw() {}
|
||||
|
||||
const std::string &dbusName() const { return m_dbus_name; }
|
||||
|
||||
private:
|
||||
std::string m_dbus_name;
|
||||
};
|
||||
|
||||
class Watch : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~Watch() {};
|
||||
|
||||
/**
|
||||
* Changes the callback triggered by this Watch. If the watch has
|
||||
* already fired, the callback is invoked immediately.
|
||||
*/
|
||||
virtual void setCallback(const boost::function<void (void)> &callback) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Special parameter type that identifies a caller. A string in practice.
|
||||
*/
|
||||
class Caller_t : public std::string
|
||||
{
|
||||
public:
|
||||
Caller_t() {}
|
||||
template <class T> Caller_t(T val) : std::string(val) {}
|
||||
template <class T> Caller_t &operator = (T val) { assign(val); return *this; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Call object which needs to be called with the results
|
||||
* of an asynchronous method call. So instead of
|
||||
* "int foo()" one would implement
|
||||
* "void foo(Result1<int> > *r)"
|
||||
* and after foo has returned, call r->done(res). Use const
|
||||
* references as type for complex results.
|
||||
*
|
||||
* A Result instance can be copied, but only called once.
|
||||
*/
|
||||
class Result
|
||||
{
|
||||
public:
|
||||
virtual ~Result() {}
|
||||
|
||||
/** report failure to caller */
|
||||
virtual void failed(const dbus_error &error) = 0;
|
||||
|
||||
/**
|
||||
* Calls the given callback once when the peer that the result
|
||||
* would be delivered to disconnects. The callback will also be
|
||||
* called if the peer is already gone by the time that the watch
|
||||
* is requested.
|
||||
*
|
||||
* Alternatively a method can ask to get called with a life Watch
|
||||
* by specifying "const boost::shared_ptr<Watch> &" as parameter
|
||||
* and then calling its setCallback().
|
||||
*/
|
||||
virtual Watch *createWatch(const boost::function<void (void)> &callback) = 0;
|
||||
};
|
||||
|
||||
class Result0 : virtual public Result
|
||||
{
|
||||
public:
|
||||
/** tell caller that we are done */
|
||||
virtual void done() = 0;
|
||||
};
|
||||
|
||||
template <typename A1>
|
||||
class Result1 : virtual public Result
|
||||
{
|
||||
public:
|
||||
/** return result to caller */
|
||||
virtual void done(A1 a1) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2>
|
||||
struct Result2 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
struct Result3 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
struct Result4 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
struct Result5 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
struct Result6 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
struct Result7 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
struct Result8 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
struct Result9 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) = 0;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
struct Result10 : virtual public Result
|
||||
{
|
||||
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) = 0;
|
||||
};
|
||||
|
||||
} // namespace GDBusCXX
|
||||
|
||||
#endif // INCL_GDBUS_CXX
|
|
@ -0,0 +1,23 @@
|
|||
if ENABLE_MODULES
|
||||
pkglib_LTLIBRARIES = src/gdbusxx/libgdbussyncevo.la
|
||||
src_gdbusxx_version_info = -version-info 0:0:0
|
||||
else
|
||||
noinst_LTLIBRARIES += src/gdbusxx/libgdbussyncevo.la
|
||||
endif
|
||||
|
||||
src_gdbusxx_libgdbussyncevo_la_SOURCES = \
|
||||
src/gdbusxx/gdbus-cxx-bridge.h \
|
||||
src/gdbusxx/gdbus-cxx-bridge.cpp \
|
||||
src/gdbusxx/gdbus-cxx.h
|
||||
|
||||
src_gdbusxx_libgdbussyncevo_la_LDFLAGS = $(src_gdbus_version_info)
|
||||
src_gdbusxx_libgdbussyncevo_la_LIBADD = @GLIB_LIBS@ @GIO_GDBUS_LIBS@
|
||||
src_gdbusxx_libgdbussyncevo_la_CXXFLAGS = @GLIB_CFLAGS@ @GIO_GDBUS_CFLAGS@
|
||||
|
||||
MAINTAINERCLEANFILES += Makefile.in
|
||||
|
||||
noinst_PROGRAMS += src/gdbusxx/example
|
||||
src_gdbusxx_example_SOURCES = src/gdbusxx/test/example.cpp
|
||||
src_gdbusxx_example_CPPFLAGS = -I$(top_srcdir)/src/gdbusxx/
|
||||
src_gdbusxx_example_CXXFLAGS = @GLIB_CFLAGS@ @GIO_GDBUS_CFLAGS@
|
||||
src_gdbusxx_example_LDADD = src/gdbusxx/libgdbussyncevo.la @GLIB_LIBS@ @GIO_GDBUS_LIBS@
|
|
@ -0,0 +1,290 @@
|
|||
/*
|
||||
*
|
||||
* Library for simple D-Bus integration with GLib
|
||||
*
|
||||
* Copyright (C) 2009 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/signal.h>
|
||||
|
||||
#include "gdbus-cxx-bridge.h"
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
namespace GDBusCXX {
|
||||
|
||||
struct args {
|
||||
int a;
|
||||
std::string b;
|
||||
std::map<std::string, std::string> c;
|
||||
};
|
||||
|
||||
static void hello_global() {}
|
||||
|
||||
class Test {
|
||||
typedef boost::shared_ptr< Result1<const std::string&> > string_result;
|
||||
struct async
|
||||
{
|
||||
async(const boost::shared_ptr<Watch> &watch, Watch *watch2, const string_result &result):
|
||||
m_watch(watch),
|
||||
m_watch2(watch2),
|
||||
m_result(result)
|
||||
{}
|
||||
~async()
|
||||
{
|
||||
delete m_watch2;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Watch> m_watch;
|
||||
Watch *m_watch2;
|
||||
string_result m_result;
|
||||
};
|
||||
|
||||
|
||||
static gboolean method_idle(gpointer data)
|
||||
{
|
||||
std::auto_ptr<async> mydata(static_cast<async *>(data));
|
||||
std::cout << "replying to method_async" << std::endl;
|
||||
mydata->m_result->done("Hello World, asynchronous and delayed");
|
||||
return false;
|
||||
}
|
||||
|
||||
static void disconnect(const std::string &id, const std::string &peer)
|
||||
{
|
||||
std::cout << id << ": " << peer << " has disconnected." << std::endl;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static void hello_static() {}
|
||||
void hello_const() const {}
|
||||
static void hello_world(const char *msg) { puts(msg); }
|
||||
void hello_base() {}
|
||||
|
||||
void method(std::string &text)
|
||||
{
|
||||
text = "Hello World";
|
||||
}
|
||||
|
||||
void method_async(const Caller_t &caller,
|
||||
const boost::shared_ptr<Watch> &watch,
|
||||
int32_t secs,
|
||||
const string_result &r)
|
||||
{
|
||||
watch->setCallback(boost::bind(disconnect, "watch1", caller));
|
||||
Watch *watch2 = r->createWatch(boost::bind(disconnect, "watch2", caller));
|
||||
std::cout << "method_async called by " << caller << " delay " << secs << std::endl;
|
||||
g_timeout_add_seconds(secs, method_idle, new async(watch, watch2, r));
|
||||
}
|
||||
|
||||
void method2(int32_t arg, int32_t &ret)
|
||||
{
|
||||
ret = arg * 2;
|
||||
}
|
||||
|
||||
int32_t method3(int32_t arg)
|
||||
{
|
||||
return arg * 3;
|
||||
}
|
||||
|
||||
void method8_simple(int32_t a1, int32_t a2, int32_t a3, int32_t a4, int32_t a5,
|
||||
int32_t a6, int32_t a7, int32_t a8)
|
||||
{
|
||||
}
|
||||
|
||||
void method9_async(Result9<int32_t, int32_t, int32_t, int32_t, int32_t,
|
||||
int32_t, int32_t, int32_t, int32_t> *r)
|
||||
{
|
||||
r->done(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
delete r;
|
||||
}
|
||||
|
||||
int32_t method9(int32_t a1, int32_t a2, int32_t a3, int32_t a4, int32_t a5,
|
||||
int32_t a6, int32_t a7, int32_t a8, int32_t a9)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void hash(const std::map<int8_t, int32_t> &in, std::map<int16_t, int32_t> &out)
|
||||
{
|
||||
for (std::map<int8_t, int32_t>::const_iterator it = in.begin();
|
||||
it != in.end();
|
||||
++it) {
|
||||
out.insert(std::make_pair((int16_t)it->first, it->second * it->second));
|
||||
}
|
||||
}
|
||||
|
||||
void array(const std::vector<int32_t> &in, std::vector<int32_t> &out)
|
||||
{
|
||||
for (std::vector<int32_t>::const_iterator it = in.begin();
|
||||
it != in.end();
|
||||
++it) {
|
||||
out.push_back(*it * *it);
|
||||
}
|
||||
}
|
||||
|
||||
void error()
|
||||
{
|
||||
throw dbus_error("org.example.error.Invalid", "error");
|
||||
}
|
||||
|
||||
void argtest(const args &in, args &out)
|
||||
{
|
||||
out = in;
|
||||
out.a = in.a + 1;
|
||||
}
|
||||
};
|
||||
|
||||
class Test2
|
||||
{
|
||||
public:
|
||||
void test2() {}
|
||||
};
|
||||
|
||||
template<> struct dbus_traits<args> :
|
||||
public dbus_struct_traits<args, dbus_member<args, int, &args::a,
|
||||
dbus_member<args, std::string, &args::b,
|
||||
dbus_member_single<args, std::map<std::string, std::string>, &args::c> > > >
|
||||
{};
|
||||
|
||||
class DBusTest : public Test, private Test2
|
||||
{
|
||||
DBusObjectHelper m_object;
|
||||
DBusObjectHelper m_secondary;
|
||||
|
||||
public:
|
||||
DBusTest(DBusConnection *conn) :
|
||||
m_object(conn, "/test", "org.example.Test"),
|
||||
// same path!
|
||||
m_secondary(conn, m_object.getPath(), "org.example.Secondary"),
|
||||
signal(m_object, "Signal")
|
||||
{
|
||||
m_object.add(this, &Test::method8_simple, "Method8Simple");
|
||||
// m_object.add(this, &Test::method10_async, "Method10Async", G_DBUS_METHOD_FLAG_ASYNC);
|
||||
// m_object.add(this, &Test::method9, "Method9");
|
||||
m_object.add(this, &Test::method2, "Method2");
|
||||
m_object.add(this, &Test::method3, "Method3");
|
||||
m_object.add(this, &Test::method, "Test");
|
||||
m_object.add(this, &Test::method_async, "TestAsync");
|
||||
m_object.add(this, &Test::argtest, "ArgTest");
|
||||
m_object.add(this, &Test::hash, "Hash");
|
||||
m_object.add(this, &Test::array, "Array");
|
||||
m_object.add(this, &Test::error, "Error");
|
||||
m_object.add(&hello_global, "Global");
|
||||
m_object.add(&DBusTest::hello_static, "Static");
|
||||
m_object.add(static_cast<Test2 *>(this), &Test2::test2, "Private");
|
||||
// The hello_const() method cannot be registered
|
||||
// because there is no matching MakeMethodEntry<>
|
||||
// specialization for it or DBusObjectHelper::add()
|
||||
// fails to determine the right function type,
|
||||
// depending how one wants to interpret the problem.
|
||||
// m_object.add2(this, &DBusTest::hello_const, "Const");
|
||||
|
||||
m_object.add(signal);
|
||||
|
||||
m_secondary.add(this, &DBusTest::hello, "Hello");
|
||||
}
|
||||
|
||||
~DBusTest()
|
||||
{
|
||||
}
|
||||
|
||||
EmitSignal3<int32_t, const std::string &, const std::map<int32_t, int32_t> &>signal;
|
||||
|
||||
void hello() {}
|
||||
static void hello_static() {}
|
||||
void hello_const() const {}
|
||||
|
||||
void activate()
|
||||
{
|
||||
m_secondary.activate();
|
||||
m_object.activate();
|
||||
}
|
||||
|
||||
void deactivate()
|
||||
{
|
||||
m_object.deactivate();
|
||||
m_secondary.deactivate();
|
||||
}
|
||||
};
|
||||
|
||||
static GMainLoop *main_loop = NULL;
|
||||
|
||||
static void sig_term(int sig)
|
||||
{
|
||||
g_main_loop_quit(main_loop);
|
||||
}
|
||||
|
||||
} // namespace GDBusCXX
|
||||
|
||||
using namespace GDBusCXX;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
DBusConnection *conn;
|
||||
DBusError err;
|
||||
struct sigaction sa;
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = sig_term;
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
sigaction(SIGTERM, &sa, NULL);
|
||||
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
sigaction(SIGPIPE, &sa, NULL);
|
||||
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
dbus_error_init(&err);
|
||||
|
||||
conn = b_dbus_setup_bus(DBUS_BUS_SESSION, "org.example", false, &err);
|
||||
if (conn == NULL) {
|
||||
if (dbus_error_is_set(&err) == TRUE) {
|
||||
fprintf(stderr, "%s\n", err.message);
|
||||
dbus_error_free(&err);
|
||||
} else
|
||||
fprintf(stderr, "Can't register with session bus\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::auto_ptr<DBusTest> test(new DBusTest(conn));
|
||||
test->activate();
|
||||
test->signal(42, "hello world", std::map<int32_t, int32_t>());
|
||||
test->deactivate();
|
||||
test->activate();
|
||||
test->signal(123, "here I am again", std::map<int32_t, int32_t>());
|
||||
|
||||
g_main_loop_run(main_loop);
|
||||
|
||||
test.reset();
|
||||
|
||||
b_dbus_cleanup_connection(conn);
|
||||
|
||||
g_main_loop_unref(main_loop);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import dbus
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
import gobject
|
||||
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
|
||||
dummy = dbus.Interface(bus.get_object('org.example', '/test'),
|
||||
'org.freedesktop.DBus.Introspectable')
|
||||
|
||||
print dummy.Introspect()
|
||||
|
||||
|
||||
object = dbus.Interface(bus.get_object('org.example', '/test'),
|
||||
'org.example.Secondary')
|
||||
object.Hello()
|
||||
|
||||
object = dbus.Interface(bus.get_object('org.example', '/test'),
|
||||
'org.example.Test')
|
||||
|
||||
print object.Test()
|
||||
print object.Method2(1)
|
||||
print object.Method3(1)
|
||||
print object.Hash({1: 1, 2: 2, 3: 3})
|
||||
print object.Array([1, 2, 3, 4])
|
||||
print object.ArgTest((1, 'hello', {'foo': 'bar'}))
|
||||
|
||||
loop = gobject.MainLoop()
|
||||
|
||||
def AsyncFinished(x=None):
|
||||
print "TestAsync:", x
|
||||
loop.quit()
|
||||
|
||||
print object.TestAsync(2,
|
||||
reply_handler=AsyncFinished,
|
||||
error_handler=AsyncFinished)
|
||||
|
||||
# This will trigger the "caller has disconnect"
|
||||
# because our client-side time out will get us
|
||||
# out of the loop and then we quit.
|
||||
object.TestAsync(600,
|
||||
reply_handler=AsyncFinished,
|
||||
error_handler=AsyncFinished,
|
||||
timeout=5)
|
||||
loop.run()
|
||||
|
||||
object.Error()
|
22
src/src.am
22
src/src.am
|
@ -5,6 +5,11 @@ include $(top_srcdir)/src/gnome-bluetooth/gnome-bluetooth.am
|
|||
src_cppflags += -I$(top_srcdir)/src/gnome-bluetooth
|
||||
endif
|
||||
|
||||
if COND_GIO_GDBUS
|
||||
GDBUS_DIR = gdbusxx
|
||||
else
|
||||
GDBUS_DIR = gdbus
|
||||
endif
|
||||
|
||||
if COND_CORE
|
||||
include $(top_srcdir)/src/syncevo/syncevo.am
|
||||
|
@ -19,9 +24,14 @@ src_cppflags += -I$(top_srcdir)/$(SYNTHESIS_SUBDIR_INCLUDES)
|
|||
endif
|
||||
|
||||
if COND_DBUS
|
||||
if COND_GIO_GDBUS
|
||||
include $(top_srcdir)/src/gdbusxx/gdbusxx.am
|
||||
src_cppflags += -I$(top_srcdir)/src/gdbusxx
|
||||
else
|
||||
include $(top_srcdir)/src/gdbus/gdbus.am
|
||||
src_cppflags += -I$(top_srcdir)/src/gdbus
|
||||
endif
|
||||
endif
|
||||
include $(top_srcdir)/src/dbus/dbus.am
|
||||
src_cppflags += -I$(top_srcdir)/src/dbus
|
||||
if COND_GUI
|
||||
|
@ -112,12 +122,12 @@ endif
|
|||
# either way this does not lead to a dependency on those libs - done explicitly
|
||||
src_syncevolution_LDADD = $(CORE_LDADD) $(KEYRING_LIBS) $(KDE_KWALLET_LIBS)
|
||||
if COND_DBUS
|
||||
src_syncevolution_LDADD += src/gdbus/libgdbussyncevo.la
|
||||
src_syncevolution_LDADD += $(builddir)/src/$(GDBUS_DIR)/libgdbussyncevo.la
|
||||
endif
|
||||
src_syncevolution_LDFLAGS = $(PCRECPP_LIBS) $(CORE_LD_FLAGS) $(DBUS_LIBS)
|
||||
src_syncevolution_CXXFLAGS = $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(KEYRING_CFLAGS) -I$(top_srcdir)/src/gdbus $(DBUS_CFLAGS) $(KDE_KWALLET_CFLAGS) $(SYNCEVO_WFLAGS)
|
||||
src_syncevolution_CXXFLAGS = $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(KEYRING_CFLAGS) -I$(srcdir)/$(GDBUS_DIR) $(DBUS_CFLAGS) $(KDE_KWALLET_CFLAGS) $(SYNCEVO_WFLAGS)
|
||||
src_syncevolution_DEPENDENCIES = $(EXTRA_LTLIBRARIES) $(CORE_DEP)
|
||||
src_syncevolution_CPPFLAGS = $(src_cppflags)
|
||||
src_syncevolution_CPPFLAGS = $(src_cppflags) -I$(top_srcdir)/src/$(GDBUS_DIR)
|
||||
|
||||
# rule which is only relevant when compiling Synthesis in subdirectory
|
||||
#$(SYNTHESIS_LIB) : $(SYNTHESIS_SUBDIR)/all
|
||||
|
@ -176,11 +186,11 @@ if ENABLE_UNIT_TESTS
|
|||
nodist_src_syncevo_dbus_server_SOURCES = test/test.cpp
|
||||
endif
|
||||
|
||||
src_syncevo_dbus_server_LDADD = src/dbus/server/libsyncevodbusserver.la src/gdbus/libgdbussyncevo.la $(CORE_LDADD) $(KEYRING_LIBS) $(LIBNOTIFY_LIBS) $(MLITE_LIBS) $(KDE_KWALLET_LIBS) $(DBUS_LIBS)
|
||||
src_syncevo_dbus_server_CPPFLAGS = -DHAVE_CONFIG_H -I$(top_srcdir)/src/gdbus $(src_cppflags) -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\"
|
||||
src_syncevo_dbus_server_LDADD = $(builddir)/src/dbus/server/libsyncevodbusserver.la $(builddir)/src/$(GDBUS_DIR)/libgdbussyncevo.la $(CORE_LDADD) $(KEYRING_LIBS) $(LIBNOTIFY_LIBS) $(MLITE_LIBS) $(KDE_KWALLET_LIBS) $(DBUS_LIBS)
|
||||
src_syncevo_dbus_server_CPPFLAGS = -DHAVE_CONFIG_H -I$(srcdir)/$(GDBUS_DIR) $(src_cppflags) -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\"
|
||||
src_syncevo_dbus_server_CXXFLAGS = $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBSOUP_CFLAGS) $(KEYRING_CFLAGS) $(LIBNOTIFY_CFLAGS) $(MLITE_CFLAGS) $(KDE_KWALLET_CFLAGS) $(SYNCEVO_WFLAGS)
|
||||
src_syncevo_dbus_server_LDFLAGS = $(PCRECPP_LIBS) $(CORE_LD_FLAGS) $(LIBSOUP_LIBS)
|
||||
src_syncevo_dbus_server_DEPENDENCIES = src/dbus/server/libsyncevodbusserver.la src/gdbus/libgdbussyncevo.la $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)
|
||||
src_syncevo_dbus_server_DEPENDENCIES = $(builddir)/src/dbus/server/libsyncevodbusserver.la $(builddir)/src/$(GDBUS_DIR)/libgdbussyncevo.la $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)
|
||||
endif
|
||||
|
||||
# With --disable-shared autotools links against libfunambol.a which does not
|
||||
|
|
Loading…
Reference in New Issue