FRIBParallelanalysis
1.0
FrameworkforMPIParalleldataanalysisatFRIB
|
#include <TCLChannel.h>
Public Member Functions | |
CTCLChannel (CTCLInterpreter *pInterp, std::string Filename, const char *pMode, int permissions) | |
Construct file channel. | |
CTCLChannel (CTCLInterpreter *pInterp, int argc, const char **pargv, int flags) | |
Construct command pipeline. More... | |
CTCLChannel (CTCLInterpreter *pInterp, int port, std::string host) | |
Construct a TCP/Client channel. | |
CTCLChannel (CTCLInterpreter *pInterp, int port, Tcl_TcpAcceptProc *proc, ClientData AppData) | |
Create a TCP/IP server listener. More... | |
CTCLChannel (CTCLInterpreter *pInterp, Tcl_Channel Channel) | |
Construct from existing channel. More... | |
CTCLChannel (const CTCLChannel &rhs) | |
Copy construction. More... | |
virtual | ~CTCLChannel () |
Tcl_Channel | getChannel () const |
bool | ClosesOnDestroy () const |
int | Read (void **pData, int nChars) |
Read data from the channel. More... | |
int | Write (const void *pData, int nBytes) |
Write data to the channel. More... | |
bool | atEof () |
True if EOF on channel. More... | |
void | Flush () |
Flush channel data buffers. More... | |
void | Close () |
Close channel (dangerous!!!). More... | |
void | Register () |
Expose channel name to scripts (dangerous!!) More... | |
void | SetEncoding (std::string Name) |
std::string | GetEncoding () |
![]() | |
CTCLInterpreterObject (CTCLInterpreter *pInterp) | |
CTCLInterpreterObject (const CTCLInterpreterObject &aCTCLInterpreterObject) | |
CTCLInterpreterObject & | operator= (const CTCLInterpreterObject &aCTCLInterpreterObject) |
int | operator== (const CTCLInterpreterObject &aCTCLInterpreterObject) const |
CTCLInterpreter * | getInterpreter () const |
CTCLInterpreter * | Bind (CTCLInterpreter &rBinding) |
CTCLInterpreter * | Bind (CTCLInterpreter *pBinding) |
Protected Member Functions | |
void | setChannel (Tcl_Channel Channel) |
void | CloseOnDestroy (bool state) |
![]() | |
CTCLInterpreter * | AssertIfNotBound () |
This class defines a class that encapsulates a TCL Channel. TCL channels in turn abstract the I/O subsystem of the underlying operating system. TCL Channels are represented in TCL by an opaque pointer typedef'd as a Tcl_Channel. This pointer contains all the state required for a channel.
We support the following types of construction:
Notes:
CTCLChannel::CTCLChannel | ( | CTCLInterpreter * | pInterp, |
int | argc, | ||
const char ** | pargv, | ||
int | flags | ||
) |
Construct command pipeline.
Construct a command pipeline channel. A command pipeline is a channel abstraction to a pipeline of executing programs. Using command pipelines, the client can feed input to stdin of the pipeline as well as gather the stdout and stderr The pipeline is specified using the argc/argv style where I believe a multistage pipe can be constructed via elements of argv that contain '|' and I/O redirection can be done similarly as described in the documentation of the Tcl [exec] and [open] commands.
pInterp | (CTCLInterpreter* [m]): The interpreter on which this channel will be registered/executed. |
argc | (int): Number of words describing the command pipeline. |
pargv | (char** [in]): The command pipeline description words. |
flags | (int) Bitwise or of Flags that describe how the pipeline is connected to the channel:
|
string | - contaning an error if there's a problem opening the pipe. |
CTCLChannel::CTCLChannel | ( | CTCLInterpreter * | pInterp, |
int | port, | ||
Tcl_TcpAcceptProc * | proc, | ||
ClientData | AppData | ||
) |
Create a TCP/IP server listener.
Construct a Tcp/ip server channel. The server channel is listening on the designated port for connection requests. When a client connects, the user's handler is called. The handler is passed three parameters in order:
Note that the seerver has already done an accept(2), the only way to reject a client is to close the corresponding channel.
pInterp | (CTCLInterpreter* [m]): The interpreter on which this channel will be opened. |
port | (int): The port on which the server we connect to will be running. |
proc | (Tcl_TcpAcceptProc [callback]): This function is called when a client connects. Parameters are described above. |
AppData | (ClientData [?]): Data that is passed to the client without any interpretation. In the OO world, this is recommended to be a pointer to the object that will service the client. |
string | If the channel cannot be opened, a string exception is thrown. The string dscribes the reason the channel could not be opened. |
CTCLChannel::CTCLChannel | ( | CTCLInterpreter * | pInterp, |
Tcl_Channel | Channel | ||
) |
Construct from existing channel.
Create a channel from an existing open channel. In this case, we are not allowed to close or register the channel... only the original creator can do that.
pInterp | (CTCLInterpreter* [m]): The interpreter on which the channel is open |
Channel | (Tcl_Channel [m]): The channel to bless into this object. |
CTCLChannel::CTCLChannel | ( | const CTCLChannel & | rhs | ) |
Copy construction.
Create a channel via copy construction. The channel created will have a copy of m_Channel, and the flags all set to false to prevent close/unregister on destroy.
|
virtual |
Destroy a channel, nothing happens unless m_fCloseOnDestroy is set then:
bool CTCLChannel::atEof | ( | ) |
True if EOF on channel.
Returns true if the channel is at eof.
void CTCLChannel::Close | ( | ) |
Close channel (dangerous!!!).
Closes the channel. This is a bit more complex than it appears:
void CTCLChannel::Flush | ( | ) |
Flush channel data buffers.
Flushes the output data buffer to the underlying stream.
string CTCLChannel::GetEncoding | ( | ) |
Return the current encoding.
int CTCLChannel::Read | ( | void ** | pData, |
int | nChars | ||
) |
Read data from the channel.
Read data from the channel. The data are read using Tcl_ReadChars which implies that transformations consistent with the current encoding on the channel are applied to convert the data to UTF-8 unless the channel encoding has been set to binary.. in which case no transformations are performed. See SetEncoding and GetEncoding for more about this... as well as the TCL documentation.
pData | (void** [in]): Points to a pointer. The pointer will be filled in with a dynamically allocated buffer in which the data have been transferred. The buffer must be deleted by the caller. It was allocated as new char[nnn]. No effot is made to null terminate etc. since in binary mode, this may be just bytes. |
This is done because in general there's no way for the caller to know a-priori how large a buffer is required to hold nchars o UTF-8 encoded textual data.
nChars | (int): The number of bytes to read. |
>= | 0: The number of characters transfered. See the special cases below. |
< | 0: An error occured that is stored in errno. |
Special cases:
void CTCLChannel::Register | ( | ) |
Expose channel name to scripts (dangerous!!)
Registers a channel to make it visible to the TCL script world.
Name | (string [in]): Name under which the channel should be registered. |
void CTCLChannel::SetEncoding | ( | std::string | Name | ) |
Set the input/output encoding of the channel (binary means no encoding).
name | (string): The name of the encoding. |
int CTCLChannel::Write | ( | const void * | pData, |
int | nBytes | ||
) |
Write data to the channel.
Writes a set of bytes to the channel. Note that unless the encoding has been set to binary, the buffer is assumed to contain nbytes of utf-8 data that will be encoded as described by the encoding. Note that data written with Write may not appear in the underlying operating system channel until Flush is called.
pData | (const void* [in]): Pointer to the data to be written. |
nBytes | (int) Number of bytes to write. |
>= | 0 Number of bytes asctually written. 0 may indicate that the channel is in nonblocking mode and cannot be written yet. <=0 Indicates an error described by errno. |
Notes: