Use ecore_pipe to communicate with the burn progress thread instead of the bad way before.
This commit is contained in:
parent
7b07c374a1
commit
7b840adb90
@ -10,11 +10,10 @@ struct Burn_Data
|
|||||||
Ecdb_Project *proj;
|
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_finished(void *data, int type, void *event);
|
||||||
int ecdb_burn_project_init(Ecdb_Burn_Project *proj);
|
int ecdb_burn_project_init(Ecdb_Burn_Project *proj);
|
||||||
int ecdb_erase_project_init(Ecdb_Erase_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 *
|
||||||
ecdb_burn_project_new(void)
|
ecdb_burn_project_new(void)
|
||||||
@ -140,9 +139,11 @@ ecdb_burn_project(Ecdb_Burn_Project *proj)
|
|||||||
burn_write_opts_free(opts);
|
burn_write_opts_free(opts);
|
||||||
|
|
||||||
printf("Disc now burning\n");
|
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);
|
pthread_detach(progress_update);
|
||||||
ecore_timer_add(0.5, _progress_gui_update, proj);
|
|
||||||
ECDB_PROJECT(proj)->ev_handler = ecore_event_handler_add
|
ECDB_PROJECT(proj)->ev_handler = ecore_event_handler_add
|
||||||
(ECDB_DRIVE_ACTION_FINISHED, ecdb_burn_finished,
|
(ECDB_DRIVE_ACTION_FINISHED, ecdb_burn_finished,
|
||||||
data);
|
data);
|
||||||
@ -150,20 +151,21 @@ ecdb_burn_project(Ecdb_Burn_Project *proj)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Replace this with ecore_point */
|
/* This function is pretty naive... Should probably update it at some time */
|
||||||
/* Event handlers */
|
|
||||||
void *
|
void *
|
||||||
_progress_update(void *d)
|
ecdb_drive_progress_update(void *data)
|
||||||
{
|
{
|
||||||
Ecdb_Project *proj;
|
Ecdb_Project *proj;
|
||||||
BurnProgress p;
|
BurnProgress p;
|
||||||
struct burn_drive *drive;
|
struct burn_drive *drive;
|
||||||
|
|
||||||
proj = d;
|
proj = data;
|
||||||
|
|
||||||
if (!proj->drive->tangible)
|
if (!proj->drive->tangible)
|
||||||
{
|
{
|
||||||
printf("No tangible drive!\n");
|
printf("No tangible drive!\n");
|
||||||
|
ecore_pipe_del(proj->pipe);
|
||||||
|
/* Call failure here */
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
drive = proj->drive->tangible[0].drive;
|
drive = proj->drive->tangible[0].drive;
|
||||||
@ -174,42 +176,29 @@ _progress_update(void *d)
|
|||||||
proj->stat = burn_drive_get_status(drive, &p);
|
proj->stat = burn_drive_get_status(drive, &p);
|
||||||
if (proj->stat == BURN_DRIVE_SPAWNING)
|
if (proj->stat == BURN_DRIVE_SPAWNING)
|
||||||
{
|
{
|
||||||
sleep(3);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (proj->stat == BURN_DRIVE_IDLE)
|
else if (proj->stat == BURN_DRIVE_IDLE)
|
||||||
{
|
{
|
||||||
|
ecore_pipe_del(proj->pipe);
|
||||||
|
/* Call the finished event handler here */
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
proj->progress = p;
|
ecore_pipe_write(proj->pipe, &p, sizeof(&p));
|
||||||
sleep(5);
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void
|
||||||
_progress_gui_update(void *data)
|
ecdb_burn_progress_handler(void *data, void *buffer, int nbyte)
|
||||||
{
|
{
|
||||||
Ecdb_Project *proj;
|
BurnProgress *p = buffer;
|
||||||
|
|
||||||
proj = data;
|
printf("Sector %d of %d\n", p->sector, p->sectors);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ecdb_burn_finished(void *data, int type, void *event)
|
ecdb_burn_finished(void *data, int type, void *event)
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
int ecdb_burn_project(Ecdb_Burn_Project *proj);
|
int ecdb_burn_project(Ecdb_Burn_Project *proj);
|
||||||
Ecdb_Burn_Project *ecdb_burn_project_new(void);
|
Ecdb_Burn_Project *ecdb_burn_project_new(void);
|
||||||
void ecdb_burn_project_destroy(Ecdb_Burn_Project *proj);
|
void ecdb_burn_project_destroy(Ecdb_Burn_Project *proj);
|
||||||
|
void *ecdb_drive_progress_update(void *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,9 +55,9 @@ struct _Ecdb_Project_Info
|
|||||||
{
|
{
|
||||||
/* The drive reference */
|
/* The drive reference */
|
||||||
Ecdb_Drive_Info *drive;
|
Ecdb_Drive_Info *drive;
|
||||||
BurnProgress progress;
|
|
||||||
BurnDriveStatus stat;
|
BurnDriveStatus stat;
|
||||||
Ecore_Event_Handler *ev_handler;
|
Ecore_Event_Handler *ev_handler;
|
||||||
|
Ecore_Pipe *pipe;
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "ecdb.h"
|
#include "ecdb.h"
|
||||||
|
|
||||||
int ecdb_erase_project_init(Ecdb_Erase_Project *proj);
|
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 *
|
||||||
ecdb_erase_project_new(void)
|
ecdb_erase_project_new(void)
|
||||||
@ -44,7 +45,7 @@ int
|
|||||||
ecdb_erase_disc(Ecdb_Erase_Project *proj)
|
ecdb_erase_disc(Ecdb_Erase_Project *proj)
|
||||||
{
|
{
|
||||||
BurnDriveStatus disc_state;
|
BurnDriveStatus disc_state;
|
||||||
//pthread_t progress_update;
|
pthread_t progress_update;
|
||||||
|
|
||||||
disc_state = burn_disc_get_status(ECDB_PROJECT(proj)->drive->
|
disc_state = burn_disc_get_status(ECDB_PROJECT(proj)->drive->
|
||||||
tangible[0].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)
|
else if (disc_state == BURN_DISC_FULL || BURN_DISC_APPENDABLE)
|
||||||
{
|
{
|
||||||
printf("Beginning to erase disc!\n");
|
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->
|
burn_disc_erase(ECDB_PROJECT(proj)->drive->
|
||||||
tangible[0].drive, proj->quick);
|
tangible[0].drive, proj->quick);
|
||||||
|
|
||||||
/*
|
pthread_create(&progress_update, NULL,
|
||||||
pthread_create(&progress_update, NULL, _progress_update,
|
ecdb_drive_progress_update, proj);
|
||||||
proj);
|
|
||||||
pthread_detach(progress_update);
|
pthread_detach(progress_update);
|
||||||
ecore_timer_add(0.5, _progress_gui_update, proj);
|
|
||||||
*/
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user