From 9ac4f0252f0784e8594b41e578e6d04f89835d13 Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Tue, 13 Jul 2010 23:12:50 +0200 Subject: compile against latest ecore --- include/dbus-c++/ecore-integration.h | 6 +++--- src/ecore-integration.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/dbus-c++/ecore-integration.h b/include/dbus-c++/ecore-integration.h index b475533..2b14b27 100644 --- a/include/dbus-c++/ecore-integration.h +++ b/include/dbus-c++/ecore-integration.h @@ -47,7 +47,7 @@ private: void toggle(); - static int timeout_handler( void* ); + static Eina_Bool timeout_handler( void* ); void _enable(); @@ -69,9 +69,9 @@ private: void toggle(); - static int watch_handler_read ( void*, Ecore_Fd_Handler *fdh); + static Eina_Bool watch_handler_read ( void*, Ecore_Fd_Handler *fdh); - static int watch_handler_error ( void*, Ecore_Fd_Handler *fdh); + static Eina_Bool watch_handler_error ( void*, Ecore_Fd_Handler *fdh); void _enable(); diff --git a/src/ecore-integration.cpp b/src/ecore-integration.cpp index e530e06..f1e24e7 100644 --- a/src/ecore-integration.cpp +++ b/src/ecore-integration.cpp @@ -50,7 +50,7 @@ void Ecore::BusTimeout::toggle() else _disable(); } -int Ecore::BusTimeout::timeout_handler( void *data ) +Eina_Bool Ecore::BusTimeout::timeout_handler( void *data ) { Ecore::BusTimeout* t = reinterpret_cast(data); @@ -118,7 +118,7 @@ void Ecore::BusWatch::toggle() else _disable(); } -int Ecore::BusWatch::watch_handler_read( void *data, Ecore_Fd_Handler *fdh ) +Eina_Bool Ecore::BusWatch::watch_handler_read( void *data, Ecore_Fd_Handler *fdh ) { Ecore::BusWatch* w = reinterpret_cast(data); @@ -133,7 +133,7 @@ int Ecore::BusWatch::watch_handler_read( void *data, Ecore_Fd_Handler *fdh ) return 1; } -int Ecore::BusWatch::watch_handler_error( void *data, Ecore_Fd_Handler *fdh ) +Eina_Bool Ecore::BusWatch::watch_handler_error( void *data, Ecore_Fd_Handler *fdh ) { //Ecore::BusWatch* w = reinterpret_cast(data); -- cgit v1.2.1 From 8a3fb381a1b53bef45b997c52a9cf115e9c40515 Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Sat, 31 Jul 2010 00:20:51 +0200 Subject: added pipe mechanism for default main loop to synchronize with other threads --- examples/echo/echo-client.cpp | 61 +++++++++++++++++++++----- include/dbus-c++/eventloop-integration.h | 54 ++++++++++++++++------- src/eventloop-integration.cpp | 74 ++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 27 deletions(-) diff --git a/examples/echo/echo-client.cpp b/examples/echo/echo-client.cpp index 8fe7ad7..f6d59a8 100644 --- a/examples/echo/echo-client.cpp +++ b/examples/echo/echo-client.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace std; @@ -31,22 +32,20 @@ static const int THREADS = 3; static bool spin = true; -void *greeter_thread(void *arg) -{ - DBus::Connection *conn = reinterpret_cast(arg); +EchoClient *g_client = NULL; - EchoClient client(*conn, ECHO_SERVER_PATH, ECHO_SERVER_NAME); +DBus::Pipe *thread_pipe_list[THREADS]; +void *greeter_thread(void *arg) +{ char idstr[16]; + int i = (int) arg; snprintf(idstr, sizeof(idstr), "%lu", pthread_self()); - for (int i = 0; i < 30 && spin; ++i) - { - cout << client.Hello(idstr) << endl; - } + thread_pipe_list[i]->write (idstr, strlen (idstr) + 1); - cout << idstr << " done " << endl; + cout << idstr << " done (" << i << ")" << endl; return NULL; } @@ -60,6 +59,36 @@ void niam(int sig) dispatcher.leave(); } +void handler1 (const void *data, void *buffer, unsigned int nbyte) +{ + char *str = (char*) buffer; + cout << "buffer1: " << str << endl; + for (int i = 0; i < 30 && spin; ++i) + { + cout << g_client->Hello (str) << endl; + } +} + +void handler2 (const void *data, void *buffer, unsigned int nbyte) +{ + char *str = (char*) buffer; + cout << "buffer2: " << str << endl; + for (int i = 0; i < 30 && spin; ++i) + { + cout << g_client->Hello (str) << endl; + } +} + +void handler3 (const void *data, void *buffer, unsigned int nbyte) +{ + char *str = (char*) buffer; + cout << "buffer3: " << str << endl; + for (int i = 0; i < 30 && spin; ++i) + { + cout << g_client->Hello (str) << endl; + } +} + int main() { signal(SIGTERM, niam); @@ -71,13 +100,19 @@ int main() DBus::Connection conn = DBus::Connection::SessionBus(); + EchoClient client (conn, ECHO_SERVER_PATH, ECHO_SERVER_NAME); + g_client = &client; + pthread_t threads[THREADS]; + thread_pipe_list[0] = dispatcher.add_pipe (handler1, NULL); + thread_pipe_list[1] = dispatcher.add_pipe (handler2, NULL); + thread_pipe_list[2] = dispatcher.add_pipe (handler3, NULL); for (int i = 0; i < THREADS; ++i) { - pthread_create(threads+i, NULL, greeter_thread, &conn); + pthread_create(threads+i, NULL, greeter_thread, (void*) i); } - + dispatcher.enter(); cout << "terminating" << endl; @@ -87,5 +122,9 @@ int main() pthread_join(threads[i], NULL); } + dispatcher.del_pipe (thread_pipe_list[0]); + dispatcher.del_pipe (thread_pipe_list[1]); + dispatcher.del_pipe (thread_pipe_list[2]); + return 0; } diff --git a/include/dbus-c++/eventloop-integration.h b/include/dbus-c++/eventloop-integration.h index b8e02c7..a061aa8 100644 --- a/include/dbus-c++/eventloop-integration.h +++ b/include/dbus-c++/eventloop-integration.h @@ -57,30 +57,51 @@ class DXXAPI BusWatch : public Watch, public DefaultWatch friend class BusDispatcher; }; -class DXXAPI BusDispatcher : public Dispatcher, public DefaultMainLoop +class DXXAPI Pipe { public: + /*! + * Write some data into the communication pipe. + * + * @param buffer The raw data to write. + * @param nbytes The number of bytes to write from the buffer. + */ + void write(const void *buffer, unsigned int nbytes); + + /*! + * Simply write one single byte into the pipe. This is a shortcut + * if there's really no data to transport, but to actvate the handler. + */ + void signal(); + +private: + void(*_handler)(const void *data, void *buffer, unsigned int nbyte); + int fd_write; + int fd_read; + const void *data; + + // allow construction only in BusDipatcher + Pipe () {}; + ~Pipe () {}; - int _pipe[2]; - - BusDispatcher() : _running(false) - { - //pipe to create a new fd used to unlock a dispatcher at any - // moment (used by leave function) - int ret = pipe(_pipe); - if (ret == -1) throw Error("PipeError:errno", toString(errno).c_str()); - - _fdunlock[0] = _pipe[0]; - _fdunlock[1] = _pipe[1]; - } +friend class BusDispatcher; +}; - ~BusDispatcher() - {} +class DXXAPI BusDispatcher : public Dispatcher, public DefaultMainLoop +{ +public: + BusDispatcher(); + + ~BusDispatcher() {} virtual void enter(); virtual void leave(); + virtual Pipe *add_pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), const void *data); + + virtual void del_pipe (Pipe *pipe); + virtual void do_iteration(); virtual Timeout *add_timeout(Timeout::Internal *); @@ -96,8 +117,9 @@ public: void timeout_expired(DefaultTimeout &); private: - bool _running; + int _pipe[2]; + std::list pipe_list; }; } /* namespace DBus */ diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index 8b9c49b..d20154a 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -31,11 +31,14 @@ #include #include +#include #include #include +#include using namespace DBus; +using namespace std; BusTimeout::BusTimeout(Timeout::Internal *ti, BusDispatcher *bd) : Timeout(ti), DefaultTimeout(Timeout::interval(), true, bd) @@ -71,6 +74,28 @@ void BusWatch::toggle() DefaultWatch::enabled(Watch::enabled()); } +void Pipe::write(const void *buffer, unsigned int nbytes) +{ + ::write(fd_write, buffer, nbytes); +} + +void Pipe::signal() +{ + ::write(fd_write, '\0', 1); +} + +BusDispatcher::BusDispatcher() : + _running(false) +{ + // pipe to create a new fd used to unlock a dispatcher at any + // moment (used by leave function) + int ret = pipe(_pipe); + if (ret == -1) throw Error("PipeError:errno", toString(errno).c_str()); + + _fdunlock[0] = _pipe[0]; + _fdunlock[1] = _pipe[1]; +} + void BusDispatcher::enter() { debug_log("entering dispatcher %p", this); @@ -80,6 +105,27 @@ void BusDispatcher::enter() while (_running) { do_iteration(); + + for (std::list ::const_iterator p_it = pipe_list.begin (); + p_it != pipe_list.end (); + ++p_it) + { + const Pipe* read_pipe = *p_it; + char buf; + char buf_str[1024]; + int i = 0; + + while (read(read_pipe->fd_read, &buf, 1) > 0) + { + buf_str[i] = buf; + ++i; + } + + if (i > 0) + { + read_pipe->_handler (read_pipe->data, buf_str, i); + } + } } debug_log("leaving dispatcher %p", this); @@ -96,6 +142,34 @@ void BusDispatcher::leave() close(_fdunlock[0]); } +Pipe *BusDispatcher::add_pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), const void *data) +{ + int fd[2]; + Pipe *new_pipe = new Pipe (); + new_pipe->_handler = handler; + new_pipe->data = data; + pipe_list.push_back (new_pipe); + + if (pipe(fd) == 0) + { + new_pipe->fd_read = fd[0]; + new_pipe->fd_write = fd[1]; + fcntl(new_pipe->fd_read, F_SETFL, O_NONBLOCK); + } + else + { + throw Error("PipeError:errno", toString(errno).c_str()); + } + + return new_pipe; +} + +void BusDispatcher::del_pipe (Pipe *pipe) +{ + pipe_list.remove (pipe); + delete pipe; +} + void BusDispatcher::do_iteration() { dispatch_pending(); -- cgit v1.2.1 From 4e6b136fe07ec539c439416ab58375e1a3edb195 Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Wed, 4 Aug 2010 00:01:23 +0200 Subject: Commit 1979ced0e0741caae3299c7f94733ba4d62a1e65 from Hubert Figuiere --- examples/Makefile.am | 2 +- include/dbus-c++/property.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Makefile.am b/examples/Makefile.am index a940bc8..40fa245 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = properties echo hal glib ecore +DIST_SUBDIRS = properties echo hal glib ecore MAINTAINERCLEANFILES = \ Makefile.in diff --git a/include/dbus-c++/property.h b/include/dbus-c++/property.h index 2e909cb..847ae89 100644 --- a/include/dbus-c++/property.h +++ b/include/dbus-c++/property.h @@ -46,7 +46,7 @@ public: T operator() (void) const { - return (T)_data->value; + return _data->value.operator T(); } PropertyAdaptor &operator = (const T &t) -- cgit v1.2.1 From 398da16b4757576f5409e1baaf1be4fe3a4bfc1f Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Wed, 4 Aug 2010 00:05:55 +0200 Subject: preserve m4 warning --- Makefile.am | 2 + bootstrap | 2 +- config/acx_pthread.m4 | 275 -------------------------------------------------- configure.ac | 1 + m4/acx_pthread.m4 | 275 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 279 insertions(+), 276 deletions(-) delete mode 100644 config/acx_pthread.m4 create mode 100644 m4/acx_pthread.m4 diff --git a/Makefile.am b/Makefile.am index 5df2cc8..912f64b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,8 @@ SUBDIRS = src tools data doc examples EXTRA_DIST = autogen.sh bootstrap libdbus-c++.spec libdbus-c++.spec.in +ACLOCAL_AMFLAGS = -I m4 + pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = dbus-c++-1.pc diff --git a/bootstrap b/bootstrap index 292c981..6b2c608 100755 --- a/bootstrap +++ b/bootstrap @@ -58,7 +58,7 @@ fi echo "Running libtoolize..." libtoolize --force --copy -aclocalinclude="$ACLOCAL_FLAGS -I config" +aclocalinclude="$ACLOCAL_FLAGS -I m4" echo "Running aclocal $aclocalinclude ..." aclocal $aclocalinclude diff --git a/config/acx_pthread.m4 b/config/acx_pthread.m4 deleted file mode 100644 index eb09f5a..0000000 --- a/config/acx_pthread.m4 +++ /dev/null @@ -1,275 +0,0 @@ -# =========================================================================== -# http://autoconf-archive.cryp.to/acx_pthread.html -# =========================================================================== -# -# SYNOPSIS -# -# ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -# -# DESCRIPTION -# -# This macro figures out how to build C programs using POSIX threads. It -# sets the PTHREAD_LIBS output variable to the threads library and linker -# flags, and the PTHREAD_CFLAGS output variable to any special C compiler -# flags that are needed. (The user can also force certain compiler -# flags/libs to be tested by setting these environment variables.) -# -# Also sets PTHREAD_CC to any special C compiler that is needed for -# multi-threaded programs (defaults to the value of CC otherwise). (This -# is necessary on AIX to use the special cc_r compiler alias.) -# -# NOTE: You are assumed to not only compile your program with these flags, -# but also link it with them as well. e.g. you should link with -# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS -# -# If you are only building threads programs, you may wish to use these -# variables in your default LIBS, CFLAGS, and CC: -# -# LIBS="$PTHREAD_LIBS $LIBS" -# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" -# CC="$PTHREAD_CC" -# -# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant -# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name -# (e.g. PTHREAD_CREATE_UNDETACHED on AIX). -# -# ACTION-IF-FOUND is a list of shell commands to run if a threads library -# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it -# is not found. If ACTION-IF-FOUND is not specified, the default action -# will define HAVE_PTHREAD. -# -# Please let the authors know if this macro fails on any platform, or if -# you have any other suggestions or comments. This macro was based on work -# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help -# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by -# Alejandro Forero Cuervo to the autoconf macro repository. We are also -# grateful for the helpful feedback of numerous users. -# -# LAST MODIFICATION -# -# 2008-04-12 -# -# COPYLEFT -# -# Copyright (c) 2008 Steven G. Johnson -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or (at your -# option) any later version. -# -# 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, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Macro Archive. When you make and -# distribute a modified version of the Autoconf Macro, you may extend this -# special exception to the GPL to apply to your modified version as well. - -AC_DEFUN([ACX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_HOST]) -AC_LANG_SAVE -AC_LANG_C -acx_pthread_ok=no - -# We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on True64 or Sequent). -# It gets checked for in the link test anyway. - -# First of all, check if the user has set any of the PTHREAD_LIBS, -# etcetera environment variables, and if threads linking works using -# them: -if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) - AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) - AC_MSG_RESULT($acx_pthread_ok) - if test x"$acx_pthread_ok" = xno; then - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" - fi - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" -fi - -# We must check for the threads library under a number of different -# names; the ordering is very important because some systems -# (e.g. DEC) have both -lpthread and -lpthreads, where one of the -# libraries is broken (non-POSIX). - -# Create a list of thread flags to try. Items starting with a "-" are -# C compiler flags, and other items are library names, except for "none" -# which indicates that we try without any flags at all, and "pthread-config" -# which is a program returning the flags for the Pth emulation library. - -acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" - -# The ordering *is* (sometimes) important. Some notes on the -# individual items follow: - -# pthreads: AIX (must check this before -lpthread) -# none: in case threads are in libc; should be tried before -Kthread and -# other compiler flags to prevent continual compiler warnings -# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) -# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) -# -pthreads: Solaris/gcc -# -mthreads: Mingw32/gcc, Lynx/gcc -# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads too; -# also defines -D_REENTRANT) -# ... -mt is also the pthreads flag for HP/aCC -# pthread: Linux, etcetera -# --thread-safe: KAI C++ -# pthread-config: use pthread-config program (for GNU Pth library) - -case "${host_cpu}-${host_os}" in - *solaris*) - - # On Solaris (at least, for some versions), libc contains stubbed - # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (We need to link with -pthreads/-mt/ - # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather - # a function called by this macro, so we could check for that, but - # who knows whether they'll stub that too in a future libc.) So, - # we'll just look for -pthreads and -lpthread first: - - acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags" - ;; -esac - -if test x"$acx_pthread_ok" = xno; then -for flag in $acx_pthread_flags; do - - case $flag in - none) - AC_MSG_CHECKING([whether pthreads work without any flags]) - ;; - - -*) - AC_MSG_CHECKING([whether pthreads work with $flag]) - PTHREAD_CFLAGS="$flag" - ;; - - pthread-config) - AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) - if test x"$acx_pthread_config" = xno; then continue; fi - PTHREAD_CFLAGS="`pthread-config --cflags`" - PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" - ;; - - *) - AC_MSG_CHECKING([for the pthreads library -l$flag]) - PTHREAD_LIBS="-l$flag" - ;; - esac - - save_LIBS="$LIBS" - save_CFLAGS="$CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - - # Check for various functions. We must include pthread.h, - # since some functions may be macros. (On the Sequent, we - # need a special flag -Kthread to make this header compile.) - # We check for pthread_join because it is in -lpthread on IRIX - # while pthread_create is in libc. We check for pthread_attr_init - # due to DEC craziness with -lpthreads. We check for - # pthread_cleanup_push because it is one of the few pthread - # functions on Solaris that doesn't have a non-functional libc stub. - # We try pthread_create on general principles. - AC_TRY_LINK([#include ], - [pthread_t th; pthread_join(th, 0); - pthread_attr_init(0); pthread_cleanup_push(0, 0); - pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], - [acx_pthread_ok=yes]) - - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" - - AC_MSG_RESULT($acx_pthread_ok) - if test "x$acx_pthread_ok" = xyes; then - break; - fi - - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" -done -fi - -# Various other checks: -if test "x$acx_pthread_ok" = xyes; then - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - - # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. - AC_MSG_CHECKING([for joinable pthread attribute]) - attr_name=unknown - for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - AC_TRY_LINK([#include ], [int attr=$attr; return attr;], - [attr_name=$attr; break]) - done - AC_MSG_RESULT($attr_name) - if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then - AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, - [Define to necessary symbol if this constant - uses a non-standard name on your system.]) - fi - - AC_MSG_CHECKING([if more special flags are required for pthreads]) - flag=no - case "${host_cpu}-${host_os}" in - *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; - *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; - esac - AC_MSG_RESULT(${flag}) - if test "x$flag" != xno; then - PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" - fi - - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" - - # More AIX lossage: must compile with xlc_r or cc_r - if test x"$GCC" != xyes; then - AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) - else - PTHREAD_CC=$CC - fi -else - PTHREAD_CC="$CC" -fi - -AC_SUBST(PTHREAD_LIBS) -AC_SUBST(PTHREAD_CFLAGS) -AC_SUBST(PTHREAD_CC) - -# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test x"$acx_pthread_ok" = xyes; then - ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) - : -else - acx_pthread_ok=no - $2 -fi -AC_LANG_RESTORE -])dnl ACX_PTHREAD diff --git a/configure.ac b/configure.ac index 2054a07..16042db 100644 --- a/configure.ac +++ b/configure.ac @@ -5,6 +5,7 @@ AC_INIT([libdbus-c++], 0.5.0, [shackan@gmail.com]) AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) AM_CONFIG_HEADER([config.h]) +AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_HOST diff --git a/m4/acx_pthread.m4 b/m4/acx_pthread.m4 new file mode 100644 index 0000000..eb09f5a --- /dev/null +++ b/m4/acx_pthread.m4 @@ -0,0 +1,275 @@ +# =========================================================================== +# http://autoconf-archive.cryp.to/acx_pthread.html +# =========================================================================== +# +# SYNOPSIS +# +# ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro figures out how to build C programs using POSIX threads. It +# sets the PTHREAD_LIBS output variable to the threads library and linker +# flags, and the PTHREAD_CFLAGS output variable to any special C compiler +# flags that are needed. (The user can also force certain compiler +# flags/libs to be tested by setting these environment variables.) +# +# Also sets PTHREAD_CC to any special C compiler that is needed for +# multi-threaded programs (defaults to the value of CC otherwise). (This +# is necessary on AIX to use the special cc_r compiler alias.) +# +# NOTE: You are assumed to not only compile your program with these flags, +# but also link it with them as well. e.g. you should link with +# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +# +# If you are only building threads programs, you may wish to use these +# variables in your default LIBS, CFLAGS, and CC: +# +# LIBS="$PTHREAD_LIBS $LIBS" +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CC="$PTHREAD_CC" +# +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant +# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name +# (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# +# ACTION-IF-FOUND is a list of shell commands to run if a threads library +# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it +# is not found. If ACTION-IF-FOUND is not specified, the default action +# will define HAVE_PTHREAD. +# +# Please let the authors know if this macro fails on any platform, or if +# you have any other suggestions or comments. This macro was based on work +# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help +# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by +# Alejandro Forero Cuervo to the autoconf macro repository. We are also +# grateful for the helpful feedback of numerous users. +# +# LAST MODIFICATION +# +# 2008-04-12 +# +# COPYLEFT +# +# Copyright (c) 2008 Steven G. Johnson +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# 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, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Macro Archive. When you make and +# distribute a modified version of the Autoconf Macro, you may extend this +# special exception to the GPL to apply to your modified version as well. + +AC_DEFUN([ACX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_SAVE +AC_LANG_C +acx_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) + AC_MSG_RESULT($acx_pthread_ok) + if test x"$acx_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# ... -mt is also the pthreads flag for HP/aCC +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case "${host_cpu}-${host_os}" in + *solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthreads/-mt/ + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags" + ;; +esac + +if test x"$acx_pthread_ok" = xno; then +for flag in $acx_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + pthread-config) + AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) + if test x"$acx_pthread_config" = xno; then continue; fi + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [acx_pthread_ok=yes]) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($acx_pthread_ok) + if test "x$acx_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$acx_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_MSG_CHECKING([for joinable pthread attribute]) + attr_name=unknown + for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_TRY_LINK([#include ], [int attr=$attr; return attr;], + [attr_name=$attr; break]) + done + AC_MSG_RESULT($attr_name) + if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then + AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case "${host_cpu}-${host_os}" in + *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + # More AIX lossage: must compile with xlc_r or cc_r + if test x"$GCC" != xyes; then + AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) + else + PTHREAD_CC=$CC + fi +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + acx_pthread_ok=no + $2 +fi +AC_LANG_RESTORE +])dnl ACX_PTHREAD -- cgit v1.2.1 From 1dcda93a6db7b8f430898e4b4f44f6006ed1d5f5 Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Wed, 4 Aug 2010 00:10:37 +0200 Subject: autor changed in configure.ac --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 16042db..bb5fc01 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # Autojunk script for libdbus-c++ AC_PREREQ(2.59) -AC_INIT([libdbus-c++], 0.5.0, [shackan@gmail.com]) +AC_INIT([libdbus-c++], 0.5.0, [andreas.volz@tux-style.com]) AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) AM_CONFIG_HEADER([config.h]) -- cgit v1.2.1 From a416700e448b336a3443547db67f5c62178210f3 Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Wed, 11 Aug 2010 22:31:37 +0200 Subject: minor --- include/dbus-c++/eventloop-integration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dbus-c++/eventloop-integration.h b/include/dbus-c++/eventloop-integration.h index a061aa8..213695d 100644 --- a/include/dbus-c++/eventloop-integration.h +++ b/include/dbus-c++/eventloop-integration.h @@ -70,7 +70,7 @@ public: /*! * Simply write one single byte into the pipe. This is a shortcut - * if there's really no data to transport, but to actvate the handler. + * if there's really no data to transport, but to activate the handler. */ void signal(); @@ -80,7 +80,7 @@ private: int fd_read; const void *data; - // allow construction only in BusDipatcher + // allow construction only in BusDispatcher Pipe () {}; ~Pipe () {}; -- cgit v1.2.1 From f0dcaa239f589106328fe325d498bbc810b2805a Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Thu, 12 Aug 2010 22:48:05 +0200 Subject: moved pipe to extra files --- include/dbus-c++/dbus.h | 1 + include/dbus-c++/eventloop-integration.h | 31 +-------------- include/dbus-c++/pipe.h | 67 ++++++++++++++++++++++++++++++++ src/Makefile.am | 3 +- src/eventloop-integration.cpp | 12 +----- src/pipe.cpp | 51 ++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 41 deletions(-) create mode 100644 include/dbus-c++/pipe.h create mode 100644 src/pipe.cpp diff --git a/include/dbus-c++/dbus.h b/include/dbus-c++/dbus.h index 7dfc164..80893cb 100644 --- a/include/dbus-c++/dbus.h +++ b/include/dbus-c++/dbus.h @@ -41,5 +41,6 @@ #include "eventloop.h" #include "eventloop-integration.h" #include "introspection.h" +#include "pipe.h" #endif//__DBUSXX_DBUS_H diff --git a/include/dbus-c++/eventloop-integration.h b/include/dbus-c++/eventloop-integration.h index 213695d..0459ebf 100644 --- a/include/dbus-c++/eventloop-integration.h +++ b/include/dbus-c++/eventloop-integration.h @@ -38,6 +38,7 @@ namespace DBus { */ class BusDispatcher; +class Pipe; class DXXAPI BusTimeout : public Timeout, public DefaultTimeout { @@ -57,36 +58,6 @@ class DXXAPI BusWatch : public Watch, public DefaultWatch friend class BusDispatcher; }; -class DXXAPI Pipe -{ -public: - /*! - * Write some data into the communication pipe. - * - * @param buffer The raw data to write. - * @param nbytes The number of bytes to write from the buffer. - */ - void write(const void *buffer, unsigned int nbytes); - - /*! - * Simply write one single byte into the pipe. This is a shortcut - * if there's really no data to transport, but to activate the handler. - */ - void signal(); - -private: - void(*_handler)(const void *data, void *buffer, unsigned int nbyte); - int fd_write; - int fd_read; - const void *data; - - // allow construction only in BusDispatcher - Pipe () {}; - ~Pipe () {}; - -friend class BusDispatcher; -}; - class DXXAPI BusDispatcher : public Dispatcher, public DefaultMainLoop { public: diff --git a/include/dbus-c++/pipe.h b/include/dbus-c++/pipe.h new file mode 100644 index 0000000..c994b6e --- /dev/null +++ b/include/dbus-c++/pipe.h @@ -0,0 +1,67 @@ +/* + * + * D-Bus++ - C++ bindings for D-Bus + * + * Copyright (C) 2005-2007 Paolo Durante + * + * + * 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) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef DBUSXX_PIPE_H +#define DBUSXX_PIPE_H + +/* Project */ +#include "api.h" + +/* STD */ +#include + +namespace DBus { + +class DXXAPI Pipe +{ +public: + /*! + * Write some data into the communication pipe. + * + * @param buffer The raw data to write. + * @param nbytes The number of bytes to write from the buffer. + */ + void write(const void *buffer, unsigned int nbytes); + + /*! + * Simply write one single byte into the pipe. This is a shortcut + * if there's really no data to transport, but to activate the handler. + */ + void signal(); + +private: + void(*_handler)(const void *data, void *buffer, unsigned int nbyte); + int fd_write; + int fd_read; + const void *data; + + // allow construction only in BusDispatcher + Pipe (); + ~Pipe () {}; + +friend class BusDispatcher; +}; + +} /* namespace DBus */ + +#endif // DBUSXX_PIPE_H diff --git a/src/Makefile.am b/src/Makefile.am index 1220db5..6c7eec4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,7 +42,8 @@ lib_includedir=$(includedir)/dbus-c++-1/dbus-c++/ lib_include_HEADERS = $(HEADER_FILES) lib_LTLIBRARIES = libdbus-c++-1.la -libdbus_c___1_la_SOURCES = $(HEADER_FILES) interface.cpp object.cpp introspection.cpp debug.cpp types.cpp connection.cpp connection_p.h property.cpp dispatcher.cpp dispatcher_p.h pendingcall.cpp pendingcall_p.h error.cpp internalerror.h message.cpp message_p.h server.cpp server_p.h eventloop.cpp eventloop-integration.cpp $(GLIB_CPP) $(ECORE_CPP) +libdbus_c___1_la_SOURCES = $(HEADER_FILES) interface.cpp object.cpp introspection.cpp debug.cpp types.cpp connection.cpp connection_p.h property.cpp dispatcher.cpp dispatcher_p.h pendingcall.cpp pendingcall_p.h error.cpp internalerror.h message.cpp message_p.h server.cpp server_p.h eventloop.cpp eventloop-integration.cpp $(GLIB_CPP) $(ECORE_CPP) \ + pipe.cpp pipe.h libdbus_c___1_la_LIBADD = $(dbus_LIBS) $(glib_LIBS) $(pthread_LIBS) $(ecore_LIBS) libdbus_c___1_la_LDFLAGS = -no-undefined diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index d20154a..e4a9ad3 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -74,16 +75,6 @@ void BusWatch::toggle() DefaultWatch::enabled(Watch::enabled()); } -void Pipe::write(const void *buffer, unsigned int nbytes) -{ - ::write(fd_write, buffer, nbytes); -} - -void Pipe::signal() -{ - ::write(fd_write, '\0', 1); -} - BusDispatcher::BusDispatcher() : _running(false) { @@ -155,6 +146,7 @@ Pipe *BusDispatcher::add_pipe(void(*handler)(const void *data, void *buffer, uns new_pipe->fd_read = fd[0]; new_pipe->fd_write = fd[1]; fcntl(new_pipe->fd_read, F_SETFL, O_NONBLOCK); + fcntl(new_pipe->fd_write, F_SETFL, O_NONBLOCK); } else { diff --git a/src/pipe.cpp b/src/pipe.cpp new file mode 100644 index 0000000..6045e0b --- /dev/null +++ b/src/pipe.cpp @@ -0,0 +1,51 @@ +/* + * + * D-Bus++ - C++ bindings for D-Bus + * + * Copyright (C) 2005-2007 Paolo Durante + * + * + * 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) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +using namespace DBus; +using namespace std; + +Pipe::Pipe () : + _handler (NULL), + fd_write (0), + fd_read (0), + data (NULL) +{ +} + +void Pipe::write(const void *buffer, unsigned int nbytes) +{ + ::write(fd_write, buffer, nbytes); +} + +void Pipe::signal() +{ + ::write(fd_write, '\0', 1); +} -- cgit v1.2.1 From 9af6f707eb62fa02d9ef473ab4cc87ebfdc1c37b Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Thu, 12 Aug 2010 23:14:45 +0200 Subject: ok, now at least the structure is better but there's still a problem with the new mechanism as the size of the data isn't put into the pipe. I need to fix tis before someone could really use it... --- include/dbus-c++/pipe.h | 10 ++++++---- src/Makefile.am | 4 ++-- src/eventloop-integration.cpp | 38 ++++++++++++-------------------------- src/pipe.cpp | 39 ++++++++++++++++++++++++++++++++------- 4 files changed, 52 insertions(+), 39 deletions(-) diff --git a/include/dbus-c++/pipe.h b/include/dbus-c++/pipe.h index c994b6e..393f39d 100644 --- a/include/dbus-c++/pipe.h +++ b/include/dbus-c++/pipe.h @@ -43,6 +43,8 @@ public: */ void write(const void *buffer, unsigned int nbytes); + ssize_t read(void *buffer, unsigned int nbytes); + /*! * Simply write one single byte into the pipe. This is a shortcut * if there's really no data to transport, but to activate the handler. @@ -51,12 +53,12 @@ public: private: void(*_handler)(const void *data, void *buffer, unsigned int nbyte); - int fd_write; - int fd_read; - const void *data; + int _fd_write; + int _fd_read; + const void *_data; // allow construction only in BusDispatcher - Pipe (); + Pipe (void(*handler)(const void *data, void *buffer, unsigned int nbyte), const void *data); ~Pipe () {}; friend class BusDispatcher; diff --git a/src/Makefile.am b/src/Makefile.am index 6c7eec4..538c031 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,14 +36,14 @@ HEADER_FILES = \ $(HEADER_DIR)/api.h \ $(HEADER_DIR)/eventloop.h \ $(HEADER_DIR)/eventloop-integration.h \ + $(HEADER_DIR)/pipe.h \ $(GLIB_H) $(ECORE_H) lib_includedir=$(includedir)/dbus-c++-1/dbus-c++/ lib_include_HEADERS = $(HEADER_FILES) lib_LTLIBRARIES = libdbus-c++-1.la -libdbus_c___1_la_SOURCES = $(HEADER_FILES) interface.cpp object.cpp introspection.cpp debug.cpp types.cpp connection.cpp connection_p.h property.cpp dispatcher.cpp dispatcher_p.h pendingcall.cpp pendingcall_p.h error.cpp internalerror.h message.cpp message_p.h server.cpp server_p.h eventloop.cpp eventloop-integration.cpp $(GLIB_CPP) $(ECORE_CPP) \ - pipe.cpp pipe.h +libdbus_c___1_la_SOURCES = $(HEADER_FILES) interface.cpp object.cpp introspection.cpp debug.cpp types.cpp connection.cpp connection_p.h property.cpp dispatcher.cpp dispatcher_p.h pendingcall.cpp pendingcall_p.h error.cpp internalerror.h message.cpp message_p.h server.cpp server_p.h eventloop.cpp eventloop-integration.cpp pipe.cpp $(GLIB_CPP) $(ECORE_CPP) libdbus_c___1_la_LIBADD = $(dbus_LIBS) $(glib_LIBS) $(pthread_LIBS) $(ecore_LIBS) libdbus_c___1_la_LDFLAGS = -no-undefined diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index e4a9ad3..689f2da 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -25,18 +25,19 @@ #include #endif -#include - +/* Project */ #include #include #include -#include -#include - +/* DBus */ #include -#include + +/* STD */ +#include #include +#include +#include using namespace DBus; using namespace std; @@ -97,16 +98,16 @@ void BusDispatcher::enter() { do_iteration(); - for (std::list ::const_iterator p_it = pipe_list.begin (); + for (std::list ::iterator p_it = pipe_list.begin (); p_it != pipe_list.end (); ++p_it) { - const Pipe* read_pipe = *p_it; + Pipe* read_pipe = *p_it; char buf; char buf_str[1024]; int i = 0; - while (read(read_pipe->fd_read, &buf, 1) > 0) + while (read_pipe->read((void*) &buf, 1) > 0) { buf_str[i] = buf; ++i; @@ -114,7 +115,7 @@ void BusDispatcher::enter() if (i > 0) { - read_pipe->_handler (read_pipe->data, buf_str, i); + read_pipe->_handler (read_pipe->_data, buf_str, i); } } } @@ -135,24 +136,9 @@ void BusDispatcher::leave() Pipe *BusDispatcher::add_pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), const void *data) { - int fd[2]; - Pipe *new_pipe = new Pipe (); - new_pipe->_handler = handler; - new_pipe->data = data; + Pipe *new_pipe = new Pipe (handler, data); pipe_list.push_back (new_pipe); - if (pipe(fd) == 0) - { - new_pipe->fd_read = fd[0]; - new_pipe->fd_write = fd[1]; - fcntl(new_pipe->fd_read, F_SETFL, O_NONBLOCK); - fcntl(new_pipe->fd_write, F_SETFL, O_NONBLOCK); - } - else - { - throw Error("PipeError:errno", toString(errno).c_str()); - } - return new_pipe; } diff --git a/src/pipe.cpp b/src/pipe.cpp index 6045e0b..328670a 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -25,27 +25,52 @@ #include #endif +/* Project */ #include +#include +#include +/* STD */ #include +#include +#include +#include using namespace DBus; using namespace std; -Pipe::Pipe () : - _handler (NULL), - fd_write (0), - fd_read (0), - data (NULL) +Pipe::Pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), const void *data) : + _handler(handler), + _fd_write (0), + _fd_read (0), + _data(data) { + int fd[2]; + + if(pipe(fd) == 0) + { + _fd_read = fd[0]; + _fd_write = fd[1]; + fcntl(_fd_read, F_SETFL, O_NONBLOCK); + fcntl(_fd_write, F_SETFL, O_NONBLOCK); + } + else + { + throw Error("PipeError:errno", toString(errno).c_str()); + } } void Pipe::write(const void *buffer, unsigned int nbytes) { - ::write(fd_write, buffer, nbytes); + ::write(_fd_write, buffer, nbytes); +} + +ssize_t Pipe::read(void *buffer, unsigned int nbytes) +{ + return ::read(_fd_read, buffer, nbytes); } void Pipe::signal() { - ::write(fd_write, '\0', 1); + ::write(_fd_write, '\0', 1); } -- cgit v1.2.1 From dc833f4a89bcb661274e453a5bb92a2d7655faba Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Tue, 17 Aug 2010 22:43:24 +0200 Subject: this fixed the correct handling of the default main loop but setting another DefaultTimeout isn't nice. I've to look later again into the problem. Maybe I did it wrong. Currently there's a compiler warning that could be ignores as long as Slot is created with void parameter, but I consider this as bug in the long time and I've to fix it!! --- examples/echo/echo-client.cpp | 22 +++++++++++++--------- include/dbus-c++/dispatcher.h | 2 +- include/dbus-c++/glib-integration.h | 4 ++-- include/dbus-c++/pipe.h | 2 +- include/dbus-c++/util.h | 22 +++++++++++++++++++--- src/eventloop-integration.cpp | 20 +++++++------------- src/eventloop.cpp | 1 + src/pipe.cpp | 14 +++++++++++--- 8 files changed, 55 insertions(+), 32 deletions(-) diff --git a/examples/echo/echo-client.cpp b/examples/echo/echo-client.cpp index f6d59a8..f01f23a 100644 --- a/examples/echo/echo-client.cpp +++ b/examples/echo/echo-client.cpp @@ -36,6 +36,9 @@ EchoClient *g_client = NULL; DBus::Pipe *thread_pipe_list[THREADS]; +DBus::BusDispatcher dispatcher; +DBus::DefaultTimeout *timeout; + void *greeter_thread(void *arg) { char idstr[16]; @@ -50,8 +53,6 @@ void *greeter_thread(void *arg) return NULL; } -DBus::BusDispatcher dispatcher; - void niam(int sig) { spin = false; @@ -62,30 +63,30 @@ void niam(int sig) void handler1 (const void *data, void *buffer, unsigned int nbyte) { char *str = (char*) buffer; - cout << "buffer1: " << str << endl; + cout << "buffer1: " << str << ", size: " << nbyte << endl; for (int i = 0; i < 30 && spin; ++i) { - cout << g_client->Hello (str) << endl; + cout << "call1: " << g_client->Hello (str) << endl; } } void handler2 (const void *data, void *buffer, unsigned int nbyte) { char *str = (char*) buffer; - cout << "buffer2: " << str << endl; + cout << "buffer2: " << str << ", size: " << nbyte <Hello (str) << endl; + cout << "call2: " << g_client->Hello (str) << endl; } } void handler3 (const void *data, void *buffer, unsigned int nbyte) { char *str = (char*) buffer; - cout << "buffer3: " << str << endl; + cout << "buffer3: " << str << ", size: " << nbyte <Hello (str) << endl; + cout << "call3: " << g_client->Hello (str) << endl; } } @@ -96,7 +97,10 @@ int main() DBus::_init_threading(); - DBus::default_dispatcher = &dispatcher; + DBus::default_dispatcher = &dispatcher; + + // increase DBus-C++ frequency + new DBus::DefaultTimeout(100, false, &dispatcher); DBus::Connection conn = DBus::Connection::SessionBus(); diff --git a/include/dbus-c++/dispatcher.h b/include/dbus-c++/dispatcher.h index 10179ff..728f9d8 100644 --- a/include/dbus-c++/dispatcher.h +++ b/include/dbus-c++/dispatcher.h @@ -44,7 +44,7 @@ public: /*! * \brief Gets the timeout interval. * - * The dbus_timeout_handle() should be called each time this interval elapses, + * The handle() should be called each time this interval elapses, * starting after it elapses once. * * The interval may change during the life of the timeout; if so, the timeout diff --git a/include/dbus-c++/glib-integration.h b/include/dbus-c++/glib-integration.h index 76eae5e..0f68852 100644 --- a/include/dbus-c++/glib-integration.h +++ b/include/dbus-c++/glib-integration.h @@ -54,9 +54,9 @@ private: private: - GSource *_source; GMainContext *_ctx; int _priority; + GSource *_source; friend class BusDispatcher; }; @@ -79,9 +79,9 @@ private: private: - GSource *_source; GMainContext *_ctx; int _priority; + GSource *_source; friend class BusDispatcher; }; diff --git a/include/dbus-c++/pipe.h b/include/dbus-c++/pipe.h index 393f39d..752d48d 100644 --- a/include/dbus-c++/pipe.h +++ b/include/dbus-c++/pipe.h @@ -43,7 +43,7 @@ public: */ void write(const void *buffer, unsigned int nbytes); - ssize_t read(void *buffer, unsigned int nbytes); + ssize_t read(void *buffer, unsigned int &nbytes); /*! * Simply write one single byte into the pipe. This is a shortcut diff --git a/include/dbus-c++/util.h b/include/dbus-c++/util.h index b46732f..8b3806d 100644 --- a/include/dbus-c++/util.h +++ b/include/dbus-c++/util.h @@ -28,6 +28,8 @@ #include #include #include +#include + #include "api.h" #include "debug.h" @@ -232,15 +234,29 @@ public: R operator()(P param) const { - /*if (_cb.get())*/ return _cb->call(param); + if (!empty()) + { + return _cb->call(param); + } + + // TODO: think about return type in this case + // this assert should help me to find the use case where it's needed... + //assert (false); } R call(P param) const { - /*if (_cb.get())*/ return _cb->call(param); + if (!empty()) + { + return _cb->call(param); + } + + // TODO: think about return type in this case + // this assert should help me to find the use case where it's needed... + //assert (false); } - bool empty() + bool empty() const { return _cb.get() == 0; } diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index 689f2da..0c86ffb 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -103,20 +103,14 @@ void BusDispatcher::enter() ++p_it) { Pipe* read_pipe = *p_it; - char buf; - char buf_str[1024]; - int i = 0; + char buffer[1024]; // TODO: should be max pipe size + unsigned int nbytes = 0; - while (read_pipe->read((void*) &buf, 1) > 0) - { - buf_str[i] = buf; - ++i; - } - - if (i > 0) - { - read_pipe->_handler (read_pipe->_data, buf_str, i); - } + while (read_pipe->read(buffer, nbytes) > 0) + { + read_pipe->_handler (read_pipe->_data, buffer, nbytes); + } + } } diff --git a/src/eventloop.cpp b/src/eventloop.cpp index 76b94f8..0268162 100644 --- a/src/eventloop.cpp +++ b/src/eventloop.cpp @@ -34,6 +34,7 @@ #include using namespace DBus; +using namespace std; static double millis(timeval tv) { diff --git a/src/pipe.cpp b/src/pipe.cpp index 328670a..96f1b30 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -35,6 +35,7 @@ #include #include #include +#include using namespace DBus; using namespace std; @@ -52,7 +53,6 @@ Pipe::Pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), c _fd_read = fd[0]; _fd_write = fd[1]; fcntl(_fd_read, F_SETFL, O_NONBLOCK); - fcntl(_fd_write, F_SETFL, O_NONBLOCK); } else { @@ -62,11 +62,19 @@ Pipe::Pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), c void Pipe::write(const void *buffer, unsigned int nbytes) { + // first write the size into the pipe... + ::write(_fd_write, static_cast (&nbytes), sizeof(nbytes)); + + // ...then write the real data ::write(_fd_write, buffer, nbytes); } -ssize_t Pipe::read(void *buffer, unsigned int nbytes) -{ +ssize_t Pipe::read(void *buffer, unsigned int &nbytes) +{ + // first read the size from the pipe... + ::read(_fd_read, &nbytes, sizeof (nbytes)); + + //ssize_t size = 0; return ::read(_fd_read, buffer, nbytes); } -- cgit v1.2.1 From 8f064c4b084312424408aab3367240324ca2d456 Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Fri, 8 Oct 2010 00:22:58 +0200 Subject: added patches from: Roman Fietze --- .gitignore | 22 ++++++++++++++++++++++ configure.ac | 2 +- examples/echo/echo-client.cpp | 10 ++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3cfba9c --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +Makefile.in +aclocal.m4 +autom4te.cache/ +config.guess +config.h.in +config.sub +configure +data/Makefile.in +depcomp +doc/Makefile.in +examples/Makefile.in +examples/echo/Makefile.in +examples/ecore/Makefile.in +examples/glib/Makefile.in +examples/hal/Makefile.in +examples/properties/Makefile.in +install-sh +ltmain.sh +m4/ +missing +src/Makefile.in +tools/Makefile.in diff --git a/configure.ac b/configure.ac index bb5fc01..a570fd4 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # Autojunk script for libdbus-c++ AC_PREREQ(2.59) -AC_INIT([libdbus-c++], 0.5.0, [andreas.volz@tux-style.com]) +AC_INIT([libdbus-c++], 0.6.0-pre1, [andreas.volz@tux-style.com]) AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) AM_CONFIG_HEADER([config.h]) diff --git a/examples/echo/echo-client.cpp b/examples/echo/echo-client.cpp index f01f23a..f84c093 100644 --- a/examples/echo/echo-client.cpp +++ b/examples/echo/echo-client.cpp @@ -28,7 +28,7 @@ void EchoClient::Echoed(const DBus::Variant &value) * For some strange reason, libdbus frequently dies with an OOM */ -static const int THREADS = 3; +static const size_t THREADS = 3; static bool spin = true; @@ -42,7 +42,7 @@ DBus::DefaultTimeout *timeout; void *greeter_thread(void *arg) { char idstr[16]; - int i = (int) arg; + size_t i = (size_t) arg; snprintf(idstr, sizeof(idstr), "%lu", pthread_self()); @@ -92,6 +92,8 @@ void handler3 (const void *data, void *buffer, unsigned int nbyte) int main() { + size_t i; + signal(SIGTERM, niam); signal(SIGINT, niam); @@ -112,7 +114,7 @@ int main() thread_pipe_list[0] = dispatcher.add_pipe (handler1, NULL); thread_pipe_list[1] = dispatcher.add_pipe (handler2, NULL); thread_pipe_list[2] = dispatcher.add_pipe (handler3, NULL); - for (int i = 0; i < THREADS; ++i) + for (i = 0; i < THREADS; ++i) { pthread_create(threads+i, NULL, greeter_thread, (void*) i); } @@ -121,7 +123,7 @@ int main() cout << "terminating" << endl; - for (int i = 0; i < THREADS; ++i) + for (i = 0; i < THREADS; ++i) { pthread_join(threads[i], NULL); } -- cgit v1.2.1 From 2379d37c3bfb894ea735d0af40368f2aa5afa72a Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Fri, 8 Oct 2010 00:35:45 +0200 Subject: patch from: Von: Mat An: dbus-cplusplus-devel@lists.sourceforge.net Betreff: [dbus-cplusplus-devel] A patch for deadlock, for dbus io error exception in the mainloop critical section. Datum: Mon, 6 Sep 2010 12:24:03 +0800 --- src/eventloop.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/eventloop.cpp b/src/eventloop.cpp index 0268162..eb2ce85 100644 --- a/src/eventloop.cpp +++ b/src/eventloop.cpp @@ -109,7 +109,8 @@ void DefaultMutex::unlock() pthread_mutex_unlock(&_mutex); } -DefaultMainLoop::DefaultMainLoop() +DefaultMainLoop::DefaultMainLoop() : + _mutex_w(true) { } -- cgit v1.2.1