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; IsoFileSrc *src;
off_t size; off_t size;
size = iso->stream->get_size(iso->stream); size = iso_stream_get_size(iso->stream);
if (size > (off_t)0xffffffff) { if (size > (off_t)0xffffffff) {
iso_msg_note(img->image, LIBISO_FILE_IGNORED, iso_msg_note(img->image, LIBISO_FILE_IGNORED,
"File \"%s\" can't be added to image because is " "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; f1 = (const IsoFileSrc *)n1;
f2 = (const IsoFileSrc *)n2; f2 = (const IsoFileSrc *)n2;
res = f1->stream->get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1); res = iso_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(f2->stream, &fs_id2, &dev_id2, &ino_id2);
//TODO take care about res <= 0 //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 iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
{ {
int res; int res;
IsoStream *stream;
IsoFileSrc *fsrc; IsoFileSrc *fsrc;
unsigned int fs_id; unsigned int fs_id;
dev_t dev_id; dev_t dev_id;
@ -60,8 +59,7 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
stream = file->stream; res = iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id);
res = stream->get_id(stream, &fs_id, &dev_id, &ino_id);
if (res < 0) { if (res < 0) {
return res; return res;
} else if (res == 0) { } else if (res == 0) {
@ -101,5 +99,5 @@ void iso_file_src_free(void *node)
off_t iso_file_src_get_size(IsoFileSrc *file) 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); 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 iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
{ {
int r; int r;
@ -158,13 +168,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
str->refcount = 1; str->refcount = 1;
str->data = data; str->data = data;
str->open = fsrc_open; str->class = &fsrc_stream_class;
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;
*stream = str; *stream = str;
return ISO_SUCCESS; return ISO_SUCCESS;
@ -178,7 +182,7 @@ void iso_stream_ref(IsoStream *stream)
void iso_stream_unref(IsoStream *stream) void iso_stream_unref(IsoStream *stream)
{ {
if (--stream->refcount == 0) { if (--stream->refcount == 0) {
stream->free(stream); stream->class->free(stream);
free(stream); free(stream);
} }
} }

View File

@ -20,7 +20,7 @@
typedef struct Iso_Stream IsoStream; typedef struct Iso_Stream IsoStream;
struct Iso_Stream typedef struct IsoStream_Iface
{ {
/** /**
* Opens the stream. * Opens the stream.
@ -85,7 +85,11 @@ struct Iso_Stream
* Use iso_stream_unref() instead. * Use iso_stream_unref() instead.
*/ */
void (*free)(IsoStream *stream); void (*free)(IsoStream *stream);
} IsoStreamIface;
struct Iso_Stream
{
IsoStreamIface *class;
int refcount; int refcount;
void *data; void *data;
}; };
@ -93,6 +97,37 @@ struct Iso_Stream
void iso_stream_ref(IsoStream *stream); void iso_stream_ref(IsoStream *stream);
void iso_stream_unref(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. * Create a stream to read from a IsoFileSource.
* The stream will take the ref. to the IsoFileSource, so after a successfully * The stream will take the ref. to the IsoFileSource, so after a successfully