Add IsoImage, equivalent to old libisofs volume and volset.

IsoImage will be a context for image creation and modification.
This commit is contained in:
Vreixo Formoso 2007-12-02 19:10:30 +01:00
parent f2deae8503
commit c83bac7d9e
4 changed files with 146 additions and 11 deletions

View File

@ -10,9 +10,12 @@ lib_LTLIBRARIES = src/libisofs.la
src_libisofs_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
src_libisofs_la_SOURCES = \
src/builder.h \
src/error.h \
src/node.h \
src/node.c \
src/image.h \
src/image.c \
src/fsource.h \
src/fsource.c \
src/fs_local.c \

86
src/image.c Normal file
View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2007 Vreixo Formoso
*
* This file is part of the libisofs project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. See COPYING file for details.
*/
#include "libisofs.h"
#include "image.h"
#include "error.h"
#include "node.h"
#include <stdlib.h>
#include <string.h>
/**
* Create a new image, empty.
*
* The image will be owned by you and should be unref() when no more needed.
*
* @param name
* Name of the image. This will be used as volset_id and volume_id.
* @param image
* Location where the image pointer will be stored.
* @return
* 1 sucess, < 0 error
*/
int iso_image_new(const char *name, IsoImage **image)
{
int res;
IsoImage *img;
if (image == NULL) {
return ISO_NULL_POINTER;
}
img = calloc(1, sizeof(IsoImage));
if (img == NULL) {
return ISO_MEM_ERROR;
}
/* fill image fields */
res = iso_node_new_root(&img->root);
if (res < 0) {
free(img);
return res;
}
img->refcount = 1;
if (name != NULL) {
img->volset_id = strdup(name);
img->volume_id = strdup(name);
}
*image = img;
return ISO_SUCCESS;
}
/**
* Increments the reference counting of the given image.
*/
void iso_image_ref(IsoImage *image)
{
++image->refcount;
}
/**
* Decrements the reference couting of the given image.
* If it reaches 0, the image is free, together with its tree nodes (whether
* their refcount reach 0 too, of course).
*/
void iso_image_unref(IsoImage *image)
{
if (--image->refcount == 0) {
/* we need to free the image */
iso_node_unref((IsoNode*)image->root);
free(image->volset_id);
free(image->volume_id);
free(image->publisher_id);
free(image->data_preparer_id);
free(image->system_id);
free(image->application_id);
free(image->copyright_file_id);
free(image->abstract_file_id);
free(image->biblio_file_id);
}
}

View File

@ -8,18 +8,36 @@
#ifndef LIBISO_IMAGE_H_
#define LIBISO_IMAGE_H_
#include "libisofs.h"
#include "node.h"
/*
* Image is a context for image manipulation.
* Global objects such as the message_queues must belogn to that
* context. Thus we will have, for example, a msg queue per image,
* so images are completelly independent and can be managed together.
* (Usefull, for example, in Multiple-Document-Interface GUI apps.
* [The stuff we have in init belongs really to image!]
*/
struct IsoImage {
/*
* Image is a context for image manipulation.
* Global objects such as the message_queues must belogn to that
* context. Thus we will have, for example, a msg queue per image,
* so images are completelly independent and can be managed together.
* (Usefull, for example, in Multiple-Document-Interface GUI apps.
* [The stuff we have in init belongs really to image!]
*/
struct Iso_Image {
int refcount;
IsoDir *root;
char *volset_id;
char *volume_id; /**< Volume identifier. */
char *publisher_id; /**< Volume publisher. */
char *data_preparer_id; /**< Volume data preparer. */
char *system_id; /**< Volume system identifier. */
char *application_id; /**< Volume application id */
char *copyright_file_id;
char *abstract_file_id;
char *biblio_file_id;
};
#endif /*LIBISO_IMAGE_H_*/

View File

@ -9,7 +9,9 @@
#define LIBISO_LIBISOFS_H_
#include <sys/stat.h>
typedef struct Iso_Image IsoImage;
typedef struct Iso_Node IsoNode;
typedef struct Iso_Dir IsoDir;
typedef struct Iso_Symlink IsoSymlink;
@ -17,6 +19,32 @@ typedef struct Iso_File IsoFile;
typedef struct Iso_Dir_Iter IsoDirIter;
/**
* Create a new image, empty.
*
* The image will be owned by you and should be unref() when no more needed.
*
* @param name
* Name of the image. This will be used as volset_id and volume_id.
* @param image
* Location where the image pointer will be stored.
* @return
* 1 sucess, < 0 error
*/
int iso_image_new(const char *name, IsoImage **image);
/**
* Increments the reference counting of the given image.
*/
void iso_image_ref(IsoImage *image);
/**
* Decrements the reference couting of the given image.
* If it reaches 0, the image is free, together with its tree nodes (whether
* their refcount reach 0 too, of course).
*/
void iso_image_unref(IsoImage *image);
/**
* Increments the reference counting of the given node.
*/