Use ecore_pipe to communicate with the burn progress thread instead of the bad way before.

This commit is contained in:
Jaime Thomas
2008-11-03 15:56:34 +00:00
parent 7b07c374a1
commit 7b840adb90
4 changed files with 35 additions and 37 deletions

View File

@@ -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)
{