Proper inheritance, etc

This commit is contained in:
Jaime Thomas 2008-05-15 00:14:33 +00:00
parent 8485d87d21
commit 2bb97ae4f9
11 changed files with 302 additions and 138 deletions

View File

@ -7,7 +7,8 @@ ecdb_SOURCES = \
ecdb_drives.c ecdb_drives.h \
ecdb_image.c ecdb_image.h \
ecdb_burn.c ecdb_burn.h \
ecdb_misc.c ecdb_misc.h
ecdb_misc.c ecdb_misc.h \
ecdb_common.h
ecdb_CFLAGS = @ECDB_CFLAGS@
ecdb_LDADD = @ECDB_LIBS@

View File

@ -11,7 +11,6 @@ int ecdb_setup();
int
main(int argc, char **argv)
{
Ecdb_Project *proj;
int i;
int ret = 0;
@ -38,7 +37,9 @@ main(int argc, char **argv)
ecdb_print_drive_info();
ecdb_burn_init();
proj = ecdb_project_new();
/* Start testing */
Ecdb_Burn_Project *proj;
proj = ecdb_burn_project_new();
i = 1;
while ((i < argc) && (argv))
@ -47,18 +48,18 @@ main(int argc, char **argv)
i++;
}
proj->simulate = TRUE;
proj->publisher_id = proj->data_preparer_id = proj->system_id =
proj->application_id = proj->copywrite_id = proj->abstract_id =
proj->biblio_id = "ecdb";
proj->publisher_id = proj->data_preparer_id = proj->system_id =
proj->application_id = proj->copywrite_id =
proj->abstract_id = proj->biblio_id = "ecdb";
if (ecdb_aquire_drive(proj, 0))
if (!ecdb_aquire_drive(ECDB_PROJECT(proj), 0))
{
printf("Couldn't grab drive!\n");
ret = 1;
goto SHUTDOWN;
}
if (ecdb_burn_project(proj))
if (!ecdb_burn_project(proj))
{
printf("Burn was unsuccessful\n");
ret = 1;
@ -73,7 +74,6 @@ SHUTDOWN:
burn_finish();
ecore_shutdown();
ecore_file_shutdown();
ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL);
printf("Program Done\n");
return ret;
};

View File

@ -24,19 +24,8 @@
if (dat) { free(dat); dat = NULL; } \
}
/* Typdefs */
typedef struct burn_source BurnSource;
typedef struct burn_disc BurnDisc;
typedef struct burn_session BurnSession;
typedef struct burn_write_opts BurnWriteOpts;
typedef struct burn_track BurnTrack;
typedef struct burn_progress BurnProgress;
typedef struct burn_drive_info BurnDriveInfo;
typedef enum burn_drive_status BurnDriveStatus;
/* ECDB Global Variables */
typedef struct _Ecdb_Main Ecdb_Main;
struct _Ecdb_Main
{
Ecore_List *projects;
@ -45,86 +34,12 @@ struct _Ecdb_Main
extern Ecdb_Main *em;
typedef struct _Ecdb_Drive_Info Ecdb_Drive_Info;
struct _Ecdb_Drive_Info
{
/* Speeds */
int *read_speeds;
int *write_speeds;
/* Profiles */
char *profile_name;
int profile_loaded;
/* Drive info */
char *vendor;
char *product;
char *revision;
char *location;
unsigned char read_dvdram:1;
unsigned char read_dvdr:1;
unsigned char read_dvdrom:1;
unsigned char read_cdr:1;
unsigned char read_cdrw:1;
unsigned char write_dvdram:1;
unsigned char write_dvdr:1;
unsigned char write_cdr:1;
unsigned char write_simulate:1;
BurnDriveInfo *tangible;
};
typedef struct _Ecdb_Project_Info Ecdb_Project;
struct _Ecdb_Project_Info
{
/* Files are important here */
Ecore_List *files;
/* Ids */
char *volume_id;
char *publisher_id;
char *data_preparer_id;
char *system_id;
char *application_id;
char *copywrite_id;
char *abstract_id;
char *biblio_id;
/* iso options */
unsigned char iso_level:1;
unsigned char use_joliet:1;
unsigned char use_rockridge:1;
unsigned char follow_symlinks:1;
unsigned char ignore_hidden:1;
unsigned char ignore_special:1;
unsigned char iso1990:1;
/* burn options */
unsigned char opc:1;
unsigned char multi:1;
unsigned char simulate:1;
unsigned char underrun_proof:1;
int speed;
/* burn stuff */
int fifo_chunksize;
int fifo_chunks;
int burn_mode;
/* The drive reference */
Ecdb_Drive_Info *drive;
BurnProgress progress;
BurnDriveStatus stat;
};
/* Callbacks */
extern int ECDB_DRIVE_ACTION_FINISHED;
extern int ECDB_DRIVE_ACTION_BEGUN;
extern int ECDB_DRIVE_ACTION_UPDATE;
#include "ecdb_common.h"
#include "ecdb_drives.h"
#include "ecdb_image.h"
#include "ecdb_burn.h"

View File

@ -13,10 +13,77 @@ struct Burn_Data
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);
Ecdb_Burn_Project *
ecdb_burn_project_new(void)
{
Ecdb_Burn_Project *proj;
proj = calloc(1, sizeof(Ecdb_Burn_Project));
if (!proj)
return NULL;
if (!ecdb_burn_project_init(proj))
{
FREE(proj);
return NULL;
}
return proj;
}
/* Event handlers */
int
ecdb_burn_project(Ecdb_Project *proj)
ecdb_burn_project_init(Ecdb_Burn_Project *proj)
{
if (!ecdb_project_init(ECDB_PROJECT(proj)))
return FALSE;
/* Create some sane defaults */
proj->burn_mode = BURN_MODE1;
proj->fifo_chunksize = 2048;
proj->fifo_chunks = 2048;
proj->underrun_proof = TRUE;
proj->opc = TRUE;
proj->multi = TRUE;
proj->files = ecore_list_new();
return TRUE;
}
Ecdb_Erase_Project *
ecdb_erase_project_new(void)
{
Ecdb_Erase_Project *proj;
proj = calloc(1, sizeof(Ecdb_Erase_Project));
if (!proj)
return NULL;
if (!ecdb_erase_project_init(proj))
{
FREE(proj);
return NULL;
}
return proj;
}
int
ecdb_erase_project_init(Ecdb_Erase_Project *proj)
{
if (!ecdb_project_init(ECDB_PROJECT(proj)))
return FALSE;
/* Proper defaults */
proj->quick = TRUE;
proj->format = FALSE;
return TRUE;
}
/* Erase and Burn Function */
int
ecdb_burn_project(Ecdb_Burn_Project *proj)
{
char reasons[BURN_REASONS_LEN];
int padding, i;
@ -28,9 +95,14 @@ ecdb_burn_project(Ecdb_Project *proj)
i = 0;
data = calloc(1, sizeof(Burn_Data));
if (!data)
{
printf("Error: Cannot create burn data structure!\n");
return FALSE;
}
data->sources = ecore_list_new();
data->tracks = ecore_list_new();
data->proj = proj;
data->proj = ECDB_PROJECT(proj);
if (proj->burn_mode != BURN_AUDIO)
padding = 300*1024;
@ -48,7 +120,7 @@ ecdb_burn_project(Ecdb_Project *proj)
{
printf("Error: Cannot attach source object to track "
"object!\n");
return 1;
return FALSE;
}
burn_session_add_track(data->session, track, BURN_POS_END);
@ -60,16 +132,18 @@ ecdb_burn_project(Ecdb_Project *proj)
if (!i)
{
printf("Failed to add any files to burn disc!\n");
return 1;
return FALSE;
}
opts = burn_write_opts_new(proj->drive->tangible[0].drive);
opts = burn_write_opts_new(ECDB_PROJECT(proj)->drive->
tangible[0].drive);
burn_write_opts_set_perform_opc(opts, proj->opc);
burn_write_opts_set_multi(opts, proj->multi);
if (proj->simulate)
printf("Simulating Burn!\n");
burn_write_opts_set_simulate(opts, proj->simulate);
burn_drive_set_speed(proj->drive->tangible->drive, 0, proj->speed);
burn_drive_set_speed(ECDB_PROJECT(proj)->drive->tangible->drive, 0,
proj->speed);
burn_write_opts_set_underrun_proof(opts, proj->underrun_proof);
printf("Searching for burn mode\n");
@ -78,20 +152,62 @@ ecdb_burn_project(Ecdb_Project *proj)
{
printf("Error: Failed to find a suitable write mode for "
"disc!\n");
return 1;
return FALSE;
}
burn_disc_write(opts, data->disc);
burn_write_opts_free(opts);
printf("Disc now burning\n");
pthread_create(&progress_update, NULL, _progress_update, data);
pthread_create(&progress_update, NULL, _progress_update, proj);
pthread_detach(progress_update);
ecore_timer_add(0.5, _progress_gui_update, data);
ecore_timer_add(0.5, _progress_gui_update, proj);
ecore_event_handler_add(ECDB_DRIVE_ACTION_FINISHED, ecdb_burn_finished,
data);
return 0;
return TRUE;
}
int
ecdb_erase_disc(Ecdb_Erase_Project *proj)
{
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");
burn_disc_erase(ECDB_PROJECT(proj)->drive->
tangible[0].drive, proj->quick);
pthread_create(&progress_update, NULL, _progress_update,
proj);
pthread_detach(progress_update);
ecore_timer_add(0.5, _progress_gui_update, proj);
return TRUE;
}
else
{
printf("Not of erasable type\n");
return FALSE;
}
}
/* Hopefully at some point EFL will become thread-safe, or ecore_timer will
@ -99,38 +215,39 @@ ecdb_burn_project(Ecdb_Project *proj)
* do away with this.
*/
/* Event handlers */
void *
_progress_update(void *d)
{
Burn_Data *data;
Ecdb_Project *proj;
BurnProgress p;
struct burn_drive *drive;
data = d;
proj = d;
if (!data->proj->drive->tangible)
if (!proj->drive->tangible)
{
printf("No tangible drive!\n");
pthread_exit(NULL);
}
drive = data->proj->drive->tangible[0].drive;
drive = proj->drive->tangible[0].drive;
printf("Progress update active\n");
while (TRUE)
{
data->proj->stat = burn_drive_get_status(drive, &p);
if (data->proj->stat == BURN_DRIVE_SPAWNING)
proj->stat = burn_drive_get_status(drive, &p);
if (proj->stat == BURN_DRIVE_SPAWNING)
{
sleep(3);
continue;
}
else if (data->proj->stat == BURN_DRIVE_IDLE)
else if (proj->stat == BURN_DRIVE_IDLE)
{
pthread_exit(NULL);
break;
}
data->proj->progress = p;
proj->progress = p;
sleep(5);
}
}
@ -138,18 +255,23 @@ _progress_update(void *d)
int
_progress_gui_update(void *data)
{
Burn_Data *d;
Ecdb_Project *proj;
d = data;
proj = data;
if (d->proj->stat == BURN_DRIVE_IDLE)
if (proj->stat == BURN_DRIVE_IDLE)
{
ecore_event_add(ECDB_DRIVE_ACTION_FINISHED, NULL, NULL, data);
/* These don't enjoy being called before
* ecore_main_loop_bugin
*/
//ecore_event_add(ECDB_DRIVE_ACTION_FINISHED, data, NULL, NULL);
ecore_event_add(ECDB_DRIVE_ACTION_FINISHED, NULL, NULL, NULL);
printf("Burn finished\n");
return ECORE_CALLBACK_CANCEL;
}
else
ecore_event_add(ECDB_DRIVE_ACTION_UPDATE, NULL, NULL, data);
ecore_event_add(ECDB_DRIVE_ACTION_UPDATE, NULL, NULL, NULL);
//ecore_event_add(ECDB_DRIVE_ACTION_UPDATE, data, NULL, NULL);
return ECORE_CALLBACK_RENEW;
}
@ -184,11 +306,13 @@ ecdb_burn_finished(void *data, int type, void *event)
printf("Releasing drive\n");
burn_drive_release(proj->proj->drive->tangible[0].drive, 1);
burn_drive_info_free(proj->proj->drive->tangible);
printf("Ze brun hath finish\n");
printf("Burn Complete\n");
/* To be removed from here at some point */
ecore_list_destroy(proj->proj->files);
FREE(proj->proj);
Ecdb_Burn_Project *t;
t = ECDB_BURN(proj->proj);
ecore_list_destroy(t->files);
FREE(t);
FREE(proj);
ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL);
return 0;

View File

@ -1,6 +1,10 @@
#ifndef ECDB_BURN_H
#define ECDB_BURN_H
int ecdb_burn_project(Ecdb_Project *proj);
int ecdb_burn_project(Ecdb_Burn_Project *proj);
int ecdb_erase_disc(Ecdb_Erase_Project *proj);
Ecdb_Burn_Project *ecdb_burn_project_new(void);
Ecdb_Erase_Project *ecdb_erase_project_new(void);
#endif

View File

@ -0,0 +1,114 @@
#ifndef ECDB_COMMON_H
#define ECDB_COMMON_H
/* Typdefs */
typedef struct burn_source BurnSource;
typedef struct burn_disc BurnDisc;
typedef struct burn_session BurnSession;
typedef struct burn_write_opts BurnWriteOpts;
typedef struct burn_track BurnTrack;
typedef struct burn_progress BurnProgress;
typedef struct burn_drive_info BurnDriveInfo;
typedef enum burn_drive_status BurnDriveStatus;
typedef struct _Ecdb_Drive_Info Ecdb_Drive_Info;
struct _Ecdb_Drive_Info
{
/* Speeds */
int *read_speeds;
int *write_speeds;
/* Profiles */
char *profile_name;
int profile_loaded;
/* Drive info */
char *vendor;
char *product;
char *revision;
char *location;
unsigned char read_dvdram:1;
unsigned char read_dvdr:1;
unsigned char read_dvdrom:1;
unsigned char read_cdr:1;
unsigned char read_cdrw:1;
unsigned char write_dvdram:1;
unsigned char write_dvdr:1;
unsigned char write_cdr:1;
unsigned char write_simulate:1;
BurnDriveInfo *tangible;
};
typedef struct _Ecdb_Project_Info Ecdb_Project;
struct _Ecdb_Project_Info
{
/* The drive reference */
Ecdb_Drive_Info *drive;
BurnProgress progress;
BurnDriveStatus stat;
};
/* Typecast a pointer to an Ecdb_Project */
#define ECDB_PROJECT(proj) ((Ecdb_Project *) proj)
typedef struct _Ecdb_Burn_Project Ecdb_Burn_Project;
struct _Ecdb_Burn_Project
{
/* Inherit from normal project */
Ecdb_Project proj;
/* Files are important here */
Ecore_List *files;
/* Ids */
char *volume_id;
char *publisher_id;
char *data_preparer_id;
char *system_id;
char *application_id;
char *copywrite_id;
char *abstract_id;
char *biblio_id;
/* iso options */
unsigned char iso_level:1;
unsigned char use_joliet:1;
unsigned char use_rockridge:1;
unsigned char follow_symlinks:1;
unsigned char ignore_hidden:1;
unsigned char ignore_special:1;
unsigned char iso1990:1;
/* burn options */
unsigned char opc:1;
unsigned char multi:1;
unsigned char simulate:1;
unsigned char underrun_proof:1;
int speed;
/* burn stuff */
int fifo_chunksize;
int fifo_chunks;
int burn_mode;
};
/* Typecast a pointer to an Ecdb_Burn_Project */
#define ECDB_BURN(proj) ((Ecdb_Burn_Project *) proj)
typedef struct _Ecdb_Erase_Project Ecdb_Erase_Project;
struct _Ecdb_Erase_Project
{
/* Inherit from normal project */
Ecdb_Project proj;
/* Speed */
unsigned char quick:1;
unsigned char format:1;
};
/* Typecast a pointer to an Ecdb_Erase_Project */
#define ECDB_ERASE(proj) ((Ecdb_Erase_Project *) proj)
#endif

View File

@ -146,18 +146,18 @@ ecdb_aquire_drive(Ecdb_Project *proj, unsigned int idx)
if (burn_drive_convert_fs_adr(info->location, adr) <= 0)
{
printf("Error: Address doesn't provide cd burner!\n");
return 1;
return FALSE;
}
if (burn_drive_scan_and_grab(&info->tangible, adr, 1) > 0)
{
proj->drive = info;
return 0;
return TRUE;
}
else
{
info->tangible = NULL;
return 1;
return FALSE;
}
}

View File

@ -3,7 +3,7 @@
/* Some limitations here need to be worked out
* Handle: audio, etc */
BurnSource *
ecdb_image_project(Ecdb_Project *proj)
ecdb_image_project(Ecdb_Burn_Project *proj)
{
IsoImage *image;
IsoDir *root;
@ -118,6 +118,7 @@ ecdb_image_project(Ecdb_Project *proj)
/* I can't call this now, as it destroys the libiso_msgr before the
* library is finished - I'll just init and finish once...
*/
//iso_finish();
efreet_mime_shutdown();

View File

@ -1,7 +1,7 @@
#ifndef ECDB_IMAGE_H
#define ECDB_IMAGE_H
BurnSource *ecdb_image_project(Ecdb_Project *proj);
BurnSource *ecdb_image_project(Ecdb_Burn_Project *proj);
#endif

View File

@ -6,20 +6,24 @@ ecdb_project_new(void)
Ecdb_Project *proj;
proj = calloc(1, sizeof(Ecdb_Project));
proj->files = ecore_list_new();
ecore_list_append(em->projects, proj);
/* Create some sane defaults */
proj->burn_mode = BURN_MODE1;
proj->fifo_chunksize = 2048;
proj->fifo_chunks = 2048;
proj->underrun_proof = TRUE;
proj->opc = TRUE;
proj->multi = TRUE;
if (!proj)
return NULL;
if (!ecdb_project_init(proj))
{
FREE(proj);
return NULL;
}
return proj;
}
int
ecdb_project_init(Ecdb_Project *proj)
{
ecore_list_append(em->projects, proj);
return TRUE;
}
int
ecdb_shutdown(void *data, int type, void *event)
{

View File

@ -2,6 +2,7 @@
#define ECDB_MISC_H
Ecdb_Project *ecdb_project_new(void);
int ecdb_project_init(Ecdb_Project *proj);
int ecdb_shutdown(void *data, int type, void *event);
void ecdb_burn_init(void);
void ecdb_image_init(void);