]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOEventSource.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / iokit / IOKit / IOEventSource.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/*
31Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
32HISTORY
33 1998-7-13 Godfrey van der Linden(gvdl)
34 Created.
35 1998-10-30 Godfrey van der Linden(gvdl)
36 Converted to C++
37*/
38#ifndef _IOKIT_IOEVENTSOURCE_H
39#define _IOKIT_IOEVENTSOURCE_H
40
41#include <sys/cdefs.h>
42
43#include <libkern/c++/OSObject.h>
44
45#include <IOKit/IOLib.h>
46#include <IOKit/system.h>
47#include <IOKit/IOWorkLoop.h>
48
49
50__BEGIN_DECLS
51#include <mach/clock_types.h>
52#include <kern/clock.h>
53__END_DECLS
54
55/*!
56 @class IOEventSource : public OSObject
57 @abstract Abstract class for all work-loop event sources.
58 @discussion The IOEventSource declares the abstract super class that all
59event sources must inherit from if an IOWorkLoop is to receive events from them.
60<br><br>
61 An event source can represent any event that should cause the work-loop of a
62device to wake up and perform work. Two examples of event sources are the
63IOInterruptEventSource which delivers interrupt notifications and IOCommandGate
64which delivers command requests.
65<br><br>
66 A kernel module can always use the work-loop model for serialising access to
67anything at all. The IOEventSource is used for communicating events to the
68work-loop, and the chain of event sources should be used to walk the possible
69event sources and demultipex them. Note a particular instance of an event
70source may only be a member of 1 linked list chain. If you need to move it
71between chains than make sure it is removed from the original chain before
72attempting to move it.
73<br><br>
74 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.
75<br><br>
76 All subclasses of the IOEventSource are expected to implement the checkForWork() member function.
77
78<br><br>
91447636 79 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.
1c79356b
A
80<br><br>
81 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.
82*/
83class IOEventSource : public OSObject
84{
85 OSDeclareAbstractStructors(IOEventSource)
86 friend class IOWorkLoop;
87
88public:
89/*!
90 @typedef Action
91 @discussion Placeholder type for C++ function overloading discrimination.
92As the all event sources require an action and it has to be stored somewhere
93and be of some type, this is that type.
94 @param owner
95 Target of the function, can be used as a refcon. The owner is set
96during initialisation. Note if a C++ function was specified this parameter
97is implicitly the first paramter in the target member function's parameter list.
98*/
99 typedef void (*Action)(OSObject *owner, ...);
100
101/*! @defined IOEventSourceAction
102 @discussion Backward compatibilty define for the old non-class scoped type definition. See $link IOEventSource::Action */
103 #define IOEventSourceAction IOEventSource::Action
104
105protected:
106/*! @var eventChainNext
107 The next event source in the event chain. nil at end of chain. */
108 IOEventSource *eventChainNext;
109
110/*! @var owner The owner object called when an event has been delivered. */
111 OSObject *owner;
112
113/*! @var action
114 The action method called when an event has been delivered */
115 Action action;
116
117/*! @var enabled
118 Is this event source enabled to deliver requests to the work-loop. */
119 bool enabled;
120
121/*! @var workLoop What is the work-loop for this event source. */
122 IOWorkLoop *workLoop;
123
124/*! @var refcon What ever the client wants to do, see $link setRefcon. */
125 void *refcon;
126
127/*! @struct ExpansionData
128 @discussion This structure will be used to expand the capablilties of the IOEventSource in the future.
129 */
130 struct ExpansionData { };
131
132/*! @var reserved
133 Reserved for future use. (Internal use only) */
134 ExpansionData *reserved;
135
136/*! @function init
137 @abstract Primary initialiser for the IOEventSource class.
138 @param owner
139 Owner of this instance of an event source. Used as the first parameter
140of the action callout. Owner will generally be an OSObject it doesn't have to
141be as no member functions will be called directly in it. It can just be a
142refcon for a client routine.
143 @param action
144 Pointer to C call out function. Action is a pointer to a C function
145that gets called when this event source has outstanding work. It will usually
146be called by the checkForWork member function. The first parameter of the
147action call out will always be the owner, this allows C++ member functions to
148be used as actions. Defaults to 0.
149 @result true if the inherited classes and this instance initialise
150successfully.
151*/
152 virtual bool init(OSObject *owner, IOEventSource::Action action = 0);
153
154/*! @function checkForWork
155 @abstract Pure Virtual member function used by IOWorkLoop for work
156scheduling.
157 @discussion This function will be called to request a subclass to check
158it's internal state for any work to do and then to call out the owner/action.
159 @result Return true if this function needs to be called again before all its outstanding events have been processed.
160 */
161 virtual bool checkForWork() = 0;
162
163/*! @function setWorkLoop
164 @abstract Set'ter for $link workLoop variable.
165 @param workLoop
166 Target work-loop of this event source instance. A subclass of
167IOWorkLoop that at least reacts to signalWorkAvailable() and onThread functions.
168*/
169 virtual void setWorkLoop(IOWorkLoop *workLoop);
170
171/*! @function setNext
172 @abstract Set'ter for $link eventChainNext variable.
173 @param next
174 Pointer to another IOEventSource instance.
175*/
176 virtual void setNext(IOEventSource *next);
177
178/*! @function getNext
179 @abstract Get'ter for $link eventChainNext variable.
180 @result value of eventChainNext.
181*/
182 virtual IOEventSource *getNext() const;
183
184
185protected:
186 // Methods to access the IOWorkLoop exported fields
9bccf70c
A
187 /* inline */ void signalWorkAvailable();
188 /* { workLoop->signalWorkAvailable(); }; */
189 /* inline */ void openGate();
190 /* { workLoop->openGate(); }; */
191 /* inline */ void closeGate();
192 /* { workLoop->closeGate(); }; */
193 /* inline */ bool tryCloseGate();
194 /* { return workLoop->tryCloseGate(); }; */
195 /* inline */ int sleepGate(void *event, UInt32 type);
196 /* { return workLoop->sleepGate(event, type); }; */
197 /* inline */ void wakeupGate(void *event, bool oneThread);
198 /* { workLoop->wakeupGate(event, oneThread); }; */
1c79356b
A
199
200public:
201/*! @function setAction
202 @abstract Set'ter for $link action variable.
203 @param action Pointer to a C function of type IOEventSource::Action. */
204 virtual void setAction(IOEventSource::Action action);
205
206/*! @function getAction
207 @abstract Get'ter for $link action variable.
208 @result value of action. */
209 virtual IOEventSource::Action getAction() const;
210
211/*! @function enable
212 @abstract Enable event source.
213 @discussion A subclass implementation is expected to respect the enabled
214state when checkForWork is called. Calling this function will cause the
215work-loop to be signalled so that a checkForWork is performed. */
216 virtual void enable();
217
218/*! @function disable
219 @abstract Disable event source.
220 @discussion A subclass implementation is expected to respect the enabled
221state when checkForWork is called. */
222 virtual void disable();
223
224/*! @function isEnabled
225 @abstract Get'ter for $link enable variable.
226 @result true if enabled. */
227 virtual bool isEnabled() const;
228
229/*! @function getWorkLoop
230 @abstract Get'ter for $link workLoop variable.
231 @result value of workLoop. */
232 virtual IOWorkLoop *getWorkLoop() const;
233
234/*! @function onThread
235 @abstract Convenience function for workLoop->onThread.
236 @result true if called on the work-loop thread.
237*/
238 virtual bool onThread() const;
239
240private:
241 OSMetaClassDeclareReservedUnused(IOEventSource, 0);
242 OSMetaClassDeclareReservedUnused(IOEventSource, 1);
243 OSMetaClassDeclareReservedUnused(IOEventSource, 2);
244 OSMetaClassDeclareReservedUnused(IOEventSource, 3);
245 OSMetaClassDeclareReservedUnused(IOEventSource, 4);
246 OSMetaClassDeclareReservedUnused(IOEventSource, 5);
247 OSMetaClassDeclareReservedUnused(IOEventSource, 6);
248 OSMetaClassDeclareReservedUnused(IOEventSource, 7);
249};
250
251#endif /* !_IOKIT_IOEVENTSOURCE_H */