From 630a3e58e8fbed70d2e5aa7a3cf07067954b3cd3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 22 May 2005 14:40:39 +0000 Subject: [PATCH] * add service type browser git-svn-id: file:///home/lennart/svn/public/avahi/trunk@85 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/Makefile.am | 3 ++- avahi-core/avahi-test.c | 17 +++++++++++++---- avahi-core/core.h | 8 +++++++- avahi-core/server.c | 3 +++ avahi-core/server.h | 1 + 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/avahi-core/Makefile.am b/avahi-core/Makefile.am index 95eeea7..39d7844 100644 --- a/avahi-core/Makefile.am +++ b/avahi-core/Makefile.am @@ -60,7 +60,8 @@ libavahi_core_la_SOURCES = \ alternative.c alternative.h \ resolve-host-name.c \ resolve-address.c \ - browse-domain.c + browse-domain.c \ + browse-service-type.c prioq_test_SOURCES = \ prioq-test.c \ diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c index 45a37f2..5603481 100644 --- a/avahi-core/avahi-test.c +++ b/avahi-core/avahi-test.c @@ -144,6 +144,11 @@ static void db_callback(AvahiDomainBrowser *b, gint iface, guchar protocol, Avah g_message("DB: (%i.%i) %s [%s]", iface, protocol, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove"); } +static void stb_callback(AvahiServiceTypeBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) { + + g_message("STB: (%i.%i) %s in %s [%s]", iface, protocol, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove"); +} + int main(int argc, char *argv[]) { GMainLoop *loop = NULL; AvahiRecordBrowser *r; @@ -153,6 +158,7 @@ int main(int argc, char *argv[]) { AvahiServerConfig config; AvahiAddress a; AvahiDomainBrowser *db; + AvahiServiceTypeBrowser *stb; avahi_server_config_init(&config); /* config.host_name = g_strdup("test"); */ @@ -160,14 +166,16 @@ int main(int argc, char *argv[]) { avahi_server_config_free(&config); k = avahi_key_new("_http._tcp.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR); - r = avahi_record_browser_new(server, 0, AF_UNSPEC, k, record_browser_callback, NULL); + r = avahi_record_browser_new(server, -1, AF_UNSPEC, k, record_browser_callback, NULL); avahi_key_unref(k); - hnr = avahi_host_name_resolver_new(server, 0, AF_UNSPEC, "codes-CompUTER.local", AF_UNSPEC, hnr_callback, NULL); + hnr = avahi_host_name_resolver_new(server, -1, AF_UNSPEC, "codes-CompUTER.local", AF_UNSPEC, hnr_callback, NULL); + + ar = avahi_address_resolver_new(server, -1, AF_UNSPEC, avahi_address_parse("192.168.50.15", AF_INET, &a), ar_callback, NULL); - ar = avahi_address_resolver_new(server, 0, AF_UNSPEC, avahi_address_parse("192.168.50.15", AF_INET, &a), ar_callback, NULL); + db = avahi_domain_browser_new(server, -1, AF_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, db_callback, NULL); - db = avahi_domain_browser_new(server, 0, AF_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, db_callback, NULL); + stb = avahi_service_type_browser_new(server, -1, AF_UNSPEC, NULL, stb_callback, NULL); loop = g_main_loop_new(NULL, FALSE); @@ -180,6 +188,7 @@ int main(int argc, char *argv[]) { avahi_record_browser_free(r); avahi_host_name_resolver_free(hnr); avahi_address_resolver_free(ar); + avahi_service_type_browser_free(stb); if (group) avahi_entry_group_free(group); diff --git a/avahi-core/core.h b/avahi-core/core.h index 4f981e0..2c3dafd 100644 --- a/avahi-core/core.h +++ b/avahi-core/core.h @@ -244,8 +244,14 @@ typedef void (*AvahiDomainBrowserCallback)(AvahiDomainBrowser *b, gint interface AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiDomainBrowserType type, AvahiDomainBrowserCallback callback, gpointer userdata); void avahi_domain_browser_free(AvahiDomainBrowser *b); -/* not yet implemented */ typedef struct AvahiServiceTypeBrowser AvahiServiceTypeBrowser; +typedef void (*AvahiServiceTypeBrowserCallback)(AvahiServiceTypeBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *type, const gchar *domain, gpointer userdata); +AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata); +void avahi_service_type_browser_free(AvahiServiceTypeBrowser *b); + + +/* Not yet implemented */ + typedef struct AvahiServiceBrowser AvahiServiceBrowser; typedef struct AvahiServiceResolver AvahiServiceResolver; diff --git a/avahi-core/server.c b/avahi-core/server.c index b00e4ee..83bec15 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -965,6 +965,7 @@ AvahiServer *avahi_server_new(GMainContext *c, const AvahiServerConfig *sc, Avah AVAHI_LLIST_HEAD_INIT(AvahiHostNameResolver, s->host_name_resolvers); AVAHI_LLIST_HEAD_INIT(AvahiAddressResolver, s->address_resolvers); AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, s->domain_browsers); + AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, s->service_type_browsers); /* Get host name */ s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name(); @@ -1009,6 +1010,8 @@ void avahi_server_free(AvahiServer* s) { avahi_address_resolver_free(s->address_resolvers); while (s->domain_browsers) avahi_domain_browser_free(s->domain_browsers); + while (s->service_type_browsers) + avahi_service_type_browser_free(s->service_type_browsers); while (s->record_browsers) avahi_record_browser_destroy(s->record_browsers); g_hash_table_destroy(s->record_browser_hashtable); diff --git a/avahi-core/server.h b/avahi-core/server.h index 4726174..60737ce 100644 --- a/avahi-core/server.h +++ b/avahi-core/server.h @@ -80,6 +80,7 @@ struct AvahiServer { AVAHI_LLIST_HEAD(AvahiHostNameResolver, host_name_resolvers); AVAHI_LLIST_HEAD(AvahiAddressResolver, address_resolvers); AVAHI_LLIST_HEAD(AvahiDomainBrowser, domain_browsers); + AVAHI_LLIST_HEAD(AvahiServiceTypeBrowser, service_type_browsers); gboolean need_entry_cleanup, need_group_cleanup, need_browser_cleanup; -- 2.7.4