Пример #1
0
/** Fill the cache with initial (current) data, setup listeners. */
void
cli_cache_start (cli_infos_t *infos)
{
	xmmsc_result_t *res;

	/* Setup async listeners */
	res = xmmsc_broadcast_playlist_current_pos (infos->conn);
	xmmsc_result_notifier_set (res, &refresh_currpos, infos->cache);
	xmmsc_result_unref (res);

	res = xmmsc_broadcast_playback_current_id (infos->conn);
	xmmsc_result_notifier_set (res, &refresh_currid, infos->cache);
	xmmsc_result_unref (res);

	res = xmmsc_broadcast_playback_status (infos->conn);
	xmmsc_result_notifier_set (res, &refresh_playback_status, infos->cache);
	xmmsc_result_unref (res);

	res = xmmsc_broadcast_playlist_changed (infos->conn);
	xmmsc_result_notifier_set (res, &update_active_playlist, infos);
	xmmsc_result_unref (res);

	res = xmmsc_broadcast_playlist_loaded (infos->conn);
	xmmsc_result_notifier_set (res, &reload_active_playlist, infos);
	xmmsc_result_unref (res);

	res = xmmsc_broadcast_collection_changed (infos->conn);
	xmmsc_result_notifier_set (res, &update_active_playlist_name, infos);
	xmmsc_result_unref (res);

	/* Setup one-time value fetchers, for init */
	cli_cache_refresh (infos);
}
Пример #2
0
/** Fill the cache with initial (current) data, setup listeners. */
void
cli_cache_start (cli_cache_t *cache, xmmsc_connection_t *conn)
{
    xmmsc_result_t *res;

    g_return_if_fail (cache->conn == NULL);

    cache->conn = xmmsc_ref (conn);

    /* Setup async listeners */
    res = xmmsc_broadcast_playlist_current_pos (conn);
    xmmsc_result_notifier_set (res, &refresh_currpos, cache);
    xmmsc_result_unref (res);

    res = xmmsc_broadcast_playback_current_id (conn);
    xmmsc_result_notifier_set (res, &refresh_currid, cache);
    xmmsc_result_unref (res);

    res = xmmsc_broadcast_playback_status (conn);
    xmmsc_result_notifier_set (res, &refresh_playback_status, cache);
    xmmsc_result_unref (res);

    res = xmmsc_broadcast_playlist_changed (conn);
    xmmsc_result_notifier_set (res, &update_active_playlist, cache);
    xmmsc_result_unref (res);

    res = xmmsc_broadcast_playlist_loaded (conn);
    xmmsc_result_notifier_set (res, &reload_active_playlist, cache);
    xmmsc_result_unref (res);

    res = xmmsc_broadcast_collection_changed (conn);
    xmmsc_result_notifier_set (res, &update_active_playlist_name, cache);
    xmmsc_result_unref (res);

    /* Setup one-time value fetchers, for init */
    cli_cache_refresh (cache);
}
Пример #3
0
int
main (int argc, char **argv)
{
	/*
	 * A struct that will hold the user data passed
	 * to the result method. In this case we need the
	 * GMainLoop and a counter in the result method.
	 */
	udata_t udata;

	/*
	 * The first part of this program is
	 * commented on in tut1.c
	 */
	xmmsc_connection_t *connection;
	xmmsc_result_t *result;

	/*
	 * In an async client we still connect as
	 * normal. Read up on this in earlier
	 * tutorials if you need.
	 */
	connection = xmmsc_init ("tutorial6");
	if (!connection) {
		fprintf (stderr, "OOM!\n");
		exit (EXIT_FAILURE);
	}

	if (!xmmsc_connect (connection, getenv ("XMMS_PATH"))) {
		fprintf (stderr, "Connection failed: %s\n",
		         xmmsc_get_last_error (connection));

		exit (EXIT_FAILURE);
	}

	/*
	 * Initialize the mainloop, for more information about GLib mainloop
	 * see the GTK docs.
	 */
	udata.ml = g_main_loop_new (NULL, FALSE);

	/*
	 * Initialize the counter to 0.
	 */
	udata.counter = 0;

	/*
	 * The big difference between a sync client and an async client is that the
	 * async client works with callbacks. When you send a command and get an
	 * xmmsc_result_t back you should set up a callback for it and directly
	 * unref it. This means we can't do syncronous operations on this connection.
	 *
	 * In simple cases you can use the XMMS_CALLBACK_SET macro, but in order to
	 * be verbose here I do it all manually. Let's ask for the current id
	 * in an async way instead of the sync way as we did in tut2.
	 */

	result = xmmsc_broadcast_playback_current_id (connection);
	xmmsc_result_notifier_set (result, my_current_id, &udata);
	xmmsc_result_unref (result);

	/*
	 * As you see we do it pretty much the same way that we did in tut2, but
	 * instead of being able to access the current id directly (as we would
	 * have if we where blocking) we need to wait until xmms calls our
	 * my_current_id function. This will keep your GUI from hanging while
	 * waiting for xmms2 to answer your command.
	 *
	 * In order to make xmmsclient call your callback functions we need to put
	 * the fd of the connection into the mainloop of our program. For your
	 * convenience the xmmsclient lib ships with automatic integration with
	 * GMainLoop. We just need to link with xmmsclient-glib and do the following
	 * call to make it work.
	 */
	xmmsc_mainloop_gmain_init (connection);

	/*
	 * We are now all set to go. Just run the main loop and watch the magic.
	 */

	g_main_loop_run (udata.ml);

	return EXIT_SUCCESS;

}