Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
vfs_async.c
Go to the documentation of this file.
00001 /*
00002  * vfs_async.c
00003  * Copyright 2010 William Pitcock
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions, and the following disclaimer.
00010  *
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  *    this list of conditions, and the following disclaimer in the documentation
00013  *    provided with the distribution.
00014  *
00015  * This software is provided "as is" and without any warranty, express or
00016  * implied. In no event shall the authors be liable for any damages arising from
00017  * the use of this software.
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 }