Developing Drivers with the Windows Driver Foundation (Pro Developer)

The WDF object model defines a set of objects that represent common driver constructs such as devices, memory, queues, I/O requests, and the driver itself. Framework objects have well-defined life cycles and contracts, and a WDF driver interacts with them through well-defined interfaces. UMDF objects are implemented as COM objects, whereas KMDF objects are implemented as a combination of opaque "handles" and functions that operate on those handles. However, at a conceptual level, the WDF object models for KMDF and UMDF are similar.

Framework objects are created by both the framework and the client WDF driver. Whether the framework or the driver creates the object depends on the particular object and its intended use:

Programming Interface

A framework object exposes a programming interface that consists of properties, methods, and events:

To handle an event, a WDF driver implements a callback and registers it with the framework:

Regardless of how they are implemented, both types of callbacks work in much the same way. Because the framework implements default handlers for all events, WDF drivers register callbacks only for those events that are relevant to their device. When an event occurs:

Object Hierarchy

Framework objects are organized in a hierarchy, which the frameworks use to manage issues such as object lifetime, object cleanup, and synchronization scope. For example, if an object has descendants, all descendants are deleted when the object is deleted. The hierarchy is not based on inheritance relationships between the various framework objects-it is based on the scope of the various objects and the order in which they must be destroyed. The hierarchy is defined as follows:

Chapter 5, "WDF Object Model," discusses the WDF object model in detail.

Concurrency and Synchronization

Managing concurrent operations is an issue for most programs. WDF simplifies the issue by implementing several internal synchronization mechanisms. In particular, a driver can direct the framework to hold a lock when the framework invokes a callback. The WDF object hierarchy supports a feature called synchronization scope-also called the locking constraint-that allows the WDF driver to specify which object's lock should be acquired when the framework calls the driver's I/O event callbacks.

Chapter 10, "Synchronization," discusses synchronization issues in general and synchronization scope in particular.

Tip 

If you're writing a KMDF driver, you should also be familiar with IRQLs and kernel-mode synchronization and locking mechanisms. Chapter 15, "Scheduling, Thread Context, and IRQL," discusses these issues.

Категории