1 /* 2 download_thread.h 3 4 5 2003 Plus Huang 6 */ 7 8 #ifndef __DOWNLOAD_THREAD_H 9 #define __DOWNLOAD_THREAD_H 10 11 #include "download_store.h" 12 #include "category_store.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 typedef struct _DownloadThread DownloadThread; 19 20 struct _DownloadThread { 21 GThread* gthread; 22 GStaticRecMutex mutex; 23 DownloadThread* prev; 24 DownloadThread* next; 25 guint thread_state; 26 27 // downloading data 28 Download* download_data; 29 GString* out_filename; 30 gboolean resumable; 31 gdouble timer_count; 32 33 Category* category; 34 GtkTreeIter iter_download; 35 GTimer* timer; 36 }; 37 38 enum DOWNLOAD_THREAD_STATE { 39 DOWNLOAD_THREAD_READY, 40 DOWNLOAD_THREAD_ACTIVE, 41 DOWNLOAD_THREAD_SKIP, // skip current job 42 DOWNLOAD_THREAD_STOP, // do something before destory 43 DOWNLOAD_THREAD_JOB_ERASED, // download job erased by user 44 DOWNLOAD_THREAD_DESTROY, // destroying thread and freeing resource 45 }; 46 47 DownloadThread* download_thread_new (Category* category, 48 GtkTreeIter* iter_download); 49 50 // notify event to DownloadThread 51 void download_thread_activate (DownloadThread* dt); 52 void download_thread_skip (DownloadThread* dt); 53 void download_thread_stop (DownloadThread* dt); 54 void download_thread_job_erased (DownloadThread* dt); 55 void download_thread_destroy (DownloadThread* dt); 56 57 void download_thread_update_screen (DownloadThread* dt); 58 59 // call it before thread finish 60 void download_thread_free_resource (DownloadThread* dt); 61 62 // lock and unlock for DownloadThread 63 #define download_thread_lock(dt) g_static_rec_mutex_lock (&(dt)->mutex) 64 #define download_thread_unlock(dt) g_static_rec_mutex_unlock (&(dt)->mutex) 65 66 void download_thread_retry_delay (DownloadThread* dt); 67 68 gboolean download_thread_test_file (DownloadThread* dt); 69 gboolean download_thread_load_next_job (DownloadThread* dt); 70 71 gdouble download_thread_get_timer (DownloadThread* dt); 72 73 // display/update job data to screen. 74 void download_thread_job_redraw (DownloadThread* dt); 75 76 // set job data 77 #define download_thread_job_set_state(dt, s) \ 78 DOWNLOAD_SETTING ((dt)->download_data)->state = (s) 79 80 #define download_thread_job_set_total(dt, size) \ 81 (dt)->download_data->total = (size) 82 83 #define download_thread_job_set_completed(dt, size) \ 84 (dt)->download_data->completed = (size) 85 86 #define download_thread_job_set_speed(dt, sp) \ 87 (dt)->download_data->speed = (sp) 88 89 #define download_thread_job_set_percent(dt, p) \ 90 (dt)->download_data->percent = (p) 91 92 #define download_thread_job_set_retry(dt, n) \ 93 (dt)->download_data->n_retries = (n) 94 95 #define download_thread_job_set_message(dt, m) \ 96 download_set_message ((dt)->download_data, m) 97 98 #define download_thread_job_set_info_valid(dt, b) \ 99 (dt)->download_data->info_valid = (b) 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif /* End of __DOWNLOAD_THREAD_H */ 106 107