Proper inheritance, etc

This commit is contained in:
Jaime Thomas 2008-05-15 00:14:33 +00:00
parent 0b2157dff6
commit fe3e1cc9f0
11 changed files with 302 additions and 138 deletions

View File

@ -7,7 +7,8 @@ ecdb_SOURCES = \
ecdb_drives.c ecdb_drives.h \ ecdb_drives.c ecdb_drives.h \
ecdb_image.c ecdb_image.h \ ecdb_image.c ecdb_image.h \
ecdb_burn.c ecdb_burn.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_CFLAGS = @ECDB_CFLAGS@
ecdb_LDADD = @ECDB_LIBS@ ecdb_LDADD = @ECDB_LIBS@

View File

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

View File

@ -24,19 +24,8 @@
if (dat) { free(dat); dat = NULL; } \ 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 */ /* ECDB Global Variables */
typedef struct _Ecdb_Main Ecdb_Main; typedef struct _Ecdb_Main Ecdb_Main;
struct _Ecdb_Main struct _Ecdb_Main
{ {
Ecore_List *projects; Ecore_List *projects;
@ -45,86 +34,12 @@ struct _Ecdb_Main
extern Ecdb_Main *em; 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 */ /* Callbacks */
extern int ECDB_DRIVE_ACTION_FINISHED; extern int ECDB_DRIVE_ACTION_FINISHED;
extern int ECDB_DRIVE_ACTION_BEGUN; extern int ECDB_DRIVE_ACTION_BEGUN;
extern int ECDB_DRIVE_ACTION_UPDATE; extern int ECDB_DRIVE_ACTION_UPDATE;
#include "ecdb_common.h"
#include "ecdb_drives.h" #include "ecdb_drives.h"
#include "ecdb_image.h" #include "ecdb_image.h"
#include "ecdb_burn.h" #include "ecdb_burn.h"

View File

@ -13,10 +13,77 @@ struct Burn_Data
void *_progress_update(void *d); void *_progress_update(void *d);
int _progress_gui_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_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 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]; char reasons[BURN_REASONS_LEN];
int padding, i; int padding, i;
@ -28,9 +95,14 @@ ecdb_burn_project(Ecdb_Project *proj)
i = 0; i = 0;
data = calloc(1, sizeof(Burn_Data)); data = calloc(1, sizeof(Burn_Data));
if (!data)
{
printf("Error: Cannot create burn data structure!\n");
return FALSE;
}
data->sources = ecore_list_new(); data->sources = ecore_list_new();
data->tracks = ecore_list_new(); data->tracks = ecore_list_new();
data->proj = proj; data->proj = ECDB_PROJECT(proj);
if (proj->burn_mode != BURN_AUDIO) if (proj->burn_mode != BURN_AUDIO)
padding = 300*1024; padding = 300*1024;
@ -48,7 +120,7 @@ ecdb_burn_project(Ecdb_Project *proj)
{ {
printf("Error: Cannot attach source object to track " printf("Error: Cannot attach source object to track "
"object!\n"); "object!\n");
return 1; return FALSE;
} }
burn_session_add_track(data->session, track, BURN_POS_END); burn_session_add_track(data->session, track, BURN_POS_END);
@ -60,16 +132,18 @@ ecdb_burn_project(Ecdb_Project *proj)
if (!i) if (!i)
{ {
printf("Failed to add any files to burn disc!\n"); 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_perform_opc(opts, proj->opc);
burn_write_opts_set_multi(opts, proj->multi); burn_write_opts_set_multi(opts, proj->multi);
if (proj->simulate) if (proj->simulate)
printf("Simulating Burn!\n"); printf("Simulating Burn!\n");
burn_write_opts_set_simulate(opts, proj->simulate); 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); burn_write_opts_set_underrun_proof(opts, proj->underrun_proof);
printf("Searching for burn mode\n"); 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 " printf("Error: Failed to find a suitable write mode for "
"disc!\n"); "disc!\n");
return 1; return FALSE;
} }
burn_disc_write(opts, data->disc); burn_disc_write(opts, data->disc);
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, data); pthread_create(&progress_update, NULL, _progress_update, proj);
pthread_detach(progress_update); 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, ecore_event_handler_add(ECDB_DRIVE_ACTION_FINISHED, ecdb_burn_finished,
data); 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 /* 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. * do away with this.
*/ */
/* Event handlers */
void * void *
_progress_update(void *d) _progress_update(void *d)
{ {
Burn_Data *data; Ecdb_Project *proj;
BurnProgress p; BurnProgress p;
struct burn_drive *drive; struct burn_drive *drive;
data = d; proj = d;
if (!data->proj->drive->tangible) if (!proj->drive->tangible)
{ {
printf("No tangible drive!\n"); printf("No tangible drive!\n");
pthread_exit(NULL); pthread_exit(NULL);
} }
drive = data->proj->drive->tangible[0].drive; drive = proj->drive->tangible[0].drive;
printf("Progress update active\n"); printf("Progress update active\n");
while (TRUE) while (TRUE)
{ {
data->proj->stat = burn_drive_get_status(drive, &p); proj->stat = burn_drive_get_status(drive, &p);
if (data->proj->stat == BURN_DRIVE_SPAWNING) if (proj->stat == BURN_DRIVE_SPAWNING)
{ {
sleep(3); sleep(3);
continue; continue;
} }
else if (data->proj->stat == BURN_DRIVE_IDLE) else if (proj->stat == BURN_DRIVE_IDLE)
{ {
pthread_exit(NULL); pthread_exit(NULL);
break; break;
} }
data->proj->progress = p; proj->progress = p;
sleep(5); sleep(5);
} }
} }
@ -138,18 +255,23 @@ _progress_update(void *d)
int int
_progress_gui_update(void *data) _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"); printf("Burn finished\n");
return ECORE_CALLBACK_CANCEL; return ECORE_CALLBACK_CANCEL;
} }
else 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; return ECORE_CALLBACK_RENEW;
} }
@ -184,11 +306,13 @@ ecdb_burn_finished(void *data, int type, void *event)
printf("Releasing drive\n"); printf("Releasing drive\n");
burn_drive_release(proj->proj->drive->tangible[0].drive, 1); burn_drive_release(proj->proj->drive->tangible[0].drive, 1);
burn_drive_info_free(proj->proj->drive->tangible); 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 */ /* To be removed from here at some point */
ecore_list_destroy(proj->proj->files); Ecdb_Burn_Project *t;
FREE(proj->proj); t = ECDB_BURN(proj->proj);
ecore_list_destroy(t->files);
FREE(t);
FREE(proj); FREE(proj);
ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL); ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL);
return 0; return 0;

View File

@ -1,6 +1,10 @@
#ifndef ECDB_BURN_H #ifndef ECDB_BURN_H
#define 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 #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) if (burn_drive_convert_fs_adr(info->location, adr) <= 0)
{ {
printf("Error: Address doesn't provide cd burner!\n"); printf("Error: Address doesn't provide cd burner!\n");
return 1; return FALSE;
} }
if (burn_drive_scan_and_grab(&info->tangible, adr, 1) > 0) if (burn_drive_scan_and_grab(&info->tangible, adr, 1) > 0)
{ {
proj->drive = info; proj->drive = info;
return 0; return TRUE;
} }
else else
{ {
info->tangible = NULL; info->tangible = NULL;
return 1; return FALSE;
} }
} }

View File

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

View File

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

View File

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

View File

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