w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
Rw11VirtTape.cpp
Go to the documentation of this file.
1// $Id: Rw11VirtTape.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2015-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-07-08 1180 1.2.2 remove dtor
8// 2018-12-19 1090 1.2.1 use RosPrintf(bool)
9// 2018-12-02 1076 1.2 use unique_ptr for New()
10// 2017-04-07 868 1.1.1 Dump(): add detail arg
11// 2017-04-02 864 1.1 move fWProt,WProt() to Rw11Virt base
12// 2015-06-04 686 1.0 Initial version
13// 2015-05-17 683 0.1 First draft
14// ---------------------------------------------------------------------------
15
19#include <memory>
20
21#include "librtools/RosFill.hpp"
25#include "Rw11VirtTapeTap.hpp"
26
27#include "Rw11VirtTape.hpp"
28
29using namespace std;
30
36// all method definitions in namespace Retro
37namespace Retro {
38
39//------------------------------------------+-----------------------------------
41
43 : Rw11Virt(punit),
44 fCapacity(0),
45 fBot(false),
46 fEot(false),
47 fEom(true),
48 fPosFile(-1),
49 fPosRecord(-1)
50{
51 fStats.Define(kStatNVTReadRec, "NVTReadRec", "ReadRecord() calls");
52 fStats.Define(kStatNVTReadByt, "NVTReadByt", "bytes read");
53 fStats.Define(kStatNVTReadEof, "NVTReadEof", "eof read");
54 fStats.Define(kStatNVTReadEom, "NVTReadEom", "eom read");
55 fStats.Define(kStatNVTReadPErr, "NVTReadPErr", "parity error read");
56 fStats.Define(kStatNVTReadLErr, "NVTReadLErr", "length error read");
57 fStats.Define(kStatNVTWriteRec, "NVTWriteRec", "WriteRecord() calls");
58 fStats.Define(kStatNVTWriteByt, "NVTWriteByt", "bytes written");
59 fStats.Define(kStatNVTWriteEof, "NVTWriteEof", "WriteEof() calls");
60 fStats.Define(kStatNVTSpaForw, "NVTSpaForw", "SpaceForw() calls");
61 fStats.Define(kStatNVTSpaBack, "NVTSpaBack", "SpaceBack() calls");
62 fStats.Define(kStatNVTRewind, "NVTRewind", "Rewind() calls");
63}
64
65//------------------------------------------+-----------------------------------
67
68std::unique_ptr<Rw11VirtTape> Rw11VirtTape::New(const std::string& url,
69 Rw11Unit* punit, RerrMsg& emsg)
70{
71 string scheme = RparseUrl::FindScheme(url, "tap");
72 unique_ptr<Rw11VirtTape> up;
73
74 if (scheme == "tap") { // scheme -> tap:
75 up.reset(new Rw11VirtTapeTap(punit));
76 if (!up->Open(url, emsg)) up.reset();
77
78 } else { // scheme -> no match
79 emsg.Init("Rw11VirtTape::New", string("Scheme '") + scheme +
80 "' is not supported");
81 }
82
83 return up;
84}
85
86//------------------------------------------+-----------------------------------
88
89void Rw11VirtTape::SetPosFile(int posfile)
90{
91 if (posfile < 0) posfile = 0;
92
93 RerrMsg emsg;
94 int opcode;
95 size_t ndone;
96 bool rc = Rewind(opcode, emsg);
97
98 while (rc && posfile != fPosFile) {
99 rc = SpaceForw(1000000000, ndone, opcode, emsg);
100 if (rc && opcode == kOpCodeEom) return;
101 }
102
103 if (!rc) throw Rexception("Rw11VirtTape::SetPosFile", emsg.Text());
104
105 return;
106}
107
108//------------------------------------------+-----------------------------------
110
112{
113 if (posrec < 0) posrec = 0;
114
115 RerrMsg emsg;
116 int opcode;
117 size_t ndone;
118
119 // space back to begin of current file (works even when fPosRecord is -1!)
120 bool rc = SpaceBack(1000000000, ndone, opcode, emsg);
121 // if eof was spaced over backwards, space forward over eof
122 if (rc && opcode == kOpCodeEof) rc = SpaceForw(1, ndone, opcode, emsg);
123 // now space forward to find record
124 if (rc && posrec != 0) {
125 rc = SpaceForw(posrec, ndone, opcode, emsg);
126 // if eof was spaced over, space backward over eof to stay in file
127 // the number of records spaced is used to setup fPosRecord
128 if (rc && opcode == kOpCodeEof) {
129 size_t ndoneeof;
130 rc = SpaceBack(1, ndoneeof, opcode, emsg);
131 if (rc) fPosRecord = ndone;
132 }
133 }
134
135 if (!rc) throw Rexception("Rw11VirtTape::SetPosFile", emsg.Text());
136
137 return;
138}
139
140//------------------------------------------+-----------------------------------
142
143void Rw11VirtTape::Dump(std::ostream& os, int ind, const char* text,
144 int detail) const
145{
146 RosFill bl(ind);
147 os << bl << (text?text:"--") << "Rw11VirtTape @ " << this << endl;
148
149 os << bl << " fCapacity: " << fCapacity << endl;
150 os << bl << " fBot: " << RosPrintf(fBot) << endl;
151 os << bl << " fEot: " << RosPrintf(fEot) << endl;
152 os << bl << " fEom: " << RosPrintf(fEom) << endl;
153 os << bl << " fPosFile: " << fPosFile << endl;
154 os << bl << " fPosRecord: " << fPosRecord << endl;
155 Rw11Virt::Dump(os, ind, " ^", detail);
156 return;
157}
158
159
160} // end namespace Retro
FIXME_docs.
Definition: RerrMsg.hpp:25
void Init(const std::string &meth, const std::string &text)
FIXME_docs.
Definition: RerrMsg.cpp:74
const std::string & Text() const
FIXME_docs.
Definition: RerrMsg.ipp:47
FIXME_docs.
Definition: Rexception.hpp:29
I/O appicator to generate fill characters.
Definition: RosFill.hpp:24
static std::string FindScheme(const std::string &url, const std::string &def="")
FIXME_docs.
Definition: RparseUrl.cpp:238
void Define(size_t ind, const std::string &name, const std::string &text)
FIXME_docs.
Definition: Rstats.cpp:72
FIXME_docs.
Definition: Rw11Unit.hpp:39
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Rw11VirtTape(Rw11Unit *punit)
Default constructor.
@ kOpCodeEof
ended at EOF
@ kOpCodeEom
ended at EOM
void SetPosFile(int posfile)
FIXME_docs.
virtual bool SpaceForw(size_t nrec, size_t &ndone, int &opcode, RerrMsg &emsg)=0
int fPosRecord
tape pos: #record (-1=unknown)
void SetPosRecord(int posrec)
FIXME_docs.
size_t fCapacity
capacity in byte (0=unlimited)
static std::unique_ptr< Rw11VirtTape > New(const std::string &url, Rw11Unit *punit, RerrMsg &emsg)
FIXME_docs.
virtual bool Rewind(int &opcode, RerrMsg &emsg)=0
bool fBot
tape at bot
virtual bool SpaceBack(size_t nrec, size_t &ndone, int &opcode, RerrMsg &emsg)=0
bool fEom
tape beyond medium
int fPosFile
tape pos: #files (-1=unknown)
bool fEot
tape beyond eot
FIXME_docs.
Definition: Rw11Virt.hpp:34
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: Rw11Virt.cpp:60
Rstats fStats
statistics
Definition: Rw11Virt.hpp:68
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Definition: RosPrintf.ipp:38
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47