w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RtclRw11Unit.cpp
Go to the documentation of this file.
1// $Id: RtclRw11Unit.cpp 1186 2019-07-12 17:49:59Z 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-02-23 1114 1.3.3 use std::bind instead of lambda
8// 2018-12-17 1085 1.3.2 use std::lock_guard instead of boost
9// 2018-12-15 1082 1.3.1 use lambda instead of boost::bind
10// 2018-12-01 1076 1.3 use unique_ptr instead of scoped_ptr
11// 2017-04-08 870 1.2 drop fpCpu, use added Cpu()=0 instead
12// 2017-04-07 868 1.1.1 M_dump: use GetArgsDump and Dump detail
13// 2017-04-02 863 1.1 add fpVirt; add DetachCleanup()
14// 2013-03-03 494 1.0 Initial version
15// 2013-02-16 488 0.1 First draft
16// ---------------------------------------------------------------------------
17
22#include <functional>
23
26
27#include "RtclRw11Unit.hpp"
28
29using namespace std;
30using namespace std::placeholders;
31
37// all method definitions in namespace Retro
38namespace Retro {
39
40//------------------------------------------+-----------------------------------
42
43RtclRw11Unit::RtclRw11Unit(const std::string& type)
44 : RtclProxyBase(type),
45 fGets(),
46 fSets(),
47 fupVirt()
48{
49 AddMeth("get", bind(&RtclRw11Unit::M_get, this, _1));
50 AddMeth("set", bind(&RtclRw11Unit::M_set, this, _1));
51 AddMeth("attach", bind(&RtclRw11Unit::M_attach, this, _1));
52 AddMeth("detach", bind(&RtclRw11Unit::M_detach, this, _1));
53 AddMeth("dump", bind(&RtclRw11Unit::M_dump, this, _1));
54 AddMeth("$default", bind(&RtclRw11Unit::M_default, this, _1));
55}
56
57//------------------------------------------+-----------------------------------
59
61{}
62
63//------------------------------------------+-----------------------------------
65
67{
68 if (!fupVirt) return;
69 DelMeth("virt");
70 fupVirt.reset();
71 return;
72}
73
74//------------------------------------------+-----------------------------------
76
78{
79 // synchronize with server thread
80 lock_guard<RlinkConnect> lock(Cpu().Connect());
81 return fGets.M_get(args);
82}
83
84//------------------------------------------+-----------------------------------
86
88{
89 // synchronize with server thread
90 lock_guard<RlinkConnect> lock(Cpu().Connect());
91 return fSets.M_set(args);
92}
93
94//------------------------------------------+-----------------------------------
96
98{
99 string url;
100 if (!args.GetArg("url", url)) return kERR;
101
102 if (!args.AllDone()) return kERR;
103
104 RerrMsg emsg;
105 // synchronize with server thread
106 lock_guard<RlinkConnect> lock(Cpu().Connect());
107
109 if (!Obj().Attach(url, emsg)) return args.Quit(emsg);
110 AttachDone();
111 return kOK;
112}
113
114//------------------------------------------+-----------------------------------
116
118{
119 if (!args.AllDone()) return kERR;
120
121 // synchronize with server thread
122 lock_guard<RlinkConnect> lock(Cpu().Connect());
123 Obj().Detach();
124 return kOK;
125}
126
127//------------------------------------------+-----------------------------------
129
131{
132 if (!fupVirt) throw Rexception("RtclRw11Unit::M_virt:",
133 "Bad state: fupVirt == nullptr");
134
135 // synchronize with server thread
136 lock_guard<RlinkConnect> lock(Cpu().Connect());
137 return fupVirt->DispatchCmd(args);
138}
139
140//------------------------------------------+-----------------------------------
142
144{
145 int detail=0;
146 if (!GetArgsDump(args, detail)) return kERR;
147 if (!args.AllDone()) return kERR;
148
149 ostringstream sos;
150 Obj().Dump(sos, 0, "", detail);
151 args.SetResult(sos);
152 return kOK;
153}
154
155//------------------------------------------+-----------------------------------
157
159{
160 if (!args.AllDone()) return kERR;
161 ostringstream sos;
162 sos << "no default output defined yet...\n";
163 args.AppendResultLines(sos);
164 return kOK;
165}
166
167} // end namespace Retro
FIXME_docs.
Definition: RerrMsg.hpp:25
FIXME_docs.
Definition: Rexception.hpp:29
FIXME_docs.
Definition: RtclArgs.hpp:41
void AppendResultLines(const std::string &str)
FIXME_docs.
Definition: RtclArgs.cpp:484
bool GetArg(const char *name, Tcl_Obj *&pval)
FIXME_docs.
Definition: RtclArgs.cpp:114
int Quit(const std::string &str)
FIXME_docs.
Definition: RtclArgs.ipp:157
void SetResult(const std::string &str)
FIXME_docs.
Definition: RtclArgs.ipp:76
bool AllDone()
FIXME_docs.
Definition: RtclArgs.cpp:447
void AddMeth(const std::string &name, methfo_t &&methfo)
FIXME_docs.
static const int kOK
Definition: RtclCmdBase.hpp:54
bool GetArgsDump(RtclArgs &args, int &detail)
FIXME_docs.
void DelMeth(const std::string &name)
FIXME_docs.
static const int kERR
Definition: RtclCmdBase.hpp:55
int M_get(RtclArgs &args)
FIXME_docs.
Definition: RtclGetList.cpp:73
int M_set(RtclArgs &args)
FIXME_docs.
virtual void AttachDone()=0
virtual Rw11Cpu & Cpu() const =0
void DetachCleanup()
FIXME_docs.
int M_dump(RtclArgs &args)
FIXME_docs.
int M_get(RtclArgs &args)
FIXME_docs.
virtual Rw11Unit & Obj()=0
int M_detach(RtclArgs &args)
FIXME_docs.
int M_virt(RtclArgs &args)
FIXME_docs.
virtual ~RtclRw11Unit()
Destructor.
RtclRw11Unit(const std::string &type)
Default constructor.
std::unique_ptr< RtclRw11Virt > fupVirt
int M_default(RtclArgs &args)
FIXME_docs.
int M_attach(RtclArgs &args)
FIXME_docs.
int M_set(RtclArgs &args)
FIXME_docs.
Definition: RtclSetList.cpp:73
virtual void Detach()
FIXME_docs.
Definition: Rw11Unit.cpp:91
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: Rw11Unit.cpp:99
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47