| 1 |
'\" |
| 2 |
'\" Copyright (c) 2008 Donal K. Fellows |
| 3 |
'\" |
| 4 |
'\" See the file "license.terms" for information on usage and redistribution |
| 5 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
'\" |
| 7 |
.TH transchan n 8.6 Tcl "Tcl Built-In Commands" |
| 8 |
.so man.macros |
| 9 |
.BS |
| 10 |
'\" Note: do not modify the .SH NAME line immediately below! |
| 11 |
.SH NAME |
| 12 |
transchan \- command handler API of channel transforms |
| 13 |
.SH SYNOPSIS |
| 14 |
\fBcmdPrefix \fIoption\fR ?\fIarg arg ...\fR? |
| 15 |
.BE |
| 16 |
.SH DESCRIPTION |
| 17 |
.PP |
| 18 |
The Tcl-level handler for a channel transformation has to be a command with |
| 19 |
subcommands (termed an \fIensemble\fR despite not implying that it must be |
| 20 |
created with \fBnamespace ensemble create\fR; this mechanism is not tied to |
| 21 |
\fBnamespace ensemble\fR in any way). Note that \fIcmdPrefix\fR is whatever |
| 22 |
was specified in the call to \fBchan push\fR, and may consist of multiple |
| 23 |
arguments; this will be expanded to multiple words in place of the prefix. |
| 24 |
.PP |
| 25 |
Of all the possible subcommands, the handler \fImust\fR support |
| 26 |
\fBinitialize\fR and \fBfinalize\fR. Transformations for writable channels |
| 27 |
must also support \fBwrite\fR, and transformations for readable channels must |
| 28 |
also support \fBread\fR. |
| 29 |
.PP |
| 30 |
Note that in the descriptions below \fIcmdPrefix\fR may be more than one word, |
| 31 |
and \fIhandle\fR is the value returned by the \fBchan push\fR call used to |
| 32 |
create the transformation. |
| 33 |
.SS "GENERIC SUBCOMMANDS" |
| 34 |
.PP |
| 35 |
The following subcommands are relevant to all types of channel. |
| 36 |
.TP |
| 37 |
\fIcmdPrefix \fBclear \fIhandle\fR |
| 38 |
. |
| 39 |
This optional subcommand is called to signify to the transformation that any |
| 40 |
data stored in internal buffers (either incoming or outgoing) must be |
| 41 |
cleared. It is called when a \fBchan seek\fR is performed on the channel being |
| 42 |
transformed. |
| 43 |
.TP |
| 44 |
\fIcmdPrefix \fBfinalize \fIhandle\fR |
| 45 |
. |
| 46 |
This mandatory subcommand is called last for the given \fIhandle\fR, and then |
| 47 |
never again, and it exists to allow for cleaning up any Tcl-level data |
| 48 |
structures associated with the transformation. \fIWarning!\fR Any errors |
| 49 |
thrown by this subcommand will be ignored. It is not guaranteed to be called |
| 50 |
if the interpreter is deleted. |
| 51 |
.TP |
| 52 |
\fIcmdPrefix \fBinitialize \fIhandle mode\fR |
| 53 |
. |
| 54 |
This mandatory subcommand is called first, and then never again (for the given |
| 55 |
\fIhandle\fR). Its responsibility is to initialize all parts of the |
| 56 |
transformation at the Tcl level. The \fImode\fR is a list containing any of |
| 57 |
\fBread \fRand \fBwrite\fR. |
| 58 |
.RS |
| 59 |
.TP |
| 60 |
\fBwrite\fR |
| 61 |
. |
| 62 |
implies that the channel is writable. |
| 63 |
.TP |
| 64 |
\fBread\fR |
| 65 |
. |
| 66 |
implies that the channel is readable. |
| 67 |
.PP |
| 68 |
The return value of the subcommand should be a list containing the names of |
| 69 |
all subcommands supported by this handler. Any error thrown by the subcommand |
| 70 |
will prevent the creation of the transformation. The thrown error will appear |
| 71 |
as error thrown by \fBchan push\fR. |
| 72 |
.RE |
| 73 |
.SS "READ-RELATED SUBCOMMANDS" |
| 74 |
.PP |
| 75 |
These subcommands are used for handling transformations applied to readable |
| 76 |
channels; though strictly \fBread \fRis optional, it must be supported if any |
| 77 |
of the others is or the channel will be made non-readable. |
| 78 |
.TP |
| 79 |
\fIcmdPrefix \fBdrain \fIhandle\fR |
| 80 |
. |
| 81 |
This optional subcommand is called whenever data in the transformation input |
| 82 |
(i.e. read) buffer has to be forced upward, i.e. towards the user or script. |
| 83 |
The result returned by the method is taken as the \fIbinary\fR data to push |
| 84 |
upward to the level above this transformation (the reader or a higher-level |
| 85 |
transformation). |
| 86 |
.RS |
| 87 |
.PP |
| 88 |
In other words, when this method is called the transformation cannot defer the |
| 89 |
actual transformation operation anymore and has to transform all data waiting |
| 90 |
in its internal read buffers and return the result of that action. |
| 91 |
.RE |
| 92 |
.TP |
| 93 |
\fIcmdPrefix \fBlimit? \fIhandle\fR |
| 94 |
. |
| 95 |
This optional subcommand is called to allow the Tcl I/O engine to determine |
| 96 |
how far ahead it should read. If present, it should return an integer number |
| 97 |
greater than zero which indicates how many bytes ahead should be read, or an |
| 98 |
integer less than zero to indicate that the I/O engine may read as far ahead |
| 99 |
as it likes. |
| 100 |
.TP |
| 101 |
\fIcmdPrefix \fBread \fIhandle buffer\fR |
| 102 |
. |
| 103 |
This subcommand, which must be present if the transformation is to work with |
| 104 |
readable channels, is called whenever the base channel, or a transformation |
| 105 |
below this transformation, pushes data upward. The \fIbuffer\fR contains the |
| 106 |
binary data which has been given to us from below. It is the responsibility of |
| 107 |
this subcommand to actually transform the data. The result returned by the |
| 108 |
subcommand is taken as the binary data to push further upward to the |
| 109 |
transformation above this transformation. This can also be the user or script |
| 110 |
that originally read from the channel. |
| 111 |
.RS |
| 112 |
.PP |
| 113 |
Note that the result is allowed to be empty, or even less than the data we |
| 114 |
received; the transformation is not required to transform everything given to |
| 115 |
it right now. It is allowed to store incoming data in internal buffers and to |
| 116 |
defer the actual transformation until it has more data. |
| 117 |
.RE |
| 118 |
.SS "WRITE-RELATED SUBCOMMANDS" |
| 119 |
.PP |
| 120 |
These subcommands are used for handling transformations applied to writable |
| 121 |
channels; though strictly \fBwrite\fR is optional, it must be supported if any |
| 122 |
of the others is or the channel will be made non-writable. |
| 123 |
.TP |
| 124 |
\fIcmdPrefix \fBflush \fIhandle\fR |
| 125 |
. |
| 126 |
This optional subcommand is called whenever data in the transformation 'write' |
| 127 |
buffer has to be forced downward, i.e. towards the base channel. The result |
| 128 |
returned by the subcommand is taken as the binary data to write to the |
| 129 |
transformation below the current transformation. This can be the base channel |
| 130 |
as well. |
| 131 |
.RS |
| 132 |
.PP |
| 133 |
In other words, when this subcommand is called the transformation cannot defer |
| 134 |
the actual transformation operation anymore and has to transform all data |
| 135 |
waiting in its internal write buffers and return the result of that action. |
| 136 |
.RE |
| 137 |
.TP |
| 138 |
\fIcmdPrefix \fBwrite \fIhandle buffer\fR |
| 139 |
. |
| 140 |
This subcommand, which must be present if the transformation is to work with |
| 141 |
writable channels, is called whenever the user, or a transformation above this |
| 142 |
transformation, writes data downward. The \fIbuffer\fR contains the binary |
| 143 |
data which has been written to us. It is the responsibility of this subcommand |
| 144 |
to actually transform the data. |
| 145 |
.RS |
| 146 |
.PP |
| 147 |
The result returned by the subcommand is taken as the binary data to write to |
| 148 |
the transformation below this transformation. This can be the base channel as |
| 149 |
well. Note that the result is allowed to be empty, or less than the data we |
| 150 |
got; the transformation is not required to transform everything which was |
| 151 |
written to it right now. It is allowed to store this data in internal buffers |
| 152 |
and to defer the actual transformation until it has more data. |
| 153 |
.RE |
| 154 |
.SH "SEE ALSO" |
| 155 |
chan(n), refchan(n) |
| 156 |
.SH KEYWORDS |
| 157 |
API, channel, ensemble, prefix, transformation |
| 158 |
'\" Local Variables: |
| 159 |
'\" mode: nroff |
| 160 |
'\" End: |