From: Vince L. <vla...@go...> - 2010-12-06 21:06:38
|
Hi Ted, On Mon, Dec 6, 2010 at 11:59 AM, Jason Glasgow <jgl...@go...> wrote: > see main() for how we attach the dbus-c++ dispatcher to the glib main loop. > > > http://git.chromium.org/gitweb/?p=cashew.git;a=blob;f=src/main.cc;h=d7f64fe5f37b99e91d7eb2ef9e4566f01833e521;hb=HEAD#l102 > > -Jason > dbus-c++ provides several flavors of dispatcher. The vanilla one (DBus::BusDispatcher) does implement its own event loop, entered by DBus::BusDispatcher::enter and exited by DBus::BusDispatcher::leave. There is a separate dispatcher for glib integration: DBus::Glib::BusDispatcher. When using the glib dispatcher, you still need to attach it, but, since it's using the glib main loop, the enter and leave routines are no-ops. You instead create a glib main loop and enter and leave the loop using the usual glib calls: g_main_loop_run and g_main_loop_quit. See the cashew link that Jason provided for an example of how to use the glib dispatcher. The add_timeout, rem_timeout, add_watch, and rem_watch methods on the default dispatcher seem promising at first glance, but the conversation quoted below suggests that you've already tried them with no luck. Andreas says in the thread below: > Are you sure the C backend of DBus provides such a feature? Could you name a function? The C backend for D-Bus is meant to allow integration of D-Bus events into an existing external event loop. So, it provides the ability for code implementing this event loop to provide a callback function for libdbus to call when libdbus wants to add a timeout that will be managed by this external event loop (and similarly for watches on fds that libdbus want the external event loop to manage). However, one would expect that the external event loop will... um... be an event loop, meaning that its public API allows timeouts and watches to be created, managed, and removed by arbitrary clients, not just by libdbus through the dbus binding. IMO, if the default dispatcher purports to be a real event loop (and it's not clear that it does, since it's intentionally very simple), it should allow timeouts and watches to be managed. It should do this just because it's an event loop, not because it's part of a D-Bus binding. Ted: An alternate approach would be to ignore the default dispatcher, look at how DBus::Glib::BusDispatcher is implemented, and follow the same model to implement DBus::EventLibThatTedPrefersInsteadOfGlib::BusDispatcher. Vince > > On Mon, Dec 6, 2010 at 1:04 PM, Theodore A. Roth <ta...@gm...> wrote: > >> On Mon, Dec 6, 2010 at 7:31 AM, Jason Glasgow <jgl...@go...> >> wrote: >> > You might try using g_timeout_add_seconds. We have used it with >> dbus-c++. >> > >> http://git.chromium.org/gitweb/?p=cashew.git;a=blob;f=src/device.cc;h=b5ac6f5103d8a1c05e82b0f6633d7bd6b965b6a0;hb=HEAD >> > -Jason >> >> Jason, >> >> Right. That's exactly what I want to do, but doesn't using >> g_timeout_add_seconds() imply that you are using the glib event loop >> and thus have to link to glib? >> >> I need to integrate my dispatcher with our own event loops so need to >> be event loop agnostic and we want to avoid using glib if possible. >> >> I was under the (most likely mistaken) impression the the generic >> dispatcher provided its own event loop which got started when you >> invoke dispatcher.enter(). Sounds like I need to do some more homework >> into how the dispatcher works. ;-) >> >> I have written some simple python apps that use the glib event loop to >> send a heartbeat signal and I was hoping to achieve the same thing >> using the default dispatcher. >> >> Ted Roth >> >> > >> > On Sun, Dec 5, 2010 at 4:58 PM, Andreas Volz <li...@br...> >> wrote: >> >> >> >> Am Fri, 3 Dec 2010 16:23:08 -0700 schrieb Theodore A. Roth: >> >> >> >> > I've been trying to figure out how to register a timeout callback >> with >> >> > the dispatcher so that my callback function will be invoked >> >> > periodically by the dispatcher main loop. The >> >> > BusDispatcher::add_timeout() method seems to take an internal timeout >> >> > object as an argument which leads me to believe that I can't use >> that. >> >> > >> >> > I'm still in the learning dbus-c++ phase and my app is a rather >> simple >> >> > server based on the echo demo, but I've stripped it down to only a >> >> > Hello method and a single signal. My goal is to invoked the signal in >> >> > the timeout. >> >> > >> >> > None of the examples in the source repo show how to do what I what, >> >> > and google hasn't been too helpful. If someone has a link to an >> >> > example of this, I would be most appreciative. >> >> >> >> Hello Ted, >> >> >> >> yes, BusDispatcher::add_timeout() is for another reason. To be honest I >> >> never needed such an feature. Are you sure the C backend of DBus >> >> provides such a feature? Could you name a function? >> >> >> >> I would solve this by writing an interface to a DBus service that >> >> provides you with configurable callbacks. :-) >> >> >> >> regards >> >> Andreas >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> What happens now with your Lotus Notes apps - do you make another >> costly >> >> upgrade, or settle for being marooned without product support? Time to >> >> move >> >> off Lotus Notes and onto the cloud with Force.com, apps are easier to >> >> build, >> >> use, and manage than apps on traditional platforms. Sign up for the >> Lotus >> >> Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d >> >> _______________________________________________ >> >> dbus-cplusplus-devel mailing list >> >> dbu...@li... >> >> https://lists.sourceforge.net/lists/listinfo/dbus-cplusplus-devel >> > >> > >> > >> ------------------------------------------------------------------------------ >> > What happens now with your Lotus Notes apps - do you make another costly >> > upgrade, or settle for being marooned without product support? Time to >> move >> > off Lotus Notes and onto the cloud with Force.com, apps are easier to >> build, >> > use, and manage than apps on traditional platforms. Sign up for the >> Lotus >> > Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d >> > _______________________________________________ >> > dbus-cplusplus-devel mailing list >> > dbu...@li... >> > https://lists.sourceforge.net/lists/listinfo/dbus-cplusplus-devel >> > >> > >> > > |