UfxDeviceNotifyDetach 函数 (ufxclient.h)
通知 UFX 设备的 USB 电缆已分离。
语法
void UfxDeviceNotifyDetach(
[in] UFXDEVICE UfxDevice
);
参数
[in] UfxDevice
通过调用 UfxDeviceCreate 调用驱动程序创建的 UFX 设备对象的句柄。
返回值
没有
言论
客户端驱动程序在收到 USB 电缆分离事件时调用此方法。 处理分离事件后,应禁用所有终结点,设备应移动到低功率模式。
客户端驱动程序通常从其 EVT_WDF_INTERRUPT_DPC 回调函数调用 UfxDeviceNotifyDetach,如以下示例所示。
VOID
DeviceInterrupt_EvtInterruptDpc (
_In_ WDFINTERRUPT Interrupt,
_In_ WDFOBJECT AssociatedObject
)
/*++
Routine Description:
'EVT_WDF_INTERRUPT_DPC' handler for the device interrupt object.
Arguments:
Interrupt - Associated interrupt object.
AssociatedObject - FDO Object
--*/
{
WDFDEVICE WdfDevice;
PDEVICE_INTERRUPT_CONTEXT InterruptContext;
PCONTROLLER_CONTEXT ControllerContext;
BOOLEAN Attached;
BOOLEAN GotAttachOrDetach;
CONTROLLER_EVENT ControllerEvent;
UNREFERENCED_PARAMETER(Interrupt);
TraceEntry();
WdfDevice = (WDFDEVICE) AssociatedObject;
ControllerContext = DeviceGetControllerContext(WdfDevice);
WdfSpinLockAcquire(ControllerContext->DpcLock);
WdfInterruptAcquireLock(ControllerContext->DeviceInterrupt);
Attached = ControllerContext->Attached;
GotAttachOrDetach = ControllerContext->GotAttachOrDetach;
ControllerContext->GotAttachOrDetach = FALSE;
WdfInterruptReleaseLock(ControllerContext->DeviceInterrupt);
//
// Handle attach/detach events
//
if (GotAttachOrDetach) {
if (Attached && ControllerContext->WasAttached) {
//
// We must have gotten at least one detach. Need to reset the state.
//
ControllerContext->RemoteWakeupRequested = FALSE;
ControllerContext->Suspended = FALSE;
UfxDeviceNotifyDetach(ControllerContext->UfxDevice);
}
if (Attached) {
ControllerContext->RemoteWakeupRequested = FALSE;
ControllerContext->Suspended = FALSE;
UfxDeviceNotifyAttach(ControllerContext->UfxDevice);
}
}
ControllerContext->WasAttached = Attached;
InterruptContext = DeviceInterruptGetContext(ControllerContext->DeviceInterrupt);
//
// #### TODO: Insert code to read and dispatch events from the controller ####
//
// The sample will assume an endpoint event of EndpointEventTransferComplete
ControllerEvent.Type = EventTypeEndpoint;
ControllerEvent.u.EndpointEvent = EndpointEventTransferComplete;
//
// Handle events from the controller
//
switch (ControllerEvent.Type) {
case EventTypeDevice:
HandleDeviceEvent(WdfDevice, ControllerEvent.u.DeviceEvent);
break;
case EventTypeEndpoint:
HandleEndpointEvent(WdfDevice, ControllerEvent.u.EndpointEvent);
break;
}
WdfSpinLockRelease(ControllerContext->DpcLock);
TraceExit();
}
要求
要求 | 价值 |
---|---|
最低支持的客户端 | Windows 10 |
目标平台 | 窗户 |
标头 | ufxclient.h |
库 | ufxstub.lib |
IRQL | DISPATCH_LEVEL |