Beispiel #1
0
static int
operator_callback (void *userdata, int cols, char **col_strs, char **col_names)
{
    struct db_info *info = userdata;
    xmmsv_t *coll = info->coll;
    xmmsv_t *op;
    int i;
    gint id;
    gint type;

    for (i = 0; i < cols; i++) {
        if (!strcmp (col_names[i], "id")) {
            id = atoi (col_strs[i]);
        } else if (!strcmp (col_names[i], "type")) {
            type = atoi (col_strs[i]);
        }
    }


    op = xmms_collection_dbread_operator (info->db, id, type);
    xmmsv_coll_add_operand (coll, op);
    xmmsv_unref (op);

    return 0;
}
Beispiel #2
0
static int
restore_callback (void *userdata, int columns, char **col_strs, char **col_names)
{
    struct db_info *info = userdata;
    static gint previd = -1;
    gint id, type, nsid, i;
    const gchar *label;
    static xmmsv_t *coll = NULL;

    for (i = 0; i < columns; i++) {
        if (!strcmp (col_names[i], "id")) {
            id = atoi (col_strs[i]);
        } else if (!strcmp (col_names[i], "type")) {
            type = atoi (col_strs[i]);
        } else if (!strcmp (col_names[i], "nsid")) {
            nsid = atoi (col_strs[i]);
        } else if (!strcmp (col_names[i], "label")) {
            label = col_strs[i];
        }
    }

    /* Do not duplicate operator if same id */
    if (previd < 0 || id != previd) {
        coll = xmms_collection_dbread_operator (info->db, id, type);
        previd = id;
    }
    else {
        xmmsv_ref (coll);  /* New label references the coll */
    }

    g_hash_table_replace (info->ht[nsid], g_strdup (label), coll);

    return 0;
}
Beispiel #3
0
/** Restore the collection DAG from the database.
 *
 * @param dag  The collection DAG to restore to.
 */
void
xmms_collection_dag_restore (xmms_coll_dag_t *dag)
{
	xmmsv_coll_t *coll = NULL;
	xmms_medialib_session_t *session;
	xmmsv_t *cmdval;
	const gchar *query;
	GList *res;
	gint previd;

	session = xmms_medialib_begin ();

	/* Fetch all label-coll_operator for all namespaces, register in table */
	query = "SELECT op.id AS id, lbl.name AS label, "
	        "       lbl.namespace AS nsid, op.type AS type "
	        "FROM CollectionOperators AS op, CollectionLabels as lbl "
	        "WHERE op.id=lbl.collid "
	        "ORDER BY id";
	res = xmms_medialib_select (session, query, NULL);

	previd = -1;

	while (res) {
		gint id, type, nsid;
		const gchar *label;

		cmdval = (xmmsv_t*) res->data;
		id = value_get_dict_int (cmdval, "id");
		type = value_get_dict_int (cmdval, "type");
		nsid = value_get_dict_int (cmdval, "nsid");
		label = value_get_dict_string (cmdval, "label");

		/* Do not duplicate operator if same id */
		if (previd < 0 || id != previd) {
			coll = xmms_collection_dbread_operator (session, id, type);
			previd = id;
		}
		else {
			xmmsv_coll_ref (coll);  /* New label references the coll */
		}

		xmms_collection_dag_replace (dag, nsid, g_strdup (label), coll);

		xmmsv_unref (cmdval);
		res = g_list_delete_link (res, res);
	}

	xmms_medialib_end (session);

	/* FIXME: validate ? */

	/* Link references in collections to actual operators */
	xmms_collection_apply_to_all_collections (dag, bind_all_references, NULL);
}
Beispiel #4
0
/** Given a collection id, query the DB to build the corresponding
 *  collection DAG.
 *
 * @param session  The medialib session connected to the DB.
 * @param id  The id of the collection to create.
 * @param type  The type of the collection operator.
 * @return  The created collection DAG.
 */
static xmmsv_coll_t *
xmms_collection_dbread_operator (xmms_medialib_session_t *session,
                                 gint id, xmmsv_coll_type_t type)
{
	xmmsv_coll_t *coll;
	xmmsv_coll_t *op;
	GList *res;
	GList *n;
	xmmsv_t *cmdval;
	gchar query[256];

	coll = xmmsv_coll_new (type);

	/* Retrieve the attributes */
	g_snprintf (query, sizeof (query),
	            "SELECT attr.key AS key, attr.value AS value "
	            "FROM CollectionOperators AS op, CollectionAttributes AS attr "
	            "WHERE op.id=%d AND attr.collid=op.id", id);

	res = xmms_medialib_select (session, query, NULL);
	for (n = res; n; n = n->next) {
		const gchar *key, *value;

		cmdval = (xmmsv_t*) n->data;
		key = value_get_dict_string (cmdval, "key");
		value = value_get_dict_string (cmdval, "value");
		xmmsv_coll_attribute_set (coll, key, value);

		xmmsv_unref (n->data);
	}
	g_list_free (res);

	/* Retrieve the idlist */
	g_snprintf (query, sizeof (query),
	            "SELECT idl.mid AS mid "
	            "FROM CollectionOperators AS op, CollectionIdlists AS idl "
	            "WHERE op.id=%d AND idl.collid=op.id "
	            "ORDER BY idl.position", id);

	res = xmms_medialib_select (session, query, NULL);
	for (n = res; n; n = n->next) {

		cmdval = (xmmsv_t *) n->data;
		xmmsv_coll_idlist_append (coll, value_get_dict_int (cmdval, "mid"));

		xmmsv_unref (cmdval);
	}
	g_list_free (res);

	/* Retrieve the operands */
	g_snprintf (query, sizeof (query),
	            "SELECT op.id AS id, op.type AS type "
	            "FROM CollectionOperators AS op, CollectionConnections AS conn "
	            "WHERE conn.to_id=%d AND conn.from_id=op.id", id);

	res = xmms_medialib_select (session, query, NULL);
	for (n = res; n; n = n->next) {
		gint _id;
		gint type;

		cmdval = (xmmsv_t *) n->data;
		_id = value_get_dict_int (cmdval, "id");
		type = value_get_dict_int (cmdval, "type");

		op = xmms_collection_dbread_operator (session, _id, type);
		xmmsv_coll_add_operand (coll, op);

		xmmsv_coll_unref (op);
		xmmsv_unref (cmdval);
	}
	g_list_free (res);

	return coll;
}