Pacifier for isoburn_read_image()

This commit is contained in:
Thomas Schmitt 2008-02-06 21:45:31 +00:00
parent f6b488c241
commit 53d97eee77
6 changed files with 79 additions and 4 deletions

View File

@ -81,6 +81,8 @@ int isoburn_new(struct isoburn **objpt, int flag)
for(i=0;i<65536;i++) for(i=0;i<65536;i++)
o->target_iso_head[i]= 0; o->target_iso_head[i]= 0;
o->image= NULL; o->image= NULL;
o->read_pacifier= NULL;
o->read_pacifier_handle= NULL;
o->prev= NULL; o->prev= NULL;
o->next= NULL; o->next= NULL;
ret= iso_image_new("ISOIMAGE", &o->image); ret= iso_image_new("ISOIMAGE", &o->image);

View File

@ -74,6 +74,12 @@ struct isoburn {
struct burn_source *iso_source; struct burn_source *iso_source;
#endif /* Libisoburn_no_fifO */ #endif /* Libisoburn_no_fifO */
/* For iso_tree_set_report_callback() */
int (*read_pacifier)(IsoImage*, IsoFileSource*);
/* For iso_image_attach_data() */
void *read_pacifier_handle;
}; };

View File

@ -100,6 +100,12 @@ IsoImage *isoburn_get_attached_image(struct burn_drive *d)
} }
static void isoburn_idle_free_function(void *ignored)
{
return;
}
/* API function. See libisoburn.h /* API function. See libisoburn.h
*/ */
int isoburn_read_image(struct burn_drive *d, int isoburn_read_image(struct burn_drive *d,
@ -195,7 +201,14 @@ int isoburn_read_image(struct burn_drive *d,
iso_read_opts_set_default_gid(ropts, read_opts->gid); iso_read_opts_set_default_gid(ropts, read_opts->gid);
iso_read_opts_set_input_charset(ropts, read_opts->input_charset); iso_read_opts_set_input_charset(ropts, read_opts->input_charset);
ds = isoburn_data_source_new(d); ds = isoburn_data_source_new(d);
iso_image_attach_data(o->image, o->read_pacifier_handle,
isoburn_idle_free_function);
if(o->read_pacifier_handle==NULL)
iso_tree_set_report_callback(o->image, NULL);
else
iso_tree_set_report_callback(o->image, o->read_pacifier);
ret = iso_image_import(o->image, ds, ropts, &features); ret = iso_image_import(o->image, ds, ropts, &features);
iso_tree_set_report_callback(o->image, NULL);
iso_read_opts_free(ropts); iso_read_opts_free(ropts);
iso_data_source_unref(ds); iso_data_source_unref(ds);
if (ret < 0) { if (ret < 0) {
@ -203,12 +216,10 @@ int isoburn_read_image(struct burn_drive *d,
return ret; return ret;
} }
/* Important: do not return until free(features) */ /* Important: do not return until free(features) */
if (image!=NULL) { if (image!=NULL) {
*image = o->image; *image = o->image;
iso_image_ref(*image); /*protects object from premature free*/ iso_image_ref(*image); /*protects object from premature free*/
} }
read_opts->hasRR = iso_read_image_features_has_rockridge(features); read_opts->hasRR = iso_read_image_features_has_rockridge(features);
read_opts->hasJoliet = iso_read_image_features_has_joliet(features); read_opts->hasJoliet = iso_read_image_features_has_joliet(features);
read_opts->hasIso1999 = iso_read_image_features_has_iso1999(features); read_opts->hasIso1999 = iso_read_image_features_has_iso1999(features);
@ -368,3 +379,20 @@ int isoburn_invalidate_iso(struct isoburn *o, int flag)
return isoburn_activate_session(o->drive); return isoburn_activate_session(o->drive);
} }
/* API @since 0.1.0 */
int isoburn_set_read_pacifier(struct burn_drive *drive,
int (*read_pacifier)(IsoImage*, IsoFileSource*),
void *read_handle)
{
int ret;
struct isoburn *o;
ret = isoburn_find_emulator(&o, drive, 0);
if(ret < 0 || o == NULL)
return -1;
o->read_pacifier_handle= read_handle;
o->read_pacifier= read_pacifier;
return(1);
}

View File

@ -618,6 +618,23 @@ int isoburn_read_image(struct burn_drive *d,
struct isoburn_read_opts *read_opts, struct isoburn_read_opts *read_opts,
IsoImage **image); IsoImage **image);
/* @since 0.1.0 */
/** Set a callback function for producing pacifier messages during the lengthy
process of image reading. The callback function and the application handle
are stored until they are needed for the underlying call to libisofs.
Other than with libisofs the handle is managed entirely by the application.
An idle .free() function is exposed to libisofs. The handle has to stay
valid until isoburn_read_image() is done. It has to be detached by
isoburn_set_read_pacifier(drive, NULL, NULL);
before it may be removed from memory.
@param drive The drive which will be used with isoburn_read_image()
@param read_pacifier The callback function
@param app_handle The app handle which the callback function can obtain
via iso_image_get_attached_data() from its IsoImage*
*/
int isoburn_set_read_pacifier(struct burn_drive *drive,
int (*read_pacifier)(IsoImage*, IsoFileSource*),
void *app_handle);
/** Set the IsoImage to be used with a drive. This eventually releases /** Set the IsoImage to be used with a drive. This eventually releases
the reference to the old IsoImage attached to the drive. the reference to the old IsoImage attached to the drive.

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.02.06.184008" #define Xorriso_timestamP "2008.02.06.214426"

View File

@ -58,6 +58,9 @@
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive, int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
int flag); int flag);
int Xorriso__read_pacifier(IsoImage *image, IsoFileSource *filesource);
#define LIBISO_ISDIR(node) (iso_node_get_type(node) == LIBISO_DIR) #define LIBISO_ISDIR(node) (iso_node_get_type(node) == LIBISO_DIR)
#define LIBISO_ISREG(node) (iso_node_get_type(node) == LIBISO_FILE) #define LIBISO_ISREG(node) (iso_node_get_type(node) == LIBISO_FILE)
#define LIBISO_ISLNK(node) (iso_node_get_type(node) == LIBISO_SYMLINK) #define LIBISO_ISLNK(node) (iso_node_get_type(node) == LIBISO_SYMLINK)
@ -381,6 +384,7 @@ int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
/* Note: no return before isoburn_ropt_destroy() */ /* Note: no return before isoburn_ropt_destroy() */
isoburn_ropt_set_extensions(ropts, isoburn_ropt_pretend_blank); isoburn_ropt_set_extensions(ropts, isoburn_ropt_pretend_blank);
isoburn_ropt_set_input_charset(ropts, NULL); isoburn_ropt_set_input_charset(ropts, NULL);
isoburn_set_read_pacifier(drive, NULL, NULL);
ret= isoburn_read_image(drive, ropts, &volset); ret= isoburn_read_image(drive, ropts, &volset);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
isoburn_ropt_destroy(&ropts, 0); isoburn_ropt_destroy(&ropts, 0);
@ -541,6 +545,8 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
#endif /* NIX */ #endif /* NIX */
Xorriso_set_image_severities(xorriso, 1); /* No DEBUG messages */ Xorriso_set_image_severities(xorriso, 1); /* No DEBUG messages */
Xorriso_pacifier_reset(xorriso, 0);
isoburn_set_read_pacifier(drive, Xorriso__read_pacifier, (void *) xorriso);
if(isoburn_read_image(drive, ropts, &volset) <= 0) { if(isoburn_read_image(drive, ropts, &volset) <= 0) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
Xorriso_set_image_severities(xorriso, 0); Xorriso_set_image_severities(xorriso, 0);
@ -923,6 +929,22 @@ int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
} }
int Xorriso__read_pacifier(IsoImage *image, IsoFileSource *filesource)
{
struct XorrisO *xorriso;
xorriso= (struct XorrisO *) iso_image_get_attached_data(image);
if(xorriso==NULL)
return(1);
xorriso->pacifier_count++;
if(xorriso->pacifier_count%10)
return(1);
Xorriso_pacifier_callback(xorriso, "nodes read", xorriso->pacifier_count, 0,
"", 0);
return(1);
}
int Xorriso_get_volume(struct XorrisO *xorriso, IsoImage **volume, int Xorriso_get_volume(struct XorrisO *xorriso, IsoImage **volume,
int flag) int flag)
{ {
@ -1328,7 +1350,7 @@ cannot_lstat:;
} }
xorriso->pacifier_count++; xorriso->pacifier_count++;
if(xorriso->pacifier_count%100) if((xorriso->pacifier_count%100)==0)
Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count, Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
xorriso->pacifier_total, "", 0); xorriso->pacifier_total, "", 0);