00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <glib.h>
00021
00022 #include "config.h"
00023 #include "vfs_async.h"
00024
00025 typedef struct {
00026 char *filename;
00027 void *buf;
00028 int64_t size;
00029 GThread *thread;
00030 void * userdata;
00031
00032 VFSConsumer cons_f;
00033 } VFSAsyncTrampoline;
00034
00035 bool_t
00036 vfs_async_file_get_contents_trampoline(void * data)
00037 {
00038 VFSAsyncTrampoline *tr = data;
00039
00040 tr->cons_f(tr->buf, tr->size, tr->userdata);
00041 g_slice_free(VFSAsyncTrampoline, tr);
00042
00043 return FALSE;
00044 }
00045
00046 void *
00047 vfs_async_file_get_contents_worker(void * data)
00048 {
00049 VFSAsyncTrampoline *tr = data;
00050
00051 vfs_file_get_contents(tr->filename, &tr->buf, &tr->size);
00052
00053 g_idle_add_full(G_PRIORITY_HIGH_IDLE, vfs_async_file_get_contents_trampoline, tr, NULL);
00054 g_thread_exit(NULL);
00055 return NULL;
00056 }
00057
00058 EXPORT void
00059 vfs_async_file_get_contents(const char *filename, VFSConsumer cons_f, void * userdata)
00060 {
00061 VFSAsyncTrampoline *tr;
00062
00063 tr = g_slice_new0(VFSAsyncTrampoline);
00064 tr->filename = g_strdup(filename);
00065 tr->cons_f = cons_f;
00066 tr->userdata = userdata;
00067 tr->thread = g_thread_create(vfs_async_file_get_contents_worker, tr, FALSE, NULL);
00068 }