4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <avahi-core/core.h>
29 #include "simple-protocol.h"
30 #include "static-services.h"
32 AvahiServer *avahi_server = NULL;
34 static void server_callback(AvahiServer *s, AvahiServerState state, gpointer userdata) {
37 if (state == AVAHI_SERVER_RUNNING) {
38 g_message("Server startup complete. Host name is <%s>", avahi_server_get_host_name_fqdn(s));
39 static_service_add_to_server();
40 } else if (state == AVAHI_SERVER_COLLISION) {
43 static_service_remove_from_server();
45 n = avahi_alternative_host_name(avahi_server_get_host_name(s));
46 g_message("Host name conflict, retrying with <%s>", n);
47 avahi_server_set_host_name(s, n);
52 int main(int argc, char *argv[]) {
53 GMainLoop *loop = NULL;
55 AvahiServerConfig config;
57 avahi_server_config_init(&config);
59 loop = g_main_loop_new(NULL, FALSE);
61 if (simple_protocol_setup(NULL) < 0)
65 if (dbus_protocol_setup () < 0)
69 if (!(avahi_server = avahi_server_new(NULL, &config, server_callback, NULL)))
72 static_service_load();
74 g_main_loop_run(loop);
80 static_service_remove_from_server();
81 static_service_free_all();
83 simple_protocol_shutdown();
86 dbus_protocol_shutdown();
90 avahi_server_free(avahi_server);
93 g_main_loop_unref(loop);
95 avahi_server_config_free(&config);