]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOEventSource.h
xnu-792.6.22.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 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
A
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.
1c79356b 11 *
e5568f75
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
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.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
24HISTORY
25 1998-7-13 Godfrey van der Linden(gvdl)
26 Created.
27 1998-10-30 Godfrey van der Linden(gvdl)
28 Converted to C++
29*/
30#ifndef _IOKIT_IOEVENTSOURCE_H
31#define _IOKIT_IOEVENTSOURCE_H
32
33#include <sys/cdefs.h>
34
35#include <libkern/c++/OSObject.h>
36
37#include <IOKit/IOLib.h>
38#include <IOKit/system.h>
39#include <IOKit/IOWorkLoop.h>
40
41
42__BEGIN_DECLS
43#include <mach/clock_types.h>
44#include <kern/clock.h>
45__END_DECLS
46
47/*!
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
51event sources must inherit from if an IOWorkLoop is to receive events from them.
52<br><br>
53 An event source can represent any event that should cause the work-loop of a
54device to wake up and perform work. Two examples of event sources are the
55IOInterruptEventSource which delivers interrupt notifications and IOCommandGate
56which delivers command requests.
57<br><br>
58 A kernel module can always use the work-loop model for serialising access to
59anything at all. The IOEventSource is used for communicating events to the
60work-loop, and the chain of event sources should be used to walk the possible
61event sources and demultipex them. Note a particular instance of an event
62source may only be a member of 1 linked list chain. If you need to move it
63between chains than make sure it is removed from the original chain before
64attempting to move it.
65<br><br>
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.
67<br><br>
68 All subclasses of the IOEventSource are expected to implement the checkForWork() member function.
69
70<br><br>
91447636 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.
1c79356b
A
72<br><br>
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.
74*/
75class IOEventSource : public OSObject
76{
77 OSDeclareAbstractStructors(IOEventSource)
78 friend class IOWorkLoop;
79
80public:
81/*!
82 @typedef Action
83 @discussion Placeholder type for C++ function overloading discrimination.
84As the all event sources require an action and it has to be stored somewhere
85and be of some type, this is that type.
86 @param owner
87 Target of the function, can be used as a refcon. The owner is set
88during initialisation. Note if a C++ function was specified this parameter
89is implicitly the first paramter in the target member function's parameter list.
90*/
91 typedef void (*Action)(OSObject *owner, ...);
92
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
96
97protected:
98/*! @var eventChainNext
99 The next event source in the event chain. nil at end of chain. */
100 IOEventSource *eventChainNext;
101
102/*! @var owner The owner object called when an event has been delivered. */
103 OSObject *owner;
104
105/*! @var action
106 The action method called when an event has been delivered */
107 Action action;
108
109/*! @var enabled
110 Is this event source enabled to deliver requests to the work-loop. */
111 bool enabled;
112
113/*! @var workLoop What is the work-loop for this event source. */
114 IOWorkLoop *workLoop;
115
116/*! @var refcon What ever the client wants to do, see $link setRefcon. */
117 void *refcon;
118
119/*! @struct ExpansionData
120 @discussion This structure will be used to expand the capablilties of the IOEventSource in the future.
121 */
122 struct ExpansionData { };
123
124/*! @var reserved
125 Reserved for future use. (Internal use only) */
126 ExpansionData *reserved;
127
128/*! @function init
129 @abstract Primary initialiser for the IOEventSource class.
130 @param owner
131 Owner of this instance of an event source. Used as the first parameter
132of the action callout. Owner will generally be an OSObject it doesn't have to
133be as no member functions will be called directly in it. It can just be a
134refcon for a client routine.
135 @param action
136 Pointer to C call out function. Action is a pointer to a C function
137that gets called when this event source has outstanding work. It will usually
138be called by the checkForWork member function. The first parameter of the
139action call out will always be the owner, this allows C++ member functions to
140be used as actions. Defaults to 0.
141 @result true if the inherited classes and this instance initialise
142successfully.
143*/
144 virtual bool init(OSObject *owner, IOEventSource::Action action = 0);
145
146/*! @function checkForWork
147 @abstract Pure Virtual member function used by IOWorkLoop for work
148scheduling.
149 @discussion This function will be called to request a subclass to check
150it'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.
152 */
153 virtual bool checkForWork() = 0;
154
155/*! @function setWorkLoop
156 @abstract Set'ter for $link workLoop variable.
157 @param workLoop
158 Target work-loop of this event source instance. A subclass of
159IOWorkLoop that at least reacts to signalWorkAvailable() and onThread functions.
160*/
161 virtual void setWorkLoop(IOWorkLoop *workLoop);
162
163/*! @function setNext
164 @abstract Set'ter for $link eventChainNext variable.
165 @param next
166 Pointer to another IOEventSource instance.
167*/
168 virtual void setNext(IOEventSource *next);
169
170/*! @function getNext
171 @abstract Get'ter for $link eventChainNext variable.
172 @result value of eventChainNext.
173*/
174 virtual IOEventSource *getNext() const;
175
176
177protected:
178 // Methods to access the IOWorkLoop exported fields
9bccf70c
A
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); }; */
1c79356b
A
191
192public:
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);
197
198/*! @function getAction
199 @abstract Get'ter for $link action variable.
200 @result value of action. */
201 virtual IOEventSource::Action getAction() const;
202
203/*! @function enable
204 @abstract Enable event source.
205 @discussion A subclass implementation is expected to respect the enabled
206state when checkForWork is called. Calling this function will cause the
207work-loop to be signalled so that a checkForWork is performed. */
208 virtual void enable();
209
210/*! @function disable
211 @abstract Disable event source.
212 @discussion A subclass implementation is expected to respect the enabled
213state when checkForWork is called. */
214 virtual void disable();
215
216/*! @function isEnabled
217 @abstract Get'ter for $link enable variable.
218 @result true if enabled. */
219 virtual bool isEnabled() const;
220
221/*! @function getWorkLoop
222 @abstract Get'ter for $link workLoop variable.
223 @result value of workLoop. */
224 virtual IOWorkLoop *getWorkLoop() const;
225
226/*! @function onThread
227 @abstract Convenience function for workLoop->onThread.
228 @result true if called on the work-loop thread.
229*/
230 virtual bool onThread() const;
231
232private:
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);
241};
242
243#endif /* !_IOKIT_IOEVENTSOURCE_H */