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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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