#include <IOKit/IOEventSource.h>
IOKit/IOEventSource.h
classIOEventSource
@class IOEventSource : public OSObject
@abstract Abstract class for all work-loop event sources.
@discussion The IOEventSource declares the abstract super class that all
event sources must inherit from if an IOWorkLoop is to receive events from them.
<br><br>
An event source can represent any event that should cause the work-loop of a
device to wake up and perform work. Two examples of event sources are the
IOInterruptEventSource which delivers interrupt notifications and IOCommandGate
which delivers command requests.
<br><br>
A kernel module can always use the work-loop model for serialising access to
anything at all. The IOEventSource is used for communicating events to the
work-loop, and the chain of event sources should be used to walk the possible
event sources and demultipex them. Note a particular instance of an event
source may only be a member of 1 linked list chain. If you need to move it
between chains than make sure it is removed from the original chain before
attempting to move it.
<br><br>
The IOEventSource makes no attempt to maintain the consistency of its 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 using an IOCommandGate and thus single threading access to its state.
<br><br>
All subclasses of IOEventSource that wish to perform work on the work-loop thread are expected to implement the checkForWork() member function. As of Mac OS X, 10.7 (Darwin 11), checkForWork is no longer pure virtual, and should not be overridden if there is no work to be done.
<br><br>
checkForWork() is the key method in this class. It is called by some work-loop when convienient and is expected to evaluate its 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.
<br><br>
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.
: public OSObject
| IOEventSource * | eventChainNext | |
| OSObject * | owner | |
| Action | action | |
| bool | enabled | |
| IOWorkLoop * | workLoop | |
| void * | refcon | |
| ExpansionData * | reserved |
virtual bool init(OSObject *owner, IOEventSource::Action action = NULL)virtual protected
@function init
@abstract Primary initialiser for the IOEventSource class.
@param owner
Owner of this instance of an event source. Used as the first parameter
of the action callout. Owner must be an OSObject.
@param action
Pointer to C call out function. Action is a pointer to a C function
that gets called when this event source has outstanding work. It will usually
be called by the checkForWork member function. The first parameter of the
action call out will always be the owner, this allows C++ member functions to
be used as actions. Defaults to 0.
@result true if the inherited classes and this instance initialise
successfully.
APPLE_KEXT_OVERRIDE
virtual void free(void)virtual protectedvirtual bool checkForWork()virtual protected
@function checkForWork
@abstract Virtual member function used by IOWorkLoop for work
scheduling.
@discussion This function will be called to request a subclass to check
its internal state for any work to do and then to call out the owner/action.
If this event source never performs any work (e.g. IOCommandGate), this
method should not be overridden. NOTE: This method is no longer declared pure
virtual. A default implementation is provided in IOEventSource.
@result Return true if this function needs to be called again before all its outstanding events have been processed.
virtual void setWorkLoop(IOWorkLoop *workLoop)virtual protected
@function setWorkLoop
@abstract Set'ter for $link workLoop variable.
@param workLoop
Target work-loop of this event source instance. A subclass of
IOWorkLoop that at least reacts to signalWorkAvailable() and onThread functions.
virtual void setNext(IOEventSource *next)virtual protected
@function setNext
@abstract Set'ter for $link eventChainNext variable.
@param next
Pointer to another IOEventSource instance.
virtual IOEventSource *getNext() constvirtual protected
@function getNext
@abstract Get'ter for $link eventChainNext variable.
@result value of eventChainNext.
void signalWorkAvailable()protected
Methods to access the IOWorkLoop exported fields
void openGate()protected
void closeGate()protected
bool tryCloseGate()protected
int sleepGate(void *event, UInt32 type)protected
int sleepGate(void *event, AbsoluteTime deadline, UInt32 type)protected
void wakeupGate(void *event, bool oneThread)protected
virtual void setAction(IOEventSource::Action action)virtual
@function setAction
@abstract Set'ter for $link action variable.
@param action Pointer to a C function of type IOEventSource::Action.
virtual IOEventSource::Action getAction() constvirtual
@function getAction
@abstract Get'ter for $link action variable.
@result value of action.
void setActionBlock(ActionBlock block)
@function setActionBlock
@abstract Setter for action ivar. The current block is released, & the new block is retained.
@param block Block pointer of type IOEventSource::ActionBlock.
ActionBlock getActionBlock(ActionBlock) const
@function getActionBlock
@abstract Getter for action ivar.
@result Block pointer of type IOEventSource::ActionBlock, if set, or NULL.
void setRefcon(void *refcon)
@function setRefcon
@abstract Setter for refcon ivar. This function will assert if a block action has been set.
@param refcon Refcon.
void * getRefcon() const
@function getRefcon
@abstract Getter for refcon ivar.
@result The refcon. This function will assert if a block action has been set.
virtual void enable()virtual
@function enable
@abstract Enable event source.
@discussion A subclass implementation is expected to respect the enabled
state when checkForWork is called. Calling this function will cause the
work-loop to be signalled so that a checkForWork is performed.
virtual void disable()virtual
@function disable
@abstract Disable event source.
@discussion A subclass implementation is expected to respect the enabled
state when checkForWork is called.
virtual bool isEnabled() constvirtual
@function isEnabled
@abstract Get'ter for $link enable variable.
@result true if enabled.
virtual IOWorkLoop *getWorkLoop() constvirtual
@function getWorkLoop
@abstract Get'ter for $link workLoop variable.
@result value of workLoop.
virtual bool onThread() constvirtual
@function onThread
@abstract Convenience function for workLoop->onThread.
@result true if called on the work-loop thread.
macroIOEventSourceAction
@defined IOEventSourceAction
@discussion Backward compatibilty define for the old non-class scoped type definition. See $link IOEventSource::Action
#define IOEventSourceAction IOEventSource::Action