OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librtcltools/] [RtclProxyBase.cpp] - Blame information for rev 40

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 wfjm
// $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $
2 10 wfjm
//
3 19 wfjm
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 10 wfjm
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16 19 wfjm
// 2013-02-09   485   1.4.2  add CommandName()
17
// 2013-02-05   483   1.4.1  ClassCmdConfig: use RtclArgs
18
// 2013-02-02   480   1.4    factor out RtclCmdBase base class
19
// 2013-02-01   479   1.3    add DispatchCmd(), support $unknown method
20 12 wfjm
// 2011-07-31   401   1.2    add ctor(type,interp,name) for direct usage
21
// 2011-04-23   380   1.1    use boost/function instead of RmethDsc
22 10 wfjm
// 2011-03-05   366   1.0.1  use AppendResultNewLines() in exception catcher
23
// 2011-02-20   363   1.0    Initial version
24
// 2011-02-11   360   0.1    First draft
25
// ---------------------------------------------------------------------------
26
 
27
/*!
28
  \file
29 19 wfjm
  \version $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $
30 10 wfjm
  \brief   Implemenation of RtclProxyBase.
31
*/
32
 
33 19 wfjm
#include "RtclProxyBase.hpp"
34 10 wfjm
 
35
#include "RtclContext.hpp"
36
#include "Rtcl.hpp"
37
 
38
using namespace std;
39
 
40
/*!
41
  \class Retro::RtclProxyBase
42
  \brief FIXME_docs
43
*/
44
 
45 19 wfjm
// all method definitions in namespace Retro
46
namespace Retro {
47 10 wfjm
 
48 19 wfjm
typedef std::pair<RtclProxyBase::mmap_it_t, bool>  mmap_ins_t;
49
 
50 10 wfjm
//------------------------------------------+-----------------------------------
51
//! FIXME_docs
52
 
53
RtclProxyBase::RtclProxyBase(const std::string& type)
54 19 wfjm
  : RtclCmdBase(),
55
    fType(type),
56 10 wfjm
    fInterp(0)
57
{}
58
 
59
//------------------------------------------+-----------------------------------
60 12 wfjm
//! FIXME_docs
61
 
62
RtclProxyBase::RtclProxyBase(const std::string& type, Tcl_Interp* interp,
63
                             const char* name)
64 19 wfjm
  : RtclCmdBase(),
65
    fType(type),
66 12 wfjm
    fInterp(0)
67
{
68
  CreateObjectCmd(interp, name);
69
}
70
 
71
//------------------------------------------+-----------------------------------
72 10 wfjm
//! Destructor
73
 
74
RtclProxyBase::~RtclProxyBase()
75
{
76
  if (fInterp) RtclContext::Find(fInterp).UnRegisterProxy(this);
77
}
78
 
79
//------------------------------------------+-----------------------------------
80
//! FIXME_docs
81
 
82 19 wfjm
int RtclProxyBase::ClassCmdConfig(RtclArgs& args)
83 10 wfjm
{
84 19 wfjm
  if (!args.AllDone()) return kERR;
85
  return kOK;
86 10 wfjm
}
87
 
88
//------------------------------------------+-----------------------------------
89
//! FIXME_docs
90
 
91 19 wfjm
std::string RtclProxyBase::CommandName() const
92 10 wfjm
{
93 19 wfjm
  return string(Tcl_GetCommandName(fInterp, fCmdToken));
94 10 wfjm
}
95
 
96
//------------------------------------------+-----------------------------------
97
//! FIXME_docs
98
 
99
void RtclProxyBase::CreateObjectCmd(Tcl_Interp* interp, const char* name)
100
{
101
  fInterp = interp;
102
  fCmdToken =
103
    Tcl_CreateObjCommand(interp, name, ThunkTclObjectCmd, (ClientData) this,
104
                         (Tcl_CmdDeleteProc *) ThunkTclCmdDeleteProc);
105
  RtclContext::Find(interp).RegisterProxy(this);
106
  Tcl_CreateExitHandler((Tcl_ExitProc*) ThunkTclExitProc, (ClientData) this);
107
  return;
108
}
109
 
110
//------------------------------------------+-----------------------------------
111
//! FIXME_docs
112
 
113
int RtclProxyBase::TclObjectCmd(Tcl_Interp* interp, int objc,
114
                                Tcl_Obj* const objv[])
115
{
116
  RtclArgs  args(interp, objc, objv, 2);
117 19 wfjm
  return DispatchCmd(args);
118 10 wfjm
}
119
 
120
//------------------------------------------+-----------------------------------
121
//! FIXME_docs
122
 
123
int RtclProxyBase::ThunkTclObjectCmd(ClientData cdata, Tcl_Interp* interp,
124
                                     int objc, Tcl_Obj* const objv[])
125
{
126
  if (!cdata) {
127
    Tcl_AppendResult(interp, "-E: BUG! ThunkTclObjectCmd called with cdata==0",
128
                     NULL);
129
    return TCL_ERROR;
130
  }
131
 
132
  try {
133
    return ((RtclProxyBase*) cdata)->TclObjectCmd(interp, objc, objv);
134
  } catch (exception& e) {
135
    Rtcl::AppendResultNewLines(interp);
136 19 wfjm
    Tcl_AppendResult(interp, "-E: exception caught '", e.what(), "'", NULL);
137 10 wfjm
  }
138
  return TCL_ERROR;
139
}
140
 
141
//------------------------------------------+-----------------------------------
142
//! FIXME_docs
143
 
144
void RtclProxyBase::ThunkTclCmdDeleteProc(ClientData cdata)
145
{
146
  Tcl_DeleteExitHandler((Tcl_ExitProc*) ThunkTclExitProc, cdata);
147
  delete ((RtclProxyBase*) cdata);
148
  return;
149
}
150
 
151
//------------------------------------------+-----------------------------------
152
//! FIXME_docs
153
 
154
void RtclProxyBase::ThunkTclExitProc(ClientData cdata)
155
{
156
  delete ((RtclProxyBase*) cdata);
157
  return;
158
}
159
 
160 19 wfjm
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.