Debian Codegraph @

doc/TraceCmd.3

raw
1 '\"
2 '\" Copyright (c) 2002 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 Tcl_TraceCommand 3 7.4 Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 .SH NAME
11 Tcl_CommandTraceInfo, Tcl_TraceCommand, Tcl_UntraceCommand \- monitor renames and deletes of a command
12 .SH SYNOPSIS
13 .nf
14 \fB#include <tcl.h>\fR
15 .sp
16 ClientData
17 \fBTcl_CommandTraceInfo(\fIinterp, cmdName, flags, proc, prevClientData\fB)\fR
18 .sp
19 int
20 \fBTcl_TraceCommand(\fIinterp, cmdName, flags, proc, clientData\fB)\fR
21 .sp
22 void
23 \fBTcl_UntraceCommand(\fIinterp, cmdName, flags, proc, clientData\fB)\fR
24 .SH ARGUMENTS
25 .AS Tcl_CommandTraceProc prevClientData
26 .AP Tcl_Interp *interp in
27 Interpreter containing the command.
28 .AP "const char" *cmdName in
29 Name of command.
30 .AP int flags in
31 OR'ed collection of the values \fBTCL_TRACE_RENAME\fR and
32 \fBTCL_TRACE_DELETE\fR.
33 .AP Tcl_CommandTraceProc *proc in
34 Procedure to call when specified operations occur to \fIcmdName\fR.
35 .AP ClientData clientData in
36 Arbitrary argument to pass to \fIproc\fR.
37 .AP ClientData prevClientData in
38 If non-NULL, gives last value returned by \fBTcl_CommandTraceInfo\fR,
39 so this call will return information about next trace. If NULL, this
40 call will return information about first trace.
41 .BE
42 .SH DESCRIPTION
43 .PP
44 \fBTcl_TraceCommand\fR allows a C procedure to monitor operations
45 performed on a Tcl command, so that the C procedure is invoked
46 whenever the command is renamed or deleted. If the trace is created
47 successfully then \fBTcl_TraceCommand\fR returns \fBTCL_OK\fR. If an error
48 occurred (e.g. \fIcmdName\fR specifies a non-existent command) then
49 \fBTCL_ERROR\fR is returned and an error message is left in the
50 interpreter's result.
51 .PP
52 The \fIflags\fR argument to \fBTcl_TraceCommand\fR indicates when the
53 trace procedure is to be invoked. It consists of an OR'ed combination
54 of any of the following values:
55 .TP
56 \fBTCL_TRACE_RENAME\fR
57 Invoke \fIproc\fR whenever the command is renamed.
58 .TP
59 \fBTCL_TRACE_DELETE\fR
60 Invoke \fIproc\fR when the command is deleted.
61 .PP
62 Whenever one of the specified operations occurs to the command,
63 \fIproc\fR will be invoked. It should have arguments and result that
64 match the type \fBTcl_CommandTraceProc\fR:
65 .PP
66 .CS
67 typedef void \fBTcl_CommandTraceProc\fR(
68 ClientData \fIclientData\fR,
69 Tcl_Interp *\fIinterp\fR,
70 const char *\fIoldName\fR,
71 const char *\fInewName\fR,
72 int \fIflags\fR);
73 .CE
74 .PP
75 The \fIclientData\fR and \fIinterp\fR parameters will have the same
76 values as those passed to \fBTcl_TraceCommand\fR when the trace was
77 created. \fIClientData\fR typically points to an application-specific
78 data structure that describes what to do when \fIproc\fR is invoked.
79 \fIOldName\fR gives the name of the command being renamed, and
80 \fInewName\fR gives the name that the command is being renamed to (or
81 NULL when the command is being deleted.)
82 \fIFlags\fR is an OR'ed combination of bits potentially providing
83 several pieces of information. One of the bits \fBTCL_TRACE_RENAME\fR and
84 \fBTCL_TRACE_DELETE\fR will be set in \fIflags\fR to indicate which
85 operation is being performed on the command. The bit
86 \fBTCL_TRACE_DESTROYED\fR will be set in \fIflags\fR if the trace is about
87 to be destroyed; this information may be useful to \fIproc\fR so that
88 it can clean up its own internal data structures (see the section
89 \fBTCL_TRACE_DESTROYED\fR below for more details). Because the
90 deletion of commands can take place as part of the deletion of the interp
91 that contains them, \fIproc\fR must be careful about checking what
92 the passed in \fIinterp\fR value can be called upon to do.
93 The routine \fBTcl_InterpDeleted\fR is an important tool for this.
94 When \fBTcl_InterpDeleted\fR returns 1, \fIproc\fR will not be able
95 to invoke any scripts in \fIinterp\fR. The function of \fIproc\fR
96 in that circumstance is limited to the cleanup of its own data structures.
97 .PP
98 \fBTcl_UntraceCommand\fR may be used to remove a trace. If the
99 command specified by \fIinterp\fR, \fIcmdName\fR, and \fIflags\fR has
100 a trace set with \fIflags\fR, \fIproc\fR, and \fIclientData\fR, then
101 the corresponding trace is removed. If no such trace exists, then the
102 call to \fBTcl_UntraceCommand\fR has no effect. The same bits are
103 valid for \fIflags\fR as for calls to \fBTcl_TraceCommand\fR.
104 .PP
105 \fBTcl_CommandTraceInfo\fR may be used to retrieve information about
106 traces set on a given command.
107 The return value from \fBTcl_CommandTraceInfo\fR is the \fIclientData\fR
108 associated with a particular trace.
109 The trace must be on the command specified by the \fIinterp\fR,
110 \fIcmdName\fR, and \fIflags\fR arguments (note that currently the
111 flags are ignored; \fIflags\fR should be set to 0 for future
112 compatibility) and its trace procedure must the same as the \fIproc\fR
113 argument.
114 If the \fIprevClientData\fR argument is NULL then the return
115 value corresponds to the first (most recently created) matching
116 trace, or NULL if there are no matching traces.
117 If the \fIprevClientData\fR argument is not NULL, then it should
118 be the return value from a previous call to \fBTcl_CommandTraceInfo\fR.
119 In this case, the new return value will correspond to the next
120 matching trace after the one whose \fIclientData\fR matches
121 \fIprevClientData\fR, or NULL if no trace matches \fIprevClientData\fR
122 or if there are no more matching traces after it.
123 This mechanism makes it possible to step through all of the
124 traces for a given command that have the same \fIproc\fR.
125 .SH "CALLING COMMANDS DURING TRACES"
126 .PP
127 During rename traces, the command being renamed is visible with both
128 names simultaneously, and the command still exists during delete
129 traces, unless the interp that contains it is being deleted.
130 However, there is no
131 mechanism for signaling that an error occurred in a trace procedure,
132 so great care should be taken that errors do not get silently lost.
133 .SH "MULTIPLE TRACES"
134 .PP
135 It is possible for multiple traces to exist on the same command.
136 When this happens, all of the trace procedures will be invoked on each
137 access, in order from most-recently-created to least-recently-created.
138 Attempts to delete the command during a delete trace will fail
139 silently, since the command is already scheduled for deletion anyway.
140 If the command being renamed is renamed by one of its rename traces,
141 that renaming takes precedence over the one that triggered the trace
142 and the collection of traces will not be reexecuted; if several traces
143 rename the command, the last renaming takes precedence.
144 .SH "TCL_TRACE_DESTROYED FLAG"
145 .PP
146 In a delete callback to \fIproc\fR, the \fBTCL_TRACE_DESTROYED\fR bit
147 is set in \fIflags\fR.
148 .\" Perhaps need some more comments here? - DKF
149 .SH KEYWORDS
150 clientData, trace, command