X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-discover-standalone%2Fmain.c;h=156b76d2125c3194c5cdebc2f2686e2651df6e74;hb=8b5cd6ffd9137b14b7ed678f10a551e3911e4a40;hp=daecdaa4908516fda806b302762fd685b5c9d55f;hpb=3bf52c1e00fd8cf4850329adb4f76c3c2649df79;p=catta diff --git a/avahi-discover-standalone/main.c b/avahi-discover-standalone/main.c index daecdaa..156b76d 100644 --- a/avahi-discover-standalone/main.c +++ b/avahi-discover-standalone/main.c @@ -29,7 +29,9 @@ #include #include #include -#include +#include +#include +#include struct ServiceType; @@ -46,7 +48,7 @@ struct Service { struct ServiceType { gchar *service_type; - AvahiServiceBrowser *browser; + AvahiSServiceBrowser *browser; GList *services; GtkTreeRowReference *tree_ref; @@ -57,9 +59,9 @@ static GtkTreeView *tree_view = NULL; static GtkTreeStore *tree_store = NULL; static GtkLabel *info_label = NULL; static AvahiServer *server = NULL; -static AvahiServiceTypeBrowser *service_type_browser = NULL; +static AvahiSServiceTypeBrowser *service_type_browser = NULL; static GHashTable *service_type_hash_table = NULL; -static AvahiServiceResolver *service_resolver = NULL; +static AvahiSServiceResolver *service_resolver = NULL; static struct Service *current_service = NULL; static struct Service *get_service(const gchar *service_type, const gchar *service_name, const gchar*domain_name, AvahiIfIndex interface, AvahiProtocol protocol) { @@ -90,7 +92,7 @@ static void free_service(struct Service *s) { current_service = NULL; if (service_resolver) { - avahi_service_resolver_free(service_resolver); + avahi_s_service_resolver_free(service_resolver); service_resolver = NULL; } @@ -112,7 +114,7 @@ static void free_service(struct Service *s) { g_free(s); } -static void service_browser_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_name, const gchar *service_type, const gchar *domain_name, gpointer userdata) { +static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_name, const gchar *service_type, const gchar *domain_name, gpointer userdata) { if (event == AVAHI_BROWSER_NEW) { struct Service *s; @@ -154,7 +156,7 @@ static void service_browser_callback(AvahiServiceBrowser *b, AvahiIfIndex interf } } -static void service_type_browser_callback(AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) { +static void service_type_browser_callback(AvahiSServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) { struct ServiceType *st; GtkTreePath *path; GtkTreeIter iter; @@ -178,7 +180,7 @@ static void service_type_browser_callback(AvahiServiceTypeBrowser *b, AvahiIfInd g_hash_table_insert(service_type_hash_table, st->service_type, st); - st->browser = avahi_service_browser_new(server, -1, AF_UNSPEC, st->service_type, domain, service_browser_callback, NULL); + st->browser = avahi_s_service_browser_new(server, -1, AF_UNSPEC, st->service_type, domain, service_browser_callback, NULL); } static void update_label(struct Service *s, const gchar *hostname, const AvahiAddress *a, guint16 port, AvahiStringList *txt) { @@ -228,13 +230,13 @@ static struct Service *get_service_on_cursor(void) { } -static void service_resolver_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *host_name, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) { +static void service_resolver_callback(AvahiSServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *host_name, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) { struct Service *s; g_assert(r); if (!(s = get_service_on_cursor()) || userdata != s) { g_assert(r == service_resolver); - avahi_service_resolver_free(service_resolver); + avahi_s_service_resolver_free(service_resolver); service_resolver = NULL; } @@ -251,11 +253,11 @@ static void tree_view_on_cursor_changed(GtkTreeView *tv, gpointer userdata) { return; if (service_resolver) - avahi_service_resolver_free(service_resolver); + avahi_s_service_resolver_free(service_resolver); update_label(s, NULL, NULL, 0, NULL); - service_resolver = avahi_service_resolver_new(server, s->interface, s->protocol, s->service_name, s->service_type->service_type, s->domain_name, AF_UNSPEC, service_resolver_callback, s); + service_resolver = avahi_s_service_resolver_new(server, s->interface, s->protocol, s->service_name, s->service_type->service_type, s->domain_name, AF_UNSPEC, service_resolver_callback, s); } static gboolean main_window_on_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { @@ -267,10 +269,16 @@ int main(int argc, char *argv[]) { GladeXML *xml; AvahiServerConfig config; GtkTreeViewColumn *c; + gint error; + AvahiGLibPoll *poll_api; gtk_init(&argc, &argv); glade_init(); + avahi_set_allocator(avahi_glib_allocator()); + + poll_api = avahi_glib_poll_new(NULL); + xml = glade_xml_new(AVAHI_INTERFACES_DIR"avahi-discover.glade", NULL, NULL); main_window = glade_xml_get_widget(xml, "main_window"); g_signal_connect(main_window, "delete-event", (GCallback) main_window_on_delete_event, NULL); @@ -293,14 +301,17 @@ int main(int argc, char *argv[]) { avahi_server_config_init(&config); config.publish_hinfo = config.publish_addresses = config.publish_domain = config.publish_workstation = FALSE; - server = avahi_server_new(NULL, &config, NULL, NULL); + server = avahi_server_new(avahi_glib_poll_get(poll_api), &config, NULL, NULL, &error); avahi_server_config_free(&config); - service_type_browser = avahi_service_type_browser_new(server, -1, AF_UNSPEC, argc >= 2 ? argv[1] : NULL, service_type_browser_callback, NULL); + g_assert(server); + + service_type_browser = avahi_s_service_type_browser_new(server, -1, AF_UNSPEC, argc >= 2 ? argv[1] : NULL, service_type_browser_callback, NULL); gtk_main(); avahi_server_free(server); + avahi_glib_poll_free(poll_api); return 0; }