// $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $
|
// $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $
|
//
|
//
|
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
// Software Foundation, either version 2, or at your option any later version.
|
// Software Foundation, either version 2, or at your option any later version.
|
//
|
//
|
// This program is distributed in the hope that it will be useful, but
|
// This program is distributed in the hope that it will be useful, but
|
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for complete details.
|
// for complete details.
|
//
|
//
|
// Revision History:
|
// Revision History:
|
// Date Rev Version Comment
|
// Date Rev Version Comment
|
// 2013-02-09 485 1.4.2 add CommandName()
|
// 2013-02-09 485 1.4.2 add CommandName()
|
// 2013-02-05 483 1.4.1 ClassCmdConfig: use RtclArgs
|
// 2013-02-05 483 1.4.1 ClassCmdConfig: use RtclArgs
|
// 2013-02-02 480 1.4 factor out RtclCmdBase base class
|
// 2013-02-02 480 1.4 factor out RtclCmdBase base class
|
// 2013-02-01 479 1.3 add DispatchCmd(), support $unknown method
|
// 2013-02-01 479 1.3 add DispatchCmd(), support $unknown method
|
// 2011-07-31 401 1.2 add ctor(type,interp,name) for direct usage
|
// 2011-07-31 401 1.2 add ctor(type,interp,name) for direct usage
|
// 2011-04-23 380 1.1 use boost/function instead of RmethDsc
|
// 2011-04-23 380 1.1 use boost/function instead of RmethDsc
|
// 2011-03-05 366 1.0.1 use AppendResultNewLines() in exception catcher
|
// 2011-03-05 366 1.0.1 use AppendResultNewLines() in exception catcher
|
// 2011-02-20 363 1.0 Initial version
|
// 2011-02-20 363 1.0 Initial version
|
// 2011-02-11 360 0.1 First draft
|
// 2011-02-11 360 0.1 First draft
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $
|
\version $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $
|
\brief Implemenation of RtclProxyBase.
|
\brief Implemenation of RtclProxyBase.
|
*/
|
*/
|
|
|
#include "RtclProxyBase.hpp"
|
#include "RtclProxyBase.hpp"
|
|
|
#include "RtclContext.hpp"
|
#include "RtclContext.hpp"
|
#include "Rtcl.hpp"
|
#include "Rtcl.hpp"
|
|
|
using namespace std;
|
using namespace std;
|
|
|
/*!
|
/*!
|
\class Retro::RtclProxyBase
|
\class Retro::RtclProxyBase
|
\brief FIXME_docs
|
\brief FIXME_docs
|
*/
|
*/
|
|
|
// all method definitions in namespace Retro
|
// all method definitions in namespace Retro
|
namespace Retro {
|
namespace Retro {
|
|
|
typedef std::pair<RtclProxyBase::mmap_it_t, bool> mmap_ins_t;
|
typedef std::pair<RtclProxyBase::mmap_it_t, bool> mmap_ins_t;
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
RtclProxyBase::RtclProxyBase(const std::string& type)
|
RtclProxyBase::RtclProxyBase(const std::string& type)
|
: RtclCmdBase(),
|
: RtclCmdBase(),
|
fType(type),
|
fType(type),
|
fInterp(0)
|
fInterp(0)
|
{}
|
{}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
RtclProxyBase::RtclProxyBase(const std::string& type, Tcl_Interp* interp,
|
RtclProxyBase::RtclProxyBase(const std::string& type, Tcl_Interp* interp,
|
const char* name)
|
const char* name)
|
: RtclCmdBase(),
|
: RtclCmdBase(),
|
fType(type),
|
fType(type),
|
fInterp(0)
|
fInterp(0)
|
{
|
{
|
CreateObjectCmd(interp, name);
|
CreateObjectCmd(interp, name);
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! Destructor
|
//! Destructor
|
|
|
RtclProxyBase::~RtclProxyBase()
|
RtclProxyBase::~RtclProxyBase()
|
{
|
{
|
if (fInterp) RtclContext::Find(fInterp).UnRegisterProxy(this);
|
if (fInterp) RtclContext::Find(fInterp).UnRegisterProxy(this);
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
int RtclProxyBase::ClassCmdConfig(RtclArgs& args)
|
int RtclProxyBase::ClassCmdConfig(RtclArgs& args)
|
{
|
{
|
if (!args.AllDone()) return kERR;
|
if (!args.AllDone()) return kERR;
|
return kOK;
|
return kOK;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
std::string RtclProxyBase::CommandName() const
|
std::string RtclProxyBase::CommandName() const
|
{
|
{
|
return string(Tcl_GetCommandName(fInterp, fCmdToken));
|
return string(Tcl_GetCommandName(fInterp, fCmdToken));
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
void RtclProxyBase::CreateObjectCmd(Tcl_Interp* interp, const char* name)
|
void RtclProxyBase::CreateObjectCmd(Tcl_Interp* interp, const char* name)
|
{
|
{
|
fInterp = interp;
|
fInterp = interp;
|
fCmdToken =
|
fCmdToken =
|
Tcl_CreateObjCommand(interp, name, ThunkTclObjectCmd, (ClientData) this,
|
Tcl_CreateObjCommand(interp, name, ThunkTclObjectCmd, (ClientData) this,
|
(Tcl_CmdDeleteProc *) ThunkTclCmdDeleteProc);
|
(Tcl_CmdDeleteProc *) ThunkTclCmdDeleteProc);
|
RtclContext::Find(interp).RegisterProxy(this);
|
RtclContext::Find(interp).RegisterProxy(this);
|
Tcl_CreateExitHandler((Tcl_ExitProc*) ThunkTclExitProc, (ClientData) this);
|
Tcl_CreateExitHandler((Tcl_ExitProc*) ThunkTclExitProc, (ClientData) this);
|
return;
|
return;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
int RtclProxyBase::TclObjectCmd(Tcl_Interp* interp, int objc,
|
int RtclProxyBase::TclObjectCmd(Tcl_Interp* interp, int objc,
|
Tcl_Obj* const objv[])
|
Tcl_Obj* const objv[])
|
{
|
{
|
RtclArgs args(interp, objc, objv, 2);
|
RtclArgs args(interp, objc, objv, 2);
|
return DispatchCmd(args);
|
return DispatchCmd(args);
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
int RtclProxyBase::ThunkTclObjectCmd(ClientData cdata, Tcl_Interp* interp,
|
int RtclProxyBase::ThunkTclObjectCmd(ClientData cdata, Tcl_Interp* interp,
|
int objc, Tcl_Obj* const objv[])
|
int objc, Tcl_Obj* const objv[])
|
{
|
{
|
if (!cdata) {
|
if (!cdata) {
|
Tcl_AppendResult(interp, "-E: BUG! ThunkTclObjectCmd called with cdata==0",
|
Tcl_AppendResult(interp, "-E: BUG! ThunkTclObjectCmd called with cdata==0",
|
NULL);
|
NULL);
|
return TCL_ERROR;
|
return TCL_ERROR;
|
}
|
}
|
|
|
try {
|
try {
|
return ((RtclProxyBase*) cdata)->TclObjectCmd(interp, objc, objv);
|
return ((RtclProxyBase*) cdata)->TclObjectCmd(interp, objc, objv);
|
} catch (exception& e) {
|
} catch (exception& e) {
|
Rtcl::AppendResultNewLines(interp);
|
Rtcl::AppendResultNewLines(interp);
|
Tcl_AppendResult(interp, "-E: exception caught '", e.what(), "'", NULL);
|
Tcl_AppendResult(interp, "-E: exception caught '", e.what(), "'", NULL);
|
}
|
}
|
return TCL_ERROR;
|
return TCL_ERROR;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
void RtclProxyBase::ThunkTclCmdDeleteProc(ClientData cdata)
|
void RtclProxyBase::ThunkTclCmdDeleteProc(ClientData cdata)
|
{
|
{
|
Tcl_DeleteExitHandler((Tcl_ExitProc*) ThunkTclExitProc, cdata);
|
Tcl_DeleteExitHandler((Tcl_ExitProc*) ThunkTclExitProc, cdata);
|
delete ((RtclProxyBase*) cdata);
|
delete ((RtclProxyBase*) cdata);
|
return;
|
return;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
void RtclProxyBase::ThunkTclExitProc(ClientData cdata)
|
void RtclProxyBase::ThunkTclExitProc(ClientData cdata)
|
{
|
{
|
delete ((RtclProxyBase*) cdata);
|
delete ((RtclProxyBase*) cdata);
|
return;
|
return;
|
}
|
}
|
|
|
} // end namespace Retro
|
} // end namespace Retro
|
|
|