2008-12-09 19:46:00 +00:00
|
|
|
/* vim: set sw=3 ts=3 sts=3 expandtab: */
|
2008-11-03 14:56:30 +00:00
|
|
|
#include "ecdb.h"
|
2009-02-17 22:48:11 +00:00
|
|
|
|
|
|
|
typedef struct Erase_Data Erase_Data;
|
|
|
|
struct Erase_Data
|
|
|
|
{
|
|
|
|
Ecdb_Project *proj;
|
|
|
|
Ecdb_Page *page;
|
|
|
|
};
|
2008-11-03 14:56:30 +00:00
|
|
|
|
2008-11-12 16:06:29 +00:00
|
|
|
static void ecdb_erase_progress_handler(void *data, void *buffer,
|
2008-12-09 05:47:59 +00:00
|
|
|
unsigned int nbyte);
|
2008-11-12 16:06:29 +00:00
|
|
|
int ecdb_erase_finished(void *data, int type, void *event);
|
2009-02-17 19:16:38 +00:00
|
|
|
|
2008-12-09 01:12:16 +00:00
|
|
|
// FIXME Make this return an error code
|
2008-11-03 14:56:30 +00:00
|
|
|
int
|
2009-02-17 19:16:38 +00:00
|
|
|
ecdb_erase_disc(Ecdb_Erase_Project *proj, Ecdb_Page *page)
|
2008-11-03 14:56:30 +00:00
|
|
|
{
|
2008-12-09 05:47:59 +00:00
|
|
|
BurnDriveStatus disc_state;
|
2009-02-17 22:48:11 +00:00
|
|
|
pthread_t progress_update;
|
|
|
|
Erase_Data *data;
|
|
|
|
|
|
|
|
data = calloc(1, sizeof(Erase_Data));
|
|
|
|
if (!data)
|
|
|
|
{
|
2009-02-23 01:22:02 +00:00
|
|
|
EINA_ERROR_PWARN("ecdb_erase_disc: NULL data!\n");
|
2009-02-17 22:48:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
data->proj = ECDB_PROJECT(proj);
|
2009-02-17 19:16:38 +00:00
|
|
|
data->page = page;
|
2008-12-09 05:47:59 +00:00
|
|
|
|
|
|
|
disc_state = burn_disc_get_status(ECDB_PROJECT(proj)->drive->
|
|
|
|
tangible[0].drive);
|
2009-04-19 19:20:04 +00:00
|
|
|
if (((disc_state == BURN_DISC_FULL)
|
|
|
|
|| (disc_state == BURN_DISC_APPENDABLE))
|
|
|
|
&& (burn_disc_erasable(ECDB_PROJECT(proj)->drive->tangible[0].drive)))
|
2008-12-09 05:47:59 +00:00
|
|
|
{
|
2009-02-23 01:22:02 +00:00
|
|
|
EINA_ERROR_PINFO("Beginning to erase disc!\n");
|
2008-12-09 05:47:59 +00:00
|
|
|
ECDB_PROJECT(proj)->pipe = ecore_pipe_add(ecdb_erase_progress_handler,
|
2009-02-17 19:16:38 +00:00
|
|
|
data);
|
2008-12-09 05:47:59 +00:00
|
|
|
burn_disc_erase(ECDB_PROJECT(proj)->drive->tangible[0].drive,
|
|
|
|
proj->quick);
|
|
|
|
pthread_create(&progress_update, NULL, ecdb_drive_progress_update, proj);
|
|
|
|
pthread_detach(progress_update);
|
|
|
|
ECDB_PROJECT(proj)->ev_handler = ecore_event_handler_add
|
2009-02-17 19:16:38 +00:00
|
|
|
(ECDB_DRIVE_ACTION_FINISHED, ecdb_erase_finished, data);
|
2008-12-09 05:47:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-19 19:20:04 +00:00
|
|
|
EINA_ERROR_PINFO("Disc not suitable for erasing\n");
|
2008-12-09 05:47:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-11-03 14:56:30 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 15:56:34 +00:00
|
|
|
static void
|
2008-11-12 16:06:29 +00:00
|
|
|
ecdb_erase_progress_handler(void *data, void *buffer, unsigned int nbyte)
|
2008-11-03 15:56:34 +00:00
|
|
|
{
|
2008-12-09 05:47:59 +00:00
|
|
|
BurnProgress *p;
|
2009-02-17 22:48:11 +00:00
|
|
|
Evas_Object *swallow;
|
2009-02-17 19:16:38 +00:00
|
|
|
Erase_Data *edata;
|
2008-12-09 05:47:59 +00:00
|
|
|
static int last_sector = 0;
|
2008-12-26 05:52:47 +00:00
|
|
|
Edje_Message_Int_Set *progress_msg;
|
2008-12-09 05:47:59 +00:00
|
|
|
|
2009-02-23 01:22:02 +00:00
|
|
|
EINA_ERROR_PDBG("In progress handler, %d, %d\n", sizeof(BurnProgress),
|
|
|
|
nbyte);
|
2008-12-26 16:41:27 +00:00
|
|
|
if (nbyte != sizeof(BurnProgress))
|
2008-12-09 05:47:59 +00:00
|
|
|
{
|
|
|
|
ecore_event_add(ECDB_DRIVE_ACTION_FINISHED, NULL, NULL, NULL);
|
2009-02-23 01:22:02 +00:00
|
|
|
EINA_ERROR_PDBG("Adding event to queue.\n");
|
2008-12-09 05:47:59 +00:00
|
|
|
last_sector = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Libburn reports p->sector as being 0 right at the end of the job,
|
|
|
|
* so store the last sector and use that to determine the proper
|
|
|
|
* percentage/sector to set
|
|
|
|
*/
|
|
|
|
if (last_sector <= p->sector)
|
|
|
|
{
|
|
|
|
last_sector = p->sector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last_sector = p->sectors;
|
2009-02-17 22:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
edata = data;
|
|
|
|
if (!edata)
|
|
|
|
{
|
2009-02-23 01:22:02 +00:00
|
|
|
EINA_ERROR_PWARN("ecdb_erase_progress_handler: NULL edata!\n");
|
2009-02-17 22:48:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!edata->page) || (!edata->proj))
|
|
|
|
{
|
2009-02-23 01:22:02 +00:00
|
|
|
EINA_ERROR_PWARN("ecdb_erase_progress_handler: NULL page or proj!\n");
|
2009-02-17 22:48:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (edata->proj->type)
|
|
|
|
{
|
|
|
|
case ECDB_ERASE_PROJECT:
|
|
|
|
swallow = edata->page->erase;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-02-23 01:22:02 +00:00
|
|
|
EINA_ERROR_PWARN("ecdb_erase_progress_handler: "
|
|
|
|
"Unrecognized project type!\n");
|
2009-02-17 22:48:11 +00:00
|
|
|
return;
|
2008-12-09 05:47:59 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 19:16:38 +00:00
|
|
|
progress_msg = alloca(sizeof(Edje_Message_Int_Set) + (2 * sizeof(int)));
|
|
|
|
progress_msg->count = 3;
|
2008-12-26 05:52:47 +00:00
|
|
|
progress_msg->val[0] = (int)((double)(last_sector + 1) /
|
|
|
|
(double)p->sectors * 100.0);
|
|
|
|
progress_msg->val[1] = last_sector;
|
|
|
|
progress_msg->val[2] = p->sectors;
|
|
|
|
edje_object_message_send(swallow, EDJE_MESSAGE_INT_SET, 0, progress_msg);
|
2008-11-03 15:56:34 +00:00
|
|
|
}
|
2008-11-12 16:06:29 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
ecdb_erase_finished(void *data, int type, void *event)
|
2009-02-17 22:48:11 +00:00
|
|
|
{
|
2009-02-17 19:16:38 +00:00
|
|
|
Erase_Data *ed;
|
2008-12-09 05:47:59 +00:00
|
|
|
Ecdb_Erase_Project *proj;
|
2009-02-17 22:48:11 +00:00
|
|
|
|
|
|
|
ed = data;
|
|
|
|
proj = ECDB_ERASE(ed->proj);
|
2008-11-12 16:06:29 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
burn_drive_release(ECDB_PROJECT(proj)->drive->tangible[0].drive, 0);
|
|
|
|
burn_drive_info_free(ECDB_PROJECT(proj)->drive->tangible);
|
|
|
|
ecore_event_handler_del(ECDB_PROJECT(proj)->ev_handler);
|
2008-12-26 16:41:27 +00:00
|
|
|
ecore_pipe_del(ECDB_PROJECT(proj)->pipe);
|
2009-02-17 19:16:38 +00:00
|
|
|
ecdb_erase_cleanup(ed->page);
|
2009-02-17 22:48:11 +00:00
|
|
|
FREE(ed);
|
2008-11-12 16:06:29 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
return TRUE;
|
2008-11-12 16:06:29 +00:00
|
|
|
}
|
|
|
|
|