IOService
The base class for managing the setup and registration of your driver.
Declaration
class IOService;Mentioned in
Overview
An IOService object is the base class the system uses to represent all devices and device-related interfaces. When the user plugs in a device, the system creates one or more service objects to manage interactions with that device. One service object represents the device itself, and additional service objects represent the interfaces or communication protocols that the device supports. For example, the driver for a USB camera that supports multiple video and audio protocols might define different service objects for each protocol.
When the user plugs in a device, the system looks for the service objects that best match the device’s capabilities. Apple’s built-in driver families support most device types and a large array of standard interfaces. You provide custom service objects to support your device’s custom behaviors.
In most cases, you subclass a child of IOService such as IOUSBHostInterface, instead of IOService itself. Use the methods of this class to do the following:
Handle the initialization, setup, and teardown of your driver.
View and manage the I/O Registry entry for the device or interface.
Configure the dispatch queue on which to execute your code.
Respond to power-level changes
For additional information about how to implement services for a particular type of device, see the service subclasses in HIDDriverKit, USBDriverKit, NetworkingDriverKit, SerialDriverKit, and USBSerialDriverKit.
Adding Member Variables to Your Custom Subclass
Don’t declare custom member variables directly in your IOService subclass. Instead, DriverKit requires you to define all variables in a separate structure. During initialization, allocate a block of memory for that structure and assign that block to the system-provided ivars variable of your service class. The following code example shows you how to define the structure and allocate it in the init method of your service class.
struct MyCustomKeyboardDriver_IVars
{
OSArray *elements;
struct {
OSArray *elements;
} keyboard;
};
bool MyCustomKeyboardDriver::init()
{
if (!super::init()) {return false;}
// Allocate memory for the instance variables.
ivars = IONewZero(MyCustomKeyboardDriver_IVars, 1);
if (!ivars) {return false;}
exit:
return true;
}
Deallocate any memory that you allocate for your custom variables in the free method of your class.
Topics
Running the Service
Registering the Service with IOKit
Managing the Registry Properties
Configuring Additional Dispatch Queues
Responding to Power-Level Changes
Creating a New Service
Instance Methods
AdjustBusyClientCrashedConfigureReportCopyNameCopyProviderPropertiesCopySystemStateNotificationServiceCoreAnalyticsSendEventCreateDefaultDispatchQueueGetBusyStateGetProviderJoinPMTreeRemovePropertyRequireMaxBusStallSetLegendSetPowerOverrideStateNotificationItemCopyStateNotificationItemCreateStateNotificationItemSetStop_asyncStringFromReturnTerminateUpdateReportCreatePMAssertionReleasePMAssertion