Developing Drivers with the Windows Driver Foundation (Pro Developer)

 UMDF   UMDF is a COM-based programming model that supports the development of function and filter drivers for protocol-based Plug and Play devices, such as USB devices. The framework is a DLL that implements the WDF object model by providing in-process COM-based driver objects, device objects, I/O request objects, and so on. The driver is a DLL that consists of a collection of in-process COM-based callback objects that handle events raised by the associated framework objects.

COM was chosen as a basis for UMDF for several reasons:

Chapter 18, "An Introduction to COM," provides information about COM programming.

The UMDF programming model is based on the following two types of objects:

The UMDF DDI-which includes both the objects that the framework provides and the callback objects that the driver implements-is exposed entirely through COM interfaces. Drivers use an interface pointer, rather than an object pointer, to interact with a framework object. Framework objects, in turn, interact with driver-implemented callback objects through the appropriate interface.

UMDF Framework Objects

With UMDF, framework objects are created in the following ways:

The interfaces that framework objects expose are named IWDFObject, where Object refers to the object that exports the interface. In addition to IUnknown, all framework objects expose one or more interfaces that provide access to the object's functionality. For example, the framework device object also exports IWDFDevice and IWDFObject. Each interface contains one or more methods that serve the following purposes:

Chapter 5, "WDF Object Model," describes the UMDF naming conventions.

UMDF Callback Objects

The framework provides default handling for all events. Drivers can override the framework's default event handling by implementing callback objects to handle events of interest and by registering the objects with the framework. Callback objects expose one or more callback interfaces, each of which handles a set of related events. Callback interfaces consist of one or more methods-one for each event-that the framework calls to notify the driver of an event and to pass the callback object any related data.

Drivers register callback objects by passing a pointer to one of the object's interfaces to the framework object that raises the related event. Drivers register callback objects in one of two ways, depending on whether the driver or the framework creates the framework object:

The events that a driver chooses to handle determine which interfaces each callback object exposes. For example, if a driver must handle a queue object's read event but not its cleanup event, the callback object would expose a single callback interface- IQueueCallbackRead. To handle both the read and cleanup events, the callback object would expose IQueueCallbackRead and IObjectCleanup. Sometimes a framework object does not raise any interesting events, so a callback object is unnecessary. For example, drivers often are not required to handle the events that memory objects raise.

 Note  Callback objects are not necessarily restricted to handling the events that a single framework object raises. For example, the Fx2_Driver sample's device callback object exposes three callback interfaces: IPnpCallbackHardware, IPnpCallback, and IRequestCallbackRequestCompletion. The first two are registered with the framework device object to handle Plug and Play and power management events. IRequestCallbackRequestCompletion is registered with a framework queue object to handle request completion.

Категории