|
|
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) 1998 Apple Computer, Inc. All rights reserved.
24: HISTORY
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:
40: __BEGIN_DECLS
41: #include <mach/clock_types.h>
42: #include <kern/clock.h>
43: __END_DECLS
44:
45: class IOWorkLoop;
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
51: event 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
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.
57: <br><br>
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.
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>
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 occured 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.
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: */
75: class IOEventSource : public OSObject
76: {
77: OSDeclareAbstractStructors(IOEventSource)
78: friend class IOWorkLoop;
79:
80: public:
81: /*!
82: @typedef Action
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.
86: @param owner
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.
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:
97: protected:
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: /*! @function init
120: @abstract Primary initialiser for the IOEventSource class.
121: @param owner
122: Owner of this instance of an event source. Used as the first parameter
123: of the action callout. Owner will generally be an OSObject it doesn't have to
124: be as no member functions will be called directly in it. It can just be a
125: refcon for a client routine.
126: @param action
127: Pointer to C call out function. Action is a pointer to a C function
128: that gets called when this event source has outstanding work. It will usually
129: be called by the checkForWork member function. The first parameter of the
130: action call out will always be the owner, this allows C++ member functions to
131: be used as actions. Defaults to 0.
132: @result true if the inherited classes and this instance initialise
133: successfully.
134: */
135: virtual bool init(OSObject *owner, IOEventSource::Action action = 0);
136:
137: /*! @function checkForWork
138: @abstract Pure Virtual member function used by IOWorkLoop for work
139: scheduling.
140: @discussion This function will be called to request a subclass to check
141: it's internal state for any work to do and then to call out the owner/action.
142: @result Return true if this function needs to be called again before all its outstanding events have been processed.
143: */
144: virtual bool checkForWork() = 0;
145:
146: /*! @function setWorkLoop
147: @abstract Set'ter for $link workLoop variable.
148: @param workLoop
149: Target work-loop of this event source instance. A subclass of
150: IOWorkLoop that at least reacts to signalWorkAvailable() and onThread functions.
151: */
152: virtual void setWorkLoop(IOWorkLoop *workLoop);
153:
154: /*! @function setNext
155: @abstract Set'ter for $link eventChainNext variable.
156: @param next
157: Pointer to another IOEventSource instance.
158: */
159: virtual void setNext(IOEventSource *next);
160:
161: /*! @function getNext
162: @abstract Get'ter for $link eventChainNext variable.
163: @result value of eventChainNext.
164: */
165: virtual IOEventSource *getNext() const;
166:
167: public:
168: /*! @function setAction
169: @abstract Set'ter for $link action variable.
170: @param action Pointer to a C function of type IOEventSource::Action. */
171: virtual void setAction(IOEventSource::Action action);
172:
173: /*! @function getAction
174: @abstract Get'ter for $link action variable.
175: @result value of action. */
176: virtual IOEventSource::Action getAction() const;
177:
178: /*! @function enable
179: @abstract Enable event source.
180: @discussion A subclass implementation is expected to respect the enabled
181: state when checkForWork is called. Calling this function will cause the
182: work-loop to be signalled so that a checkForWork is performed. */
183: virtual void enable();
184:
185: /*! @function disable
186: @abstract Disable event source.
187: @discussion A subclass implementation is expected to respect the enabled
188: state when checkForWork is called. */
189: virtual void disable();
190:
191: /*! @function isEnabled
192: @abstract Get'ter for $link enable variable.
193: @result true if enabled. */
194: virtual bool isEnabled() const;
195:
196: /*! @function getWorkLoop
197: @abstract Get'ter for $link workLoop variable.
198: @result value of workLoop. */
199: virtual IOWorkLoop *getWorkLoop() const;
200:
201: /*! @function onThread
202: @abstract Convenience function for workLoop->onThread.
203: @result true if called on the work-loop thread.
204: */
205: virtual bool onThread() const;
206: };
207:
208: #endif /* !_IOKIT_IOEVENTSOURCE_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.