casacore
Loading...
Searching...
No Matches
TapeIO.h
Go to the documentation of this file.
1//# TapeIO.h: Class for IO on a tape device.
2//# Copyright (C) 1999,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_TAPEIO_H
27#define CASA_TAPEIO_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/IO/ByteIO.h>
31#include <casacore/casa/BasicSL/String.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35class Path;
36
37// <summary>Class for IO on a tape device</summary>
38
39// <use visibility=export>
40
41// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
42// </reviewed>
43
44// <prerequisite>
45// <li> <linkto class=ByteIO>ByteIO</linkto> class
46// <li> Tape descriptors
47// </prerequisite>
48
49// <synopsis>
50// This class is a specialization of class
51// <linkto class=ByteIO>ByteIO</linkto>. It uses a file descriptor
52// to read/write data.
53// <p>
54// The file associated with the file descriptor has to be opened
55// before hand.
56// The constructor will determine automatically if the file is
57// readable, writable and seekable.
58// Note that on destruction the file descriptor is NOT closed.
59// </synopsis>
60
61// <example>
62// This example shows how FiledesIO can be used with an fd.
63// It uses the fd for a regular file, which could be done in an easier
64// way using class <linkto class=RegularFileIO>RegularFileIO</linkto>.
65// However, when using pipes or sockets, this would be the only way.
66// <srcblock>
67// // Get a file descriptor for the file.
68// int fd = open ("file.name");
69// // Use that as the source of AipsIO (which will also use CanonicalIO).
70// FiledesIO fio (fd);
71// AipsIO stream (&fio);
72// // Read the data.
73// Int vali;
74// Bool valb;
75// stream >> vali >> valb;
76// </srcblock>
77// </example>
78
79// <motivation>
80// Make it possible to use the Casacore IO functionality on any file.
81// In this way any device can be hooked to the IO framework.
82// </motivation>
83
84
85class TapeIO: public ByteIO
86{
87public:
88 // Default constructor.
89 // A stream can be attached using the attach function.
91
92 // Construct from the given file descriptor. The file descriptor must have
93 // been obtained using the TapeIO::open static function. When constructed
94 // this way the class will not take over the file descriptor and hence not
95 // close the Tape device when this class is destroyed.
96 explicit TapeIO(int fd);
97
98 // Construct from the given device. The device must point to a tape device
99 // and if requested it is checked if the device is writeable. Throws an
100 // exception if the device could not be opened correctly. When constructed
101 // this way the class will close the Tape device when this class is destroyed
102 // or the TapeIO object is attached to a new file descriptor.
103 TapeIO(const Path& device, Bool writable = False);
104
105 // The destructor will only close the file if the appropriate constructor, or
106 // attach function, was used.
107 virtual ~TapeIO();
108
109 // Attach to the given file descriptor. The file descriptor will not be
110 // closed when this class is destroyed.
111 void attach(int fd);
112
113 // Attach to the given tape device. The tape will be closed when this class
114 // is destroyed or the TapeIO object is attached to a new descriptor.
115 void attach(const Path& device, Bool writable = False);
116
117 // Write the specified number of bytes.
118 virtual void write(Int64 size, const void* buf);
119
120 // Read <src>size</src> bytes from the tape. Returns the number of bytes
121 // actually read or a negative number if an error occured. Will throw an
122 // exception (AipsError) if the requested number of bytes could not be read,
123 // or an error occured, unless throwException is set to False. Will always
124 // throw an exception if the tape is not readable or the system call returns
125 // an undocumented value. Returns zero if the tape is at the end of the
126 // current file (and size is non-zero and throwException is False).
127 virtual Int64 read(Int64 size, void* buf, Bool throwException=True);
128
129 // Rewind the tape device to the beginning.
130 virtual void rewind();
131
132 // skip the specified number of files (ie tape marks) on the tape. Throws an
133 // exception if you try to skip past the last filemark.
134 virtual void skip(uInt howMany=1);
135
136 // write the specified number of filemarks.
137 virtual void mark(uInt howMany=1);
138
139 // returns True if the tape device is configured to use a fixed block size
141
142 // returns the block size in bytes. Returns zero if the device is configured
143 // to use variable length blocks.
145
146 // Configure the tape device to use fixed length blocks of the specified
147 // size. The size must be bigger than zero (dugh!). Values bigger than 64k
148 // may cause problems on some systems. Currently this function only does
149 // anything under Solaris and Linux systems.
150 void setFixedBlockSize(uInt sizeInBytes);
151
152 // Configure the tape device to use variable length blocks. Currently this
153 // function only does anything under Solaris and Linux systems.
155
156 // Get the length of the tape device. Not a meaningful function for this
157 // class and this function always returns -1.
158 virtual Int64 length();
159
160 // Is the tape device readable?
161 virtual Bool isReadable() const;
162
163 // Is the tape device writable?
164 virtual Bool isWritable() const;
165
166 // Is the tape device seekable?
167 virtual Bool isSeekable() const;
168
169 // Get the name of the attached device or return a zero length string if it
170 // cannot be determined.
171 virtual String fileName() const;
172
173 // Some static convenience functions for file descriptor opening &
174 // closing. The open function returns a file descriptor and the close
175 // function requires a file descriptor as an argument.
176 // <group>
177 static int open(const Path& device, Bool writable = False);
178 static void close(int fd);
179 // </group>
180
181protected:
182 // Detach the FILE. Close it when it is owned.
183 void detach();
184
185 // Determine if the file is readable and/or writable.
187
188 // Determine if the file is seekable.
190
191 // Reset the position pointer to the given value. It returns the new
192 // position. May not work on all Tape devices use the isSeekable(0 member
193 // function to see if this function is usuable. Otherwise an Exception
194 // (AipsError) is thrown.
196
197private:
198 // The following functions are made private so that the compiler does not
199 // generate default ones. They cannot be used and are not defined.
200 TapeIO (const TapeIO& that);
201 TapeIO& operator= (const TapeIO& that);
202
203 void setBlockSize(uInt sizeInBytes);
205
212};
213
214
215
216
217} //# NAMESPACE CASACORE - END
218
219#endif
SeekOption
Define the possible seek options.
Definition ByteIO.h:80
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual Int64 doSeek(Int64 offset, ByteIO::SeekOption)
Reset the position pointer to the given value.
void detach()
Detach the FILE.
virtual void skip(uInt howMany=1)
skip the specified number of files (ie tape marks) on the tape.
void setBlockSize(uInt sizeInBytes)
void fillRWFlags()
Determine if the file is readable and/or writable.
void fillSeekable()
Determine if the file is seekable.
uInt fixedBlockSize() const
returns the block size in bytes.
void attach(const Path &device, Bool writable=False)
Attach to the given tape device.
virtual Bool isSeekable() const
Is the tape device seekable?
virtual void write(Int64 size, const void *buf)
Write the specified number of bytes.
TapeIO(const TapeIO &that)
The following functions are made private so that the compiler does not generate default ones.
String itsDeviceName
Definition TapeIO.h:211
static void close(int fd)
virtual Bool isWritable() const
Is the tape device writable?
void setFixedBlockSize(uInt sizeInBytes)
Configure the tape device to use fixed length blocks of the specified size.
virtual ~TapeIO()
The destructor will only close the file if the appropriate constructor, or attach function,...
void setVariableBlockSize()
Configure the tape device to use variable length blocks.
virtual String fileName() const
Get the name of the attached device or return a zero length string if it cannot be determined.
virtual void rewind()
Rewind the tape device to the beginning.
TapeIO(int fd)
Construct from the given file descriptor.
TapeIO(const Path &device, Bool writable=False)
Construct from the given device.
uInt getBlockSize() const
virtual Int64 read(Int64 size, void *buf, Bool throwException=True)
Read size bytes from the tape.
virtual Int64 length()
Get the length of the tape device.
void attach(int fd)
Attach to the given file descriptor.
TapeIO()
Default constructor.
virtual void mark(uInt howMany=1)
write the specified number of filemarks.
static int open(const Path &device, Bool writable=False)
Some static convenience functions for file descriptor opening & closing.
virtual Bool isReadable() const
Is the tape device readable?
Bool fixedBlocks() const
returns True if the tape device is configured to use a fixed block size
TapeIO & operator=(const TapeIO &that)
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41