w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
Rw11VirtDisk.cpp
Go to the documentation of this file.
1// $Id: Rw11VirtDisk.cpp 1190 2019-07-13 17:05:39Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-06-21 1167 1.4.1 remove dtor
8// 2018-12-02 1076 1.4 use unique_ptr for New()
9// 2018-10-27 1061 1.3 add fNCyl,fNHead,fNSect; add Rw11VirtDiskRam
10// 2017-04-07 868 1.2.1 Dump(): add detail arg
11// 2017-04-02 866 1.2 add default scheme handling
12// 2017-04-02 864 1.1 add Rw11VirtDiskOver
13// 2013-03-03 494 1.0 Initial version
14// 2013-02-13 488 0.1 First draft
15// ---------------------------------------------------------------------------
16
20#include <memory>
21
22#include "librtools/RosFill.hpp"
25#include "Rw11VirtDiskFile.hpp"
26#include "Rw11VirtDiskOver.hpp"
27#include "Rw11VirtDiskRam.hpp"
28
29#include "Rw11VirtDisk.hpp"
30
31using namespace std;
32
38// all method definitions in namespace Retro
39namespace Retro {
40
41//------------------------------------------+-----------------------------------
42// static definitions
43
44std::string Rw11VirtDisk::sDefaultScheme("file");
45
46//------------------------------------------+-----------------------------------
48
50 : Rw11Virt(punit),
51 fBlkSize(0),
52 fNBlock(0),
53 fNCyl(0),
54 fNHead(0),
55 fNSect(0)
56{
57 fStats.Define(kStatNVDRead, "NVDRead", "Read() calls");
58 fStats.Define(kStatNVDReadBlk, "NVDReadBlk", "blocks read");
59 fStats.Define(kStatNVDWrite, "NVDWrite", "Write() calls");
60 fStats.Define(kStatNVDWriteBlk,"NVDWriteBlk", "blocks written");
61}
62
63//------------------------------------------+-----------------------------------
65
66void Rw11VirtDisk::Dump(std::ostream& os, int ind, const char* text,
67 int detail) const
68{
69 RosFill bl(ind);
70 os << bl << (text?text:"--") << "Rw11VirtDisk @ " << this << endl;
71
72 os << bl << " fBlkSize: " << fBlkSize << endl;
73 os << bl << " fNBlock: " << fNBlock << endl;
74 os << bl << " fNCyl: " << fNCyl << endl;
75 os << bl << " fNHead: " << fNHead << endl;
76 os << bl << " fNSect: " << fNSect << endl;
77 Rw11Virt::Dump(os, ind, " ^", detail);
78 return;
79}
80
81//------------------------------------------+-----------------------------------
83
84std::unique_ptr<Rw11VirtDisk> Rw11VirtDisk::New(const std::string& url,
85 Rw11Unit* punit,
86 RerrMsg& emsg)
87{
88 string scheme = RparseUrl::FindScheme(url, sDefaultScheme);
89 unique_ptr<Rw11VirtDisk> up;
90
91 if (scheme == "file") { // scheme -> file:
92 up.reset(new Rw11VirtDiskFile(punit));
93 if (!up->Open(url, emsg)) up.reset();
94
95 } else if (scheme == "over") { // scheme -> over:
96 up.reset(new Rw11VirtDiskOver(punit));
97 if (!up->Open(url, emsg)) up.reset();
98
99 } else if (scheme == "ram") { // scheme -> ram:
100 up.reset(new Rw11VirtDiskRam(punit));
101 if (!up->Open(url, emsg)) up.reset();
102
103 } else { // scheme -> no match
104 emsg.Init("Rw11VirtDisk::New", string("Scheme '") + scheme +
105 "' is not supported");
106 }
107
108 return up;
109}
110
111//------------------------------------------+-----------------------------------
113
114const std::string& Rw11VirtDisk::DefaultScheme()
115{
116 return sDefaultScheme;
117}
118//------------------------------------------+-----------------------------------
120
121void Rw11VirtDisk::SetDefaultScheme(const std::string& scheme)
122{
123 if (scheme != "file" && scheme != "over")
124 throw Rexception("Rw11VirtDisk::SetDefaultScheme",
125 "only 'file' or 'over' allowed");
126
127 sDefaultScheme = scheme;
128 return;
129}
130
131} // 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
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
static void SetDefaultScheme(const std::string &scheme)
FIXME_docs.
static std::string sDefaultScheme
default scheme
static std::unique_ptr< Rw11VirtDisk > New(const std::string &url, Rw11Unit *punit, RerrMsg &emsg)
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
size_t fNBlock
disk size in blocks
size_t fBlkSize
block size in byte
Rw11VirtDisk(Rw11Unit *punit)
Default constructor.
static const std::string & DefaultScheme()
FIXME_docs.
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
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47