void avahi_unregister_game(void) { #ifdef HAVE_AVAHI /* Cleanup things */ if (group) { avahi_entry_group_free(group); group = NULL; } if (client) { avahi_client_free(client); client = NULL; } if (glib_poll) { avahi_glib_poll_free(glib_poll); glib_poll = NULL; } if (name) { avahi_free(name); name = NULL; } log_message(MSG_INFO, _("Unregistering Avahi.\n")); #endif // HAVE_AVAHI }
void NetworkServicesProviderAvahi::stopUpdating() { while (m_services) removeServiceInfo(m_services); avahi_string_list_free(m_browsedTypes); m_browsedTypes = 0; // clean all internal fields and counters m_avahiBrowser = 0; m_allForNow = 0; m_resolving = 0; m_services = 0; m_currentService = 0; if (m_avahiClient) { avahi_client_free(m_avahiClient); m_avahiClient = 0; } if (m_glibPoll) { avahi_glib_poll_free(m_glibPoll); m_glibPoll = 0; } }
static void aur_client_finalize (GObject * object) { AurClient *client = (AurClient *) (object); #if HAVE_AVAHI if (client->avahi_sb) avahi_service_browser_free (client->avahi_sb); if (client->avahi_client) avahi_client_free (client->avahi_client); if (client->glib_poll) avahi_glib_poll_free (client->glib_poll); #endif if (client->net_clock) gst_object_unref (client->net_clock); if (client->soup) g_object_unref (client->soup); if (client->json) g_object_unref (client->json); if (client->player) { gst_object_unref (client->player); } if (client->context) g_main_context_unref (client->context); g_free (client->server_host); g_free (client->connected_server); g_free (client->uri); g_free (client->language); free_player_info (client->player_info); G_OBJECT_CLASS (aur_client_parent_class)->finalize (object); }
static void snra_client_finalize (GObject * object) { SnraClient *client = (SnraClient *) (object); if (client->avahi_sb) avahi_service_browser_free (client->avahi_sb); if (client->avahi_client) avahi_client_free (client->avahi_client); if (client->glib_poll) avahi_glib_poll_free (client->glib_poll); if (client->net_clock) gst_object_unref (client->net_clock); if (client->soup) g_object_unref (client->soup); if (client->json) g_object_unref (client->json); if (client->player) { GstBus *bus = gst_element_get_bus (client->player); gst_bus_remove_signal_watch (bus); gst_object_unref (bus); gst_object_unref (client->player); } g_free (client->server_host); g_free (client->connected_server); G_OBJECT_CLASS (snra_client_parent_class)->finalize (object); }
gboolean _mdns_init_session(BonjourDnsSd *data) { AvahiSessionImplData *idata = g_new0(AvahiSessionImplData, 1); const AvahiPoll *poll_api; int error; /* Tell avahi to use g_malloc and g_free */ avahi_set_allocator (avahi_glib_allocator ()); /* This currently depends on the glib mainloop, * we should make it use the libpurple abstraction */ idata->glib_poll = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT); poll_api = avahi_glib_poll_get(idata->glib_poll); idata->client = avahi_client_new(poll_api, 0, NULL, data, &error); if (idata->client == NULL) { purple_debug_error("bonjour", "Error initializing Avahi: %s", avahi_strerror(error)); avahi_glib_poll_free(idata->glib_poll); g_free(idata); return FALSE; } data->mdns_impl_data = idata; return TRUE; }
static void client_callback(AvahiClient * c, AvahiClientState state, AVAHI_GCC_UNUSED void *userdata) { Game *game = (Game *) userdata; g_assert(c != NULL); /* Called whenever the client or server state changes */ switch (state) { case AVAHI_CLIENT_S_RUNNING: /* The server has startup successfully and registered its host * name on the network, so it's time to create our services */ if (!group) create_services(c, game); break; case AVAHI_CLIENT_S_COLLISION: /* Let's drop our registered services. When the server is back * in AVAHI_SERVER_RUNNING state we will register them * again with the new host name. */ if (group) avahi_entry_group_reset(group); break; case AVAHI_CLIENT_FAILURE: log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), "Client failure", avahi_strerror(avahi_client_errno(c))); avahi_glib_poll_free(glib_poll); break; case AVAHI_CLIENT_CONNECTING: case AVAHI_CLIENT_S_REGISTERING: ; } }
static void dmap_mdns_browser_dispose (GObject * object) { DMAPMdnsBrowser *browser = DMAP_MDNS_BROWSER (object); GSList *walk; DMAPMdnsBrowserService *service; for (walk = browser->priv->services; walk; walk = walk->next) { service = (DMAPMdnsBrowserService *) walk->data; free_service (service); } g_slist_free (browser->priv->services); if (browser->priv->resolvers) { g_slist_foreach (browser->priv->resolvers, (GFunc) avahi_service_resolver_free, NULL); g_slist_free (browser->priv->resolvers); } if (browser->priv->service_browser) { avahi_service_browser_free (browser->priv->service_browser); } if (browser->priv->client) { avahi_client_free (browser->priv->client); } if (browser->priv->poll) { avahi_glib_poll_free (browser->priv->poll); } G_OBJECT_CLASS (dmap_mdns_browser_parent_class)->dispose (object); }
Avahi::PresencePublisher::~PresencePublisher () { free_client (); avahi_glib_poll_free (glib_poll); avahi_free (name); }
Avahi::Heap::~Heap () { if (client != NULL) avahi_client_free (client); if (poll != NULL) avahi_glib_poll_free (poll); }
Avahi::Heap::~Heap () { if (resolver != NULL) avahi_service_resolver_free (resolver); if (client != NULL) avahi_client_free (client); if (poll != NULL) avahi_glib_poll_free (poll); }
static void aur_avahi_finalize (GObject * object) { AurAvahi *avahi = (AurAvahi *) (object); if (avahi->priv->group) avahi_entry_group_free (avahi->priv->group); if (avahi->priv->client) avahi_client_free (avahi->priv->client); avahi_glib_poll_free (avahi->priv->glib_poll); }
ControllerDiscoveryMDNS::~ControllerDiscoveryMDNS() { if ( group ) { avahi_s_entry_group_free( group ); } if ( server ) { avahi_server_free( server ); } avahi_glib_poll_free( poll ); }
void _mdns_stop(BonjourDnsSd *data) { AvahiSessionImplData *idata = data->mdns_impl_data; if (idata == NULL || idata->client == NULL) return; if (idata->sb != NULL) avahi_service_browser_free(idata->sb); avahi_client_free(idata->client); avahi_glib_poll_free(idata->glib_poll); g_free(idata); data->mdns_impl_data = NULL; }
static void register_service (void) { int error; const AvahiPoll *poll_api; AvahiGLibPoll *glib_poll; AvahiClient *client = NULL; name = avahi_strdup ("XMMS2 mDNS Agent"); glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); poll_api = avahi_glib_poll_get (glib_poll); client = avahi_client_new (poll_api, 0, client_callback, NULL, &error); if (!client) { printf ("Failed to create Avahi client: %s\n", avahi_strerror (error)); avahi_client_free (client); avahi_glib_poll_free (glib_poll); } }
void NetworkServicesProviderAvahi::startUpdating() { const AvahiPoll* pollApi; int error; if (m_avahiClient) return; m_glibPoll = avahi_glib_poll_new(0, G_PRIORITY_DEFAULT); pollApi = avahi_glib_poll_get(m_glibPoll); /* Create a new AvahiClient instance */ m_avahiClient = avahi_client_new(pollApi, (AvahiClientFlags)0, avahiClientCallback, static_cast<void*>(this), &error); /* Check the error return code */ if (!m_avahiClient) { /* Print out the error string */ g_warning("Error initializing Avahi: %s", avahi_strerror(error)); avahi_glib_poll_free(m_glibPoll); notifyDiscoveryFinished(); } }
gboolean daap_mdns_setup () { const AvahiPoll *av_poll; GMainLoop *ml = NULL; gint errval; struct timeval tv; browse_callback_userdata_t *browse_userdata; if (gl_poll) { goto fail; } browse_userdata = g_new0 (browse_callback_userdata_t, 1); avahi_set_allocator (avahi_glib_allocator ()); ml = g_main_loop_new (NULL, FALSE); gl_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); av_poll = avahi_glib_poll_get (gl_poll); avahi_elapse_time (&tv, 2000, 0); av_poll->timeout_new (av_poll, &tv, daap_mdns_timeout, NULL); client = avahi_client_new (av_poll, 0, daap_mdns_client_cb, ml, &errval); if (!client) { goto fail; } browse_userdata->client = client; browse_userdata->mainloop = ml; browser = avahi_service_browser_new (client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_daap._tcp", NULL, 0, daap_mdns_browse_cb, browse_userdata); if (!browser) { goto fail; } return TRUE; fail: if (ml) g_main_loop_unref (ml); if (client) avahi_client_free (client); client = NULL; browser = NULL; g_free (browse_userdata); if (gl_poll) avahi_glib_poll_free (gl_poll); gl_poll = NULL; return FALSE; }
int main (AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) { GMainLoop *loop = NULL; const AvahiPoll *poll_api; AvahiGLibPoll *glib_poll; AvahiClient *client; struct timeval tv; const char *version; int error; /* Optional: Tell avahi to use g_malloc and g_free */ avahi_set_allocator (avahi_glib_allocator ()); /* Create the GLIB main loop */ loop = g_main_loop_new (NULL, FALSE); /* Create the GLIB Adaptor */ glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); poll_api = avahi_glib_poll_get (glib_poll); /* Example, schedule a timeout event with the Avahi API */ avahi_elapse_time (&tv, /* timeval structure */ 1000, /* 1 second */ 0); /* "jitter" - Random additional delay from 0 to this value */ poll_api->timeout_new (poll_api, /* The AvahiPoll object */ &tv, /* struct timeval indicating when to go activate */ avahi_timeout_event, /* Pointer to function to call */ NULL); /* User data to pass to function */ /* Schedule a timeout event with the glib api */ g_timeout_add (5000, /* 5 seconds */ avahi_timeout_event_glib, /* Pointer to function callback */ loop); /* User data to pass to function */ /* Create a new AvahiClient instance */ client = avahi_client_new (poll_api, /* AvahiPoll object from above */ 0, avahi_client_callback, /* Callback function for Client state changes */ loop, /* User data */ &error); /* Error return */ /* Check the error return code */ if (client == NULL) { /* Print out the error string */ g_warning ("Error initializing Avahi: %s", avahi_strerror (error)); goto fail; } /* Make a call to get the version string from the daemon */ version = avahi_client_get_version_string (client); /* Check if the call suceeded */ if (version == NULL) { g_warning ("Error getting version string: %s", avahi_strerror (avahi_client_errno (client))); goto fail; } g_message ("Avahi Server Version: %s", version); /* Start the GLIB Main Loop */ g_main_loop_run (loop); fail: /* Clean up */ g_main_loop_unref (loop); avahi_client_free (client); avahi_glib_poll_free (glib_poll); return 0; }
static void create_services(AvahiClient * c, Game * game) { gchar *hostname; gchar *servicename; AvahiStringList *sl; int ret; g_assert(c != NULL); /* If this is the first time we're called, let's create a new entry group */ if (!group) { if (! (group = avahi_entry_group_new(c, entry_group_callback, NULL))) { log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), "avahi_entry_group_new() failed", avahi_strerror(avahi_client_errno(c))); avahi_glib_poll_free(glib_poll); return; } } sl = avahi_string_list_new(NULL, NULL); sl = avahi_string_list_add_printf(sl, "version=%s", PROTOCOL_VERSION); sl = avahi_string_list_add_printf(sl, "title=%s", game->params->title); /* Add the service for IPP */ hostname = game->hostname ? g_strdup(game->hostname) : get_my_hostname(); servicename = g_strdup_printf("%s [%s]", hostname, game->server_port); g_free(hostname); ret = avahi_entry_group_add_service_strlst(group, AVAHI_IF_UNSPEC, AVAHI_NETWORK_PROTOCOL, 0, servicename, AVAHI_ANNOUNCE_NAME, NULL, NULL, atoi(game->server_port), sl); g_free(servicename); if (ret < 0) { gchar *msg = g_strdup_printf("Failed to add '%s' service", AVAHI_ANNOUNCE_NAME); log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), msg, avahi_strerror(ret)); g_free(msg); avahi_string_list_free(sl); avahi_glib_poll_free(glib_poll); return; } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), "Failed to commit entry_group", avahi_strerror(ret)); avahi_string_list_free(sl); avahi_glib_poll_free(glib_poll); return; } avahi_string_list_free(sl); return; }