Audacious $Id:Doxyfile42802007-03-2104:39:00Znenolod$
vfs_async.c
Go to the documentation of this file.
00001 /*
00002  * Audacious
00003  * Copyright (c) 2010 William Pitcock <nenolod@dereferenced.org>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; under version 3 of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses>.
00016  *
00017  * The Audacious team does not consider modular code linking to
00018  * Audacious or using our public API to be a derived work.
00019  */
00020 
00021 #include <libaudcore/vfs_async.h>
00022 
00023 typedef struct {
00024     gchar *filename;
00025     void *buf;
00026     gint64 size;
00027     GThread *thread;
00028     gpointer userdata;
00029 
00030     VFSConsumer cons_f;
00031 } VFSAsyncTrampoline;
00032 
00033 gboolean
00034 vfs_async_file_get_contents_trampoline(gpointer data)
00035 {
00036     VFSAsyncTrampoline *tr = data;
00037 
00038     tr->cons_f(tr->buf, tr->size, tr->userdata);
00039     g_slice_free(VFSAsyncTrampoline, tr);
00040 
00041     return FALSE;
00042 }
00043 
00044 gpointer
00045 vfs_async_file_get_contents_worker(gpointer data)
00046 {
00047     VFSAsyncTrampoline *tr = data;
00048 
00049     vfs_file_get_contents(tr->filename, &tr->buf, &tr->size);
00050 
00051     g_idle_add_full(G_PRIORITY_HIGH_IDLE, vfs_async_file_get_contents_trampoline, tr, NULL);
00052     g_thread_exit(NULL);
00053     return NULL;
00054 }
00055 
00056 void
00057 vfs_async_file_get_contents(const gchar *filename, VFSConsumer cons_f, gpointer userdata)
00058 {
00059     VFSAsyncTrampoline *tr;
00060 
00061     tr = g_slice_new0(VFSAsyncTrampoline);
00062     tr->filename = g_strdup(filename);
00063     tr->cons_f = cons_f;
00064     tr->userdata = userdata;
00065     tr->thread = g_thread_create(vfs_async_file_get_contents_worker, tr, FALSE, NULL);
00066 }