Users can now attach app specific data to IsoImage.

This commit is contained in:
Vreixo Formoso 2008-01-29 00:12:33 +01:00
parent b3f4ca1cf7
commit 6434de535c
3 changed files with 72 additions and 0 deletions

View File

@ -93,6 +93,10 @@ void iso_image_unref(IsoImage *image)
{
if (--image->refcount == 0) {
/* we need to free the image */
if (image->user_data != NULL) {
/* free attached data */
image->user_data_free(image->user_data);
}
iso_node_unref((IsoNode*)image->root);
iso_node_builder_unref(image->builder);
iso_filesystem_unref(image->fs);
@ -110,6 +114,46 @@ void iso_image_unref(IsoImage *image)
}
}
/**
* Attach user defined data to the image. Use this if your application needs
* to store addition info together with the IsoImage. If the image already
* has data attached, the old data will be freed.
*
* @param data
* Pointer to application defined data that will be attached to the
* image. You can pass NULL to remove any already attached data.
* @param free
* Function that will be called when the image does not need the data
* any more. It receives the data pointer as an argumente, and eventually
* causes data to be free.
*/
int iso_image_attach_data(IsoImage *image, void *data, void (*free)(void*))
{
if (image == NULL || (data != NULL && free == NULL)) {
return ISO_NULL_POINTER;
}
if (image->user_data != NULL) {
/* free previously attached data */
image->user_data_free(image->user_data);
image->user_data = NULL;
}
if (data != NULL) {
image->user_data = data;
image->user_data_free = free;
}
return ISO_SUCCESS;
}
/**
* The the data previously attached with iso_image_attach_data()
*/
void *iso_image_get_attached_data(IsoImage *image)
{
return image->user_data;
}
IsoDir *iso_image_get_root(const IsoImage *image)
{
return image->root;

View File

@ -101,6 +101,12 @@ struct Iso_Image
* 1 add, 0 ignore, < 0 cancel
*/
int (*report)(IsoImage *image, IsoFileSource *src);
/**
* User supplied data
*/
void *user_data;
void (*user_data_free)(void *ptr);
};
#endif /*LIBISO_IMAGE_H_*/

View File

@ -996,6 +996,28 @@ void iso_image_ref(IsoImage *image);
*/
void iso_image_unref(IsoImage *image);
/**
* Attach user defined data to the image. Use this if your application needs
* to store addition info together with the IsoImage. If the image already
* has data attached, the old data will be freed.
*
* @param data
* Pointer to application defined data that will be attached to the
* image. You can pass NULL to remove any already attached data.
* @param free
* Function that will be called when the image does not need the data
* any more. It receives the data pointer as an argumente, and eventually
* causes data to be free.
* @return
* 1 on succes, < 0 on error
*/
int iso_image_attach_data(IsoImage *image, void *data, void (*free)(void*));
/**
* The the data previously attached with iso_image_attach_data()
*/
void *iso_image_get_attached_data(IsoImage *image);
/**
* Get the root directory of the image.
* No extra ref is added to it, so you musn't unref it. Use iso_node_ref()