]> git.meshlink.io Git - catta/blob - avahi-daemon/main.c
d59e9fb3df2ffe1d62418f8a39ec6d3a73ad5ba2
[catta] / avahi-daemon / main.c
1 /* $Id$ */
2
3 /***
4   This file is part of avahi.
5  
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.
10  
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.
15  
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
19   USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <avahi-core/core.h>
27
28 #include "main.h"
29 #include "simple-protocol.h"
30 #include "static-services.h"
31
32 AvahiServer *avahi_server = NULL;
33
34 static void server_callback(AvahiServer *s, AvahiServerState state, gpointer userdata) {
35     g_assert(s);
36
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) {
41         gchar *n;
42
43         static_service_remove_from_server();
44         
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);
48         g_free(n);
49     }
50 }
51
52 static void help(FILE *f, const gchar *argv0) {
53     fprintf(f,
54             "%s [options]\n"
55             " -h --help        Show this help\n"
56             " -D --daemon      Daemonize after startup\n"
57             " -k --kill        Kill a running daemon\n"
58             " -v --version     Show version\n",
59             argv0);
60 }
61
62 static gint parse_command_line(AvahiServerConfig *config, int argc, char *argv[]) {
63
64     return 0;
65 }
66
67 static gint load_config_file(AvahiServerConfig *config) {
68
69     return 0;
70 }
71
72 int main(int argc, char *argv[]) {
73     GMainLoop *loop = NULL;
74     gint r = 255;
75     AvahiServerConfig config;
76
77     avahi_server_config_init(&config);
78
79     if (load_config_file(&config) < 0)
80         goto finish;
81
82     if (parse_command_line(&config, argc, argv) < 0)
83         goto finish;
84     
85     loop = g_main_loop_new(NULL, FALSE);
86
87     if (simple_protocol_setup(NULL) < 0)
88         goto finish;
89
90 #ifdef ENABLE_DBUS
91     if (dbus_protocol_setup (loop) < 0)
92         goto finish;
93 #endif
94
95     if (!(avahi_server = avahi_server_new(NULL, &config, server_callback, NULL)))
96         goto finish;
97
98     static_service_load();
99
100     g_main_loop_run(loop);
101
102     r = 0;
103     
104 finish:
105
106     static_service_remove_from_server();
107     static_service_free_all();
108     
109     simple_protocol_shutdown();
110
111 #ifdef ENABLE_DBUS
112     dbus_protocol_shutdown();
113 #endif
114
115     if (avahi_server)
116         avahi_server_free(avahi_server);
117     
118     if (loop)
119         g_main_loop_unref(loop);
120
121     avahi_server_config_free(&config);
122
123     return r;
124 }