Improve IsoStream interface implementation.

This commit is contained in:
Vreixo Formoso 2007-12-20 20:58:03 +01:00
parent a161f4249c
commit 449ed65fe9
4 changed files with 54 additions and 17 deletions

View File

@ -114,7 +114,7 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node)
IsoFileSrc *src;
off_t size;
size = iso->stream->get_size(iso->stream);
size = iso_stream_get_size(iso->stream);
if (size > (off_t)0xffffffff) {
iso_msg_note(img->image, LIBISO_FILE_IGNORED,
"File \"%s\" can't be added to image because is "

View File

@ -24,8 +24,8 @@ int iso_file_src_cmp(const void *n1, const void *n2)
f1 = (const IsoFileSrc *)n1;
f2 = (const IsoFileSrc *)n2;
res = f1->stream->get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1);
res = f2->stream->get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2);
res = iso_stream_get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1);
res = iso_stream_get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2);
//TODO take care about res <= 0
@ -50,7 +50,6 @@ int iso_file_src_cmp(const void *n1, const void *n2)
int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
{
int res;
IsoStream *stream;
IsoFileSrc *fsrc;
unsigned int fs_id;
dev_t dev_id;
@ -60,8 +59,7 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
return ISO_NULL_POINTER;
}
stream = file->stream;
res = stream->get_id(stream, &fs_id, &dev_id, &ino_id);
res = iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id);
if (res < 0) {
return res;
} else if (res == 0) {
@ -101,5 +99,5 @@ void iso_file_src_free(void *node)
off_t iso_file_src_get_size(IsoFileSrc *file)
{
return file->stream->get_size(file->stream);
return iso_stream_get_size(file->stream);
}

View File

@ -121,6 +121,16 @@ void fsrc_free(IsoStream *stream)
free(data);
}
IsoStreamIface fsrc_stream_class = {
fsrc_open,
fsrc_close,
fsrc_get_size,
fsrc_read,
fsrc_is_repeatable,
fsrc_get_id,
fsrc_free
};
int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
{
int r;
@ -158,13 +168,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
str->refcount = 1;
str->data = data;
str->open = fsrc_open;
str->close = fsrc_close;
str->get_size = fsrc_get_size;
str->read = fsrc_read;
str->is_repeatable = fsrc_is_repeatable;
str->get_id = fsrc_get_id;
str->free = fsrc_free;
str->class = &fsrc_stream_class;
*stream = str;
return ISO_SUCCESS;
@ -178,7 +182,7 @@ void iso_stream_ref(IsoStream *stream)
void iso_stream_unref(IsoStream *stream)
{
if (--stream->refcount == 0) {
stream->free(stream);
stream->class->free(stream);
free(stream);
}
}

View File

@ -20,7 +20,7 @@
typedef struct Iso_Stream IsoStream;
struct Iso_Stream
typedef struct IsoStream_Iface
{
/**
* Opens the stream.
@ -85,14 +85,49 @@ struct Iso_Stream
* Use iso_stream_unref() instead.
*/
void (*free)(IsoStream *stream);
} IsoStreamIface;
struct Iso_Stream
{
IsoStreamIface *class;
int refcount;
void *data;
void *data;
};
void iso_stream_ref(IsoStream *stream);
void iso_stream_unref(IsoStream *stream);
extern inline
int iso_stream_open(IsoStream *stream) {
return stream->class->open(stream);
}
extern inline
int iso_stream_close(IsoStream *stream) {
return stream->class->close(stream);
}
extern inline
off_t iso_stream_get_size(IsoStream *stream) {
return stream->class->get_size(stream);
}
extern inline
int iso_stream_read(IsoStream *stream, void *buf, size_t count) {
return stream->class->read(stream, buf, count);
}
extern inline
int iso_stream_is_repeatable(IsoStream *stream) {
return stream->class->is_repeatable(stream);
}
extern inline
int iso_stream_get_id(IsoStream *stream, unsigned int *fs_id,
dev_t *dev_id, ino_t *ino_id) {
return stream->class->get_id(stream, fs_id, dev_id, ino_id);
}
/**
* Create a stream to read from a IsoFileSource.
* The stream will take the ref. to the IsoFileSource, so after a successfully