Annotation of XNU/iokit/IOKit/IOTimerEventSource.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /*
                     23:  * Copyright (c) 1999 Apple Computer, Inc.  All rights reserved. 
                     24:  *
                     25:  * IOTimerEventSource.h
                     26:  *
                     27:  * HISTORY
                     28:  * 2-Feb-1999          Joe Liu (jliu) created.
                     29:  *
                     30:  */
                     31: 
                     32: #ifndef _IOTIMEREVENTSOURCE
                     33: #define _IOTIMEREVENTSOURCE
                     34: 
                     35: #include <sys/cdefs.h>
                     36: 
                     37: __BEGIN_DECLS
                     38: #include <kern/clock.h>
                     39: __END_DECLS
                     40: 
                     41: #include <IOKit/IOEventSource.h>
                     42: 
                     43: /*!
                     44:     @class IOTimerEventSource : public IOEventSource
                     45:     @abstract Time based event source mechanism.
                     46:     @discussion An event source that implements a simple timer.         A timeout handler is called once the timeout period expires.  This timeout handler will be called by the work-loop that this event source is attached to.
                     47: <br><br>
                     48:        Usually a timer event source will be used to implement a timeout.  In general when a driver makes a request it will need to setup a call to keep track of when the I/O doesn't complete.  This class is designed to make that somewhat easier.
                     49: <br><br>
                     50:        Remember the system doesn't guarantee the accuracy of the callout.      It is possible that a higher priority thread is running which will delay the execution of the action routine.  In fact the thread will be made runable at the exact requested time, within the accuracy of the CPU's decrementer based interrupt, but the scheduler will then control execution.
                     51: */
                     52: class IOTimerEventSource : public IOEventSource
                     53: {
                     54:     OSDeclareDefaultStructors(IOTimerEventSource)
                     55: 
                     56: protected:
                     57: /*! @var calloutEntry thread_call entry for preregistered thread callouts */
                     58:     void *calloutEntry;
                     59: 
                     60: /*! @var abstime time to wake up next, see enable. */
                     61:     AbsoluteTime abstime;
                     62: 
                     63: /*! @function timeout
                     64:     @abstract Function that routes the call from the OS' timeout mechanism into a work-loop context.
                     65:     @discussion timeout will normally not be called nor overridden by a subclass.  If the event source is enabled then close the work-loop's gate and call the action routine.
                     66:     @param self This argument will be cast to an IOTimerEventSource. */
                     67:     static void timeout(void *self);
                     68: 
                     69: /*! @function setTimeoutFunc
                     70:     @abstract Set's timeout as the function of calloutEntry.
                     71:     @discussion IOTimerEventSource is based upon the kern/thread_call.h APIs currently.         This function allocates the calloutEntry member variable by using thread_call_allocate(timeout, this).  If you need to write your own subclass of IOTimerEventSource you probably should override this method to allocate an entry that points to your own timeout routine. */
                     72:     virtual void setTimeoutFunc();
                     73: 
                     74: /*! @function free
                     75:     @abstract Sub-class implementation of free method, frees calloutEntry */
                     76:     virtual void free();
                     77: 
                     78: /*! @function checkForWork
                     79:     @abstract Have to implement it is mandatory in $link IOEventSource, but IOTimerEventSources don't actually use this work-loop mechanism. */
                     80:     virtual bool checkForWork();
                     81: 
                     82: public:
                     83: 
                     84: /*! @enum Scale Factors
                     85:     @discussion Used when a scale_factor parameter is required to define a unit of time.
                     86:     @constant kNanosecondScale Scale factor for nanosecond based times.
                     87:     @constant kMicrosecondScale Scale factor for microsecond based times.
                     88:     @constant kMillisecondScale Scale factor for millisecond based times. */
                     89:     enum {
                     90:        kNanosecondScale  = 1,
                     91:        kMicrosecondScale = 1000,
                     92:        kMillisecondScale = 1000 * 1000
                     93:     };
                     94: 
                     95: /*! @typedef Action
                     96:     @discussion 'C' Function pointer defining the callout routine of this event source.
                     97:     @param owner Owning target object. Note by a startling coincidence the first parameter in a C callout is currently used to define the target of a C++ member function.
                     98:     @param sender The object that timed out. */
                     99:     typedef void (*Action)(OSObject *owner, IOTimerEventSource *sender);
                    100: 
                    101: /*! @function timerEventSource
                    102:     @abstract Allocates and returns an initialized timer instance.
                    103:     @param owner
                    104:     @param action */
                    105:     static IOTimerEventSource *
                    106:        timerEventSource(OSObject *owner, Action action = 0);
                    107: 
                    108: /*! @function init
                    109:     @abstract Initializes the timer with an owner, and a handler to call when the timeout expires.
                    110:     @param owner 
                    111:     @param action */
                    112:     virtual bool init(OSObject *owner, Action action = 0);
                    113: 
                    114: /*! @function enable
                    115:     @abstract Enables a call to the action.
                    116:     @discussion Allows the action function to be called.  If the timer event source was disabled while a call was outstanding and the call wasn't cancelled then it will be rescheduled.  So a disable/enable pair will disable calls from this event source. */
                    117:     virtual void enable();
                    118: 
                    119: /*! @function disable
                    120:     @abstract Disable a timed callout.
                    121:     @discussion When disable returns the action will not be called until the next time enable(qv) is called. */
                    122:     virtual void disable();
                    123: 
                    124: 
                    125: /*! @function setTimeoutTicks
                    126:     @abstract Setup a callback at after the delay in scheduler ticks.  See wakeAtTime(AbsoluteTime).
                    127:     @param interval Delay from now to wake up, in scheduler ticks, whatever that may be.
                    128:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    129:     virtual IOReturn setTimeoutTicks(UInt32 ticks);
                    130: 
                    131: /*! @function setTimeoutMS
                    132:     @abstract Setup a callback at after the delay in milliseconds.  See wakeAtTime(AbsoluteTime).
                    133:     @param interval Delay from now to wake up, time in milliseconds.
                    134:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    135:     virtual IOReturn setTimeoutMS(UInt32 ms);
                    136: 
                    137: /*! @function setTimeoutUS
                    138:         @abstract Setup a callback at after the delay in microseconds.  See wakeAtTime(AbsoluteTime).
                    139:     @param interval Delay from now to wake up, time in microseconds.
                    140:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    141:     virtual IOReturn setTimeoutUS(UInt32 us);
                    142: 
                    143: /*! @function setTimeout
                    144:     @abstract Setup a callback at after the delay in some unit.         See wakeAtTime(AbsoluteTime).
                    145:     @param interval Delay from now to wake up in some defined unit.
                    146:     @param scale_factor Define the unit of interval, default to nanoseconds.
                    147:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    148:     virtual IOReturn setTimeout(UInt32 interval,
                    149:                                UInt32 scale_factor = kNanosecondScale);
                    150: 
                    151: /*! @function setTimeout
                    152:     @abstract Setup a callback at after the delay in decrementer ticks.         See wakeAtTime(AbsoluteTime).
                    153:     @param interval Delay from now to wake up.
                    154:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    155:     virtual IOReturn setTimeout(mach_timespec_t interval);
                    156: 
                    157: /*! @function setTimeout
                    158:     @abstract Setup a callback at after the delay in decrementer ticks.         See wakeAtTime(AbsoluteTime).
                    159:     @param interval Delay from now to wake up in decrementer ticks.
                    160:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    161:     virtual IOReturn setTimeout(AbsoluteTime interval);
                    162: 
                    163: /*! @function wakeAtTimeTicks
                    164:     @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
                    165:     @param abstime Time to wake up in scheduler quantums, whatever that is?
                    166:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    167:     virtual IOReturn wakeAtTimeTicks(UInt32 ticks);
                    168: 
                    169: /*! @function wakeAtTimeMS
                    170:     @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
                    171:     @param abstime Time to wake up in milliseconds.
                    172:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    173:     virtual IOReturn wakeAtTimeMS(UInt32 ms);
                    174: 
                    175: /*! @function wakeAtTimeUS
                    176:     @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
                    177:     @param abstime Time to wake up in microseconds.
                    178:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    179:     virtual IOReturn wakeAtTimeUS(UInt32 us);
                    180: 
                    181: /*! @function wakeAtTime
                    182:     @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
                    183:     @param abstime Time to wake up in some unit.
                    184:     @param scale_factor Define the unit of abstime, default to nanoseconds.
                    185:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    186:     virtual IOReturn wakeAtTime(UInt32 abstime,
                    187:                                UInt32 scale_factor = kNanosecondScale);
                    188: 
                    189: /*! @function wakeAtTime
                    190:     @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
                    191:     @param abstime mach_timespec_t of the desired callout time.
                    192:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
                    193:     virtual IOReturn wakeAtTime(mach_timespec_t abstime);
                    194: 
                    195: /*! @function wakeAtTime
                    196:     @abstract Setup a callback at this absolute time.
                    197:     @discussion Starts the timer, which will expire at abstime. After it expires, the timer will call the 'action' registered in the init() function. This timer is not periodic, a further call is needed to reset and restart the timer after it expires.  
                    198:     @param abstime Absolute Time when to wake up, counted in 'decrementer' units and starts at zero when system boots.
                    199:     @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared by init or IOEventSource::setAction (qqv). */
                    200:     virtual IOReturn wakeAtTime(AbsoluteTime abstime);
                    201: 
                    202: /*! @function cancelTimeout
                    203:     @abstract Disable any outstanding calls to this event source.
                    204:     @discussion Clear down any oustanding calls.  By the time this function completes it is guaranteed that the action will not be called again. */
                    205:    virtual void cancelTimeout();
                    206: };
                    207: 
                    208: #endif /* !_IOTIMEREVENTSOURCE */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.