ADC Home > Reference Library > Reference > Darwin > Kernel Framework Reference

 


IOEventSource

Inherits from:
Declared In:

Overview

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.

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.

A kernel module can always use the work-loop model for serializing 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.

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 handing off change request to its own thread and thus single threading access to its state.

All subclasses of the IOEventSource are expected to implement the checkForWork() member function.



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.

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.



Functions

checkForWork

Pure Virtual member function used by IOWorkLoop for work scheduling.

disable

Disables event source.

enable

Enables event source.

getAction

Get'ter for action variable.

getNext

Get'ter for eventChainNext variable.

getWorkLoop

Get'ter for workLoop variable.

init

Primary initializer for the IOEventSource class.

isEnabled

Get'ter for enable variable.

onThread

Convenience function for workLoop->onThread.

setAction

Set'ter for action variable.

setNext

Set'ter for eventChainNext variable.

setWorkLoop

Set'ter for workLoop variable.


checkForWork


Pure Virtual member function used by IOWorkLoop for work scheduling.

protected

virtual bool checkForWork() = 0;
Return Value

Returns true if this function needs to be called again before all its outstanding events have been processed.

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.


disable


Disables event source.

public

virtual void disable();
Discussion

A subclass implementation is expected to respect the enabled state when checkForWork is called.


enable


Enables event source.

public

virtual void enable();
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.


getAction


Get'ter for action variable.

public

virtual IOEventSource::Action getAction() const;
Return Value

Returns the value of action.


getNext


Get'ter for eventChainNext variable.

protected

virtual IOEventSource *getNext() const;
Return Value

Returns the value of eventChainNext.


getWorkLoop


Get'ter for workLoop variable.

public

virtual IOWorkLoop *getWorkLoop() const;
Return Value

Returns the value of workLoop.


init


Primary initializer for the IOEventSource class.

protected

virtual bool init( OSObject *owner, IOEventSource::Action action = 0);
Parameters
owner

Owner of this instance of an event source. Used as the first parameter of the action callout. Owner will generally be an OSObject it doesn't have to be as no member functions will be called directly in it. It can just be a refcon for a client routine.

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.

Return Value

Returns true if the inherited classes and this instance initialize successfully.


isEnabled


Get'ter for enable variable.

public

virtual bool isEnabled() const;
Return Value

Returns true if enabled.


onThread


Convenience function for workLoop->onThread.

public

virtual bool onThread() const;
Return Value

Returns true if called on the work loop thread.


setAction


Set'ter for action variable.

public

virtual void setAction( IOEventSource::Action action);
Parameters
action

Pointer to a C function of type IOEventSource::Action.


setNext


Set'ter for eventChainNext variable.

protected

virtual void setNext( IOEventSource *next);
Parameters
next

Pointer to another IOEventSource instance.


setWorkLoop


Set'ter for workLoop variable.

protected

virtual void setWorkLoop( IOWorkLoop *workLoop);
Parameters
workLoop

Target work loop of this event source instance. A subclass of IOWorkLoop that at least reacts to signalWorkAvailable() and onThread functions.

Typedefs


Action


public

typedef void ( *Action)( OSObject *owner, ...);
Fields
owner

Target of the function, can be used as a refcon. The owner is set during initialization. Note if a C++ function was specified this parameter is implicitly the first paramter in the target member function's parameter list.

Discussion

Placeholder type for C++ function overloading discrimination. As the all event sources require an action and it has to be stored somewhere and be of some type, this is that type.

Structs and Unions


ExpansionData


protected

struct ExpansionData { };
Discussion

This structure will be used to expand the capablilties of the IOEventSource in the future.

Member Data


action


protected

Action action;
Discussion

The action method called when an event has been delivered


enabled


protected

bool enabled;
Discussion

Is this event source enabled to deliver requests to the work-loop.


eventChainNext


protected

IOEventSource *eventChainNext;
Discussion

The next event source in the event chain. nil at end of chain.


owner


protected

OSObject *owner;
Discussion
The owner object called when an event has been delivered.


refcon


protected

void *refcon;
Discussion
Whatever the client wants to do.


reserved


protected

ExpansionData *reserved;
Discussion

Reserved for future use. (Internal use only)


workLoop


protected

IOWorkLoop *workLoop;
Discussion
What is the work-loop for this event source.

#defines


IOEventSourceAction


#define IOEventSourceAction IOEventSource::Action 
Discussion

Backward compatibilty define for the old non-class scoped type definition. See Action.


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.

 

Last Updated: 2008-12-19