⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notifier.3

📁 linux系统下的音频通信
💻 3
📖 第 1 页 / 共 2 页
字号:
'\"'\" Copyright (c) 1995-1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) Notifier.3 1.16 97/05/17 17:03:17'\" .so man.macros.TH Notifier 3 8.0 Tcl "Tcl Library Procedures".BS.VS.SH NAMETcl_CreateEventSource, Tcl_DeleteEventSource, Tcl_SetMaxBlockTime, Tcl_QueueEvent, Tcl_DeleteEvents, Tcl_WaitForEvent, Tcl_SetTimer, Tcl_ServiceAll, Tcl_ServiceEvent, Tcl_GetServiceMode, Tcl_SetServiceMode \- the event queue and notifier interfaces.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.sp\fBTcl_CreateEventSource\fR(\fIsetupProc, checkProc, clientData\fB)\fR.sp\fBTcl_DeleteEventSource\fR(\fIsetupProc, checkProc, clientData\fB)\fR.sp\fBTcl_SetMaxBlockTime\fR(\fItimePtr\fB)\fR.sp\fBTcl_QueueEvent\fR(\fIevPtr, position\fR).VS.sp\fBTcl_DeleteEvents\fR(\fIdeleteProc, clientData\fR).spint\fBTcl_WaitForEvent\fR(\fItimePtr\fR).sp\fBTcl_SetTimer\fR(\fItimePtr\fR).spint\fBTcl_ServiceAll\fR().spint\fBTcl_ServiceEvent\fR(\fIflags\fR).spint\fBTcl_GetServiceMode\fR().spint		\fBTcl_SetServiceMode\fR(\fImode\fR).VE.SH ARGUMENTS.AS Tcl_EventDeleteProc milliseconds.AS Tcl_EventSetupProc *setupProc.AP Tcl_EventSetupProc *setupProc inProcedure to invoke to prepare for event wait in \fBTcl_DoOneEvent\fR..AP Tcl_EventCheckProc *checkProc inProcedure for \fBTcl_DoOneEvent\fR to invoke after waiting forevents.  Checks to see if any events have occurred and, if so,queues them..AP ClientData clientData inArbitrary one-word value to pass to \fIsetupProc\fR, \fIcheckProc\fR, or\fIdeleteProc\fR..AP Tcl_Time *timePtr inIndicates the maximum amount of time to wait for an event.  Thisis specified as an interval (how long to wait), not an absolutetime (when to wakeup).  If the pointer passed to \fBTcl_WaitForEvent\fRis NULL, it means there is no maximum wait time:  wait forever ifnecessary..AP Tcl_Event *evPtr inAn event to add to the event queue.  The storage for the event musthave been allocated by the caller using \fBTcl_Alloc\fR or \fBckalloc\fR..AP Tcl_QueuePosition position inWhere to add the new event in the queue:  \fBTCL_QUEUE_TAIL\fR,\fBTCL_QUEUE_HEAD\fR, or \fBTCL_QUEUE_MARK\fR..AP int flags inWhat types of events to service.  These flags are the same as thosepassed to \fBTcl_DoOneEvent\fR..AP Tcl_EventDeleteProc *deleteProc inProcedure to invoke for each queued event in \fBTcl_DeleteEvents\fR..VS.AP int mode inInidicates whether events should be serviced by \fBTcl_ServiceAll\fR.Must be one of \fBTCL_SERVICE_NONE\fR or \fBTCL_SERVICE_ALL\fR..VE.BE.SH INTRODUCTION.PP.VSThe interfaces described here are used to customize the Tcl eventloop.  The two most common customizations are to add new sources ofevents and to merge Tcl's event loop with some other event loop, suchas one provided by an application in which Tcl is embedded.  Each ofthese tasks is described in a separate section below..VE.PPThe procedures in this manual entry are the building blocks out of whichthe Tcl event notifier is constructed.  The event notifier is the lowestlayer in the Tcl event mechanism.  It consists of three things:.IP [1]Event sources: these represent the ways in which events can begenerated.  For example, there is a timer event source that implementsthe \fBTcl_CreateTimerHandler\fR procedure and the \fBafter\fRcommand, and there is a file event source that implements the\fBTcl_CreateFileHandler\fR procedure on Unix systems.  An eventsource must work with the notifier to detect events at the righttimes, record them on the event queue, and eventually notifyhigher-level software that they have occurred.  The procedures\fBTcl_CreateEventSource\fR, \fBTcl_DeleteEventSource\fR,and \fBTcl_SetMaxBlockTime\fR, \fBTcl_QueueEvent\fR, and\fBTcl_DeleteEvents\fR are used primarily by event sources..IP [2]The event queue: there is a single queue for the whole application,containing events that have been detected but not yet serviced.  Eventsources place events onto the queue so that they may be processed inorder at appropriate times during the event loop. The event queueguarantees a fair discipline of event handling, so that no eventsource can starve the others.  It also allows events to be saved forservicing at a future time..VS\fBTcl_QueueEvent\fR is used (primarilyby event sources) to add events to the event queue and \fBTcl_DeleteEvents\fR is used to remove events from the queue withoutprocessing them..IP [3]The event loop: in order to detect and process events, the applicationenters a loop that waits for events to occur, places them on the eventqueue, and then processes them.  Most applications will do this bycalling the procedure \fBTcl_DoOneEvent\fR, which is described in aseparate manual entry..PPMost Tcl applications need not worry about any of the internals ofthe Tcl notifier.  However, the notifier now has enough flexibilityto be retargeted either for a new platform or to use an external eventloop (such as the Motif event loop, when Tcl is embedded in a Motifapplication).  The procedures \fBTcl_WaitForEvent\fR and\fBTcl_SetTimer\fR are normally implemented by Tcl, but may bereplaced with new versions to retarget the notifier (the \fBTcl_Sleep\fR,\fBTcl_CreateFileHandler\fR, and \fBTcl_DeleteFileHandler\fR mustalso be replaced; see CREATING A NEW NOTIFIER below for details).The procedures \fBTcl_ServiceAll\fR, \fBTcl_ServiceEvent\fR,\fBTcl_GetServiceMode\fR, and \fBTcl_SetServiceMode\fR are providedto help connect Tcl's event loop to an external event loop such asMotif's..SH "NOTIFIER BASICS".VE.PPThe easiest way to understand how the notifier works is to considerwhat happens when \fBTcl_DoOneEvent\fR is called.\fBTcl_DoOneEvent\fR is passed a \fIflags\fR argument that indicateswhat sort of events it is OK to process and also whether or not toblock if no events are ready.  \fBTcl_DoOneEvent\fR does the followingthings:.IP [1]Check the event queue to see if it contains any events that canbe serviced.  If so, service the first possible event, remove it.VSfrom the queue, and return.  It does this by calling\fBTcl_ServiceEvent\fR and passing in the \fIflags\fR argument..VE.IP [2]Prepare to block for an event.  To do this, \fBTcl_DoOneEvent\fRinvokes a \fIsetup procedure\fR in each event source.The event source will perform event-source specific initialization and.VSpossibly call \fBTcl_SetMaxBlockTime\fR to limit how long.VE\fBTcl_WaitForEvent\fR will block if no new events occur..IP [3]Call \fBTcl_WaitForEvent\fR.  This procedure is implemented differentlyon different platforms;  it waits for an event to occur, based on theinformation provided by the event sources.It may cause the application to block if \fItimePtr\fR specifiesan interval other than 0.\fBTcl_WaitForEvent\fR returns when something has happened,such as a file becoming readable or the interval given by \fItimePtr\fRexpiring.  If there are no events for \fBTcl_WaitForEvent\fR towait for, so that it would block forever, then it returns immediatelyand \fBTcl_DoOneEvent\fR returns 0..IP [4]Call a \fIcheck procedure\fR in each event source.  The checkprocedure determines whether any events of interest to this sourceoccurred.  If so, the events are added to the event queue..IP [5]Check the event queue to see if it contains any events that canbe serviced.  If so, service the first possible event, remove itfrom the queue, and return..IP [6]See if there are idle callbacks pending. If so, invoke all of them andreturn..IP [7]Either return 0 to indicate that no events were ready, or go back tostep [2] if blocking was requested by the caller..SH "CREATING A NEW EVENT SOURCE".PPAn event source consists of three procedures invoked by the notifier,plus additional C procedures that are invoked by higher-level codeto arrange for event-driven callbacks.  The three procedures calledby the notifier consist of the setup and check procedures describedabove, plus an additional procedure that is invoked when an eventis removed from the event queue for servicing..PPThe procedure \fBTcl_CreateEventSource\fR creates a new event source.Its arguments specify the setup procedure and check procedure forthe event source.\fISetupProc\fR should match the following prototype:.CStypedef void Tcl_EventSetupProc(	ClientData \fIclientData\fR,	int \fIflags\fR);.CEThe \fIclientData\fR argument will be the same as the \fIclientData\fRargument to \fBTcl_CreateEventSource\fR;  it is typically used topoint to private information managed by the event source.The \fIflags\fR argument will be the same as the \fIflags\fRargument passed to \fBTcl_DoOneEvent\fR except that it will neverbe 0 (\fBTcl_DoOneEvent\fR replaces 0 with \fBTCL_ALL_EVENTS\fR).\fIFlags\fR indicates what kinds of events should be considered;if the bit corresponding to this event source isn't set, the eventsource should return immediately without doing anything.  Forexample, the file event source checks for the \fBTCL_FILE_EVENTS\fRbit..PP\fISetupProc\fR's job is to make sure that the application wakes upwhen events of the desired type occur.  This is typically done in aplatform-dependent fashion.  For example, under Unix an event sourcemight call \fBTcl_CreateFileHandler\fR; under Windows it mightrequest notification with a Windows event.  For timer-driven eventsources such as timer events or any polled event, the event sourcecan call \fBTcl_SetMaxBlockTime\fR to force the application to wakeup after a specified time even if no events have occurred..VSIf no event source calls \fBTcl_SetMaxBlockTime\fRthen \fBTcl_WaitForEvent\fR will wait as long as necessary for anevent to occur; otherwise, it will only wait as long as the shortestinterval passed to \fBTcl_SetMaxBlockTime\fR by one of the eventsources.  If an event source knows that it already has events ready toreport, it can request a zero maximum block time.  For example, thesetup procedure for the X event source looks to see if there areevents already queued.  If there are, it calls\fBTcl_SetMaxBlockTime\fR with a 0 block time so that\fBTcl_WaitForEvent\fR does not block if there is no new data on the Xconnection..VEThe \fItimePtr\fR argument to \fBTcl_WaitForEvent\fR points toa structure that describes a time interval in seconds andmicroseconds:.CStypedef struct Tcl_Time {	long \fIsec\fR;	long \fIusec\fR;} Tcl_Time;.CEThe \fIusec\fR field should be less than 1000000..PP.VSInformation provided to \fBTcl_SetMaxBlockTime\fRis only used for the next call to \fBTcl_WaitForEvent\fR; it isdiscarded after \fBTcl_WaitForEvent\fR returns..VEThe next time an event wait is done each of the event sources'setup procedures will be called again, and they can specify newinformation for that event wait..PP.VSIf the application uses an external event loop rather than\fBTcl_DoOneEvent\fR, the event sources may need to call\fBTcl_SetMaxBlockTime\fR at other times.  For example, if a new eventhandler is registered that needs to poll for events, the event sourcemay call \fBTcl_SetMaxBlockTime\fR to set the block time to zero to

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -