1
0
mirror of https://github.com/wfjm/w11.git synced 2026-01-13 15:37:43 +00:00

add HasPort/HasVirt(); Port() and Virt() return reference

This commit is contained in:
wfjm 2018-12-15 14:49:34 +01:00
parent 70f0911b37
commit 11e6c81379
33 changed files with 281 additions and 206 deletions

View File

@ -105,6 +105,8 @@ The full set of tests is only run for tagged releases.
- replace boost with std
- use std::unique_ptr instead of boost::scoped_ptr
- use std::shared_ptr instead of boost
- reduce usage of pointers in APIs
- add HasPort/HasVirt(); Port() and Virt() return reference
- rw11/shell.tcl: add workaround for tclreadline and `after` interference
### Bug Fixes

View File

@ -1,4 +1,4 @@
// $Id: RlinkConnect.cpp 1076 2018-12-02 12:45:49Z mueller $
// $Id: RlinkConnect.cpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 2.8 add HasPort(); return ref for Port()
// 2018-12-01 1076 2.7 use unique_ptr instead of scoped_ptr
// 2018-11-30 1075 2.6.4 use list-init; use range loop
// 2018-10-27 1059 2.6.3 coverity fixup (uncaught exception in dtor)
@ -176,19 +177,19 @@ bool RlinkConnect::Open(const std::string& name, RerrMsg& emsg)
Close();
fupPort = move(RlinkPortFactory::Open(name, emsg));
if (!fupPort) return false;
if (!HasPort()) return false;
fSndPkt.SetXonEscape(fupPort->XonEnable()); // transfer XON enable
fSndPkt.SetXonEscape(Port().XonEnable()); // transfer XON enable
fupPort->SetLogFile(fspLog);
fupPort->SetTraceLevel(fTraceLevel);
Port().SetLogFile(fspLog);
Port().SetTraceLevel(fTraceLevel);
fLinkInitDone = false;
fRbufSize = 2048; // use minimum (2kB) as startup
fSysId = 0xffffffff;
fUsrAcc = 0x00000000;
if (! fupPort->Url().FindOpt("noinit")) {
if (! Port().Url().FindOpt("noinit")) {
if (!LinkInit(emsg)) {
Close();
return false;
@ -203,13 +204,13 @@ bool RlinkConnect::Open(const std::string& name, RerrMsg& emsg)
void RlinkConnect::Close()
{
if (!fupPort) return;
if (!HasPort()) return;
if (fpServ) fpServ->Stop(); // stop server in case still running
if (fupPort->Url().FindOpt("keep")) {
if (Port().Url().FindOpt("keep")) {
RerrMsg emsg;
fSndPkt.SndKeep(fupPort.get(), emsg);
fSndPkt.SndKeep(Port(), emsg);
}
fupPort.reset();
@ -513,7 +514,7 @@ int RlinkConnect::WaitAttn(const Rtime& timeout, Rtime& twait,
Rtime tbeg = tnow;
while (tnow < tend) {
int irc = fRcvPkt.ReadData(fupPort.get(), tend-tnow, emsg);
int irc = fRcvPkt.ReadData(Port(), tend-tnow, emsg);
if (irc == RlinkPort::kTout) return -1;
if (irc == RlinkPort::kErr) return -2;
tnow.GetClock(CLOCK_MONOTONIC);
@ -547,7 +548,7 @@ bool RlinkConnect::SndOob(uint16_t addr, uint16_t data, RerrMsg& emsg)
{
boost::lock_guard<RlinkConnect> lock(*this);
fStats.Inc(kStatNSndOob);
return fSndPkt.SndOob(fupPort.get(), addr, data, emsg);
return fSndPkt.SndOob(Port(), addr, data, emsg);
}
//------------------------------------------+-----------------------------------
@ -556,7 +557,7 @@ bool RlinkConnect::SndOob(uint16_t addr, uint16_t data, RerrMsg& emsg)
bool RlinkConnect::SndAttn(RerrMsg& emsg)
{
boost::lock_guard<RlinkConnect> lock(*this);
return fSndPkt.SndAttn(fupPort.get(), emsg);
return fSndPkt.SndAttn(Port(), emsg);
}
//------------------------------------------+-----------------------------------
@ -619,7 +620,7 @@ void RlinkConnect::SetDumpLevel(uint32_t lvl)
void RlinkConnect::SetTraceLevel(uint32_t lvl)
{
fTraceLevel = lvl;
if (fupPort) fupPort->SetTraceLevel(lvl);
if (HasPort()) Port().SetTraceLevel(lvl);
return;
}
@ -687,8 +688,8 @@ void RlinkConnect::Dump(std::ostream& os, int ind, const char* text,
RosFill bl(ind);
os << bl << (text?text:"--") << "RlinkConnect @ " << this << endl;
if (fupPort) {
fupPort->Dump(os, ind+2, "fupPort: ", detail);
if (HasPort()) {
Port().Dump(os, ind+2, "fupPort: ", detail);
} else {
os << bl << " fupPort: " << fupPort.get() << endl;
}
@ -740,7 +741,7 @@ void RlinkConnect::HandleUnsolicitedData()
boost::lock_guard<RlinkConnect> lock(*this);
RerrMsg emsg;
int irc = fRcvPkt.ReadData(fupPort.get(), Rtime(), emsg);
int irc = fRcvPkt.ReadData(Port(), Rtime(), emsg);
if (irc == 0) return;
if (irc < 0) {
RlogMsg lmsg(*fspLog, 'E');
@ -766,7 +767,7 @@ bool RlinkConnect::ExecPart(RlinkCommandList& clist, size_t ibeg, size_t iend,
EncodeRequest(clist, ibeg, iend);
// FIXME_code: handle send fail properly;
if (!fSndPkt.SndPacket(fupPort.get(), emsg)) return false;
if (!fSndPkt.SndPacket(Port(), emsg)) return false;
// FIXME_code: handle recoveries
// FIXME_code: use proper value for timeout (rest time for Exec ?)
@ -1084,7 +1085,7 @@ bool RlinkConnect::ReadResponse(const Rtime& timeout, RerrMsg& emsg)
Rtime tend = tnow + timeout;
while (tnow < tend) {
int irc = fRcvPkt.ReadData(fupPort.get(), tend-tnow, emsg);
int irc = fRcvPkt.ReadData(Port(), tend-tnow, emsg);
if (irc <= 0) {
RlogMsg lmsg(*fspLog, 'E');
lmsg << "ReadResponse: IO error or timeout: " << emsg;

View File

@ -1,4 +1,4 @@
// $Id: RlinkConnect.hpp 1078 2018-12-08 14:19:03Z mueller $
// $Id: RlinkConnect.hpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 2.8 add HasPort(); return ref for Port()
// 2018-12-07 1078 2.7.1 use std::shared_ptr instead of boost
// 2018-12-01 1076 2.7 use unique_ptr instead of scoped_ptr
// 2017-04-22 883 2.6.3 add rbus monitor probe, add HasRbmon()
@ -87,7 +88,9 @@ namespace Retro {
bool Open(const std::string& name, RerrMsg& emsg);
void Close();
bool IsOpen() const;
RlinkPort* Port() const;
bool HasPort() const;
RlinkPort& Port();
const RlinkPort& Port() const;
bool LinkInit(RerrMsg& emsg);
bool LinkInitDone() const;

View File

@ -1,4 +1,4 @@
// $Id: RlinkConnect.ipp 1078 2018-12-08 14:19:03Z mueller $
// $Id: RlinkConnect.ipp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 2.7 add HasPort; return ref for Port()
// 2018-12-07 1078 2.6.1 use std::shared_ptr instead of boost
// 2018-12-01 1076 2.6 use unique_ptr instead of scoped_ptr
// 2017-04-22 883 2.5.2 add rbus monitor probe, add HasRbmon()
@ -50,9 +51,25 @@ inline bool RlinkConnect::IsOpen() const
//------------------------------------------+-----------------------------------
//! FIXME_docs
inline RlinkPort* RlinkConnect::Port() const
inline bool RlinkConnect::HasPort() const
{
return fupPort.get();
return bool(fupPort);
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
inline RlinkPort& RlinkConnect::Port()
{
return *fupPort;
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
inline const RlinkPort& RlinkConnect::Port() const
{
return *fupPort;
}
//------------------------------------------+-----------------------------------

View File

@ -1,6 +1,6 @@
// $Id: RlinkPacketBufRcv.cpp 983 2018-01-02 20:35:59Z mueller $
// $Id: RlinkPacketBufRcv.cpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2014-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 1.2 use ref not ptr for RlinkPort
// 2017-04-07 868 1.1.1 Dump(): add detail arg
// 2017-02-19 853 1.1 use Rtime
// 2014-12-25 621 1.0.1 Reorganize packet send/revd stats
@ -76,10 +77,10 @@ RlinkPacketBufRcv::~RlinkPacketBufRcv()
//------------------------------------------+-----------------------------------
//! FIXME_docs
int RlinkPacketBufRcv::ReadData(RlinkPort* port, const Rtime& timeout,
int RlinkPacketBufRcv::ReadData(RlinkPort& port, const Rtime& timeout,
RerrMsg& emsg)
{
if (port == nullptr)
if (&port==nullptr || !port.IsOpen())
throw Rexception("RlinkPacketBufRcv::ReadData()",
"Bad state: port not open");
if (fRawBufDone != fRawBufSize)
@ -89,7 +90,7 @@ int RlinkPacketBufRcv::ReadData(RlinkPort* port, const Rtime& timeout,
fRawBufDone = 0;
fRawBufSize = 0;
int irc = port->Read(fRawBuf, sizeof(fRawBuf), timeout, emsg);
int irc = port.Read(fRawBuf, sizeof(fRawBuf), timeout, emsg);
if (timeout.IsZero() && irc == RlinkPort::kTout) return 0;

View File

@ -1,6 +1,6 @@
// $Id: RlinkPacketBufRcv.hpp 1052 2018-09-30 08:10:52Z mueller $
// $Id: RlinkPacketBufRcv.hpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2014-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 1.2 use ref not ptr for RlinkPort
// 2017-04-07 868 1.1.1 Dump(): add detail arg
// 2017-02-19 853 1.1 use Rtime
// 2014-12-25 621 1.0.1 Reorganize packet send/revd stats
@ -40,7 +41,7 @@ namespace Retro {
RlinkPacketBufRcv();
~RlinkPacketBufRcv();
int ReadData(RlinkPort* port, const Rtime& timeout,
int ReadData(RlinkPort& port, const Rtime& timeout,
RerrMsg& emsg);
bool ProcessData();
void AcceptPacket();

View File

@ -1,6 +1,6 @@
// $Id: RlinkPacketBufSnd.cpp 983 2018-01-02 20:35:59Z mueller $
// $Id: RlinkPacketBufSnd.cpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2014-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 1.2 use ref not ptr for RlinkPort
// 2017-04-07 868 1.1.1 Dump(): add detail arg
// 2015-04-11 666 1.1 handle xon/xoff escaping, add (Set)XonEscape()
// 2014-12-25 621 1.0.1 Reorganize packet send/revd stats
@ -89,7 +90,7 @@ void RlinkPacketBufSnd::PutWithCrc(const uint16_t* pdata, size_t count)
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RlinkPacketBufSnd::SndPacket(RlinkPort* port, RerrMsg& emsg)
bool RlinkPacketBufSnd::SndPacket(RlinkPort& port, RerrMsg& emsg)
{
size_t nesc = 0;
size_t nxesc = 0;
@ -138,7 +139,7 @@ bool RlinkPacketBufSnd::SndPacket(RlinkPort* port, RerrMsg& emsg)
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RlinkPacketBufSnd::SndOob(RlinkPort* port, uint16_t addr, uint16_t data,
bool RlinkPacketBufSnd::SndOob(RlinkPort& port, uint16_t addr, uint16_t data,
RerrMsg& emsg)
{
Init();
@ -161,7 +162,7 @@ bool RlinkPacketBufSnd::SndOob(RlinkPort* port, uint16_t addr, uint16_t data,
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RlinkPacketBufSnd::SndKeep(RlinkPort* port, RerrMsg& emsg)
bool RlinkPacketBufSnd::SndKeep(RlinkPort& port, RerrMsg& emsg)
{
Init();
@ -175,7 +176,7 @@ bool RlinkPacketBufSnd::SndKeep(RlinkPort* port, RerrMsg& emsg)
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RlinkPacketBufSnd::SndAttn(RlinkPort* port, RerrMsg& emsg)
bool RlinkPacketBufSnd::SndAttn(RlinkPort& port, RerrMsg& emsg)
{
Init();
@ -187,7 +188,7 @@ bool RlinkPacketBufSnd::SndAttn(RlinkPort* port, RerrMsg& emsg)
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RlinkPacketBufSnd::SndNak(RlinkPort* port, RerrMsg& emsg)
bool RlinkPacketBufSnd::SndNak(RlinkPort& port, RerrMsg& emsg)
{
Init();
@ -199,7 +200,7 @@ bool RlinkPacketBufSnd::SndNak(RlinkPort* port, RerrMsg& emsg)
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RlinkPacketBufSnd::SndUnJam(RlinkPort* port, RerrMsg& emsg)
bool RlinkPacketBufSnd::SndUnJam(RlinkPort& port, RerrMsg& emsg)
{
Init();
@ -236,13 +237,13 @@ void RlinkPacketBufSnd::Dump(std::ostream& os, int ind, const char* text,
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RlinkPacketBufSnd::SndRaw(RlinkPort* port, RerrMsg& emsg)
bool RlinkPacketBufSnd::SndRaw(RlinkPort& port, RerrMsg& emsg)
{
if (port==0 || !port->IsOpen())
if (&port==nullptr || !port.IsOpen())
throw Rexception("RlinkPacketBufSnd::SndRaw()", "Bad state: port not open");
size_t rawbufsize = fRawBuf.size();
int irc = port->Write(fRawBuf.data(), rawbufsize, emsg);
int irc = port.Write(fRawBuf.data(), rawbufsize, emsg);
if (irc < 0) return false;
if ((size_t)irc != rawbufsize) {
emsg.Init("RlinkPacketBufSnd::SndRaw()", "failed to write all data");

View File

@ -1,6 +1,6 @@
// $Id: RlinkPacketBufSnd.hpp 983 2018-01-02 20:35:59Z mueller $
// $Id: RlinkPacketBufSnd.hpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2014-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 1.2 use ref not ptr for RlinkPort
// 2017-04-07 868 1.1.2 Dump(): add detail arg
// 2015-04-11 666 1.1 handle xon/xoff escaping, add (Set)XonEscape()
// 2014-12-25 621 1.0.1 Reorganize packet send/revd stats
@ -38,7 +39,7 @@ namespace Retro {
public:
RlinkPacketBufSnd();
~RlinkPacketBufSnd();
~RlinkPacketBufSnd();
void SetXonEscape(bool xon);
bool XonEscape() const;
@ -52,13 +53,13 @@ namespace Retro {
void PutRawEsc(uint8_t ec);
bool SndPacket(RlinkPort* port, RerrMsg& emsg);
bool SndOob(RlinkPort* port, uint16_t addr, uint16_t data,
bool SndPacket(RlinkPort& port, RerrMsg& emsg);
bool SndOob(RlinkPort& port, uint16_t addr, uint16_t data,
RerrMsg& emsg);
bool SndKeep(RlinkPort* port, RerrMsg& emsg);
bool SndAttn(RlinkPort* port, RerrMsg& emsg);
bool SndNak(RlinkPort* port, RerrMsg& emsg);
bool SndUnJam(RlinkPort* port, RerrMsg& emsg);
bool SndKeep(RlinkPort& port, RerrMsg& emsg);
bool SndAttn(RlinkPort& port, RerrMsg& emsg);
bool SndNak(RlinkPort& port, RerrMsg& emsg);
bool SndUnJam(RlinkPort& port, RerrMsg& emsg);
size_t RawSize() const;
@ -73,7 +74,7 @@ namespace Retro {
};
protected:
bool SndRaw(RlinkPort* port, RerrMsg& emsg);
bool SndRaw(RlinkPort& port, RerrMsg& emsg);
protected:
bool fXonEscape; //!< escape XON/XOFF

View File

@ -1,4 +1,4 @@
// $Id: RlinkServer.cpp 1078 2018-12-08 14:19:03Z mueller $
// $Id: RlinkServer.cpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -413,7 +413,7 @@ void RlinkServer::StartOrResume(bool resume)
Exec(clist);
// setup poll handler for Rlink traffic
int rlinkfd = fspConn->Port()->FdRead();
int rlinkfd = fspConn->Port().FdRead();
if (!fELoop.TestPollHandler(rlinkfd, POLLIN))
fELoop.AddPollHandler(boost::bind(&RlinkServer::RlinkHandler, this, _1),
rlinkfd, POLLIN);

View File

@ -1,4 +1,4 @@
// $Id: RtclRlinkConnect.cpp 1077 2018-12-07 19:37:03Z mueller $
// $Id: RtclRlinkConnect.cpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 1.6.4 use HasPort(); Port() returns now ref
// 2018-12-07 1077 1.6.3 use SetLastExpectBlock move semantics
// 2018-11-16 1070 1.6.2 use auto; use range loop
// 2018-09-16 1047 1.6.1 coverity fixup (uninitialized scalar)
@ -197,7 +198,7 @@ int RtclRlinkConnect::M_open(RtclArgs& args)
if (args.NOptMiss() == 0) { // open path
if (!Obj().Open(path, emsg)) return args.Quit(emsg);
} else { // open
string name = Obj().IsOpen() ? Obj().Port()->Url().Url() : string();
string name = Obj().IsOpen() ? Obj().Port().Url().Url() : string();
args.SetResult(name);
}
return kOK;
@ -684,6 +685,8 @@ int RtclRlinkConnect::M_oob(RtclArgs& args)
int RtclRlinkConnect::M_rawread(RtclArgs& args)
{
if (!(Obj().HasPort() &&
Obj().Port().IsOpen())) return args.Quit("-E: port not open");
return RtclRlinkPort::DoRawRead(args, Obj().Port());
}
@ -692,6 +695,8 @@ int RtclRlinkConnect::M_rawread(RtclArgs& args)
int RtclRlinkConnect::M_rawrblk(RtclArgs& args)
{
if (!(Obj().HasPort() &&
Obj().Port().IsOpen())) return args.Quit("-E: port not open");
size_t errcnt = 0;
int rc = RtclRlinkPort::DoRawRblk(args, Obj().Port(), errcnt);
Obj().Context().IncErrorCount(errcnt);
@ -703,6 +708,8 @@ int RtclRlinkConnect::M_rawrblk(RtclArgs& args)
int RtclRlinkConnect::M_rawwblk(RtclArgs& args)
{
if (!(Obj().HasPort() &&
Obj().Port().IsOpen())) return args.Quit("-E: port not open");
return RtclRlinkPort::DoRawWblk(args, Obj().Port());
}
@ -716,8 +723,8 @@ int RtclRlinkConnect::M_stats(RtclArgs& args)
if (!RtclStats::Collect(args, cntx, Obj().Stats())) return kERR;
if (!RtclStats::Collect(args, cntx, Obj().SndStats())) return kERR;
if (!RtclStats::Collect(args, cntx, Obj().RcvStats())) return kERR;
if (Obj().Port()) {
if (!RtclStats::Collect(args, cntx, Obj().Port()->Stats())) return kERR;
if (Obj().HasPort()) {
if (!RtclStats::Collect(args, cntx, Obj().Port().Stats())) return kERR;
}
return kOK;
}

View File

@ -1,4 +1,4 @@
// $Id: RtclRlinkPort.cpp 1076 2018-12-02 12:45:49Z mueller $
// $Id: RtclRlinkPort.cpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 1.4 use ref not ptr for RlinkPort
// 2018-12-01 1076 1.3 use unique_ptr
// 2017-04-29 888 1.2 LogFileName(): returns now const std::string&
// drop M_rawio; add M_rawread,M_rawrblk,M_rawwblk
@ -64,7 +65,9 @@ RtclRlinkPort::RtclRlinkPort(Tcl_Interp* interp, const char* name)
fupObj(),
fspLog(new RlogFile(&cout)),
fTraceLevel(0),
fErrCnt(0)
fErrCnt(0),
fGets(),
fSets()
{
CreateObjectCmd(interp, name);
AddMeth("open", boost::bind(&RtclRlinkPort::M_open, this, _1));
@ -119,7 +122,7 @@ int RtclRlinkPort::M_open(RtclArgs& args)
int RtclRlinkPort::M_close(RtclArgs& args)
{
if (!args.AllDone()) return kERR;
if (!TestOpen(args)) return kERR;
if (!TestPort(args, false)) return kERR;
fupObj.reset();
SetupGetSet();
return kOK;
@ -150,7 +153,8 @@ int RtclRlinkPort::M_errcnt(RtclArgs& args)
int RtclRlinkPort::M_rawread(RtclArgs& args)
{
return DoRawRead(args, fupObj.get());
if (!TestPort(args)) return kERR;
return DoRawRead(args, *fupObj);
}
//------------------------------------------+-----------------------------------
@ -158,7 +162,8 @@ int RtclRlinkPort::M_rawread(RtclArgs& args)
int RtclRlinkPort::M_rawrblk(RtclArgs& args)
{
return DoRawRblk(args, fupObj.get(), fErrCnt);
if (!TestPort(args)) return kERR;
return DoRawRblk(args, *fupObj, fErrCnt);
}
//------------------------------------------+-----------------------------------
@ -166,7 +171,8 @@ int RtclRlinkPort::M_rawrblk(RtclArgs& args)
int RtclRlinkPort::M_rawwblk(RtclArgs& args)
{
return DoRawWblk(args, fupObj.get());
if (!TestPort(args)) return kERR;
return DoRawWblk(args, *fupObj);
}
//------------------------------------------+-----------------------------------
@ -176,7 +182,7 @@ int RtclRlinkPort::M_stats(RtclArgs& args)
{
RtclStats::Context cntx;
if (!TestOpen(args)) return kERR;
if (!TestPort(args, false)) return kERR;
if (!RtclStats::GetArgs(args, cntx)) return kERR;
if (!RtclStats::Collect(args, cntx, fupObj->Stats())) return kERR;
return kOK;
@ -202,7 +208,7 @@ int RtclRlinkPort::M_dump(RtclArgs& args)
int detail=0;
if (!GetArgsDump(args, detail)) return kERR;
if (!args.AllDone()) return kERR;
if (!TestOpen(args)) return kERR;
if (!TestPort(args, false)) return kERR;
ostringstream sos;
fupObj->Dump(sos, 0, "", 0);
@ -266,9 +272,9 @@ void RtclRlinkPort::SetupGetSet()
//------------------------------------------+-----------------------------------
//! FIXME_docs
bool RtclRlinkPort::TestOpen(RtclArgs& args)
bool RtclRlinkPort::TestPort(RtclArgs& args, bool testopen)
{
if (fupObj) return true;
if (fupObj && (!testopen || fupObj->IsOpen())) return true;
args.AppendResult("-E: port not open", nullptr);
return false;
}
@ -298,10 +304,8 @@ inline const std::string& RtclRlinkPort::LogFileName() const
//------------------------------------------+-----------------------------------
//! FIXME_docs
int RtclRlinkPort::DoRawRead(RtclArgs& args, RlinkPort* pport)
int RtclRlinkPort::DoRawRead(RtclArgs& args, RlinkPort& port)
{
if (!(pport && pport->IsOpen())) return args.Quit("-E: port not open");
int32_t rsize;
string rvname;
vector<uint8_t> rdata;
@ -322,8 +326,8 @@ int RtclRlinkPort::DoRawRead(RtclArgs& args, RlinkPort* pport)
Rtime tused;
rdata.resize(rsize);
int irc = pport->RawRead(rdata.data(), rdata.size(), false, Rtime(timeout),
tused, emsg);
int irc = port.RawRead(rdata.data(), rdata.size(), false, Rtime(timeout),
tused, emsg);
if (irc == RlinkPort::kEof) return args.Quit("-E: RawRead EOF");
if (irc == RlinkPort::kTout) return args.Quit("-E: RawRead timeout");
@ -342,10 +346,8 @@ int RtclRlinkPort::DoRawRead(RtclArgs& args, RlinkPort* pport)
//------------------------------------------+-----------------------------------
//! FIXME_docs
int RtclRlinkPort::DoRawRblk(RtclArgs& args, RlinkPort* pport, size_t& errcnt)
int RtclRlinkPort::DoRawRblk(RtclArgs& args, RlinkPort& port, size_t& errcnt)
{
if (!(pport && pport->IsOpen())) return args.Quit("-E: port not open");
int32_t rsize;
string rvname;
vector<uint8_t> rdata;
@ -371,8 +373,8 @@ int RtclRlinkPort::DoRawRblk(RtclArgs& args, RlinkPort* pport, size_t& errcnt)
Rtime tused;
rdata.resize(rsize);
int irc = pport->RawRead(rdata.data(), rdata.size(), true, Rtime(timeout),
tused, emsg);
int irc = port.RawRead(rdata.data(), rdata.size(), true, Rtime(timeout),
tused, emsg);
if (irc == RlinkPort::kEof) return args.Quit("-E: RawRead EOF");
if (irc == RlinkPort::kTout) return args.Quit("-E: RawRead timeout");
if (irc < 0) return args.Quit(emsg);
@ -399,15 +401,13 @@ int RtclRlinkPort::DoRawRblk(RtclArgs& args, RlinkPort* pport, size_t& errcnt)
//------------------------------------------+-----------------------------------
//! FIXME_docs
int RtclRlinkPort::DoRawWblk(RtclArgs& args, RlinkPort* pport)
int RtclRlinkPort::DoRawWblk(RtclArgs& args, RlinkPort& port)
{
if (!(pport && pport->IsOpen())) return args.Quit("-E: port not open");
vector<uint8_t> wdata;
if (!args.GetArg("data", wdata, 1, 4096)) return kERR;
RerrMsg emsg;
int irc = pport->RawWrite(wdata.data(), wdata.size(), emsg);
int irc = port.RawWrite(wdata.data(), wdata.size(), emsg);
if (irc != (int)wdata.size()) return args.Quit(emsg);
return kOK;

View File

@ -1,4 +1,4 @@
// $Id: RtclRlinkPort.hpp 1078 2018-12-08 14:19:03Z mueller $
// $Id: RtclRlinkPort.hpp 1079 2018-12-09 10:56:59Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-08 1079 1.3 use ref not ptr for RlinkPort
// 2018-12-07 1078 1.2.1 use std::shared_ptr instead of boost
// 2018-12-01 1076 1.2 use unique_ptr
// 2017-04-29 888 1.1 LogFileName(): returns now const std::string&
@ -65,13 +66,13 @@ namespace Retro {
int M_default(RtclArgs& args);
void SetupGetSet();
bool TestOpen(RtclArgs& args);
bool TestPort(RtclArgs& args, bool testopen=true);
void SetLogFileName(const std::string& name);
const std::string& LogFileName() const;
static int DoRawRead(RtclArgs& args, RlinkPort* pport);
static int DoRawRblk(RtclArgs& args, RlinkPort* pport, size_t& errcnt);
static int DoRawWblk(RtclArgs& args, RlinkPort* pport);
static int DoRawRead(RtclArgs& args, RlinkPort& port);
static int DoRawRblk(RtclArgs& args, RlinkPort& port, size_t& errcnt);
static int DoRawWblk(RtclArgs& args, RlinkPort& port);
protected:
RlinkPort::port_uptr_t fupObj; //!< uptr to managed port

View File

@ -1,4 +1,4 @@
// $Id: Rw11CntlDEUNA.cpp 1078 2018-12-08 14:19:03Z mueller $
// $Id: Rw11CntlDEUNA.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 0.5.4 use HasVirt(); Virt() returns ref
// 2018-12-08 1078 0.5.3 BUGFIX: Start(Tx|Rx)Ring, was broken in r1049
// when fixing -Wunused-variable warnings
// 2018-11-30 1075 0.5.2 use list-init
@ -380,7 +381,7 @@ void Rw11CntlDEUNA::UnitSetup(size_t /*ind*/)
void Rw11CntlDEUNA::SetType(const std::string& type)
{
if (fPr1State != kSTATE_READY || fspUnit[0]->Virt())
if (fPr1State != kSTATE_READY || fspUnit[0]->HasVirt())
throw Rexception("Rw11CntlDEUNA::SetType",
string("Bad state: not in READY state or attached"));
@ -444,7 +445,7 @@ void Rw11CntlDEUNA::SetMacDefault(const std::string& mac)
throw Rexception("Rw11CntlDEUNA::SetMacDefault",
string("Bad args: mcast address given, lsb not 0"));
if (fPr1State == kSTATE_READY && // if not running
(!fspUnit[0]->Virt()) && // and not attached
(!fspUnit[0]->HasVirt()) && // and not attached
fMacList[0] == fMacDefault) { // and old pa was old dpa
fMacList[0] = bmac; // update also pa !
}
@ -1363,7 +1364,7 @@ uint16_t Rw11CntlDEUNA::GetPr1() const
if (fPr1Delua) {
pr1 |= kPR1_M_DELUA;
} else {
if (!fspUnit[0]->Virt()) {
if (!fspUnit[0]->HasVirt()) {
pr1 |= kPR1_M_XPWR | kPR1_M_ICAB;
}
}
@ -1561,9 +1562,9 @@ int Rw11CntlDEUNA::TxRingHandler()
}
LogFrameInfo('t', fTxBuf); // log transmitted frame
if (unit.Virt()) { // attached ?
if (unit.HasVirt()) { // attached ?
RerrMsg emsg;
unit.Virt()->Snd(fTxBuf, emsg);
unit.Virt().Snd(fTxBuf, emsg);
// FIXME_code: error handling
}

View File

@ -1,4 +1,4 @@
// $Id: Rw11CntlLP11.cpp 983 2018-01-02 20:35:59Z mueller $
// $Id: Rw11CntlLP11.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -123,7 +123,7 @@ void Rw11CntlLP11::Start()
void Rw11CntlLP11::UnitSetup(size_t ind)
{
Rw11UnitLP11& unit = *fspUnit[ind];
SetOnline(unit.Virt()); // online if stream attached
SetOnline(unit.HasVirt()); // online if stream attached
return;
}

View File

@ -1,4 +1,4 @@
// $Id: Rw11CntlPC11.cpp 1062 2018-10-28 11:14:20Z mueller $
// $Id: Rw11CntlPC11.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.3.2 use HasVirt(); Virt() returns ref
// 2018-10-28 1062 1.3.1 replace boost/foreach
// 2017-05-14 897 1.3 trace received chars
// 2017-04-02 865 1.2.2 Dump(): add detail arg
@ -226,7 +227,7 @@ bool Rw11CntlPC11::BootCode(size_t /*unit*/, std::vector<uint16_t>& code,
void Rw11CntlPC11::UnitSetup(size_t ind)
{
Rw11UnitPC11& unit = *fspUnit[ind];
SetOnline(ind, unit.Virt()); // online if stream attached
SetOnline(ind, unit.HasVirt()); // online if stream attached
return;
}

View File

@ -1,4 +1,4 @@
// $Id: Rw11CntlRHRP.cpp 1062 2018-10-28 11:14:20Z mueller $
// $Id: Rw11CntlRHRP.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2015-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Other credits:
@ -15,6 +15,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.7 use HasVirt(); Virt() returns ref
// 2018-10-28 1062 1.0.6 replace boost/foreach
// 2017-04-02 865 1.0.5 Dump(): add detail arg
// 2017-03-03 858 1.0.4 use cntl name as message prefix
@ -297,7 +298,7 @@ void Rw11CntlRHRP::UnitSetup(size_t ind)
if (unit.Type() != "off") { // is enabled
rpds |= kRPDS_M_DPR;
if (unit.Virt()) { // file attached
if (unit.HasVirt()) { // file attached
rpds |= kRPDS_M_MOL; // -> set MOL
rpds |= kRPDS_M_ERP; // -> clear ER1 via ERP=1
if (unit.WProt()) rpds |= kRPDS_M_WRL; // in case write protected
@ -498,7 +499,7 @@ int Rw11CntlRHRP::AttnHandler(RlinkServer::AttnArgs& args)
// SEEK and others are done in ibdr_rhrp autonomously
// not attached --> signal drive unsave status
if (! unit.Virt()) { // not attached
if (! unit.HasVirt()) { // not attached
AddErrorExit(clist, kRPER1_M_UNS); // signal UNS (drive unsafe)
Server().Exec(clist); // doit
return 0;

View File

@ -1,4 +1,4 @@
// $Id: Rw11CntlRK11.cpp 1062 2018-10-28 11:14:20Z mueller $
// $Id: Rw11CntlRK11.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Other credits:
@ -15,6 +15,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 2.0.7 use HasVirt(); Virt() returns ref
// 2018-10-28 1062 2.0.6 replace boost/foreach
// 2017-04-02 865 2.0.5 Dump(): add detail arg
// 2017-03-03 858 2.0.4 use cntl name as message prefix
@ -232,7 +233,7 @@ void Rw11CntlRK11::UnitSetup(size_t ind)
RlinkCommandList clist;
uint16_t rkds = ind<<kRKDS_V_ID;
if (unit.Virt()) { // file attached
if (unit.HasVirt()) { // file attached
rkds |= kRKDS_M_HDEN; // always high density
rkds |= kRKDS_M_SOK; // always sector counter OK ?FIXME?
rkds |= kRKDS_M_DRY; // drive available
@ -390,7 +391,7 @@ int Rw11CntlRK11::AttnHandler(RlinkServer::AttnArgs& args)
// check for general abort conditions
if (fu != kFUNC_CRESET && // function not control reset
(!unit.Virt())) { // and drive not attached
(!unit.HasVirt())) { // and drive not attached
rker = kRKER_M_NXD; // --> abort with NXD error
} else if (fu != kFUNC_WRITE && // function neither write

View File

@ -1,4 +1,4 @@
// $Id: Rw11CntlRL11.cpp 1062 2018-10-28 11:14:20Z mueller $
// $Id: Rw11CntlRL11.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Other credits:
@ -16,6 +16,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.7 use HasVirt(); Virt() returns ref
// 2018-10-28 1062 1.0.6 replace boost/foreach
// 2017-04-02 865 1.0.5 Dump(): add detail arg
// 2017-03-03 858 1.0.4 use cntl name as message prefix
@ -278,7 +279,7 @@ void Rw11CntlRL11::UnitSetup(size_t ind)
if (unit.Type() == "rl02") // is it RL02
sta |= kSTA_M_DT; // set DT bit (1=RL02,0=RL01)
if (unit.Virt()) { // file attached
if (unit.HasVirt()) { // file attached
sta |= kSTA_M_HO | kSTA_M_BH | kST_LOCK; // HO=1; BH=1; ST=LOCK
if (unit.WProt()) // in case write protected
sta |= kSTA_M_WL; // WL=1
@ -471,7 +472,7 @@ int Rw11CntlRL11::AttnHandler(RlinkServer::AttnArgs& args)
// SEEK and GSTA are done in ibdr_rl11 autonomously
// not attached --> assumed Offline, status = load
if (! unit.Virt()) { // not attached
if (! unit.HasVirt()) { // not attached
AddErrorExit(clist, kERR_OPI); // just signal OPI
// drive stat is LOAD anyway
Server().Exec(clist); // doit

View File

@ -1,4 +1,4 @@
// $Id: Rw11CntlTM11.cpp 1062 2018-10-28 11:14:20Z mueller $
// $Id: Rw11CntlTM11.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2015-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Other credits:
@ -15,6 +15,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.6 use HasVirt(); Virt() returns ref
// 2018-10-28 1062 1.0.5 replace boost/foreach
// 2017-04-02 865 1.0.4 Dump(): add detail arg
// 2017-03-03 858 1.0.3 use cntl name as message prefix
@ -216,10 +217,10 @@ void Rw11CntlTM11::UnitSetup(size_t ind)
RlinkCommandList clist;
uint16_t tmds = 0;
if (unit.Virt()) { // file attached
if (unit.HasVirt()) { // file attached
tmds |= kTMRL_M_ONL;
if (unit.Virt()->WProt()) tmds |= kTMRL_M_WRL;
if (unit.Virt()->Bot()) tmds |= kTMRL_M_BOT;
if (unit.Virt().WProt()) tmds |= kTMRL_M_WRL;
if (unit.Virt().Bot()) tmds |= kTMRL_M_BOT;
}
unit.SetTmds(tmds);
cpu.AddWibr(clist, fBase+kTMCR, (uint16_t(ind)<<kTMCR_V_RUNIT)|
@ -364,7 +365,7 @@ int Rw11CntlTM11::AttnHandler(RlinkServer::AttnArgs& args)
fu == kFUNC_WEIRG ||
fu == kFUNC_WEOF;
if ((!unit.Virt()) || (wcmd && unit.Virt()->WProt()) ) {
if ((!unit.HasVirt()) || (wcmd && unit.Virt().WProt()) ) {
AddErrorExit(clist, kTMCR_M_RICMD);
Server().Exec(clist);
return 0;
@ -508,12 +509,12 @@ void Rw11CntlTM11::AddFastExit(RlinkCommandList& clist, int opcode, size_t ndone
uint16_t tmds = 0;
// AddFastExit() is also called after UNLOAD, which calls unit.Detach()
// So unlike in all other cases, Virt() may be 0, so check on this
if (unit.Virt()) {
// So unlike in all other cases, HasVirt() may be false, so check on this
if (unit.HasVirt()) {
tmds |= kTMRL_M_ONL;
if (unit.Virt()->WProt()) tmds |= kTMRL_M_WRL;
if (unit.Virt()->Bot()) tmds |= kTMRL_M_BOT;
if (unit.Virt()->Eot()) tmds |= kTMRL_M_EOT;
if (unit.Virt().WProt()) tmds |= kTMRL_M_WRL;
if (unit.Virt().Bot()) tmds |= kTMRL_M_BOT;
if (unit.Virt().Eot()) tmds |= kTMRL_M_EOT;
}
switch (opcode) {
@ -566,9 +567,9 @@ void Rw11CntlTM11::AddNormalExit(RlinkCommandList& clist, size_t ndone,
Rw11Cpu& cpu = Cpu();
uint16_t tmds = kTMRL_M_ONL;
if (unit.Virt()->WProt()) tmds |= kTMRL_M_WRL;
if (unit.Virt()->Bot()) tmds |= kTMRL_M_BOT;
if (unit.Virt()->Eot()) tmds |= kTMRL_M_EOT;
if (unit.Virt().WProt()) tmds |= kTMRL_M_WRL;
if (unit.Virt().Bot()) tmds |= kTMRL_M_BOT;
if (unit.Virt().Eot()) tmds |= kTMRL_M_EOT;
uint32_t addr = fRd_addr + 2*ndone;
uint16_t tmbc = fRd_tmbc + 2*uint16_t(ndone);

View File

@ -1,4 +1,4 @@
// $Id: Rw11UnitDEUNA.cpp 1076 2018-12-02 12:45:49Z mueller $
// $Id: Rw11UnitDEUNA.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.2 use HasVirt(); Virt() returns ref
// 2018-12-01 1076 1.0.1 use unique_ptr
// 2017-01-29 847 1.0 Initial version
// 2014-06-09 561 0.1 First draft
@ -72,7 +73,7 @@ void Rw11UnitDEUNA::Dump(std::ostream& os, int ind, const char* text,
void Rw11UnitDEUNA::AttachDone()
{
fupVirt->SetupRcvCallback(boost::bind(&Rw11CntlDEUNA::RcvCallback,
Virt().SetupRcvCallback(boost::bind(&Rw11CntlDEUNA::RcvCallback,
&Cntl(), _1));
Cntl().UnitSetup(0);
return;

View File

@ -1,4 +1,4 @@
// $Id: Rw11UnitDisk.cpp 1060 2018-10-27 11:32:39Z mueller $
// $Id: Rw11UnitDisk.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.3 use HasVirt(); Virt() returns ref
// 2017-04-07 868 1.0.2 Dump(): add detail arg
// 2015-03-21 659 1.0.1 add fEnabled, Enabled()
// 2013-04-19 507 1.0 Initial version
@ -74,11 +75,11 @@ void Rw11UnitDisk::SetType(const std::string& /*type*/)
bool Rw11UnitDisk::VirtRead(size_t lba, size_t nblk, uint8_t* data,
RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitDisk::VirtRead", "no disk attached");
return false;
}
return Virt()->Read(lba, nblk, data, emsg);
return Virt().Read(lba, nblk, data, emsg);
}
//------------------------------------------+-----------------------------------
@ -87,11 +88,11 @@ bool Rw11UnitDisk::VirtRead(size_t lba, size_t nblk, uint8_t* data,
bool Rw11UnitDisk::VirtWrite(size_t lba, size_t nblk, const uint8_t* data,
RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitDisk::VirtWrite", "no disk attached");
return false;
}
return Virt()->Write(lba, nblk, data, emsg);
return Virt().Write(lba, nblk, data, emsg);
}
//------------------------------------------+-----------------------------------

View File

@ -1,4 +1,4 @@
// $Id: Rw11UnitDiskBase.ipp 1061 2018-10-27 17:39:11Z mueller $
// $Id: Rw11UnitDiskBase.ipp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.1.3 use HasVirt(); Virt() returns ref
// 2018-10-27 1061 1.1.2 adapt to new Rw11VirtDisk::Setup interface
// 2017-04-07 868 1.1.1 Dump(): add detail arg
// 2013-05-03 515 1.1 use AttachDone(),DetachCleanup(),DetachDone()
@ -80,7 +81,7 @@ void Rw11UnitDiskBase<TC>::Dump(std::ostream& os, int ind, const char* text,
template <class TC>
void Rw11UnitDiskBase<TC>::AttachDone()
{
Virt()->Setup(BlockSize(), NBlock(), NCylinder(), NHead(), NSector());
Virt().Setup(BlockSize(), NBlock(), NCylinder(), NHead(), NSector());
Cntl().UnitSetup(Index());
return;
}

View File

@ -1,6 +1,6 @@
// $Id: Rw11UnitRHRP.cpp 983 2018-01-02 20:35:59Z mueller $
// $Id: Rw11UnitRHRP.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2015-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2015-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.2 use HasVirt(); Virt() returns ref
// 2017-04-07 868 1.0.1 Dump(): add detail arg
// 2015-05-14 680 1.0 Initial version
// 2015-03-21 659 0.1 First draft
@ -77,7 +78,7 @@ Rw11UnitRHRP::~Rw11UnitRHRP()
void Rw11UnitRHRP::SetType(const std::string& type)
{
if (Virt()) {
if (HasVirt()) {
throw Rexception("Rw11UnitRHRP::SetType",
string("Bad state: file attached"));
}

View File

@ -1,6 +1,6 @@
// $Id: Rw11UnitRL11.cpp 983 2018-01-02 20:35:59Z mueller $
// $Id: Rw11UnitRL11.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2014-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2014-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.3 use HasVirt(); Virt() returns ref
// 2017-04-07 868 1.0.2 Dump(): add detail arg
// 2015-03-21 659 1.0.1 BUGFIX: SetType(): set fType;
// 2014-06-08 561 1.0 Initial version
@ -70,7 +71,7 @@ Rw11UnitRL11::~Rw11UnitRL11()
void Rw11UnitRL11::SetType(const std::string& type)
{
if (Virt()) {
if (HasVirt()) {
throw Rexception("Rw11UnitRL11::SetType",
string("Bad state: file attached"));
}

View File

@ -1,6 +1,6 @@
// $Id: Rw11UnitStream.cpp 983 2018-01-02 20:35:59Z mueller $
// $Id: Rw11UnitStream.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.1.2 use HasVirt(); Virt() returns ref; Pos() not const
// 2017-04-07 868 1.1.1 Dump(): add detail arg
// 2017-02-04 848 1.1 Pos(): return -1 if not attached
// 2013-05-04 515 1.0 Initial version
@ -61,23 +62,23 @@ Rw11UnitStream::~Rw11UnitStream()
void Rw11UnitStream::SetPos(int pos)
{
if (!Virt())
if (!HasVirt())
throw Rexception("Rw11UnitStream::SetPos", "no stream attached");
RerrMsg emsg;
if (!Virt()->Seek(pos, emsg)) throw Rexception(emsg);
if (!Virt().Seek(pos, emsg)) throw Rexception(emsg);
return;
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
int Rw11UnitStream::Pos() const
int Rw11UnitStream::Pos()
{
if (!Virt()) return -1; // allow tcl 'get ?' if not attached
if (!HasVirt()) return -1; // allow tcl 'get ?' if not attached
RerrMsg emsg;
int irc = Virt()->Tell(emsg);
int irc = Virt().Tell(emsg);
if (irc < 0) throw Rexception(emsg);
return irc;
}
@ -87,12 +88,12 @@ int Rw11UnitStream::Pos() const
int Rw11UnitStream::VirtRead(uint8_t* data, size_t count, RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
fStats.Inc(kStatNPreAttMiss);
emsg.Init("Rw11UnitStream::VirtRead", "no stream attached");
return -1;
}
return Virt()->Read(data, count, emsg);
return Virt().Read(data, count, emsg);
}
//------------------------------------------+-----------------------------------
@ -100,12 +101,12 @@ int Rw11UnitStream::VirtRead(uint8_t* data, size_t count, RerrMsg& emsg)
bool Rw11UnitStream::VirtWrite(const uint8_t* data, size_t count, RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
fStats.Inc(kStatNPreAttDrop, double(count));
emsg.Init("Rw11UnitStream::VirtWrite", "no stream attached");
return false;
}
return Virt()->Write(data, count, emsg);
return Virt().Write(data, count, emsg);
}
//------------------------------------------+-----------------------------------
@ -113,11 +114,11 @@ bool Rw11UnitStream::VirtWrite(const uint8_t* data, size_t count, RerrMsg& emsg)
bool Rw11UnitStream::VirtFlush(RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitStream::VirtFlush", "no stream attached");
return false;
}
return Virt()->Flush(emsg);
return Virt().Flush(emsg);
}
//------------------------------------------+-----------------------------------

View File

@ -1,6 +1,6 @@
// $Id: Rw11UnitStream.hpp 983 2018-01-02 20:35:59Z mueller $
// $Id: Rw11UnitStream.hpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.2 Pos() not const anymore
// 2017-04-07 868 1.0.1 Dump(): add detail arg
// 2013-05-04 515 1.0 Initial version
// 2013-05-01 513 0.1 First draft
@ -39,7 +40,7 @@ namespace Retro {
~Rw11UnitStream();
void SetPos(int pos);
int Pos() const;
int Pos();
int VirtRead(uint8_t* data, size_t count, RerrMsg& emsg);
bool VirtWrite(const uint8_t* data, size_t count, RerrMsg& emsg);

View File

@ -1,4 +1,4 @@
// $Id: Rw11UnitTape.cpp 1060 2018-10-27 11:32:39Z mueller $
// $Id: Rw11UnitTape.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2015-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.2 use HasVirt(); Virt() returns ref
// 2017-04-07 868 1.0.1 Dump(): add detail arg
// 2015-06-04 686 1.0 Initial version
// 2015-05-17 683 0.1 First draft
@ -68,8 +69,8 @@ void Rw11UnitTape::SetType(const std::string& /*type*/)
void Rw11UnitTape::SetWProt(bool wprot)
{
if (Virt()) throw Rexception("Rw11UnitTape::SetWProt",
"not allowed when tape attached");
if (HasVirt()) throw Rexception("Rw11UnitTape::SetWProt",
"not allowed when tape attached");
fWProt = wprot;
return;
}
@ -79,8 +80,8 @@ void Rw11UnitTape::SetWProt(bool wprot)
void Rw11UnitTape::SetCapacity(size_t nbyte)
{
if (Virt()) throw Rexception("Rw11UnitTape::SetCapacity",
"not allowed when tape attached");
if (HasVirt()) throw Rexception("Rw11UnitTape::SetCapacity",
"not allowed when tape attached");
fCapacity = nbyte;
return;
}
@ -90,9 +91,9 @@ void Rw11UnitTape::SetCapacity(size_t nbyte)
void Rw11UnitTape::SetPosFile(int posfile)
{
if (!Virt()) throw Rexception("Rw11UnitTape::SetPosFile",
"no tape attached");
Virt()->SetPosFile(posfile);
if (!HasVirt()) throw Rexception("Rw11UnitTape::SetPosFile",
"no tape attached");
Virt().SetPosFile(posfile);
return;
}
@ -101,9 +102,9 @@ void Rw11UnitTape::SetPosFile(int posfile)
void Rw11UnitTape::SetPosRecord(int posrec)
{
if (!Virt()) throw Rexception("Rw11UnitTape::SetPosRecord",
"no tape attached");
Virt()->SetPosRecord(posrec);
if (!HasVirt()) throw Rexception("Rw11UnitTape::SetPosRecord",
"no tape attached");
Virt().SetPosRecord(posrec);
return;
}
@ -112,8 +113,8 @@ void Rw11UnitTape::SetPosRecord(int posrec)
bool Rw11UnitTape::Bot() const
{
if (!Virt()) return false;
return Virt()->Bot();
if (!HasVirt()) return false;
return Virt().Bot();
}
//------------------------------------------+-----------------------------------
@ -121,8 +122,8 @@ bool Rw11UnitTape::Bot() const
bool Rw11UnitTape::Eot() const
{
if (!Virt()) return false;
return Virt()->Eot();
if (!HasVirt()) return false;
return Virt().Eot();
}
//------------------------------------------+-----------------------------------
@ -130,8 +131,8 @@ bool Rw11UnitTape::Eot() const
bool Rw11UnitTape::Eom() const
{
if (!Virt()) return false;
return Virt()->Eom();
if (!HasVirt()) return false;
return Virt().Eom();
}
//------------------------------------------+-----------------------------------
@ -139,8 +140,8 @@ bool Rw11UnitTape::Eom() const
int Rw11UnitTape::PosFile() const
{
if (!Virt()) return -1;
return Virt()->PosFile();
if (!HasVirt()) return -1;
return Virt().PosFile();
}
//------------------------------------------+-----------------------------------
@ -148,8 +149,8 @@ int Rw11UnitTape::PosFile() const
int Rw11UnitTape::PosRecord() const
{
if (!Virt()) return -1;
return Virt()->PosRecord();
if (!HasVirt()) return -1;
return Virt().PosRecord();
}
//------------------------------------------+-----------------------------------
@ -158,11 +159,11 @@ int Rw11UnitTape::PosRecord() const
bool Rw11UnitTape::VirtReadRecord(size_t nbyte, uint8_t* data, size_t& ndone,
int& opcode, RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitTape::VirtReadRecord", "no tape attached");
return false;
}
return Virt()->ReadRecord(nbyte, data, ndone, opcode, emsg);
return Virt().ReadRecord(nbyte, data, ndone, opcode, emsg);
}
//------------------------------------------+-----------------------------------
@ -171,11 +172,11 @@ bool Rw11UnitTape::VirtReadRecord(size_t nbyte, uint8_t* data, size_t& ndone,
bool Rw11UnitTape::VirtWriteRecord(size_t nbyte, const uint8_t* data,
int& opcode, RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitTape::VirtWriteRecord", "no tape attached");
return false;
}
return Virt()->WriteRecord(nbyte, data, opcode, emsg);
return Virt().WriteRecord(nbyte, data, opcode, emsg);
}
//------------------------------------------+-----------------------------------
@ -183,11 +184,11 @@ bool Rw11UnitTape::VirtWriteRecord(size_t nbyte, const uint8_t* data,
bool Rw11UnitTape::VirtWriteEof(RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitTape::VirtWriteEof", "no tape attached");
return false;
}
return Virt()->WriteEof(emsg);
return Virt().WriteEof(emsg);
}
//------------------------------------------+-----------------------------------
@ -196,11 +197,11 @@ bool Rw11UnitTape::VirtWriteEof(RerrMsg& emsg)
bool Rw11UnitTape::VirtSpaceForw(size_t nrec, size_t& ndone,
int& opcode, RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitTape::VirtSpaceForw", "no tape attached");
return false;
}
return Virt()->SpaceForw(nrec, ndone, opcode, emsg);
return Virt().SpaceForw(nrec, ndone, opcode, emsg);
}
//------------------------------------------+-----------------------------------
@ -209,11 +210,11 @@ bool Rw11UnitTape::VirtSpaceForw(size_t nrec, size_t& ndone,
bool Rw11UnitTape::VirtSpaceBack(size_t nrec, size_t& ndone,
int& opcode, RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitTape::VirtSpaceBack", "no tape attached");
return false;
}
return Virt()->SpaceBack(nrec, ndone, opcode, emsg);
return Virt().SpaceBack(nrec, ndone, opcode, emsg);
}
//------------------------------------------+-----------------------------------
@ -221,11 +222,11 @@ bool Rw11UnitTape::VirtSpaceBack(size_t nrec, size_t& ndone,
bool Rw11UnitTape::VirtRewind(int& opcode, RerrMsg& emsg)
{
if (!Virt()) {
if (!HasVirt()) {
emsg.Init("Rw11UnitTape::VirtRewind", "no tape attached");
return false;
}
return Virt()->Rewind(opcode, emsg);
return Virt().Rewind(opcode, emsg);
}
//------------------------------------------+-----------------------------------

View File

@ -1,6 +1,6 @@
// $Id: Rw11UnitTape.ipp 983 2018-01-02 20:35:59Z mueller $
// $Id: Rw11UnitTape.ipp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2015- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2015-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.1 use HasVirt(); Virt() returns ref
// 2015-06-04 686 1.0 Initial version
// 2015-05-17 683 0.1 First draft
// ---------------------------------------------------------------------------
@ -46,7 +47,7 @@ inline bool Rw11UnitTape::Enabled() const
inline bool Rw11UnitTape::WProt() const
{
return Virt() ? Virt()->WProt() : fWProt;
return HasVirt() ? Virt().WProt() : fWProt;
}
//------------------------------------------+-----------------------------------
@ -54,7 +55,7 @@ inline bool Rw11UnitTape::WProt() const
inline size_t Rw11UnitTape::Capacity() const
{
return Virt() ? Virt()->Capacity() : fCapacity;
return HasVirt() ? Virt().Capacity() : fCapacity;
}

View File

@ -1,6 +1,6 @@
// $Id: Rw11UnitTapeBase.ipp 983 2018-01-02 20:35:59Z mueller $
// $Id: Rw11UnitTapeBase.ipp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2015-2017 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2015-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.0.2 use HasVirt(); Virt() returns ref
// 2017-04-07 868 1.0.1 Dump(): add detail arg
// 2015-06-04 686 1.0 Initial version
// 2015-05-17 683 0.1 First draft
@ -79,7 +80,7 @@ template <class TC>
void Rw11UnitTapeBase<TC>::AttachDone()
{
// transfer, if defined capacity from unit to virt
if (Capacity()!=0 && Virt()->Capacity()==0) Virt()->SetCapacity(Capacity());
if (Capacity()!=0 && Virt().Capacity()==0) Virt().SetCapacity(Capacity());
Cntl().UnitSetup(Index());
return;
}

View File

@ -1,4 +1,4 @@
// $Id: Rw11UnitTerm.cpp 1076 2018-12-02 12:45:49Z mueller $
// $Id: Rw11UnitTerm.cpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.1.4 use HasVirt(); Virt() returns ref
// 2018-12-01 1076 1.1.3 use unique_ptr
// 2017-04-07 868 1.1.2 Dump(): add detail arg
// 2017-02-25 855 1.1.1 RcvNext() --> RcvQueueNext(); WakeupCntl() now pure
@ -75,7 +76,7 @@ Rw11UnitTerm::~Rw11UnitTerm()
const std::string& Rw11UnitTerm::ChannelId() const
{
if (fupVirt) return fupVirt->ChannelId();
if (HasVirt()) return Virt().ChannelId();
static string nil;
return nil;
}
@ -204,9 +205,9 @@ bool Rw11UnitTerm::Snd(const uint8_t* buf, size_t count)
}
}
if (fupVirt) { // if virtual device attached
if (HasVirt()) { // if virtual device attached
RerrMsg emsg;
ok = fupVirt->Snd(bufout, bufcnt, emsg);
ok = Virt().Snd(bufout, bufcnt, emsg);
// FIXME_code: handler errors
} else { // no virtual device attached
@ -293,8 +294,8 @@ void Rw11UnitTerm::Dump(std::ostream& os, int ind, const char* text,
void Rw11UnitTerm::AttachDone()
{
fupVirt->SetupRcvCallback(boost::bind(&Rw11UnitTerm::RcvCallback,
this, _1, _2));
Virt().SetupRcvCallback(boost::bind(&Rw11UnitTerm::RcvCallback,
this, _1, _2));
return;
}

View File

@ -1,4 +1,4 @@
// $Id: Rw11UnitVirt.hpp 1076 2018-12-02 12:45:49Z mueller $
// $Id: Rw11UnitVirt.hpp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.2 add HasVirt(); return ref for Virt()
// 2018-12-01 1076 1.1 use unique_ptr instead of scoped_ptr
// 2017-04-15 875 1.0.2 add VirtBase()
// 2017-04-07 868 1.0.1 Dump(): add detail arg
@ -42,7 +43,9 @@ namespace Retro {
Rw11UnitVirt(Rw11Cntl* pcntl, size_t index);
~Rw11UnitVirt();
TV* Virt() const;
bool HasVirt() const;
TV& Virt();
const TV& Virt() const;
virtual Rw11Virt* VirtBase() const;
virtual bool Attach(const std::string& url, RerrMsg& emsg);

View File

@ -1,4 +1,4 @@
// $Id: Rw11UnitVirt.ipp 1076 2018-12-02 12:45:49Z mueller $
// $Id: Rw11UnitVirt.ipp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.4 add HasVirt(); return ref for Virt()
// 2018-12-01 1076 1.3 use unique_ptr instead of scoped_ptr
// 2017-04-15 875 1.2.2 add VirtBase()
// 2017-04-07 868 1.2.1 Dump(): add detail arg
@ -62,9 +63,27 @@ Rw11UnitVirt<TV>::~Rw11UnitVirt()
//! FIXME_docs
template <class TV>
inline TV* Rw11UnitVirt<TV>::Virt() const
inline bool Rw11UnitVirt<TV>::HasVirt() const
{
return fupVirt.get();
return bool(fupVirt);
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
template <class TV>
inline TV& Rw11UnitVirt<TV>::Virt()
{
return *fupVirt;
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
template <class TV>
inline const TV& Rw11UnitVirt<TV>::Virt() const
{
return *fupVirt;
}
//------------------------------------------+-----------------------------------

View File

@ -1,4 +1,4 @@
// $Id: RtclRw11UnitBase.ipp 1078 2018-12-08 14:19:03Z mueller $
// $Id: RtclRw11UnitBase.ipp 1080 2018-12-09 20:30:33Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
@ -13,6 +13,7 @@
//
// Revision History:
// Date Rev Version Comment
// 2018-12-09 1080 1.3.4 use HasVirt(); Virt() returns ref
// 2018-12-07 1078 1.3.3 use std::shared_ptr instead of boost
// 2018-12-01 1076 1.3.2 use unique_ptr
// 2017-04-15 875 1.3.1 add attached,attachutl getters
@ -127,8 +128,8 @@ inline const std::shared_ptr<TU>& RtclRw11UnitBase<TU,TUV,TB>::ObjSPtr()
template <class TU, class TUV, class TB>
void RtclRw11UnitBase<TU,TUV,TB>::AttachDone()
{
if (!Obj().Virt()) return;
std::unique_ptr<RtclRw11Virt> pvirt(RtclRw11VirtFactory(Obj().Virt()));
if (!Obj().HasVirt()) return;
std::unique_ptr<RtclRw11Virt> pvirt(RtclRw11VirtFactory(&Obj().Virt()));
if (!pvirt) return;
this->fupVirt = move(pvirt);
this->AddMeth("virt", boost::bind(&RtclRw11Unit::M_virt, this, _1));
@ -144,8 +145,8 @@ int RtclRw11UnitBase<TU,TUV,TB>::M_stats(RtclArgs& args)
RtclStats::Context cntx;
if (!RtclStats::GetArgs(args, cntx)) return TB::kERR;
if (!RtclStats::Collect(args, cntx, Obj().Stats())) return TB::kERR;
if (Obj().Virt()) {
if (!RtclStats::Collect(args, cntx, Obj().Virt()->Stats())) return TB::kERR;
if (Obj().HasVirt()) {
if (!RtclStats::Collect(args, cntx, Obj().Virt().Stats())) return TB::kERR;
}
return TB::kOK;
}