Example of how to integrate avahi use with GLIB/GTK applications
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib.h>
#include <avahi-common/timeval.h>
static void
avahi_timeout_event (AVAHI_GCC_UNUSED
AvahiTimeout *timeout, AVAHI_GCC_UNUSED
void *userdata)
{
g_message ("Avahi API Timeout reached!");
}
static gboolean
avahi_timeout_event_glib (void *userdata)
{
GMainLoop *loop = userdata;
g_message ("GLIB API Timeout reached, quitting main loop!");
g_main_loop_quit (loop);
return FALSE;
}
static void
{
GMainLoop *loop = userdata;
g_message ("Avahi Client State Change: %d", state);
{
g_main_loop_quit (loop);
}
}
int
main (AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[])
{
GMainLoop *loop = NULL;
struct timeval tv;
const char *version;
int error;
loop = g_main_loop_new (NULL, FALSE);
avahi_elapse_time (&tv,
1000,
0);
&tv,
avahi_timeout_event,
NULL);
g_timeout_add (5000,
avahi_timeout_event_glib,
loop);
0,
avahi_client_callback,
loop,
&error);
if (client == NULL)
{
goto fail;
}
if (version == NULL)
{
goto fail;
}
g_message ("Avahi Server Version: %s", version);
g_main_loop_run (loop);
fail:
g_main_loop_unref (loop);
return 0;
}