예제 #1
0
void search_new_search(sp_search *s)
{
	search_clear();
	sp_search_add_ref(s);
	search = s;
}
예제 #2
0
SP_LIBEXPORT(sp_search *) sp_search_create(sp_session *session, const char *query, int track_offset, int track_count, int album_offset, int album_count, int artist_offset, int artist_count, search_complete_cb *callback, void *userdata) {
	sp_search *search;
	void **container;
	struct search_ctx *search_ctx;

	search = malloc(sizeof(sp_search));
	if(search == NULL)
		return NULL;

	search->query = strdup(query);
	search->did_you_mean = NULL;

	search->track_offset = track_offset;
	search->track_count = track_count;

	/* Currently not used due to lack of support in cmd_search() */
	search->album_offset = album_offset;
	search->album_count = album_count;
	search->artist_offset = artist_offset;
	search->artist_count = artist_count;

	search->callback = callback;
	search->userdata = userdata;

	search->num_albums = 0;
	search->albums = NULL;

	search->num_artists = 0;
	search->artists = NULL;

	search->num_tracks = 0;
	search->tracks = NULL;

	search->error = SP_ERROR_IS_LOADING;
	search->is_loaded = 0;
	search->ref_count = 1;


	/*
	 * Temporarily increase ref count for the albumbrowse so it's not free'd
	 * accidentily. It will be decreaed by the chanel callback.
	 *
	 */
	sp_search_add_ref(search);


	/* The album callback context */
	search_ctx = (struct search_ctx *)malloc(sizeof(struct search_ctx));


	search_ctx->session = session;
	search_ctx->req = NULL; /* Filled in by the request processor */
	search_ctx->buf = buf_new();
	search_ctx->search = search;

	/* Request input container. Will be free'd when the request is finished. */
	container = (void **)malloc(sizeof(void *));
	*container = search_ctx;


	request_post(session, REQ_TYPE_SEARCH, container);

	return search;
}