|
From: Andreas V. <li...@br...> - 2009-05-18 19:35:08
|
Am Mon, 18 May 2009 15:22:24 +0200 schrieb Meier, Andreas:
> Hello,
>
> > ...
> > I also played around with the echo example and had various threading
> > problems. As long as you use the own main loop dispatcher you'll get
> > those problem. You should use the glib or ecore integration to get
> > it working.
> >
> > I've some ideas to get the Dbus-C++ main loop working also with
> > threads. But you're right the echo example is broken currently.
> > Don't use it currently or change it to use glib and provide a patch.
>
> In the end I would like to have a client-side application with a main
> loop
> and various threads from where blocking method calls are invoked.
>
> I started with the echo-example and found it broken.
>
> I would be glad if you could describe your previously mentioned ideas
> in short terms? So I have a better understanding of where to start
> looking for the problem.
Hello Andreas,
The problem is to get a hook from the event loop where it's save to
queue new requests in dbus-c++. In the Glib and Ecore there's a real
event loop. So I would do it in dispatcher.cpp:
void BusDispatcher::enter()
{
debug_log("entering dispatcher %p", this);
_running = true;
while (_running)
{
// -> call the callback here!
do_iteration();
}
debug_log("leaving dispatcher %p", this);
}
The while loop there is our main event loop. So as long as Dbus-C++
isn't complete thread save it's only save to queue new requests outside
the do_iteration() function. So far the theory... :-)
I would add a function callback to the prototype of enter(). Then in
the loop before the do_iteration() I would call that callback function.
Then in the e.g. echo example you've this callback function from where
it's save to call Dbus-C++ functions. So here is a snippet from the
echo client:
void *greeter_thread(void *arg)
{
DBus::Connection *conn = reinterpret_cast<DBus::Connection
*>(arg);
EchoClient client(*conn, ECHO_SERVER_PATH, ECHO_SERVER_NAME);
char idstr[16];
string s ("TestString");
snprintf(idstr, sizeof(idstr), "%lu", pthread_self());
for (int i = 0; i < 1000 && spin; ++i)
{
cout << client.Echo(s) << endl;
}
cout << idstr << " done " << endl;
return NULL;
}
I would create a queue protected by a mutex and queue requests from the
thread and work on this queue in the callback function. So it's sure to
call a Dbus-C++ function.
I would try it this way. But sorry I'm busy with another project. But
if you had success I'll commit your patches into both branches.
regards
Andreas
|