New API functions isoburn_preset_msgs_submit(), isoburn_set_msgs_submit()

This commit is contained in:
Thomas Schmitt 2008-06-18 16:14:44 +00:00
parent 72ac776e5e
commit 7a6421b0ad
7 changed files with 195 additions and 77 deletions

View File

@ -47,6 +47,16 @@
/* The global list of isoburn objects. Usually there is only one. */
extern struct isoburn *isoburn_list_start; /* in isoburn.c */
/* Default values for application provided msgs_submit methods.
To be attached to newly aquired drives.
Storage location is isoburn.c
*/
extern int (*libisoburn_default_msgs_submit)
(void *handle, int error_code, char msg_text[],
int os_errno, char severity[], int flag);
extern void *libisoburn_default_msgs_submit_handle;
extern int libisoburn_default_msgs_submit_flag;
int isoburn_emulate_toc(struct burn_drive *d, int flag);
@ -217,6 +227,18 @@ int isoburn_libburn_req(int *major, int *minor, int *micro)
}
int isoburn_preset_msgs_submit(int (*msgs_submit)(void *handle, int error_code,
char msg_text[], int os_errno,
char severity[], int flag),
void *submit_handle, int submit_flag, int flag)
{
libisoburn_default_msgs_submit= msgs_submit;
libisoburn_default_msgs_submit_handle= submit_handle;
libisoburn_default_msgs_submit_flag= submit_flag;
return(1);
}
int isoburn_is_intermediate_dvd_rw(struct burn_drive *d, int flag)
{
int profile, ret= 0, format_status, num_formats;
@ -263,6 +285,9 @@ static int isoburn_welcome_media(struct isoburn **o, struct burn_drive *d,
if(ret<=0)
goto ex;
(*o)->drive= d;
(*o)->msgs_submit= libisoburn_default_msgs_submit;
(*o)->msgs_submit_handle= libisoburn_default_msgs_submit_handle;
(*o)->msgs_submit_flag= libisoburn_default_msgs_submit_flag;
#ifdef Hardcoded_cd_rW
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo */
@ -361,7 +386,7 @@ int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],
if(conv_ret<=0) {
sprintf(msg, "Unsuitable drive address: '%s'\n",adr);
msg[BURN_MSGS_MESSAGE_LEN-1]= 0;
burn_msgs_submit(0x00060000, msg, 0, "FAILURE", NULL);
isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "FAILURE", 0);
ret= 0; goto ex;
}
@ -433,8 +458,8 @@ int isoburn_find_emulator(struct isoburn **pt,
if(ret<=0)
return(0);
if((*pt)->emulation_mode==-1) {
burn_msgs_submit(0x00060000,
"Unsuitable drive and media state", 0, "FAILURE", NULL);
isoburn_msgs_submit(*pt, 0x00060000,
"Unsuitable drive and media state", 0, "FAILURE", 0);
return(-1);
}
if((*pt)->emulation_mode==0)
@ -552,8 +577,8 @@ int isoburn_disc_get_msc1(struct burn_drive *d, int *start_lba)
if(isoburn_disc_get_status(d)!=BURN_DISC_APPENDABLE &&
isoburn_disc_get_status(d)!=BURN_DISC_FULL) {
burn_msgs_submit(0x00060000,
"Media contains no recognizable data", 0, "SORRY",NULL);
isoburn_msgs_submit(NULL, 0x00060000,
"Media contains no recognizable data", 0, "SORRY", 0);
return(0);
}
ret= isoburn_find_emulator(&o, d, 0);
@ -639,10 +664,10 @@ void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
*/
sprintf(msg,
"DVD-RW insufficiently formatted. (Intermediate State, size unknown)");
burn_msgs_submit(0x00060000, msg, 0, "FAILURE", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "FAILURE", 0);
sprintf(msg,
"It might help to first deformat it and then format it again");
burn_msgs_submit(0x00060000, msg, 0, "HINT", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "HINT", 0);
burn_drive_cancel(drive); /* mark run as failure */
return;
}
@ -656,7 +681,7 @@ void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
write_type= burn_write_opts_auto_write_type(opts, disc, reasons, 0);
if (write_type == BURN_WRITE_NONE) {
sprintf(msg, "Failed to find a suitable write mode:\n%s", reasons);
burn_msgs_submit(0x00060000, msg, 0, "FAILURE", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "FAILURE", 0);
if(o!=NULL)
o->wrote_well= 0;
/* To cause a negative reply with burn_drive_wrote_well() */
@ -668,7 +693,7 @@ void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
sprintf(msg, "Write_type = %s\n",
(write_type == BURN_WRITE_SAO ? "SAO" :
(write_type == BURN_WRITE_TAO ? "TAO" : reasons)));
burn_msgs_submit(0x00060000, msg, 0, "DEBUG", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "DEBUG", 0);
#ifdef Hardcoded_cd_rW
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo */
@ -746,9 +771,9 @@ int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag)
if(ret<=0)
goto ex;
if(!caps->start_adr) {
burn_msgs_submit(0x00060000,
"Cannot set start byte address with this type of media",
0, "FAILURE", NULL);
isoburn_msgs_submit(o, 0x00060000,
"Cannot set start byte address with this type of media",
0, "FAILURE", 0);
{ret= 0; goto ex;}
}
o->min_start_byte= value;
@ -930,9 +955,9 @@ int isoburn_read_iso_head_parse(struct burn_drive *d, unsigned char *data,
else
info[i]= 0;
} else {
burn_msgs_submit(0x00060000,
isoburn_msgs_submit(NULL, 0x00060000,
"Program error: Unknown info mode with isoburn_read_iso_head()",
0, "FATAL", NULL);
0, "FATAL", 0);
return(-1);
}
return(1);
@ -1025,7 +1050,7 @@ int isoburn_emulate_toc(struct burn_drive *d, int flag)
sprintf(msg,
"Chain of ISO session headers broken at #%d, LBA %ds",
session_count+1, lba);
burn_msgs_submit(0x00060000, msg, 0, "WARNING", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "WARNING", 0);
}
{ret= 0; goto failure;}
}
@ -1033,9 +1058,9 @@ int isoburn_emulate_toc(struct burn_drive *d, int flag)
lba-= 16;
ret= isoburn_toc_entry_new(&item, o->toc, 0);
if(ret<=0) {
burn_msgs_submit(0x00060000,
"Not enough memory for emulated TOC entry object",
0, "FATAL", NULL);
isoburn_msgs_submit(o, 0x00060000,
"Not enough memory for emulated TOC entry object",
0, "FATAL", 0);
ret= -1; goto failure;
}
if(o->toc==NULL)
@ -1045,20 +1070,13 @@ int isoburn_emulate_toc(struct burn_drive *d, int flag)
item->track_no= session_count;
item->start_lba= lba;
item->track_blocks= track_blocks;
now= time(NULL);
#ifdef Not_yeT
/* >>> need asynchronous delivery of messages */;
if(now - last_pacifier > 5) {
last_pacifier= now;
sprintf(msg, "Scanning found %d ISO session headers in %.f seconds",
session_count, (double) (now - start_time));
burn_msgs_submit(0x00060000, msg, 0, "UPDATE", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "UPDATE", 0);
}
#endif
lba+= track_blocks;
if(lba % Libisoburn_nwa_alignemenT)
lba+= Libisoburn_nwa_alignemenT - (lba % Libisoburn_nwa_alignemenT);
@ -1071,7 +1089,7 @@ int isoburn_emulate_toc(struct burn_drive *d, int flag)
now= time(NULL);
sprintf(msg, "Scanning found %d ISO session headers in %.f seconds",
session_count, (double) (now - start_time));
burn_msgs_submit(0x00060000, msg, 0, sev, NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, sev, 0);
return(1);
failure:;
isoburn_toc_entry_destroy(&(o->toc), 1);
@ -1352,6 +1370,25 @@ int isoburn_get_track_lba(struct isoburn_toc_track *track, int *lba, int flag)
}
int isoburn_set_msgs_submit(struct burn_drive *d,
int (*msgs_submit)(void *handle, int error_code,
char msg_text[], int os_errno,
char severity[], int flag),
void *submit_handle, int submit_flag, int flag)
{
struct isoburn *o;
int ret;
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0 || o==NULL)
return(-1);
o->msgs_submit= msgs_submit;
o->msgs_submit_handle= submit_handle;
o->msgs_submit_flag= submit_flag;
return(1);
}
int isoburn_set_msc1(struct burn_drive *d, int adr_mode, char *adr_value,
int flag)
{
@ -1380,7 +1417,7 @@ not_found:;
goto unknown_mode;
sprintf(msg, "Failed to find %s %s", mode_names[adr_mode],
strlen(adr_value)<=80 ? adr_value : "-oversized-string-");
burn_msgs_submit(0x00060000, msg, 0, "FAILURE", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "FAILURE", 0);
ret= 0; goto ex;
}
sessions= isoburn_toc_disc_get_sessions(disc, &num_sessions);
@ -1448,7 +1485,7 @@ not_found:;
} else {
unknown_mode:;
sprintf(msg, "Program error: Unknown msc1 address mode %d", adr_mode);
burn_msgs_submit(0x00060000, msg, 0, "FATAL", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "FATAL", 0);
ret= 0; goto ex;
}
ret= 1;

View File

@ -1,7 +1,8 @@
/*
data source for libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
Copyright 2007 - 2008 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
and Thomas Schmitt <scdbackup@gmx.net>
*/
#include <stdlib.h>
@ -148,7 +149,7 @@ int ds_read_block(IsoDataSource *src, uint32_t lba, uint8_t *buffer)
if(ret >= 0)
ret = -1;
sprintf(msg, "ds_read_block(%lu) returns %d", (unsigned long) lba, ret);
burn_msgs_submit(0x00060000, msg, 0, "DEBUG", NULL);
isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "DEBUG", 0);
return ret;
}

View File

@ -37,10 +37,16 @@
#include "isoburn.h"
/* No more: version numbers out of configure.ac
major.minor.micro now comes from libisoburn.h
#include "../version.h"
/* Default values for application provided msgs_submit methods.
To be attached to newly aquired drives.
*/
int (*libisoburn_default_msgs_submit)
(void *handle, int error_code, char msg_text[],
int os_errno, char severity[], int flag)= NULL;
void *libisoburn_default_msgs_submit_handle= NULL;
int libisoburn_default_msgs_submit_flag= 0;
/* ----------------------- isoburn_toc_entry ---------------------- */
@ -53,9 +59,9 @@ int isoburn_toc_entry_new(struct isoburn_toc_entry **objpt,
*objpt= o= (struct isoburn_toc_entry *)
malloc(sizeof(struct isoburn_toc_entry));
if(o==NULL) {
burn_msgs_submit(0x00060000,
"Cannot allocate memory for isoburn toc entry",
0, "FATAL", NULL);
isoburn_msgs_submit(NULL, 0x00060000,
"Cannot allocate memory for isoburn toc entry",
0, "FATAL", 0);
return(-1);
}
o->session= 0;
@ -104,9 +110,9 @@ int isoburn_new(struct isoburn **objpt, int flag)
*objpt= o= (struct isoburn *) malloc(sizeof(struct isoburn));
if(o==NULL) {
burn_msgs_submit(0x00060000,
"Cannot allocate memory for isoburn control object",
0, "FATAL", NULL);
isoburn_msgs_submit(NULL, 0x00060000,
"Cannot allocate memory for isoburn control object",
0, "FATAL", 0);
return(-1);
}
@ -126,6 +132,9 @@ int isoburn_new(struct isoburn **objpt, int flag)
o->image= NULL;
o->read_pacifier= NULL;
o->read_pacifier_handle= NULL;
o->msgs_submit= NULL;
o->msgs_submit_handle= NULL;
o->msgs_submit_flag= 0;
o->prev= NULL;
o->next= NULL;
ret= iso_image_new("ISOIMAGE", &o->image);
@ -300,6 +309,31 @@ int isoburn_find_by_drive(struct isoburn **pt, struct burn_drive *d, int flag)
}
int isoburn_msgs_submit(struct isoburn *o, int error_code, char msg_text[],
int os_errno, char severity[], int flag)
{
int ret, use_drive_method= 0;
if(o!=NULL)
if(o->msgs_submit!=NULL)
use_drive_method= 1;
if(use_drive_method) {
ret= o->msgs_submit(o->msgs_submit_handle, error_code, msg_text, os_errno,
severity, o->msgs_submit_flag);
return(ret);
}
if(libisoburn_default_msgs_submit != NULL) {
ret= libisoburn_default_msgs_submit(libisoburn_default_msgs_submit_handle,
error_code, msg_text, os_errno, severity,
libisoburn_default_msgs_submit_flag);
return(ret);
}
/* Fallback: use message queue of libburn */
burn_msgs_submit(error_code, msg_text, os_errno, severity, NULL);
return(1);
}
static
int isoburn_prepare_disc_aux(struct burn_drive *in_d, struct burn_drive *out_d,
struct burn_disc **disc,
@ -325,14 +359,14 @@ int isoburn_prepare_disc_aux(struct burn_drive *in_d, struct burn_drive *out_d,
state = isoburn_disc_get_status(in_d);
if (state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE &&
state != BURN_DISC_FULL) {
burn_msgs_submit(0x00060000, "Unsuitable source media state",
0, "FAILURE", NULL);
isoburn_msgs_submit(in_o, 0x00060000, "Unsuitable source media state",
0, "FAILURE", 0);
{ret= -2; goto ex;}
}
state = isoburn_disc_get_status(out_d);
if (state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
burn_msgs_submit(0x00060000, "Unsuitable target media state",
0, "FAILURE", NULL);
isoburn_msgs_submit(out_o, 0x00060000, "Unsuitable target media state",
0, "FAILURE", 0);
{ret= -2; goto ex;}
}
@ -374,14 +408,14 @@ int isoburn_prepare_disc_aux(struct burn_drive *in_d, struct burn_drive *out_d,
ret = isoburn_disc_track_lba_nwa(out_d, NULL, 0, &lba, &nwa);
if (ret != 1) {
burn_msgs_submit(0x00060000, "Cannot determine next writeable address", 0,
"FAILURE", NULL);
isoburn_msgs_submit(out_o, 0x00060000,
"Cannot determine next writeable address", 0, "FAILURE", 0);
{ret= -3; goto ex;}
}
if (nwa == 0 && state == BURN_DISC_APPENDABLE) {
burn_msgs_submit(0x00060000,
"Encountered 0 as next writeable address of appendable",
0, "FAILURE", NULL);
isoburn_msgs_submit(out_o, 0x00060000,
"Encountered 0 as next writeable address of appendable",
0, "FAILURE", 0);
{ret= -4; goto ex;}
}
iso_write_opts_set_ms_block(wopts, nwa);
@ -525,8 +559,8 @@ int isoburn_ropt_new(struct isoburn_read_opts **new_o, int flag)
o= (*new_o)= calloc(1, sizeof(struct isoburn_read_opts));
if(o==NULL) {
burn_msgs_submit(0x00060000, "Cannot allocate memory for read options",
0, "FATAL", NULL);
isoburn_msgs_submit(NULL, 0x00060000,
"Cannot allocate memory for read options", 0, "FATAL", 0);
return(-1);
}
o->norock= 0;
@ -662,9 +696,9 @@ int isoburn_igopt_new(struct isoburn_imgen_opts **new_o, int flag)
o= (*new_o)= calloc(1, sizeof(struct isoburn_imgen_opts));
if(o==NULL) {
burn_msgs_submit(0x00060000,
"Cannot allocate memory for image generation options",
0, "FATAL", NULL);
isoburn_msgs_submit(NULL, 0x00060000,
"Cannot allocate memory for image generation options",
0, "FATAL", 0);
return(-1);
}
o->level= 2;

View File

@ -110,6 +110,12 @@ struct isoburn {
/* For iso_image_attach_data() */
void *read_pacifier_handle;
/* An application provided method to immediately deliver messages */
int (*msgs_submit)(void *handle, int error_code, char msg_text[],
int os_errno, char severity[], int flag);
void *msgs_submit_handle; /* specific to application method */
int msgs_submit_flag; /* specific to application method */
};
@ -168,6 +174,11 @@ int isoburn_invalidate_iso(struct isoburn *o, int flag);
int isoburn_find_emulator(struct isoburn **pt,
struct burn_drive *drive, int flag);
/* Deliver an event message. Either via a non-NULL o->msgs_submit() method
or via burn_msgs_submit() of libburn.
*/
int isoburn_msgs_submit(struct isoburn *o, int error_code, char msg_text[],
int os_errno, char severity[], int flag);
/** Set the start address for an emulated add-on session. The value will
be rounded up to the alignment necessary for the media. The aligned

View File

@ -121,18 +121,18 @@ int isoburn_read_image(struct burn_drive *d,
IsoDataSource *ds= NULL;
struct isoburn *o= NULL;
if(read_opts==NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_read_image: read_opts==NULL",
0, "FATAL", NULL);
return(-1);
}
if(d != NULL) {
ret = isoburn_find_emulator(&o, d, 0);
if (ret < 0 || o == NULL)
return 0;
status = isoburn_disc_get_status(d);
}
if(read_opts==NULL) {
isoburn_msgs_submit(o, 0x00060000,
"Program error: isoburn_read_image: read_opts==NULL",
0, "FATAL", 0);
return(-1);
}
if (d == NULL || status == BURN_DISC_BLANK || read_opts->pretend_blank) {
create_blank_image:;
/*
@ -142,9 +142,9 @@ create_blank_image:;
if (d == NULL) {
/* New empty image without relation to a drive */
if (image==NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_read_image: image==NULL",
0, "FATAL", NULL);
isoburn_msgs_submit(o, 0x00060000,
"Program error: isoburn_read_image: image==NULL",
0, "FATAL", 0);
return -1;
}
/* create a new image */
@ -170,9 +170,9 @@ create_blank_image:;
}
if (status != BURN_DISC_APPENDABLE && status != BURN_DISC_FULL) {
burn_msgs_submit(0x00060000,
isoburn_msgs_submit(o, 0x00060000,
"Program error: isoburn_read_image: incorrect disc status",
0, "FATAL", NULL);
0, "FATAL", 0);
return -4;
}
@ -185,7 +185,7 @@ create_blank_image:;
ret = isoburn_read_iso_head(d, int_num, &dummy, NULL, 0);
if (ret <= 0) {
sprintf(msg, "No ISO 9660 image at LBA %d. Creating blank image.", int_num);
burn_msgs_submit(0x00060000, msg, 0, "WARNING", NULL);
isoburn_msgs_submit(o, 0x00060000, msg, 0, "WARNING", 0);
goto create_blank_image;
}
@ -248,15 +248,15 @@ int isoburn_attach_image(struct burn_drive *d, IsoImage *image)
int ret;
struct isoburn *o;
if (image == NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_attach_image: image==NULL",
0, "FATAL", NULL);
return -1;
}
ret = isoburn_find_emulator(&o, d, 0);
if (ret < 0 || o == NULL)
return 0;
if (image == NULL) {
isoburn_msgs_submit(o, 0x00060000,
"Program error: isoburn_attach_image: image==NULL",
0, "FATAL", 0);
return -1;
}
if(o->image != NULL)
iso_image_unref(o->image);
o->image = image;
@ -304,9 +304,9 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
struct ecma119_pri_vol_desc *pvm;
if(o==NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_start_emulation: o==NULL",
0, "FATAL", NULL);
isoburn_msgs_submit(NULL, 0x00060000,
"Program error: isoburn_start_emulation: o==NULL",
0, "FATAL", 0);
return -1;
}

View File

@ -298,6 +298,24 @@ and would leave out the ugly compile time traps.
*/
/** Announce to the library an application provided method for immediate
delivery of messages. It is attached by default to any newly aquired drive
and can later be changed by isoburn_set_msgs_submit().
The preset method is also used when no drive is directly related to
a message.
If no method is preset or if the method is set to NULL then libisoburn
delivers its messages through the message queue of libburn.
@param msgs_submit The function call which implements the method
@param submit_handle Handle to be used as first argument of msgs_submit
@param submit_flag Flag to be used as last argument of msgs_submit
@param flag Unused yet, submit 0
@since 0.2.0
*/
int isoburn_preset_msgs_submit(int (*msgs_submit)(void *handle, int error_code,
char msg_text[], int os_errno,
char severity[], int flag),
void *submit_handle, int submit_flag, int flag);
/** Aquire a target drive by its filesystem path resp. libburn persistent
address.
Wrapper for: burn_drive_scan_and_grab()
@ -339,7 +357,6 @@ int isoburn_drive_scan_and_grab(struct burn_drive_info *drive_infos[],
int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],
char* adr, int flag);
/** Aquire a drive from the burn_drive_info[] array which was obtained by
a previous call of burn_drive_scan().
Wrapper for: burn_drive_grab()
@ -351,6 +368,24 @@ int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],
int isoburn_drive_grab(struct burn_drive *drive, int load);
/** Attach to a drive an application provided method for immediate
delivery of messages.
If no method is set or if the method is set to NULL then libisoburn
delivers messages of the drive through the message queue of libburn.
@since 0.2.0
@param d The drive to which this function, handle and flag shall apply
@param msgs_submit The function call which implements the method
@param submit_handle Handle to be used as first argument of msgs_submit
@param submit_flag Flag to be used as last argument of msgs_submit
@param flag Unused yet, submit 0
*/
int isoburn_set_msgs_submit(struct burn_drive *d,
int (*msgs_submit)(void *handle, int error_code,
char msg_text[], int os_errno,
char severity[], int flag),
void *submit_handle, int submit_flag, int flag);
/** Inquire the media status. Expect the whole spectrum of libburn BURN_DISC_*
with multi-session media. Emulated states with random access media are
BURN_DISC_BLANK and BURN_DISC_APPENDABLE.

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.06.18.132057"
#define Xorriso_timestamP "2008.06.18.161512"