AvahiClient * rb_daap_mdns_avahi_get_client (void) { if (g_once_init_enter (&client_init)) { AvahiClientFlags flags = 0; AvahiGLibPoll *apoll; int error = 0; avahi_set_allocator (avahi_glib_allocator ()); apoll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); if (apoll == NULL) { g_warning ("Unable to create AvahiGlibPoll object for mDNS"); } client = avahi_client_new (avahi_glib_poll_get (apoll), flags, (AvahiClientCallback) client_cb, NULL, &error); if (error != 0) { g_warning ("Unable to initialize mDNS: %s", avahi_strerror (error)); } g_once_init_leave (&client_init, 1); } return client; }
static void search_for_server (SnraClient * client) { const AvahiPoll *poll_api; int error; if (client->glib_poll == NULL) { client->glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); if (client->glib_poll == NULL) return; } poll_api = avahi_glib_poll_get (client->glib_poll); if (client->avahi_client == NULL) { client->avahi_client = avahi_client_new (poll_api, AVAHI_CLIENT_NO_FAIL, (AvahiClientCallback) snra_avahi_client_callback, client, &error); if (client->avahi_client == NULL) { fprintf (stderr, "Failed to connect to Avahi: %s", avahi_strerror (error)); return; } } }
void avahi_register_game(Game * game) { #ifdef HAVE_AVAHI const AvahiPoll *poll_api; int error; glib_poll = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT); poll_api = avahi_glib_poll_get(glib_poll); /* Allocate main loop object */ if (!poll_api) { log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), _("Unable to register Avahi server"), "Failed to create glib poll object"); avahi_unregister_game(); return; } name = avahi_strdup(game->params->title); /* Allocate a new client */ client = avahi_client_new(poll_api, 0, client_callback, game, &error); /* Check whether creating the client object succeeded */ if (!client) { log_message(MSG_ERROR, _("Avahi error: %s, %s\n"), _("Unable to register Avahi server"), avahi_strerror(error)); avahi_unregister_game(); } #endif // HAVE_AVAHI }
static AvahiClient* epc_shell_get_avahi_client (GError **error) { g_return_val_if_fail (NULL != epc_shell_avahi_client || NULL != error, NULL); if (G_UNLIKELY (NULL == epc_shell_avahi_client)) { gint error_code = AVAHI_OK; epc_shell_init (); epc_shell_avahi_client = avahi_client_new (avahi_glib_poll_get (epc_shell_avahi_poll), AVAHI_CLIENT_NO_FAIL, epc_shell_avahi_client_cb, NULL, &error_code); if (NULL == epc_shell_avahi_client) g_set_error (error, EPC_AVAHI_ERROR, error_code, _("Cannot create Avahi client: %s"), avahi_strerror (error_code)); } return epc_shell_avahi_client; }
void Avahi::PresencePublisher::create_client () { free_client (); // don't get the client there : wait what we'll get from the callback avahi_client_new (avahi_glib_poll_get (glib_poll), AVAHI_CLIENT_NO_FAIL, (AvahiClientCallback)client_cb, this, NULL); }
static void aur_avahi_init (AurAvahi * avahi) { AurAvahiPrivate *priv = avahi->priv = G_TYPE_INSTANCE_GET_PRIVATE (avahi, AUR_TYPE_AVAHI, AurAvahiPrivate); priv->service_name = g_strdup ("Aurena media server"); priv->glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); priv->poll_api = avahi_glib_poll_get (priv->glib_poll); priv->port = 5457; }
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); } }
static AvahiClient * get_global_avahi_client (GError **error) { static AvahiGLibPoll *glib_poll = NULL; int avahi_error; if (!avahi_initialized) { avahi_initialized = TRUE; if (glib_poll == NULL) { avahi_set_allocator (avahi_glib_allocator ()); glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); } /* Create a new AvahiClient instance */ global_client = avahi_client_new (avahi_glib_poll_get (glib_poll), AVAHI_CLIENT_NO_FAIL, avahi_client_callback, glib_poll, &avahi_error); if (global_client == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Error initializing Avahi: %s"), avahi_strerror (avahi_error)); goto out; } } out: return global_client; }
int publish_avahi(int port_passed, char *type_in_passed) { int error; AvahiGLibPoll *glib_poll; port = port_passed; type_in = strndup(type_in_passed,32); avahi_set_allocator (avahi_glib_allocator ()); /* Create the GLIB Adaptor */ glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); name = avahi_strdup("Lyricue Display"); /* Allocate a new client */ client = avahi_client_new(avahi_glib_poll_get(glib_poll), 0, client_callback, NULL, &error); /* Check if creating the client object succeeded */ if (!client) { l_debug("Failed to create client: %s", avahi_strerror(error)); unpublish_avahi(); } /* Create the service browser */ if (miniviews==NULL) { miniviews = g_hash_table_new(g_str_hash, g_str_equal); } if (sb == NULL) { if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_INET, "_lyricue._tcp", NULL, 0, browse_callback, client))) { l_debug("Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); } } return 0; }
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; }