Do the loading inside the fetcher thread.
[gmpc.git] / test / GmpcEasyDownload / ged.c
blobe7a3a99fc807aaf57461623af38726f4ddcba778
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <glib.h>
5 #include "gmpc_easy_download.h"
7 gpointer config = NULL;
9 void show_error_message(void)
14 void playlist3_show_error_message(const char *message, int el)
18 /**
19 * Dummy config system
21 int cfg_get_single_value_as_int_with_default(gpointer *config, const gchar *a, const gchar *b, int def)
23 return def;
25 gchar * cfg_get_single_value_as_string_with_default(gpointer *config, const gchar *a, const gchar *b, gchar* def)
27 return g_strdup(def);
29 gchar *cfg_get_single_value_as_string(gpointer *config, const gchar *a, const gchar *b)
31 return NULL;
33 void cfg_set_single_value_as_string(gpointer *config, const gchar *a, const gchar *b, gchar *def)
37 void cfg_set_single_value_as_int(gpointer *config, const gchar *a, const gchar *b, int def )
41 void downloaded2(const GEADAsyncHandler *handle, GEADStatus status, gpointer user_data)
43 GMainLoop *loop = user_data;
44 if(status == GEAD_PROGRESS) return;
45 else if(status == GEAD_DONE){
46 gsize length;
47 const guchar *data = gmpc_easy_handler_get_data(handle, &length);
48 printf("Download: %li bytes\n", length);
50 }else{
51 g_error("Download failed\n");
53 g_main_loop_quit(loop);
56 void downloaded(const GEADAsyncHandler *handle, GEADStatus status, gpointer user_data)
58 GMainLoop *loop = user_data;
59 if(status == GEAD_PROGRESS) return;
60 else if(status == GEAD_DONE){
61 GEADAsyncHandler *handle2;
62 gsize length;
63 const guchar *data = gmpc_easy_handler_get_data(handle, &length);
64 printf("Download: %li bytes\n", length);
65 handle2 = gmpc_easy_async_downloader("http://maps.google.com", downloaded2, loop);
66 }else{
67 g_error("Download failed\n");
68 g_main_loop_quit(loop);
71 int main(int argc, char **argv)
73 GEADAsyncHandler *handle;
74 GMainLoop *loop;
75 g_type_init();
76 loop = g_main_loop_new(NULL, FALSE);
77 if(!g_thread_supported())
78 g_thread_init(NULL);
79 handle = gmpc_easy_async_downloader("http://www.google.com", downloaded, loop);
80 g_main_loop_run(loop);
81 gmpc_easy_async_quit();
82 g_main_loop_unref(loop);
83 return EXIT_FAILURE;