w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
Rw11UnitStream.cpp
Go to the documentation of this file.
1// $Id: Rw11UnitStream.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-09 1080 1.1.2 use HasVirt(); Virt() returns ref; Pos() not const
8// 2017-04-07 868 1.1.1 Dump(): add detail arg
9// 2017-02-04 848 1.1 Pos(): return -1 if not attached
10// 2013-05-04 515 1.0 Initial version
11// 2013-05-01 513 0.1 First draft
12// ---------------------------------------------------------------------------
13
19
20#include "Rw11UnitStream.hpp"
21
22using namespace std;
23
29// all method definitions in namespace Retro
30namespace Retro {
31
32//------------------------------------------+-----------------------------------
34
36 : Rw11UnitVirt<Rw11VirtStream>(pcntl, index)
37{
38 fStats.Define(kStatNPreAttDrop, "NPreAttDrop",
39 "output bytes dropped prior attach");
40 fStats.Define(kStatNPreAttMiss, "NPreAttMiss",
41 "input bytes missed prior attach");
42}
43
44//------------------------------------------+-----------------------------------
46
48{}
49
50//------------------------------------------+-----------------------------------
52
54{
55 if (!HasVirt())
56 throw Rexception("Rw11UnitStream::SetPos", "no stream attached");
57
58 RerrMsg emsg;
59 if (!Virt().Seek(pos, emsg)) throw Rexception(emsg);
60 return;
61}
62
63//------------------------------------------+-----------------------------------
65
67{
68 if (!HasVirt()) return -1; // allow tcl 'get ?' if not attached
69
70 RerrMsg emsg;
71 int irc = Virt().Tell(emsg);
72 if (irc < 0) throw Rexception(emsg);
73 return irc;
74}
75
76//------------------------------------------+-----------------------------------
78
79int Rw11UnitStream::VirtRead(uint8_t* data, size_t count, RerrMsg& emsg)
80{
81 if (!HasVirt()) {
83 emsg.Init("Rw11UnitStream::VirtRead", "no stream attached");
84 return -1;
85 }
86 return Virt().Read(data, count, emsg);
87}
88
89//------------------------------------------+-----------------------------------
91
92bool Rw11UnitStream::VirtWrite(const uint8_t* data, size_t count, RerrMsg& emsg)
93{
94 if (!HasVirt()) {
95 fStats.Inc(kStatNPreAttDrop, double(count));
96 emsg.Init("Rw11UnitStream::VirtWrite", "no stream attached");
97 return false;
98 }
99 return Virt().Write(data, count, emsg);
100}
101
102//------------------------------------------+-----------------------------------
104
106{
107 if (!HasVirt()) {
108 emsg.Init("Rw11UnitStream::VirtFlush", "no stream attached");
109 return false;
110 }
111 return Virt().Flush(emsg);
112}
113
114//------------------------------------------+-----------------------------------
116
117void Rw11UnitStream::Dump(std::ostream& os, int ind, const char* text,
118 int detail) const
119{
120 RosFill bl(ind);
121 os << bl << (text?text:"--") << "Rw11UnitStream @ " << this << endl;
122 Rw11UnitVirt<Rw11VirtStream>::Dump(os, ind, " ^", detail);
123 return;
124}
125
126
127} // 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
void Inc(size_t ind, double val=1.)
FIXME_docs.
Definition: Rstats.ipp:29
void Define(size_t ind, const std::string &name, const std::string &text)
FIXME_docs.
Definition: Rstats.cpp:72
FIXME_docs.
Definition: Rw11Cntl.hpp:42
int VirtRead(uint8_t *data, size_t count, RerrMsg &emsg)
FIXME_docs.
~Rw11UnitStream()
Destructor.
Rw11UnitStream(Rw11Cntl *pcntl, size_t index)
Constructor.
void SetPos(int pos)
FIXME_docs.
bool VirtWrite(const uint8_t *data, size_t count, RerrMsg &emsg)
FIXME_docs.
bool VirtFlush(RerrMsg &emsg)
FIXME_docs.
int Pos()
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Implemenation (inline) of Rw11UnitVirt.
Rw11VirtStream & Virt()
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Rstats fStats
statistics
Definition: Rw11Unit.hpp:90
bool Write(const uint8_t *data, size_t count, RerrMsg &emsg)
FIXME_docs.
int Read(uint8_t *data, size_t count, RerrMsg &emsg)
FIXME_docs.
int Tell(RerrMsg &emsg)
FIXME_docs.
bool Flush(RerrMsg &emsg)
FIXME_docs.
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47