Esempio n. 1
0
/**
 * Format a client-to-client message.
 *
 * Messages are dictionaries of the form:\n
 * "sender" : id of the sender client\n
 * "destination" : id of the destination client\n
 * "id" : 0 if the message doesn't expect reply, else a message id\n
 * "payload" : the contents of the message
 *
 * @param sender the id of the sender client
 * @param dest the id of the destination client
 * @param id the id of the message
 * @param payload the contents of the message
 *
 * @return the formatted message
 *
 * @note Increases the refcount of payload.
 */
xmmsv_t *
xmmsv_c2c_message_format (int sender, int dest, int id,
                          xmmsv_t *payload)
{
	xmmsv_ref (payload);
	return xmmsv_build_dict (XMMSV_DICT_ENTRY_INT ("sender", sender),
	                         XMMSV_DICT_ENTRY_INT ("destination", dest),
	                         XMMSV_DICT_ENTRY_INT ("id", id),
	                         XMMSV_DICT_ENTRY ("payload", payload),
	                         XMMSV_DICT_END);
}
Esempio n. 2
0
/**
 * Returns a random entry from a collection
 *
 * @param coll The collection to find a random entry in
 * @return A random entry from the collection, 0 if the collection is empty
 */
xmms_medialib_entry_t
xmms_medialib_query_random_id (xmms_medialib_session_t *session,
                               xmmsv_t *coll)
{
	xmms_medialib_entry_t ret;
	xmmsv_t *spec, *res;
	xmms_error_t err;

	spec = xmmsv_build_list (XMMSV_LIST_ENTRY_STR ("id"),
	                         XMMSV_LIST_END);

	spec = xmmsv_build_dict (XMMSV_DICT_ENTRY_STR ("type", "metadata"),
	                         XMMSV_DICT_ENTRY_STR ("aggregate", "random"),
	                         XMMSV_DICT_ENTRY ("get", spec),
	                         XMMSV_DICT_END);

	res = xmms_medialib_query (session, coll, spec, &err);
	xmmsv_get_int (res, &ret);

	xmmsv_unref (spec);
	xmmsv_unref (res);

	return ret;
}