Example #1
0
void *
xmmsc_mainloop_gmain_init (xmmsc_connection_t *c)
{
	xmmsc_glib_watch_t *watch;
	gint fd;

	g_return_val_if_fail (c, NULL);
	fd = xmmsc_io_fd_get (c);

	watch = g_new0 (xmmsc_glib_watch_t, 1);
	watch->conn = xmmsc_ref (c);
	watch->iochan = g_io_channel_unix_new (fd);

	xmmsc_io_need_out_callback_set (c, xmmsc_mainloop_need_out_cb, watch);
	watch->source_id = g_io_add_watch (watch->iochan,
	                                   G_IO_IN | G_IO_ERR | G_IO_HUP,
	                                   xmmsc_glib_read_cb,
	                                   watch);
	g_io_channel_unref (watch->iochan);

	if (xmmsc_io_want_out (c)) {
		xmmsc_mainloop_need_out_cb (TRUE, watch);
	}

	return watch;
}
Example #2
0
xmmsc_connection_t *
xmmsc_init (const char *clientname)
{
	xmmsc_connection_t *c;
	int i = 0;
	char j;

	x_api_error_if (!clientname, "with NULL clientname", NULL);

	if (!(c = x_new0 (xmmsc_connection_t, 1))) {
		return NULL;
	}

	while (clientname[i]) {
		j = clientname[i];
		if (!isalnum (j) && j != '_' && j != '-') {
			/* snyggt! */
			free (c);
			x_api_error_if (true, "clientname contains invalid chars, just alphanumeric chars are allowed!", NULL);
		}
		i++;
	}

	if (!(c->clientname = strdup (clientname))) {
		free (c);
		return NULL;
	}

	c->visc = 0;
	c->visv = NULL;
	return xmmsc_ref (c);
}
Example #3
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);
}