w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RtclProxyBase.cpp
Go to the documentation of this file.
1// $Id: RtclProxyBase.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-18 1089 1.5.2 use c++ style casts
8// 2018-09-16 1047 1.5.1 coverity fixup (uninitialized pointer)
9// 2017-03-11 859 1.5 adopt new DispatchCmd() logic
10// 2014-08-22 584 1.4.3 use nullptr
11// 2013-02-09 485 1.4.2 add CommandName()
12// 2013-02-05 483 1.4.1 ClassCmdConfig: use RtclArgs
13// 2013-02-02 480 1.4 factor out RtclCmdBase base class
14// 2013-02-01 479 1.3 add DispatchCmd(), support $unknown method
15// 2011-07-31 401 1.2 add ctor(type,interp,name) for direct usage
16// 2011-04-23 380 1.1 use boost/function instead of RmethDsc
17// 2011-03-05 366 1.0.1 use AppendResultNewLines() in exception catcher
18// 2011-02-20 363 1.0 Initial version
19// 2011-02-11 360 0.1 First draft
20// ---------------------------------------------------------------------------
21
26#include "RtclProxyBase.hpp"
27
28#include "RtclContext.hpp"
29#include "Rtcl.hpp"
30
31using namespace std;
32
38// all method definitions in namespace Retro
39namespace Retro {
40
41//------------------------------------------+-----------------------------------
43
44RtclProxyBase::RtclProxyBase(const std::string& type)
45 : RtclCmdBase(),
46 fType(type),
47 fInterp(nullptr),
48 fCmdToken(0)
49{}
50
51//------------------------------------------+-----------------------------------
53
54RtclProxyBase::RtclProxyBase(const std::string& type, Tcl_Interp* interp,
55 const char* name)
56 : RtclCmdBase(),
57 fType(type),
58 fInterp(nullptr)
59{
60 CreateObjectCmd(interp, name);
61}
62
63//------------------------------------------+-----------------------------------
65
67{
69}
70
71//------------------------------------------+-----------------------------------
73
75{
76 if (!args.AllDone()) return kERR;
77 return kOK;
78}
79
80//------------------------------------------+-----------------------------------
82
83std::string RtclProxyBase::CommandName() const
84{
85 return string(Tcl_GetCommandName(fInterp, fCmdToken));
86}
87
88//------------------------------------------+-----------------------------------
90
91void RtclProxyBase::CreateObjectCmd(Tcl_Interp* interp, const char* name)
92{
93 fInterp = interp;
94 fCmdToken =
95 Tcl_CreateObjCommand(interp, name, ThunkTclObjectCmd,
96 reinterpret_cast<ClientData>(this),
97 reinterpret_cast<Tcl_CmdDeleteProc*>(ThunkTclCmdDeleteProc));
98 RtclContext::Find(interp).RegisterProxy(this);
99 Tcl_CreateExitHandler(reinterpret_cast<Tcl_ExitProc*>(ThunkTclExitProc),
100 reinterpret_cast<ClientData>(this));
101 return;
102}
103
104//------------------------------------------+-----------------------------------
106
107int RtclProxyBase::TclObjectCmd(Tcl_Interp* interp, int objc,
108 Tcl_Obj* const objv[])
109{
110 RtclArgs args(interp, objc, objv, 1);
111 return DispatchCmd(args);
112}
113
114//------------------------------------------+-----------------------------------
116
117int RtclProxyBase::ThunkTclObjectCmd(ClientData cdata, Tcl_Interp* interp,
118 int objc, Tcl_Obj* const objv[])
119{
120 if (!cdata) {
121 Tcl_AppendResult(interp, "-E: BUG! ThunkTclObjectCmd called with cdata==0",
122 nullptr);
123 return TCL_ERROR;
124 }
125
126 try {
127 return (reinterpret_cast<RtclProxyBase*>(cdata))->TclObjectCmd(interp,
128 objc, objv);
129 } catch (exception& e) {
131 Tcl_AppendResult(interp, "-E: exception caught '", e.what(), "'", nullptr);
132 }
133 return TCL_ERROR;
134}
135
136//------------------------------------------+-----------------------------------
138
140{
141 Tcl_DeleteExitHandler(reinterpret_cast<Tcl_ExitProc*>(ThunkTclExitProc),
142 cdata);
143 delete (reinterpret_cast<RtclProxyBase*>(cdata));
144 return;
145}
146
147//------------------------------------------+-----------------------------------
149
151{
152 delete (reinterpret_cast<RtclProxyBase*>(cdata));
153 return;
154}
155
156} // end namespace Retro
FIXME_docs.
Definition: RtclArgs.hpp:41
bool AllDone()
FIXME_docs.
Definition: RtclArgs.cpp:447
static const int kOK
Definition: RtclCmdBase.hpp:54
static const int kERR
Definition: RtclCmdBase.hpp:55
int DispatchCmd(RtclArgs &args)
FIXME_docs.
Definition: RtclCmdBase.cpp:64
void RegisterProxy(RtclProxyBase *pobj)
FIXME_docs.
Definition: RtclContext.cpp:79
void UnRegisterProxy(RtclProxyBase *pobj)
FIXME_docs.
Definition: RtclContext.cpp:91
static RtclContext & Find(Tcl_Interp *interp)
FIXME_docs.
void CreateObjectCmd(Tcl_Interp *interp, const char *name)
FIXME_docs.
Tcl_Interp * fInterp
tcl interpreter
virtual int ClassCmdConfig(RtclArgs &args)
FIXME_docs.
RtclProxyBase(const std::string &type=std::string())
FIXME_docs.
Tcl_Command fCmdToken
cmd token for object command
virtual ~RtclProxyBase()
Destructor.
static int ThunkTclObjectCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
FIXME_docs.
std::string CommandName() const
FIXME_docs.
static void ThunkTclCmdDeleteProc(ClientData cdata)
FIXME_docs.
int TclObjectCmd(Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
FIXME_docs.
static void ThunkTclExitProc(ClientData cdata)
FIXME_docs.
void AppendResultNewLines(Tcl_Interp *interp)
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47