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 bf0361c8c9
commit 3069596f20
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)
{

View File

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

View File

@ -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;
};

View File

@ -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);
}