Beispiel #1
0
void
coll_save (cli_infos_t *infos, xmmsv_coll_t *coll,
           xmmsc_coll_namespace_t ns, gchar *name, gboolean force)
{
	xmmsc_result_t *res;
	xmmsv_t *val;
	gboolean save = TRUE;

	if (!force) {
		xmmsv_coll_t *exists;
		res = xmmsc_coll_get (infos->sync, name, ns);
		xmmsc_result_wait (res);
		val = xmmsc_result_get_value (res);
		if (xmmsv_get_coll (val, &exists)) {
			g_printf (_("Error: A collection already exists "
			            "with the target name!\n"));
			save = FALSE;
		}
		xmmsc_result_unref (res);
	}

	if (save) {
		res = xmmsc_coll_save (infos->sync, coll, name, ns);
		xmmsc_result_wait (res);
		done (res, infos);
	} else {
		cli_infos_loop_resume (infos);
	}
}
Beispiel #2
0
void
collection_print_config (xmmsc_result_t *res, cli_infos_t *infos,
                         gchar *attrname)
{
	xmmsv_coll_t *coll;
	gchar *attrvalue;
	xmmsv_t *val;

	val = xmmsc_result_get_value (res);

	if (xmmsv_get_coll (val, &coll)) {
		if (attrname == NULL) {
			xmmsc_coll_attribute_foreach (coll,
			                              coll_print_attributes, NULL);
		} else {
			if (xmmsc_coll_attribute_get (coll, attrname, &attrvalue)) {
				coll_print_attributes (attrname, attrvalue, NULL);
			} else {
				g_printf (_("Invalid attribute!\n"));
			}
		}
	} else {
		g_printf (_("Invalid collection!\n"));
	}

	cli_infos_loop_resume (infos);

	xmmsc_result_unref (res);
}
Beispiel #3
0
	Coll::Coll* extract_collection( xmmsv_t* val )
	{
		Coll::Coll* temp = 0;
		xmmsv_coll_t* coll = 0;
		xmmsv_get_coll( val, &coll );
		switch( xmmsv_coll_get_type( coll ) ) {

			case XMMS_COLLECTION_TYPE_REFERENCE: {
				temp = new Coll::Reference( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_UNION: {
				temp = new Coll::Union( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_INTERSECTION: {
				temp = new Coll::Intersection( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_COMPLEMENT: {
				temp = new Coll::Complement( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_HAS: {
				temp = new Coll::Has( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_SMALLER: {
				temp = new Coll::Smaller( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_GREATER: {
				temp = new Coll::Greater( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_EQUALS: {
				temp = new Coll::Equals( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_MATCH: {
				temp = new Coll::Match( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_IDLIST: {
				temp = new Coll::Idlist( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_QUEUE: {
				temp = new Coll::Queue( coll );
				break;
			}
			case XMMS_COLLECTION_TYPE_PARTYSHUFFLE: {
				temp = new Coll::PartyShuffle( coll );
				break;
			}

		}

		return temp;
	}
Beispiel #4
0
static void
run_tests (xmms_medialib_t *medialib, xmmsv_t *testcases, xmms_test_predicate predicate,
           gint format, const gchar *datasetname)
{
	xmmsv_list_iter_t *it;

	xmmsv_get_list_iter (testcases, &it);
	while (xmmsv_list_iter_valid (it)) {
		xmmsv_t *dict, *content, *specification, *holder, *expected;
		xmmsv_coll_t *coll;
		const gchar *name;
		dict = NULL;

		g_assert (xmmsv_list_iter_entry (it, &dict));

		xmmsv_dict_entry_get_string (dict, "name", &name);

		xmmsv_dict_get (dict, "medialib", &content);
		xmmsv_dict_get (dict, "specification", &specification);
		xmmsv_dict_get (dict, "collection", &holder);
		xmmsv_dict_get (dict, "expected", &expected);

		xmmsv_get_coll (holder, &coll);

		predicate (medialib, name, content, coll, specification,
		           expected, format, datasetname);

		xmmsv_list_iter_next (it);
	}
}
Beispiel #5
0
static VALUE
coll_get (xmmsv_t *val)
{
	xmmsc_coll_t *coll = NULL;

	if (!xmmsv_get_coll (val, &coll))
		rb_raise (eValueError, "cannot retrieve value");

	return TO_XMMS_CLIENT_COLLECTION (coll);
}
Beispiel #6
0
static void
operands_each (xmmsv_t *value, void *user_data)
{
	xmmsv_coll_t *operand = NULL;

	xmmsv_get_coll (value, &operand);
	xmmsc_coll_ref (operand);

	rb_yield (TO_XMMS_CLIENT_COLLECTION (operand));
}
Beispiel #7
0
static xmmsv_t *
duplicate_coll_value (xmmsv_t *val)
{
	xmmsv_t *dup_val;
	xmmsv_coll_t *new_coll, *orig_coll;

	xmmsv_get_coll (val, &orig_coll);
	assert (orig_coll);

	new_coll = xmmsv_coll_copy (orig_coll);
	dup_val = xmmsv_new_coll (new_coll);

	return dup_val;
}
Beispiel #8
0
void
configure_playlist (xmmsc_result_t *res, cli_infos_t *infos, gchar *playlist,
                    gint history, gint upcoming, xmmsv_coll_type_t type,
                    gchar *input)
{
	xmmsc_result_t *saveres;
	xmmsv_coll_t *coll;
	xmmsv_coll_t *newcoll;
	xmmsv_t *val;

	gboolean copied = FALSE;

	val = xmmsc_result_get_value (res);

	if (xmmsv_get_coll (val, &coll)) {
		if (type >= 0 && xmmsv_coll_get_type (coll) != type) {
			newcoll = coll_copy_retype (coll, type);
			coll = newcoll;
			copied = TRUE;
		}
		if (history >= 0) {
			coll_int_attribute_set (coll, "history", history);
		}
		if (upcoming >= 0) {
			coll_int_attribute_set (coll, "upcoming", upcoming);
		}
		if (input) {
			/* Replace previous operand. */
			newcoll = coll_make_reference (input, XMMS_COLLECTION_NS_COLLECTIONS);
			xmmsv_list_clear (xmmsv_coll_operands_get (coll));
			xmmsv_coll_add_operand (coll, newcoll);
			xmmsv_coll_unref (newcoll);
		}

		saveres = xmmsc_coll_save (infos->sync, coll, playlist,
		                           XMMS_COLLECTION_NS_PLAYLISTS);
		xmmsc_result_wait (saveres);
		done (saveres, infos);
	} else {
		g_printf (_("Cannot find the playlist to configure!\n"));
		cli_infos_loop_resume (infos);
	}

	if (copied) {
		xmmsv_coll_unref (coll);
	}

	xmmsc_result_unref (res);
}
Beispiel #9
0
/* (from src/clients/cli/cmd_coll.c) */
static void
coll_dump_list (xmmsv_t *list, unsigned int level)
{
	xmmsv_list_iter_t *it;
	xmmsv_coll_t *operand;
	xmmsv_t *v;

	xmmsv_get_list_iter (list, &it);
	while (xmmsv_list_iter_entry (it, &v)) {
		if (xmmsv_get_coll (v, &operand)) {
			coll_dump (operand, level);
		}
		xmmsv_list_iter_next (it);
	}

}
static void
query_append_intersect_operand (coll_query_t *query, xmms_coll_dag_t *dag,
                                xmmsv_coll_t *coll)
{
	xmmsv_coll_t *op;
	xmmsv_t *tmp;

	if (xmmsv_list_get (xmmsv_coll_operands_get (coll), 0, &tmp)) {
		xmmsv_get_coll (tmp, &op);

		if (!operator_is_allmedia (op)) {
			query_append_string (query, " AND ");
			xmms_collection_append_to_query (dag, op, query);
		}
	}
}
Beispiel #11
0
void
cmd_addpls (xmmsc_connection_t *conn, gint argc, gchar **argv)
{
	gchar *playlist;
	xmmsc_result_t *res, *res2;
	xmmsv_t *val;
	xmmsv_coll_t *coll;
	gchar *url;

	if (argc < 3) {
		print_error ("Supply path to playlist file");
	}

	if (argc == 3) {
		playlist = NULL;
		url = format_url (argv[2], G_FILE_TEST_IS_REGULAR);
	} else {
		playlist = argv[2];
		url = format_url (argv[3], G_FILE_TEST_IS_REGULAR);
	}

	res = xmmsc_coll_idlist_from_playlist_file (conn, url);
	g_free (url);

	xmmsc_result_wait (res);
	val = xmmsc_result_get_value (res);

	if (xmmsv_is_error (val)) {
		print_error ("%s", xmmsv_get_error_old (val));
	}

	if (!xmmsv_get_coll (val, &coll)) {
		print_error ("Couldn't get collection from result!");
	}

	res2 = xmmsc_playlist_add_idlist (conn, playlist, coll);
	xmmsc_result_wait (res2);
	if (xmmsc_result_iserror (res2)) {
		print_error ("%s", xmmsc_result_get_error (res2));
	}

	print_info ("Playlist with %d entries added", xmmsv_coll_idlist_get_size (coll));

	xmmsc_result_unref (res);
	xmmsc_result_unref (res2);
}
Beispiel #12
0
xmmsv_coll_t *
xmmsv_coll_copy (xmmsv_coll_t *orig_coll)
{
	xmmsv_coll_t *new_coll, *coll_elem;
	xmmsv_list_iter_t *it;
	xmmsv_dict_iter_t *itd;
	xmmsv_t *v, *list, *dict;
	const char *key;
	int32_t i;
	const char *s;

	new_coll = xmmsv_coll_new (xmmsv_coll_get_type (orig_coll));

	list = xmmsv_coll_idlist_get (orig_coll);
	x_return_val_if_fail (xmmsv_get_list_iter (list, &it), NULL);
	while (xmmsv_list_iter_valid (it)) {
		xmmsv_list_iter_entry (it, &v);
		xmmsv_get_int (v, &i);
		xmmsv_coll_idlist_append (new_coll, i);
		xmmsv_list_iter_next (it);
	}
	xmmsv_list_iter_explicit_destroy (it);

	list = xmmsv_coll_operands_get (orig_coll);
	x_return_val_if_fail (xmmsv_get_list_iter (list, &it), NULL);
	while (xmmsv_list_iter_valid (it)) {
		xmmsv_list_iter_entry (it, &v);
		xmmsv_get_coll (v, &coll_elem);
		xmmsv_coll_add_operand (new_coll, xmmsv_coll_copy (coll_elem));
		xmmsv_list_iter_next (it);
	}
	xmmsv_list_iter_explicit_destroy (it);

	dict = xmmsv_coll_attributes_get (orig_coll);
	x_return_val_if_fail (xmmsv_get_dict_iter (dict, &itd), NULL);
	while (xmmsv_dict_iter_valid (itd)) {
		xmmsv_dict_iter_pair (itd, &key, &v);
		xmmsv_get_string (v, &s);
		xmmsv_coll_attribute_set (new_coll, key, s);
		xmmsv_dict_iter_next (itd);
	}
	xmmsv_dict_iter_explicit_destroy (itd);
	return new_coll;
}
Beispiel #13
0
void
playlist_print_config (xmmsc_result_t *res, cli_infos_t *infos,
                       gchar *playlist)
{
	xmmsv_coll_t *coll;
	xmmsv_t *val;

	val = xmmsc_result_get_value (res);

	if (xmmsv_get_coll (val, &coll)) {
		pl_print_config (coll, playlist);
	} else {
		g_printf (_("Invalid playlist!\n"));
	}

	cli_infos_loop_resume (infos);

	xmmsc_result_unref (res);
}
Beispiel #14
0
void
coll_show (cli_infos_t *infos, xmmsc_result_t *res)
{
	const gchar *err;
	xmmsv_coll_t *coll;
	xmmsv_t *val;

	val = xmmsc_result_get_value (res);

	if (!xmmsv_get_error (val, &err)) {
		xmmsv_get_coll (val, &coll);
		coll_dump (coll, 0);
	} else {
		g_printf (_("Server error: %s\n"), err);
	}

	cli_infos_loop_resume (infos);
	xmmsc_result_unref (res);
}
Beispiel #15
0
static void
pl_print_config (xmmsv_coll_t *coll, const char *name)
{
	xmmsv_coll_t *op;
	xmmsv_coll_type_t type;
	gchar *upcoming = NULL;
	gchar *history = NULL;
	gchar *input = NULL;
	gchar *input_ns = NULL;
	xmmsv_t *v;

	type = xmmsv_coll_get_type (coll);

	xmmsv_coll_attribute_get (coll, "upcoming", &upcoming);
	xmmsv_coll_attribute_get (coll, "history", &history);

	g_printf (_("name: %s\n"), name);

	switch (type) {
	case XMMS_COLLECTION_TYPE_IDLIST:
		g_printf (_("type: list\n"));
		break;
	case XMMS_COLLECTION_TYPE_QUEUE:
		g_printf (_("type: queue\n"));
		g_printf (_("history: %s\n"), history);
		break;
	case XMMS_COLLECTION_TYPE_PARTYSHUFFLE:
		if (xmmsv_list_get (xmmsv_coll_operands_get (coll), 0, &v) &&
		    xmmsv_get_coll (v, &op)) {
			xmmsv_coll_attribute_get (op, "reference", &input);
			xmmsv_coll_attribute_get (op, "namespace", &input_ns);
		}

		g_printf (_("type: pshuffle\n"));
		g_printf (_("history: %s\n"), history);
		g_printf (_("upcoming: %s\n"), upcoming);
		g_printf (_("input: %s/%s\n"), input_ns, input);
		break;
	default:
		g_printf (_("type: unknown!\n"));
		break;
	}
}
Beispiel #16
0
void configure_collection (xmmsc_result_t *res, cli_infos_t *infos,
                           gchar *ns, gchar *name,
                           gchar *attrname, gchar *attrvalue)
{
	xmmsv_coll_t *coll;
	xmmsv_t *val;

	val = xmmsc_result_get_value (res);

	if (xmmsv_get_coll (val, &coll)) {
		xmmsc_coll_attribute_set (coll, attrname, attrvalue);
		coll_save (infos, coll, ns, name, TRUE);
	} else {
		g_printf (_("Invalid collection!\n"));
		cli_infos_loop_resume (infos);
	}

	xmmsc_result_unref (res);
}
Beispiel #17
0
static void
xmms_playlist_update_partyshuffle (xmms_playlist_t *playlist,
                                   const gchar *plname, xmmsv_coll_t *coll)
{
	gint history, upcoming, currpos, size;
	xmmsv_coll_t *src;
	xmmsv_t *tmp;

	XMMS_DBG ("PLAYLIST: Update partyshuffle.");

	if (!xmms_collection_get_int_attr (coll, "history", &history)) {
		history = 0;
	}

	if (!xmms_collection_get_int_attr (coll, "upcoming", &upcoming)) {
		upcoming = XMMS_DEFAULT_PARTYSHUFFLE_UPCOMING;
	}

	currpos = xmms_playlist_coll_get_currpos (coll);
	while (currpos > history) {
		/* Removing entries is fast enough to be processed at once. */
		xmms_playlist_remove_unlocked (playlist, plname, coll, 0, NULL);
		currpos = xmms_playlist_coll_get_currpos (coll);
	}

	g_return_if_fail(xmmsv_list_get (xmmsv_coll_operands_get (coll), 0, &tmp));
	g_return_if_fail(xmmsv_get_coll (tmp, &src));

	/* Since getting random media can be slow on huge medialibs, we refill only
	 * one entry at a time. This let other threads a chance to get the lock on
	 * the playlist object as soon as possible. */
	size = xmms_playlist_coll_get_size (coll);
	if (size < currpos + 1 + upcoming) {
		xmms_medialib_entry_t randentry;
		randentry = xmms_collection_get_random_media (playlist->colldag, src);
		if (randentry > 0) {
			xmms_playlist_add_entry_unlocked (playlist, plname, coll, randentry, NULL);
		}
	}
}
Beispiel #18
0
void
copy_playlist (xmmsc_result_t *res, cli_infos_t *infos, gchar *playlist)
{
	xmmsc_result_t *saveres;
	xmmsv_coll_t *coll;

	xmmsv_t *val;

	val = xmmsc_result_get_value (res);

	if (xmmsv_get_coll (val, &coll)) {
		saveres = xmmsc_coll_save (infos->sync, coll, playlist,
		                           XMMS_COLLECTION_NS_PLAYLISTS);
		xmmsc_result_wait (saveres);
		done (saveres, infos);
	} else {
		g_printf (_("Cannot find the playlist to copy!\n"));
		cli_infos_loop_resume (infos);
	}

	xmmsc_result_unref (res);
}
Beispiel #19
0
void
add_pls (xmmsc_result_t *plsres, cli_infos_t *infos,
          gchar *playlist, gint pos)
{
	xmmsc_result_t *res;
	xmmsv_coll_t *coll;
	xmmsv_t *val;
	const char *err;

	val = xmmsc_result_get_value (plsres);

	if (!xmmsv_get_error (val, &err) &&
	    xmmsv_get_coll (val, &coll)) {
		res = xmmsc_playlist_add_idlist (infos->sync, playlist, coll);
		xmmsc_result_wait (res);
		xmmsc_result_unref (res);
	} else {
		g_printf (_("Server error: %s\n"), err);
	}

	xmmsc_result_unref (plsres);
}
/* Recursively append conditions corresponding to the given collection to the query. */
static void
xmms_collection_append_to_query (xmms_coll_dag_t *dag, xmmsv_coll_t *coll,
                                 coll_query_t *query)
{
	xmmsv_coll_t *op;
	xmms_medialib_entry_t entry;
	gchar *attr1, *attr2, *attr3;
	gboolean case_sens;
	xmmsv_list_iter_t *iter;
	xmmsv_t *tmp;
	gboolean first;

	xmmsv_coll_type_t type = xmmsv_coll_get_type (coll);
	switch (type) {
	case XMMS_COLLECTION_TYPE_REFERENCE:
		if (!operator_is_allmedia (coll)) {
			query_append_operand (query, dag, coll);
		} else {
			/* FIXME: Hackish solution to append a ref to All Media */
			query_append_string (query, "1");
		}
		break;

	case XMMS_COLLECTION_TYPE_UNION:
	case XMMS_COLLECTION_TYPE_INTERSECTION:
		first = TRUE;
		query_append_string (query, "(");

		xmmsv_get_list_iter (xmmsv_coll_operands_get (coll), &iter);

		for (xmmsv_list_iter_first (iter);
		     xmmsv_list_iter_valid (iter);
		     xmmsv_list_iter_next (iter)) {
			if (first) {
				first = FALSE;
			} else {
				if (type == XMMS_COLLECTION_TYPE_UNION)
					query_append_string (query, " OR ");
				else
					query_append_string (query, " AND ");
			}
			xmmsv_list_iter_entry (iter, &tmp);
			xmmsv_get_coll (tmp, &op);
			xmms_collection_append_to_query (dag, op, query);
		}
		xmmsv_list_iter_explicit_destroy (iter);

		query_append_string (query, ")");
		break;

	case XMMS_COLLECTION_TYPE_COMPLEMENT:
		query_append_string (query, "NOT ");
		query_append_operand (query, dag, coll);
		break;

	case XMMS_COLLECTION_TYPE_HAS:
	case XMMS_COLLECTION_TYPE_EQUALS:
	case XMMS_COLLECTION_TYPE_MATCH:
	case XMMS_COLLECTION_TYPE_SMALLER:
	case XMMS_COLLECTION_TYPE_GREATER:
		xmmsv_coll_attribute_get (coll, "field", &attr1);
		xmmsv_coll_attribute_get (coll, "value", &attr2);
		xmmsv_coll_attribute_get (coll, "case-sensitive", &attr3);
		case_sens = (attr3 != NULL && strcmp (attr3, "true") == 0);

		query_append_string (query, "(");
		query_append_filter (query, type, attr1, attr2, case_sens);

		query_append_intersect_operand (query, dag, coll);
		query_append_string (query, ")");
		break;

	case XMMS_COLLECTION_TYPE_IDLIST:
	case XMMS_COLLECTION_TYPE_QUEUE:
	case XMMS_COLLECTION_TYPE_PARTYSHUFFLE:
		first = TRUE;
		query_append_string (query, "m0.id IN (");

		xmmsv_get_list_iter (xmmsv_coll_idlist_get (coll), &iter);
		for (xmmsv_list_iter_first (iter);
		     xmmsv_list_iter_valid (iter);
		     xmmsv_list_iter_next (iter)) {

			if (first) {
				first = FALSE;
			} else {
				query_append_string (query, ",");
			}

			xmmsv_list_iter_entry_int (iter, &entry);
			query_append_int (query, entry);
		}
		xmmsv_list_iter_explicit_destroy (iter);

		query_append_string (query, ")");
		break;

	/* invalid type */
	default:
		XMMS_DBG ("Cannot append invalid collection operator!");
		g_assert_not_reached ();
		break;
	}

}
Beispiel #21
0
/** Write the given operator to the database under the given id.
 *
 * @param session  The medialib session connected to the DB.
 * @param collid  The id under which to save the collection.
 * @param coll  The structure of the collection to save.
 * @return  The next free collection id.
 */
static guint
xmms_collection_dbwrite_operator (xmms_medialib_session_t *session,
                                  guint collid, xmmsv_coll_t *coll)
{
	gchar query[128];
	guint *idlist;
	gint i;
	xmmsv_coll_t *op;
	xmmsv_t *attrs;
	gint newid, nextid;
	coll_dbwrite_t dbwrite_infos = { session, collid, 0 };

	/* Write operator */
	g_snprintf (query, sizeof (query),
	            "INSERT INTO CollectionOperators VALUES(%d, %d)",
	            collid, xmmsv_coll_get_type (coll));

	xmms_medialib_select (session, query, NULL);

	/* Write attributes */
	attrs = xmmsv_coll_attributes_get (coll);
	xmmsv_dict_foreach (attrs, dbwrite_coll_attributes, &dbwrite_infos);
	attrs = NULL; /* no unref needed. */

	/* Write idlist */
	idlist = xmmsv_coll_get_idlist (coll);
	for (i = 0; idlist[i] != 0; i++) {
		g_snprintf (query, sizeof (query),
		            "INSERT INTO CollectionIdlists VALUES(%d, %d, %d)",
		            collid, i, idlist[i]);

		xmms_medialib_select (session, query, NULL);
	}

	/* Save operands and connections (don't recurse in ref operand) */
	newid = collid + 1;
	if (xmmsv_coll_get_type (coll) != XMMS_COLLECTION_TYPE_REFERENCE) {
		xmmsv_t *tmp;
		xmmsv_list_iter_t *iter;

		xmmsv_get_list_iter (xmmsv_coll_operands_get (coll), &iter);

		for (xmmsv_list_iter_first (iter);
		     xmmsv_list_iter_valid (iter);
		     xmmsv_list_iter_next (iter)) {

			xmmsv_list_iter_entry (iter, &tmp);
			xmmsv_get_coll (tmp, &op);

			nextid = xmms_collection_dbwrite_operator (session, newid, op);
			g_snprintf (query, sizeof (query),
			            "INSERT INTO CollectionConnections VALUES(%d, %d)",
			            newid, collid);
			xmms_medialib_select (session, query, NULL);
			newid = nextid;
		}
		xmmsv_list_iter_explicit_destroy (iter);
	}

	/* return next available id */
	return newid;
}
Beispiel #22
0
static bool
_internal_put_on_bb_collection (xmmsv_t *bb, xmmsv_coll_t *coll)
{
	xmmsv_list_iter_t *it;
	xmmsv_t *v, *attrs;
	int n;
	uint32_t ret;
	int32_t entry;
	xmmsv_coll_t *op;

	if (!bb || !coll) {
		return false;
	}

	/* push type */
	if (!xmmsv_bitbuffer_put_bits (bb, 32, xmmsv_coll_get_type (coll)))
		return false;

	/* attribute counter and values */
	attrs = xmmsv_coll_attributes_get (coll);
	n = 0;

	xmmsv_dict_foreach (attrs, _internal_put_on_bb_count_coll_attr, &n);
	if (!xmmsv_bitbuffer_put_bits (bb, 32, n))
		return false;

	/* needs error checking! */
	xmmsv_dict_foreach (attrs, _internal_put_on_bb_append_coll_attr, bb);

	attrs = NULL; /* no unref needed. */

	/* idlist counter and content */
	xmmsv_bitbuffer_put_bits (bb, 32, xmmsv_coll_idlist_get_size (coll));

	xmmsv_get_list_iter (xmmsv_coll_idlist_get (coll), &it);
	for (xmmsv_list_iter_first (it);
	     xmmsv_list_iter_valid (it);
	     xmmsv_list_iter_next (it)) {

		if (!xmmsv_list_iter_entry_int (it, &entry)) {
			x_api_error ("Non integer in idlist", 0);
		}
		xmmsv_bitbuffer_put_bits (bb, 32, entry);
	}
	xmmsv_list_iter_explicit_destroy (it);

	/* operands counter and objects */
	n = 0;
	if (xmmsv_coll_get_type (coll) != XMMS_COLLECTION_TYPE_REFERENCE) {
		n = xmmsv_list_get_size (xmmsv_coll_operands_get (coll));
	}

	ret = xmmsv_bitbuffer_pos (bb);
	xmmsv_bitbuffer_put_bits (bb, 32, n);

	if (n > 0) {
		xmmsv_get_list_iter (xmmsv_coll_operands_get (coll), &it);

		while (xmmsv_list_iter_entry (it, &v)) {
			if (!xmmsv_get_coll (v, &op)) {
				x_api_error ("Non collection operand", 0);
			}

			_internal_put_on_bb_int32 (bb, XMMSV_TYPE_COLL);

			ret = _internal_put_on_bb_collection (bb, op);
			xmmsv_list_iter_next (it);
		}
	}

	return ret;
}
Beispiel #23
0
void
cmd_playlist_type (xmmsc_connection_t *conn, gint argc, gchar **argv)
{
	gchar *name;
	xmmsv_coll_type_t prevtype, newtype;
	xmmsc_result_t *res;
	xmmsv_t *val;
	xmmsv_coll_t *coll;

	/* Read playlist name */
	if (argc < 4) {
		print_error ("usage: type_playlist [playlistname] [type] [options]");
	}
	name = argv[3];

	/* Retrieve the playlist operator */
	res = xmmsc_coll_get (conn, name, XMMS_COLLECTION_NS_PLAYLISTS);
	xmmsc_result_wait (res);
	val = xmmsc_result_get_value (res);

	if (xmmsv_is_error (val)) {
		print_error ("%s", xmmsv_get_error_old (val));
	}

	xmmsv_get_coll (val, &coll);
	prevtype = xmmsv_coll_get_type (coll);

	/* No type argument, simply display the current type */
	if (argc < 5) {
		print_info (get_playlist_type_string (prevtype));

	/* Type argument, set the new type */
	} else {
		gint typelen;
		gint idlistsize;
		xmmsc_result_t *saveres;
		xmmsv_coll_t *newcoll;
		gint i;

		typelen = strlen (argv[4]);
		if (g_ascii_strncasecmp (argv[4], "list", typelen) == 0) {
			newtype = XMMS_COLLECTION_TYPE_IDLIST;
		} else if (g_ascii_strncasecmp (argv[4], "queue", typelen) == 0) {
			newtype = XMMS_COLLECTION_TYPE_QUEUE;
		} else if (g_ascii_strncasecmp (argv[4], "pshuffle", typelen) == 0) {
			newtype = XMMS_COLLECTION_TYPE_PARTYSHUFFLE;

			/* Setup operand for party shuffle (set operand) ! */
			if (argc < 6) {
				print_error ("Give the source collection for the party shuffle");
			}

		} else {
			print_error ("Invalid playlist type (valid types: list, queue, pshuffle)");
		}

		/* Copy collection idlist, attributes and operand (if needed) */
		newcoll = xmmsv_coll_new (newtype);

		idlistsize = xmmsv_coll_idlist_get_size (coll);
		for (i = 0; i < idlistsize; i++) {
			guint id;
			xmmsv_coll_idlist_get_index (coll, i, &id);
			xmmsv_coll_idlist_append (newcoll, id);
		}

		xmmsv_coll_attribute_foreach (coll, coll_copy_attributes, newcoll);

		if (newtype == XMMS_COLLECTION_TYPE_PARTYSHUFFLE) {
			playlist_setup_pshuffle (conn, newcoll, argv[5]);
		}

		/* Overwrite with new collection */
		saveres = xmmsc_coll_save (conn, newcoll, name, XMMS_COLLECTION_NS_PLAYLISTS);
		xmmsc_result_wait (saveres);

		if (xmmsc_result_iserror (saveres)) {
			print_error ("Couldn't save %s : %s",
			             name, xmmsc_result_get_error (saveres));
		}

		xmmsv_coll_unref (newcoll);
		xmmsc_result_unref (saveres);
	}

	xmmsc_result_unref (res);
}
Beispiel #24
0
int
xmmsv_bitbuffer_serialize_value (xmmsv_t *bb, xmmsv_t *v)
{
	bool ret;
	int32_t i;
	const char *s;
	xmmsv_coll_t *c;
	const unsigned char *bc;
	unsigned int bl;
	xmmsv_type_t type;

	type = xmmsv_get_type (v);
	ret = _internal_put_on_bb_int32 (bb, type);
	if (!ret)
		return ret;

	switch (type) {
	case XMMSV_TYPE_ERROR:
		if (!xmmsv_get_error (v, &s)) {
			return false;
		}
		ret = _internal_put_on_bb_error (bb, s);
		break;
	case XMMSV_TYPE_INT32:
		if (!xmmsv_get_int (v, &i)) {
			return false;
		}
		ret = _internal_put_on_bb_int32 (bb, i);
		break;
	case XMMSV_TYPE_STRING:
		if (!xmmsv_get_string (v, &s)) {
			return false;
		}
		ret = _internal_put_on_bb_string (bb, s);
		break;
	case XMMSV_TYPE_COLL:
		if (!xmmsv_get_coll (v, &c)) {
			return false;
		}
		ret = _internal_put_on_bb_collection (bb, c);
		break;
	case XMMSV_TYPE_BIN:
		if (!xmmsv_get_bin (v, &bc, &bl)) {
			return false;
		}
		ret = _internal_put_on_bb_bin (bb, bc, bl);
		break;
	case XMMSV_TYPE_LIST:
		ret = _internal_put_on_bb_value_list (bb, v);
		break;
	case XMMSV_TYPE_DICT:
		ret = _internal_put_on_bb_value_dict (bb, v);
		break;

	case XMMSV_TYPE_NONE:
		break;
	default:
		x_internal_error ("Tried to serialize value of unsupported type");
		return false;
	}

	return ret;
}