w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RtclRw11Cntl.cpp
Go to the documentation of this file.
1// $Id: RtclRw11Cntl.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-06-07 1160 1.1.6 use RtclStats::Exec()
8// 2019-02-23 1114 1.1.5 use std::bind instead of lambda
9// 2018-12-17 1085 1.1.4 use std::lock_guard instead of boost
10// 2018-12-15 1082 1.1.3 use lambda instead of boost::bind
11// 2017-04-16 877 1.1.2 add UnitCommands(); add Class()
12// 2017-04-02 865 1.0.2 M_dump: use GetArgsDump and Dump detail
13// 2015-03-27 660 1.0.1 add M_start
14// 2013-03-06 495 1.0 Initial version
15// 2013-02-08 484 0.1 First draft
16// ---------------------------------------------------------------------------
17
22#include <functional>
23
26
27#include "RtclRw11Cntl.hpp"
28
29using namespace std;
30using namespace std::placeholders;
31
37// all method definitions in namespace Retro
38namespace Retro {
39
40//------------------------------------------+-----------------------------------
42
43RtclRw11Cntl::RtclRw11Cntl(const std::string& type,
44 const std::string& cclass)
45 : RtclProxyBase(type),
46 fClass(cclass),
47 fGets(),
48 fSets()
49{
50 AddMeth("get", bind(&RtclRw11Cntl::M_get, this, _1));
51 AddMeth("set", bind(&RtclRw11Cntl::M_set, this, _1));
52 AddMeth("probe", bind(&RtclRw11Cntl::M_probe, this, _1));
53 AddMeth("start", bind(&RtclRw11Cntl::M_start, this, _1));
54 AddMeth("stats", bind(&RtclRw11Cntl::M_stats, this, _1));
55 AddMeth("dump", bind(&RtclRw11Cntl::M_dump, this, _1));
56 AddMeth("$default", bind(&RtclRw11Cntl::M_default, this, _1));
57
58 fGets.Add<Tcl_Obj*> ("units",
59 bind(&RtclRw11Cntl::UnitCommands, this));
60 fGets.Add<const string&> ("class",
61 bind(&RtclRw11Cntl::Class, this));
62}
63
64//------------------------------------------+-----------------------------------
66
68{}
69
70//------------------------------------------+-----------------------------------
72
74{
75 // synchronize with server thread
76 lock_guard<RlinkConnect> lock(Obj().Connect());
77 return fGets.M_get(args);
78}
79
80//------------------------------------------+-----------------------------------
82
84{
85 // synchronize with server thread
86 lock_guard<RlinkConnect> lock(Obj().Connect());
87 return fSets.M_set(args);
88}
89
90//------------------------------------------+-----------------------------------
92
94{
95 if (!args.AllDone()) return kERR;
96 args.SetResult(Obj().Probe());
97 return kOK;
98}
99
100//------------------------------------------+-----------------------------------
102
104{
105 if (!args.AllDone()) return kERR;
106 Obj().Probe();
107 Obj().Start();
108 return kOK;
109}
110
111//------------------------------------------+-----------------------------------
113
115{
117 if (!RtclStats::GetArgs(args, cntx)) return kERR;
118 if (!RtclStats::Exec(args, cntx, Obj().Stats())) return kERR;
119 return kOK;
120}
121
122//------------------------------------------+-----------------------------------
124
126{
127 int detail=0;
128 if (!GetArgsDump(args, detail)) return kERR;
129 if (!args.AllDone()) return kERR;
130
131 ostringstream sos;
132 Obj().Dump(sos, 0, "", detail);
133 args.SetResult(sos);
134 return kOK;
135}
136
137//------------------------------------------+-----------------------------------
139
141{
142 if (!args.AllDone()) return kERR;
143 ostringstream sos;
144 sos << "no default output defined yet...\n";
145 args.AppendResultLines(sos);
146 return kOK;
147}
148
149//------------------------------------------+-----------------------------------
151
153{
154 Tcl_Obj* rlist = Tcl_NewListObj(0,nullptr);
155 for (size_t i = 0; i < Obj().NUnit(); i++) {
156 string ucmd = CommandName() + to_string(i);
157 RtclOPtr pele(Tcl_NewStringObj(ucmd.data(), ucmd.length()));
158 Tcl_ListObjAppendElement(nullptr, rlist, pele);
159 }
160 return rlist;
161}
162
163//------------------------------------------+-----------------------------------
165
166const std::string& RtclRw11Cntl::Class() const
167{
168 return fClass;
169}
170
171} // end namespace Retro
FIXME_docs.
Definition: RtclArgs.hpp:41
void AppendResultLines(const std::string &str)
FIXME_docs.
Definition: RtclArgs.cpp:484
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.
static const int kERR
Definition: RtclCmdBase.hpp:55
int M_get(RtclArgs &args)
FIXME_docs.
Definition: RtclGetList.cpp:73
void Add(const std::string &name, get_uptr_t &&upget)
FIXME_docs.
Definition: RtclGetList.cpp:52
Implemenation (inline) of RtclOPtr.
Definition: RtclOPtr.hpp:23
std::string CommandName() const
FIXME_docs.
int M_dump(RtclArgs &args)
FIXME_docs.
virtual int M_default(RtclArgs &args)
FIXME_docs.
RtclRw11Cntl(const std::string &type, const std::string &cclass)
Constructor.
Tcl_Obj * UnitCommands()
FIXME_docs.
int M_start(RtclArgs &args)
FIXME_docs.
const std::string & Class() const
FIXME_docs.
int M_get(RtclArgs &args)
FIXME_docs.
virtual Rw11Cntl & Obj()=0
virtual int M_stats(RtclArgs &args)
FIXME_docs.
int M_probe(RtclArgs &args)
FIXME_docs.
int M_set(RtclArgs &args)
FIXME_docs.
virtual ~RtclRw11Cntl()
Destructor.
int M_set(RtclArgs &args)
FIXME_docs.
Definition: RtclSetList.cpp:73
static bool Exec(RtclArgs &args, const Context &cntx, Rstats &stats)
FIXME_docs.
Definition: RtclStats.cpp:75
static bool GetArgs(RtclArgs &args, Context &cntx)
FIXME_docs.
Definition: RtclStats.cpp:37
virtual void Start()
FIXME_docs.
Definition: Rw11Cntl.cpp:84
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: Rw11Cntl.cpp:133
virtual bool Probe()
FIXME_docs.
Definition: Rw11Cntl.cpp:76
virtual size_t NUnit() const =0
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47