legacy/experimental/ecdb/trunk/src/ecdb_erase.c

119 lines
3.5 KiB
C
Raw Normal View History

/* vim: set sw=3 ts=3 sts=3 expandtab: */
2008-11-03 14:56:30 +00:00
#include "ecdb.h"
static void ecdb_erase_progress_handler(void *data, void *buffer,
2008-12-09 05:47:59 +00:00
unsigned int nbyte);
int ecdb_erase_finished(void *data, int type, void *event);
2008-12-09 05:47:59 +00:00
// FIXME Make this return an error code
2008-11-03 14:56:30 +00:00
int
ecdb_erase_disc(Ecdb_Erase_Project *proj)
{
2008-12-09 05:47:59 +00:00
BurnDriveStatus disc_state;
pthread_t progress_update;
disc_state = burn_disc_get_status(ECDB_PROJECT(proj)->drive->
tangible[0].drive);
if (disc_state == BURN_DISC_BLANK)
{
printf("Disc is already blank!\n");
return FALSE;
}
else if (disc_state == BURN_DISC_EMPTY)
{
printf("No disc!\n");
return FALSE;
}
else if (!burn_disc_erasable(ECDB_PROJECT(proj)->drive->
tangible[0].drive))
{
printf("Not able to erase!\n");
return FALSE;
}
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,
proj);
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
(ECDB_DRIVE_ACTION_FINISHED, ecdb_erase_finished, proj);
return TRUE;
}
else
{
printf("Not of erasable type\n");
return FALSE;
}
2008-11-03 14:56:30 +00:00
}
static void
ecdb_erase_progress_handler(void *data, void *buffer, unsigned int nbyte)
{
2008-12-09 05:47:59 +00:00
BurnProgress *p;
Evas_Object *swallow;
static int last_sector = 0;
Edje_Message_Int_Set *progress_msg;
2008-12-09 05:47:59 +00:00
printf("In progress handler, %d, %d\n", sizeof(BurnProgress), nbyte);
if (nbyte != sizeof(BurnProgress))
2008-12-09 05:47:59 +00:00
{
ecore_event_add(ECDB_DRIVE_ACTION_FINISHED, NULL, NULL, NULL);
printf("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;
}
swallow = evas_object_name_find(ecore_evas_get(em->main_win_ee),
"erase_page");
progress_msg = alloca(sizeof(Edje_Message_Int_Set) + (4 * sizeof(int)));
progress_msg->count = 5;
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;
progress_msg->val[3] = (int)p->buffer_available;
progress_msg->val[4] = (int)p->buffer_capacity;
edje_object_message_send(swallow, EDJE_MESSAGE_INT_SET, 0, progress_msg);
}
int
ecdb_erase_finished(void *data, int type, void *event)
{
2008-12-09 05:47:59 +00:00
Ecdb_Erase_Project *proj;
2008-12-09 05:47:59 +00:00
proj = data;
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);
ecore_pipe_del(ECDB_PROJECT(proj)->pipe);
2008-12-09 05:47:59 +00:00
ecdb_erase_project_destroy(proj);
ecdb_erase_cleanup();
2008-12-09 05:47:59 +00:00
return TRUE;
}