TapeIO.h

Classes

TapeIO -- Class for IO on a tape device (full description)

class TapeIO: public ByteIO

Interface

Public Members
TapeIO()
explicit TapeIO(int fd)
TapeIO(const Path& device, Bool writable = False)
virtual ~TapeIO()
void attach(int fd)
void attach(const Path& device, Bool writable = False)
virtual void write(uInt size, const void* buf)
virtual Int read(uInt size, void* buf, Bool throwException=True)
virtual void rewind()
virtual void skip(uInt howMany=1)
virtual void mark(uInt howMany=1)
Bool fixedBlocks() const
uInt fixedBlockSize() const
void setFixedBlockSize(uInt sizeInBytes)
void setVariableBlockSize()
virtual Int64 length()
virtual Bool isReadable() const
virtual Bool isWritable() const
virtual Bool isSeekable() const
virtual String fileName() const
static int open(const Path& device, Bool writable = False)
static void close(int fd)
Protected Members
void detach()
void fillRWFlags()
void fillSeekable()
virtual Int64 doSeek(Int64 offset, ByteIO::ByteIO)
Private Members
TapeIO (const TapeIO& that)
TapeIO& operator= (const TapeIO& that)
void setBlockSize(uInt sizeInBytes)
uInt getBlockSize() const

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Synopsis

This class is a specialization of class ByteIO. It uses a file descriptor to read/write data.

The file associated with the file descriptor has to be opened before hand. The constructor will determine automatically if the file is readable, writable and seekable. Note that on destruction the file descriptor is NOT closed.

Example

This example shows how FiledesIO can be used with an fd. It uses the fd for a regular file, which could be done in an easier way using class RegularFileIO. However, when using pipes or sockets, this would be the only way.
    // Get a file descriptor for the file.
    int fd = open ("file.name");
    // Use that as the source of AipsIO (which will also use CanonicalIO).
    FiledesIO fio (fd);
    AipsIO stream (&fio);
    // Read the data.
    Int vali;
    Bool valb;
    stream >> vali >> valb;

Motivation

Make it possible to use the AIPS++ IO functionality on any file. In this way any device can be hooked to the IO framework.

Member Description

TapeIO()

Default constructor. A stream can be attached using the attach function.

explicit TapeIO(int fd)

Construct from the given file descriptor. The file descriptor must have been obtained using the TapeIO::open static function. When constructed this way the class will not take over the file descriptor and hence not close the Tape device when this class is destroyed.

TapeIO(const Path& device, Bool writable = False)

Construct from the given device. The device must point to a tape device and if requested it is checked if the device is writeable. Throws an exception if the device could not be opened correctly. When constructed this way the class will close the Tape device when this class is destroyed or the TapeIO object is attached to a new file descriptor.

virtual ~TapeIO()

The destructor will only close the file if the appropriate constructor, or attach function, was used.

void attach(int fd)

Attach to the given file descriptor. The file descriptor will not be closed when this class is destroyed.

void attach(const Path& device, Bool writable = False)

Attach to the given tape device. The tape will be closed when this class is destroyed or the TapeIO object is attached to a new descriptor.

virtual void write(uInt size, const void* buf)

Write the specified number of bytes.

virtual Int read(uInt size, void* buf, Bool throwException=True)

Read size bytes from the tape. Returns the number of bytes actually read or a negative number if an error occured. Will throw an exception (AipsError) if the requested number of bytes could not be read, or an error occured, unless throwException is set to False. Will always throw an exception if the tape is not readable or the system call returns an undocumented value. Returns zero if the tape is at the end of the current file (and size is non-zero and throwException is False).

virtual void rewind()

Rewind the tape device to the beginning.

virtual void skip(uInt howMany=1)

skip the specified number of files (ie tape marks) on the tape. Throws an exception if you try to skip past the last filemark.

virtual void mark(uInt howMany=1)

write the specified number of filemarks.

Bool fixedBlocks() const

returns True if the tape device is configured to use a fixed block size

uInt fixedBlockSize() const

returns the block size in bytes. Returns zero if the device is configured to use variable length blocks.

void setFixedBlockSize(uInt sizeInBytes)

Configure the tape device to use fixed length blocks of the specified size. The size must be bigger than zero (dugh!). Values bigger than 64k may cause problems on some systems. Currently this function only does anything under Solaris and Linux systems.

void setVariableBlockSize()

Configure the tape device to use variable length blocks. Currently this function only does anything under Solaris and Linux systems.

virtual Int64 length()

Get the length of the tape device. Not a meaningful function for this class and this function always returns -1.

virtual Bool isReadable() const

Is the tape device readable?

virtual Bool isWritable() const

Is the tape device writable?

virtual Bool isSeekable() const

Is the tape device seekable?

virtual String fileName() const

Get the name of the attached device or return a zero length string if it cannot be determined.

static int open(const Path& device, Bool writable = False)
static void close(int fd)

Some static convenience functions for file descriptor opening & closing. The open function returns a file descriptor and the close function requires a file descriptor as an argument.

void detach()

Detach the FILE. Close it when it is owned.

void fillRWFlags()

Determine if the file is readable and/or writable.

void fillSeekable()

Determine if the file is seekable.

virtual Int64 doSeek(Int64 offset, ByteIO::ByteIO)

Reset the position pointer to the given value. It returns the new position. May not work on all Tape devices use the isSeekable(0 member function to see if this function is usuable. Otherwise an Exception (AipsError) is thrown.

TapeIO (const TapeIO& that)

The following functions are made private so that the compiler does not generate default ones. They cannot be used and are not defined.

TapeIO& operator= (const TapeIO& that)

void setBlockSize(uInt sizeInBytes)

uInt getBlockSize() const