* Added a wrapper for dbus_threads_init_default

* Added a wrapper for dbus_connection_set_exit_on_disconnect
* Added a multithreaded test case for the echo example


git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@11874 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
pdurante 2007-07-07 01:23:13 +00:00
parent b116f68663
commit 568ec7fc45
10 changed files with 137 additions and 5 deletions

View file

@ -4,13 +4,23 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
noinst_PROGRAMS = echo-server
echo_server_SOURCES = echo-glue.h echo-server.h echo-server.cpp
echo_server_SOURCES = echo-server-glue.h echo-server.h echo-server.cpp
echo_server_LDADD = $(top_builddir)/src/libdbus-c++-1.la
echo-glue.h: echo-introspect.xml
echo-server-glue.h: echo-introspect.xml
$(top_builddir)/tools/dbusxx-xml2cpp $^ --adaptor=$@
BUILT_SOURCES = echo-glue.h
if HAVE_PTHREAD
noinst_PROGRAMS += echo-client-mt
endif
echo_client_mt_SOURCES = echo-client-glue.h echo-client.h echo-client.cpp
echo_client_mt_LDADD = $(top_builddir)/src/libdbus-c++-1.la -lpthread
echo-client-glue.h: echo-introspect.xml
$(top_builddir)/tools/dbusxx-xml2cpp $^ --proxy=$@
BUILT_SOURCES = echo-server-glue.h echo-client-glue.h
CLEANFILES = $(BUILT_SOURCES)
dist-hook:

View file

@ -0,0 +1,80 @@
#include "echo-client.h"
#include <iostream>
#include <pthread.h>
#include <signal.h>
using namespace std;
static const char* ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo";
static const char* ECHO_SERVER_PATH = "/org/freedesktop/DBus/Examples/Echo";
EchoClient::EchoClient( DBus::Connection& connection, const char* path, const char* name )
: DBus::ObjectProxy(connection, path, name)
{
}
void EchoClient::Echoed( const DBus::Variant& value )
{
cout << "!";
}
/* NOTE: using many threads is likely to trigger a race condition in the event loop
* in fact access to the list of timeouts and watches inside the default dispatcher
* implementation (DBus::BusDispatcher) is NOT serialized
*
* (yes, I'm well aware of how much this sucks)
*/
static const int THREADS = 1;
static bool spin = true;
void* greeter_thread( void* )
{
DBus::Connection conn = DBus::Connection::SessionBus();
EchoClient client(conn, ECHO_SERVER_PATH, ECHO_SERVER_NAME);
while(spin)
{
client.Hello("client");
cout << "*";
}
return NULL;
}
DBus::BusDispatcher dispatcher;
void niam( int sig )
{
spin = false;
dispatcher.leave();
}
int main()
{
signal(SIGTERM, niam);
signal(SIGINT, niam);
DBus::_init_threading();
DBus::default_dispatcher = &dispatcher;
pthread_t threads[THREADS];
for(int i = 0; i < THREADS; ++i)
{
pthread_create(threads+i, NULL, greeter_thread, NULL);
}
dispatcher.enter();
for(int i = 0; i < THREADS; ++i)
{
pthread_join(threads[i], NULL);
}
return 0;
}

View file

@ -0,0 +1,19 @@
#ifndef __DEMO_ECHO_CLIENT_H
#define __DEMO_ECHO_CLIENT_H
#include <dbus-c++/dbus.h>
#include "echo-client-glue.h"
class EchoClient
: public org::freedesktop::DBus::EchoDemo,
public DBus::IntrospectableProxy,
public DBus::ObjectProxy
{
public:
EchoClient( DBus::Connection& connection, const char* path, const char* name );
void Echoed( const DBus::Variant& value );
};
#endif//__DEMO_ECHO_CLIENT_H

View file

@ -2,7 +2,7 @@
#define __DEMO_ECHO_SERVER_H
#include <dbus-c++/dbus.h>
#include "echo-glue.h"
#include "echo-server-glue.h"
class EchoServer
: public org::freedesktop::DBus::EchoDemo,