From 3069596f205baae9ee7a86fe3f35a1dcaa93c856 Mon Sep 17 00:00:00 2001 From: Jaime Thomas Date: Mon, 3 Nov 2008 15:56:34 +0000 Subject: [PATCH] Use ecore_pipe to communicate with the burn progress thread instead of the bad way before. --- ecdb/trunk/src/ecdb_burn.c | 49 ++++++++++++++---------------------- ecdb/trunk/src/ecdb_burn.h | 1 + ecdb/trunk/src/ecdb_common.h | 2 +- ecdb/trunk/src/ecdb_erase.c | 20 ++++++++++----- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/ecdb/trunk/src/ecdb_burn.c b/ecdb/trunk/src/ecdb_burn.c index 97a91ed..a6befb8 100644 --- a/ecdb/trunk/src/ecdb_burn.c +++ b/ecdb/trunk/src/ecdb_burn.c @@ -10,11 +10,10 @@ struct Burn_Data Ecdb_Project *proj; }; -void *_progress_update(void *d); -int _progress_gui_update(void *d); int ecdb_burn_finished(void *data, int type, void *event); int ecdb_burn_project_init(Ecdb_Burn_Project *proj); int ecdb_erase_project_init(Ecdb_Erase_Project *proj); +static void ecdb_burn_progress_handler(void *data, void *buffer, int nbyte); Ecdb_Burn_Project * ecdb_burn_project_new(void) @@ -140,9 +139,11 @@ ecdb_burn_project(Ecdb_Burn_Project *proj) burn_write_opts_free(opts); printf("Disc now burning\n"); - pthread_create(&progress_update, NULL, _progress_update, proj); + ECDB_PROJECT(proj)->pipe = ecore_pipe_add(ecdb_burn_progress_handler, + NULL); + pthread_create(&progress_update, NULL, ecdb_drive_progress_update, + proj); pthread_detach(progress_update); - ecore_timer_add(0.5, _progress_gui_update, proj); ECDB_PROJECT(proj)->ev_handler = ecore_event_handler_add (ECDB_DRIVE_ACTION_FINISHED, ecdb_burn_finished, data); @@ -150,20 +151,21 @@ ecdb_burn_project(Ecdb_Burn_Project *proj) return TRUE; } -/* TODO: Replace this with ecore_point */ -/* Event handlers */ +/* This function is pretty naive... Should probably update it at some time */ void * -_progress_update(void *d) +ecdb_drive_progress_update(void *data) { Ecdb_Project *proj; BurnProgress p; struct burn_drive *drive; - proj = d; + proj = data; if (!proj->drive->tangible) { printf("No tangible drive!\n"); + ecore_pipe_del(proj->pipe); + /* Call failure here */ pthread_exit(NULL); } drive = proj->drive->tangible[0].drive; @@ -174,43 +176,30 @@ _progress_update(void *d) proj->stat = burn_drive_get_status(drive, &p); if (proj->stat == BURN_DRIVE_SPAWNING) { - sleep(3); + sleep(1); continue; } else if (proj->stat == BURN_DRIVE_IDLE) { + ecore_pipe_del(proj->pipe); + /* Call the finished event handler here */ pthread_exit(NULL); break; } - proj->progress = p; - sleep(5); + ecore_pipe_write(proj->pipe, &p, sizeof(&p)); + sleep(1); } } -int -_progress_gui_update(void *data) +static void +ecdb_burn_progress_handler(void *data, void *buffer, int nbyte) { - Ecdb_Project *proj; + BurnProgress *p = buffer; - proj = data; - - if (proj->stat == BURN_DRIVE_IDLE) - { - /* These don't enjoy being called before - * ecore_main_loop_begin - */ - ecore_event_add(ECDB_DRIVE_ACTION_FINISHED, data, NULL, NULL); - printf("Burn finished\n"); - return ECORE_CALLBACK_CANCEL; - } - else - ecore_event_add(ECDB_DRIVE_ACTION_UPDATE, data, NULL, NULL); - - return ECORE_CALLBACK_RENEW; + printf("Sector %d of %d\n", p->sector, p->sectors); } - int ecdb_burn_finished(void *data, int type, void *event) { diff --git a/ecdb/trunk/src/ecdb_burn.h b/ecdb/trunk/src/ecdb_burn.h index 6423c87..f6239e9 100644 --- a/ecdb/trunk/src/ecdb_burn.h +++ b/ecdb/trunk/src/ecdb_burn.h @@ -4,5 +4,6 @@ int ecdb_burn_project(Ecdb_Burn_Project *proj); Ecdb_Burn_Project *ecdb_burn_project_new(void); void ecdb_burn_project_destroy(Ecdb_Burn_Project *proj); +void *ecdb_drive_progress_update(void *data); #endif diff --git a/ecdb/trunk/src/ecdb_common.h b/ecdb/trunk/src/ecdb_common.h index 3e90428..a386a68 100644 --- a/ecdb/trunk/src/ecdb_common.h +++ b/ecdb/trunk/src/ecdb_common.h @@ -55,9 +55,9 @@ struct _Ecdb_Project_Info { /* The drive reference */ Ecdb_Drive_Info *drive; - BurnProgress progress; BurnDriveStatus stat; Ecore_Event_Handler *ev_handler; + Ecore_Pipe *pipe; unsigned int type; }; diff --git a/ecdb/trunk/src/ecdb_erase.c b/ecdb/trunk/src/ecdb_erase.c index 61cfe1a..3cd2d39 100644 --- a/ecdb/trunk/src/ecdb_erase.c +++ b/ecdb/trunk/src/ecdb_erase.c @@ -1,6 +1,7 @@ #include "ecdb.h" int ecdb_erase_project_init(Ecdb_Erase_Project *proj); +static void ecdb_erase_progress_handler(void *data, void *buffer, int nbyte); Ecdb_Erase_Project * ecdb_erase_project_new(void) @@ -44,7 +45,7 @@ int ecdb_erase_disc(Ecdb_Erase_Project *proj) { BurnDriveStatus disc_state; - //pthread_t progress_update; + pthread_t progress_update; disc_state = burn_disc_get_status(ECDB_PROJECT(proj)->drive-> tangible[0].drive); @@ -67,15 +68,15 @@ ecdb_erase_disc(Ecdb_Erase_Project *proj) else if (disc_state == BURN_DISC_FULL || BURN_DISC_APPENDABLE) { printf("Beginning to erase disc!\n"); + ECDB_PROJECT(proj)->pipe = ecore_pipe_add + (ecdb_erase_progress_handler, + NULL); burn_disc_erase(ECDB_PROJECT(proj)->drive-> tangible[0].drive, proj->quick); - /* - pthread_create(&progress_update, NULL, _progress_update, - proj); + pthread_create(&progress_update, NULL, + ecdb_drive_progress_update, proj); pthread_detach(progress_update); - ecore_timer_add(0.5, _progress_gui_update, proj); - */ return TRUE; } else @@ -85,3 +86,10 @@ ecdb_erase_disc(Ecdb_Erase_Project *proj) } } +static void +ecdb_erase_progress_handler(void *data, void *buffer, int nbyte) +{ + BurnProgress *p = buffer; + + printf("Sector %d of %d\n", p->sector, p->sectors); +}