示例#1
0
void
Avahi::Heap::load ()
{
  const AvahiPoll *poll_api = NULL;
  int error;

  /* let's make sure those are sanely initialized */
  poll = NULL;
  client = NULL;
  resolver = NULL;

  avahi_set_allocator (avahi_glib_allocator ());
  poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
  poll_api = avahi_glib_poll_get (poll);

  /* this may not be the final valid client pointer according to
   * avahi's documentation... we'll take what our callback gets
   */
  client = avahi_client_new (poll_api, (AvahiClientFlags)AVAHI_CLIENT_NO_FAIL,
			     avahi_client_callback, this,
			     &error);
#if DEBUG
  if (client == NULL)
    std::cout << __PRETTY_FUNCTION__ << " client is NULL!" << std::endl;
#endif
}
ControllerDiscoveryMDNS::ControllerDiscoveryMDNS( TPContext * context, const String & n, int _port , int _http_port )
    :
    poll( NULL ),
    server( NULL ),
    group( NULL ),
    name( n ),
    ready( false ),
    port( _port ),
    http_port( _http_port )
{
    avahi_set_allocator( avahi_glib_allocator() );

    poll = avahi_glib_poll_new( NULL, TRICKPLAY_PRIORITY );
    g_assert( poll );

    AvahiServerConfig config;
    avahi_server_config_init( &config );

    config.publish_workstation = 0;

    int error;

    server = avahi_server_new( avahi_glib_poll_get( poll ), &config, avahi_server_callback, this, &error );

    if ( !server )
    {
        g_warning( "FAILED TO CREATE AVAHI SERVER : %s", avahi_strerror( error ) );
    }
}
static void
avahi_client_init (DMAPMdnsBrowser * browser)
{
	gint error = 0;

	avahi_set_allocator (avahi_glib_allocator ());

	browser->priv->poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);

	if (!browser->priv->poll) {
		g_debug ("Unable to create AvahiGlibPoll object for mDNS");
	}
#ifdef HAVE_AVAHI_0_5
	browser->priv->client =
		avahi_client_new (avahi_glib_poll_get (browser->priv->poll),
				  (AvahiClientCallback) client_cb, browser,
				  &error);
#endif
#ifdef HAVE_AVAHI_0_6
	{
		AvahiClientFlags flags = 0;

		browser->priv->client =
			avahi_client_new (avahi_glib_poll_get
					  (browser->priv->poll), flags,
					  (AvahiClientCallback) client_cb,
					  browser, &error);
	}
#endif
}
示例#4
0
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;
}
示例#5
0
int
main (int argc, char *argv[])
{
  SnraClient *client = NULL;
  int ret = 1;
  const gchar *server = NULL;

  gst_init (&argc, &argv);

  if (argc > 1) {
    /* Connect directly to the requested server, no avahi */
    server = argv[1];
  }

  avahi_set_allocator (avahi_glib_allocator ());

  g_timeout_add (250, sigint_check, NULL);
  sigint_setup ();

  client = snra_client_new (server);
  if (client == NULL)
    goto fail;

  ml = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (ml);

  ret = 0;
fail:
  if (client)
    g_object_unref (client);
  if (ml)
    g_main_loop_unref (ml);
  return ret;
}
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;
}
示例#7
0
文件: shell.c 项目: GNOME/libepc
static void
epc_shell_init (void)
{
  if (G_UNLIKELY (NULL == epc_shell_avahi_poll))
    {
      gnutls_global_init ();
      avahi_set_allocator (avahi_glib_allocator ());
      /* deprecated: g_atexit (epc_shell_exit); */

      epc_shell_avahi_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
      g_assert (NULL != epc_shell_avahi_poll);

      /* TODO?
      bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
      bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
      */
    }
}
示例#8
0
static void
aur_avahi_class_init (AurAvahiClass * klass)
{
  GObjectClass *gobject_class = (GObjectClass *) (klass);

  gobject_class->constructed = aur_avahi_constructed;
  gobject_class->finalize = aur_avahi_finalize;
  gobject_class->set_property = aur_avahi_set_property;
  gobject_class->get_property = aur_avahi_get_property;

  g_type_class_add_private (gobject_class, sizeof (AurAvahiPrivate));

  g_object_class_install_property (gobject_class, PROP_PORT,
    g_param_spec_int ("aur-port", "Aurena port",
                         "port for Aurena service",
                         1, 65535, 5457,
                         G_PARAM_READWRITE|G_PARAM_CONSTRUCT));

  avahi_set_allocator (avahi_glib_allocator ());
}
示例#9
0
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;
}
示例#10
0
文件: avahi.c 项目: cjd/lyricue
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;
}
示例#11
0
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;
}
示例#12
0
int
main (int argc, char **argv)
{
	xmmsc_connection_t *conn;
	gchar *path;
	gchar *gp = NULL;
	gchar **s;
	gchar **ipcsplit;
	int i;

	printf ("Starting XMMS2 mDNS Agent...\n");

	path = getenv ("XMMS_PATH_FULL");
	if (!path) {
		printf ("Sorry you need XMMS_PATH_FULL set\n");
		exit (1);
	}

	ipcsplit = g_strsplit (path, ";", 0);
	for (i = 0; ipcsplit[i]; i++) {
		if (g_ascii_strncasecmp (ipcsplit[i], "tcp://", 6) == 0) {
			gp = ipcsplit[i];
		}
	}

	if (!gp) {
		printf ("Need to have a socket listening to TCP before we can do that!\n");
		exit (1);
	}

	s = g_strsplit (gp, ":", 0);
	if (s && s[2]) {
		port = strtol (s[2], NULL, 10);
	} else {
		port = XMMS_DEFAULT_TCP_PORT;
	}

	conn = xmmsc_init ("xmms2-mdns");

	if (!conn) {
		printf ("Could not init xmmsc_connection!\n");
		exit (1);
	}

	if (!xmmsc_connect (conn, gp)) {
		printf ("Could not connect to xmms2d: %s\n", xmmsc_get_last_error (conn));
		exit (1);
	}

	avahi_set_allocator (avahi_glib_allocator ());

	ml = g_main_loop_new (NULL, FALSE);

	XMMS_CALLBACK_SET (conn, xmmsc_broadcast_quit, handle_quit, ml);
	xmmsc_disconnect_callback_set (conn, disconnected, NULL);

	register_service ();

	xmmsc_mainloop_gmain_init (conn);

	g_main_loop_run (ml);

	xmmsc_unref (conn);
	printf ("XMMS2-mDNS shutting down...\n");

	g_main_loop_unref (ml);

	avahi_free (name);

	return 0;
}
示例#13
0
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;
}
示例#14
0
int
main (int argc, char *argv[])
{
  SnraClient *client = NULL;
  int ret = 1;
  const gchar *server = NULL;
  GOptionContext *ctx;
  GError *error = NULL;
  GtkWidget *window, *eventbox, *button;

  ctx = g_option_context_new ("Aurena fullscreen client");

  g_option_context_add_group (ctx, gtk_get_option_group(TRUE));
  g_option_context_add_group (ctx, gst_init_get_option_group());
  if (!g_option_context_parse (ctx, &argc, &argv, &error)) {
    g_print ("Arguments error: %s", error->message);
    return 1;
  }
  g_option_context_free (ctx);

  if (argc > 1) {
    /* Connect directly to the requested server, no avahi */
    server = argv[1];
  }

  avahi_set_allocator (avahi_glib_allocator ());

  client = snra_client_new (server, SNRA_CLIENT_PLAYER);
  if (client == NULL)
    goto fail;

  g_object_set (gtk_settings_get_default (),
      "gtk-application-prefer-dark-theme", TRUE, NULL);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_double_buffered (window, FALSE);
  gtk_widget_set_redraw_on_allocate (window, FALSE);
  gtk_widget_set_app_paintable (window, TRUE);

  g_signal_connect_after (window, "delete-event", G_CALLBACK (quit_clicked),
      NULL);

  eventbox = gtk_event_box_new ();
  g_object_set (eventbox,
      "halign", GTK_ALIGN_END,
      "valign", GTK_ALIGN_START,
      "expand", FALSE,
      NULL);
  gtk_widget_set_double_buffered (eventbox, TRUE);
  gtk_widget_set_redraw_on_allocate (eventbox, TRUE);
  gtk_widget_set_app_paintable (eventbox, FALSE);
    gtk_container_add (GTK_CONTAINER (window), eventbox);

  button = gtk_button_new_from_stock (GTK_STOCK_QUIT);
  gtk_container_add (GTK_CONTAINER (eventbox), button);
  g_signal_connect (button, "clicked", G_CALLBACK (quit_clicked), NULL);

  gtk_window_fullscreen (GTK_WINDOW (window));
  gtk_widget_show_all (window);

  g_signal_connect (client, "player-created", G_CALLBACK(player_created),
		   window);


  gtk_widget_realize (button);
  gdk_window_ensure_native (gtk_widget_get_window (eventbox));

  ml = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (ml);

  ret = 0;
fail:
  if (client)
    g_object_unref (client);
  if (ml)
    g_main_loop_unref (ml);
  return ret;
}