]>
git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOEventSource.h
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
25 1998-7-13 Godfrey van der Linden(gvdl)
27 1998-10-30 Godfrey van der Linden(gvdl)
30 #ifndef _IOKIT_IOEVENTSOURCE_H
31 #define _IOKIT_IOEVENTSOURCE_H
33 #include <sys/cdefs.h>
35 #include <libkern/c++/OSObject.h>
37 #include <IOKit/IOLib.h>
38 #include <IOKit/system.h>
39 #include <IOKit/IOWorkLoop.h>
43 #include <mach/clock_types.h>
44 #include <kern/clock.h>
48 @class IOEventSource : public OSObject
49 @abstract Abstract class for all work-loop event sources.
50 @discussion The IOEventSource declares the abstract super class that all
51 event sources must inherit from if an IOWorkLoop is to receive events from them.
53 An event source can represent any event that should cause the work-loop of a
54 device to wake up and perform work. Two examples of event sources are the
55 IOInterruptEventSource which delivers interrupt notifications and IOCommandGate
56 which delivers command requests.
58 A kernel module can always use the work-loop model for serialising access to
59 anything at all. The IOEventSource is used for communicating events to the
60 work-loop, and the chain of event sources should be used to walk the possible
61 event sources and demultipex them. Note a particular instance of an event
62 source may only be a member of 1 linked list chain. If you need to move it
63 between chains than make sure it is removed from the original chain before
64 attempting to move it.
66 The IOEventSource makes no attempt to maintain the consitency of it's internal data across multi-threading. It is assumed that the user of these basic tools will protect the data that these objects represent in some sort of device wide instance lock. For example the IOWorkLoop maintains the event chain by handing off change request to its own thread and thus single threading access to its state.
68 All subclasses of the IOEventSource are expected to implement the checkForWork() member function.
71 checkForWork() is the key method in this class. It is called by some work-loop when convienient and is expected to evaluate it's internal state and determine if an event has occurred since the last call. In the case of an event having occurred then the instance defined target(owner)/action will be called. The action is stored as an ordinary C function pointer but the first parameter is always the owner. This means that a C++ member function can be used as an action function though this depends on the ABI.
73 Although the eventChainNext variable contains a reference to the next event source in the chain this reference is not retained. The list 'owner' i.e. the client that creates the event, not the work-loop, is expected to retain the source.
75 class IOEventSource
: public OSObject
77 OSDeclareAbstractStructors ( IOEventSource
)
78 friend class IOWorkLoop
;
83 @discussion Placeholder type for C++ function overloading discrimination.
84 As the all event sources require an action and it has to be stored somewhere
85 and be of some type, this is that type.
87 Target of the function, can be used as a refcon. The owner is set
88 during initialisation. Note if a C++ function was specified this parameter
89 is implicitly the first paramter in the target member function's parameter list.
91 typedef void (* Action
)( OSObject
* owner
, ...);
93 /*! @defined IOEventSourceAction
94 @discussion Backward compatibilty define for the old non-class scoped type definition. See $link IOEventSource::Action */
95 #define IOEventSourceAction IOEventSource::Action
98 /*! @var eventChainNext
99 The next event source in the event chain. nil at end of chain. */
100 IOEventSource
* eventChainNext
;
102 /*! @var owner The owner object called when an event has been delivered. */
106 The action method called when an event has been delivered */
110 Is this event source enabled to deliver requests to the work-loop. */
113 /*! @var workLoop What is the work-loop for this event source. */
114 IOWorkLoop
* workLoop
;
116 /*! @var refcon What ever the client wants to do, see $link setRefcon. */
119 /*! @struct ExpansionData
120 @discussion This structure will be used to expand the capablilties of the IOEventSource in the future.
122 struct ExpansionData
{ };
125 Reserved for future use. (Internal use only) */
126 ExpansionData
* reserved
;
129 @abstract Primary initialiser for the IOEventSource class.
131 Owner of this instance of an event source. Used as the first parameter
132 of the action callout. Owner will generally be an OSObject it doesn't have to
133 be as no member functions will be called directly in it. It can just be a
134 refcon for a client routine.
136 Pointer to C call out function. Action is a pointer to a C function
137 that gets called when this event source has outstanding work. It will usually
138 be called by the checkForWork member function. The first parameter of the
139 action call out will always be the owner, this allows C++ member functions to
140 be used as actions. Defaults to 0.
141 @result true if the inherited classes and this instance initialise
144 virtual bool init ( OSObject
* owner
, IOEventSource :: Action action
= 0 );
146 /*! @function checkForWork
147 @abstract Pure Virtual member function used by IOWorkLoop for work
149 @discussion This function will be called to request a subclass to check
150 it's internal state for any work to do and then to call out the owner/action.
151 @result Return true if this function needs to be called again before all its outstanding events have been processed.
153 virtual bool checkForWork () = 0 ;
155 /*! @function setWorkLoop
156 @abstract Set'ter for $link workLoop variable.
158 Target work-loop of this event source instance. A subclass of
159 IOWorkLoop that at least reacts to signalWorkAvailable() and onThread functions.
161 virtual void setWorkLoop ( IOWorkLoop
* workLoop
);
163 /*! @function setNext
164 @abstract Set'ter for $link eventChainNext variable.
166 Pointer to another IOEventSource instance.
168 virtual void setNext ( IOEventSource
* next
);
170 /*! @function getNext
171 @abstract Get'ter for $link eventChainNext variable.
172 @result value of eventChainNext.
174 virtual IOEventSource
* getNext () const ;
178 // Methods to access the IOWorkLoop exported fields
179 /* inline */ void signalWorkAvailable ();
180 /* { workLoop->signalWorkAvailable(); }; */
181 /* inline */ void openGate ();
182 /* { workLoop->openGate(); }; */
183 /* inline */ void closeGate ();
184 /* { workLoop->closeGate(); }; */
185 /* inline */ bool tryCloseGate ();
186 /* { return workLoop->tryCloseGate(); }; */
187 /* inline */ int sleepGate ( void * event
, UInt32 type
);
188 /* { return workLoop->sleepGate(event, type); }; */
189 /* inline */ void wakeupGate ( void * event
, bool oneThread
);
190 /* { workLoop->wakeupGate(event, oneThread); }; */
193 /*! @function setAction
194 @abstract Set'ter for $link action variable.
195 @param action Pointer to a C function of type IOEventSource::Action. */
196 virtual void setAction ( IOEventSource :: Action action
);
198 /*! @function getAction
199 @abstract Get'ter for $link action variable.
200 @result value of action. */
201 virtual IOEventSource :: Action
getAction () const ;
204 @abstract Enable event source.
205 @discussion A subclass implementation is expected to respect the enabled
206 state when checkForWork is called. Calling this function will cause the
207 work-loop to be signalled so that a checkForWork is performed. */
208 virtual void enable ();
210 /*! @function disable
211 @abstract Disable event source.
212 @discussion A subclass implementation is expected to respect the enabled
213 state when checkForWork is called. */
214 virtual void disable ();
216 /*! @function isEnabled
217 @abstract Get'ter for $link enable variable.
218 @result true if enabled. */
219 virtual bool isEnabled () const ;
221 /*! @function getWorkLoop
222 @abstract Get'ter for $link workLoop variable.
223 @result value of workLoop. */
224 virtual IOWorkLoop
* getWorkLoop () const ;
226 /*! @function onThread
227 @abstract Convenience function for workLoop->onThread.
228 @result true if called on the work-loop thread.
230 virtual bool onThread () const ;
233 OSMetaClassDeclareReservedUnused ( IOEventSource
, 0 );
234 OSMetaClassDeclareReservedUnused ( IOEventSource
, 1 );
235 OSMetaClassDeclareReservedUnused ( IOEventSource
, 2 );
236 OSMetaClassDeclareReservedUnused ( IOEventSource
, 3 );
237 OSMetaClassDeclareReservedUnused ( IOEventSource
, 4 );
238 OSMetaClassDeclareReservedUnused ( IOEventSource
, 5 );
239 OSMetaClassDeclareReservedUnused ( IOEventSource
, 6 );
240 OSMetaClassDeclareReservedUnused ( IOEventSource
, 7 );
243 #endif /* !_IOKIT_IOEVENTSOURCE_H */