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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librlinktpp/] [RtclAttnShuttle.cpp] - Blame information for rev 19

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

Line No. Rev Author Line
1 19 wfjm
// $Id: RtclAttnShuttle.cpp 495 2013-03-06 17:13:48Z mueller $
2
//
3
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
//
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
// 2013-03-01   493   1.0    Initial version
17
// 2013-01-12   475   0.5    First draft
18
// ---------------------------------------------------------------------------
19
 
20
/*!
21
  \file
22
  \version $Id: RtclAttnShuttle.cpp 495 2013-03-06 17:13:48Z mueller $
23
  \brief   Implemenation of class RtclAttnShuttle.
24
 */
25
 
26
#include "errno.h"
27
 
28
#include "boost/bind.hpp"
29
 
30
#include "librtools/Rexception.hpp"
31
 
32
#include "RtclAttnShuttle.hpp"
33
 
34
using namespace std;
35
 
36
/*!
37
  \class Retro::RtclAttnShuttle
38
  \brief FIXME_docs
39
*/
40
 
41
// all method definitions in namespace Retro
42
namespace Retro {
43
 
44
//------------------------------------------+-----------------------------------
45
//! constructor
46
 
47
RtclAttnShuttle::RtclAttnShuttle(uint16_t mask, Tcl_Obj* pobj)
48
  : fpServ(0),
49
    fpInterp(0),
50
    fFdPipeRead(0),
51
    fFdPipeWrite(0),
52
    fShuttleChn(0),
53
    fMask(mask),
54
    fpScript(pobj)
55
{
56
  int pipefd[2];
57
  int irc = pipe(pipefd);
58
  if (irc < 0)
59
    throw Rexception("RtclAttnShuttle::<ctor>", "pipe() failed: ", errno);
60
  fFdPipeRead  = pipefd[0];
61
  fFdPipeWrite = pipefd[1];
62
}
63
 
64
//------------------------------------------+-----------------------------------
65
//! Destructor
66
 
67
RtclAttnShuttle::~RtclAttnShuttle()
68
{
69
  Remove();
70
  close(fFdPipeWrite);
71
  close(fFdPipeRead);
72
}
73
 
74
//------------------------------------------+-----------------------------------
75
//! FIXME_docs
76
 
77
void RtclAttnShuttle::Add(RlinkServer* pserv, Tcl_Interp* interp)
78
{
79
  // connect to RlinkServer
80
  pserv->AddAttnHandler(boost::bind(&RtclAttnShuttle::AttnHandler, this, _1),
81
                        fMask, (void*)this);
82
  fpServ = pserv;
83
 
84
  // connect to Tcl
85
  fShuttleChn = Tcl_MakeFileChannel((ClientData)fFdPipeRead, TCL_READABLE);
86
  Tcl_CreateChannelHandler(fShuttleChn, TCL_READABLE,
87
                           (Tcl_FileProc*) ThunkTclChannelHandler,
88
                           (ClientData) this);
89
  fpInterp = interp;
90
  return;
91
}
92
 
93
//------------------------------------------+-----------------------------------
94
//! FIXME_docs
95
 
96
void RtclAttnShuttle::Remove()
97
{
98
  // disconnect from RlinkServer
99
  if (fpServ) {
100
    fpServ->RemoveAttnHandler(fMask, (void*)this);
101
    fpServ = 0;
102
  }
103
  // disconnect from Tcl
104
  if (fpInterp) {
105
    Tcl_DeleteChannelHandler(fShuttleChn,
106
                             (Tcl_FileProc*) ThunkTclChannelHandler,
107
                             (ClientData) this);
108
    Tcl_Close(fpInterp, fShuttleChn);
109
    fpInterp = 0;
110
  }
111
 
112
  return;
113
}
114
 
115
//------------------------------------------+-----------------------------------
116
//! FIXME_docs
117
 
118
int RtclAttnShuttle::AttnHandler(const RlinkServer::AttnArgs& args)
119
{
120
  uint16_t apat = args.fAttnPatt & args.fAttnMask;
121
  int irc = write(fFdPipeWrite, (void*) &apat, sizeof(apat));
122
  if (irc < 0)
123
    throw Rexception("RtclAttnShuttle::AttnHandler()",
124
                     "write() failed: ", errno);
125
  return 0;
126
}
127
 
128
//------------------------------------------+-----------------------------------
129
//! FIXME_docs
130
 
131
void RtclAttnShuttle::TclChannelHandler(int mask)
132
{
133
  uint16_t apat;
134
  Tcl_ReadRaw(fShuttleChn, (char*) &apat, sizeof(apat));
135
  // FIXME_code: handle return code
136
 
137
  Tcl_SetVar2Ex(fpInterp, "Rlink_attnbits", NULL, Tcl_NewIntObj((int)apat), 0);
138
  // FIXME_code: handle return code
139
 
140
  Tcl_EvalObjEx(fpInterp, fpScript, TCL_EVAL_GLOBAL);
141
  // FIXME_code: handle return code
142
  return;
143
}
144
 
145
//------------------------------------------+-----------------------------------
146
//! FIXME_docs
147
 
148
void RtclAttnShuttle::ThunkTclChannelHandler(ClientData cdata, int mask)
149
{
150
  ((RtclAttnShuttle*) cdata)->TclChannelHandler(mask);
151
  return;
152
}
153
 
154
} // end namespace Retro

powered by: WebSVN 2.1.0

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