From f334deaf9d630782be3f7f535265ff7488162f85 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Jun 2005 16:32:27 +0000 Subject: * update avahi_address_parse() to work with AF_UNSPEC address family * complete simple protocol * defer scanning already cached RRs when browsing into its own main loop job git-svn-id: file:///home/lennart/svn/public/avahi/trunk@114 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-daemon/main.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'avahi-daemon/main.c') diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c index 3875865..7b3f209 100644 --- a/avahi-daemon/main.c +++ b/avahi-daemon/main.c @@ -29,10 +29,13 @@ #include #include +#include "main.h" #include "simple-protocol.h" #define DBUS_SERVICE_AVAHI "org.freedesktop.Avahi" +AvahiServer *avahi_server = NULL; + static DBusHandlerResult do_register (DBusConnection *conn, DBusMessage *message) { @@ -112,12 +115,30 @@ signal_filter (DBusConnection *conn, DBusMessage *message, void *user_data) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - + +static void server_callback(AvahiServer *s, AvahiServerState state, gpointer userdata) { + g_assert(s); + + if (state == AVAHI_SERVER_RUNNING) + g_message("Server startup complete. Host name is <%s>", avahi_server_get_host_name_fqdn(s)); + else if (state == AVAHI_SERVER_COLLISION) { + gchar *n; + n = avahi_alternative_host_name(avahi_server_get_host_name(s)); + g_message("Host name conflict, retrying with <%s>", n); + avahi_server_set_host_name(s, n); + g_free(n); + } +} + int main(int argc, char *argv[]) { GMainLoop *loop = NULL; DBusConnection *bus = NULL; DBusError error; - gint r = -1; + gint r = 255; + AvahiServer *server = NULL; + AvahiServerConfig config; + + avahi_server_config_init(&config); loop = g_main_loop_new(NULL, FALSE); @@ -162,6 +183,9 @@ int main(int argc, char *argv[]) { if (simple_protocol_setup(NULL) < 0) goto finish; + if (!(avahi_server = avahi_server_new(NULL, &config, server_callback, NULL))) + goto finish; + g_main_loop_run(loop); r = 0; @@ -175,8 +199,13 @@ finish: dbus_connection_unref(bus); } + if (avahi_server) + avahi_server_free(avahi_server); + if (loop) g_main_loop_unref(loop); + avahi_server_config_free(&config); + return r; } -- cgit