[avahi] browsing without event loop ?
Lennart Poettering
lennart at poettering.net
Mon Sep 3 09:17:57 PDT 2007
On Mon, 03.09.07 16:57, Ludovic Courtès (ludovic.courtes at laas.fr) wrote:
Hi!
> > Why would you want to avoid running an event loop anyway?
>
> My guess is that it's because it's cumbersome.
>
> Sometimes, you'd like to write something like:
>
> for machine in services(type=_workstation._tcp)
> do
> shutdown $machine
> done
>
> Using the call-back API makes it hard to express such simple things.
You're welcome to run the Avahi event loop only until a certain
condition holds. i.e.:
while (avahi_client_get_state(client) != AVAHI_CLIENT_FAILURE) {
if (avahi_simple_poll_iterate(p, NULL) != 0)
break;
}
Then, in your event callback just run avai_simple_poll_quit() and this
loop will exit, because avahi_simple_poll_iterate() will return
1. A good candidate for calling that function at would be
ALL_FOR_NOW.
> FWIW, I'm planning to add a "threaded" API to Guile-Avahi, whereby the
> event loop would be run in a separate thread. User threads would send
> requests such as "list all services of a given type" to the
> event-processing thread and would block until the event-processing
> thread is done (e.g., until "ALL_FOR_NOW" or an error is caught).
You are aware of AvahiThreadedPoll which does exactly this in C and
has been part of Avahi since 0.6.3?
See http://avahi.org/wiki/RunningAvahiClientAsThread for more
information.
Lennart
--
Lennart Poettering Red Hat, Inc.
lennart [at] poettering [dot] net ICQ# 11060553
http://0pointer.net/lennart/ GnuPG 0x1A015CC4
More information about the avahi
mailing list