Dispatch.c
资源名称:虚拟串口驱动程序.rar [点击查看]
上传用户:zanmei2
上传日期:2010-03-06
资源大小:775k
文件大小:3k
源码类别:
通讯编程文档
开发平台:
C/C++
- /*++
- Copyright (c) 2005 Changzhi Zhou All Rights Reserved
- Module Name:
- Dispatch.c
- Abstract:
- This module works for Dispatch routines which are
- Create, Close, Cleanup, PowerDispatch.
- Environment:
- Kernel mode
- Revision History:
- Changzhi Zhou Dec 20 2004
- --*/
- #include <ntddk.h>
- #include "main.h"
- #include "..incwdmioctl.h"
- #ifdef ALLOC_PRAGMA
- #pragma alloc_text (PAGE, SamplePowerDispatch)
- #endif
- NTSTATUS SampleCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
- { // SampleCreate
- PDEVICE_EXTENSION deviceExtension;
- NTSTATUS status;
- KIRQL oldIrql;
- PAGED_CODE();
- DbgPrint("--- IRP_MJ_CREATn");
- status = STATUS_SUCCESS;
- deviceExtension = DeviceObject->DeviceExtension;
- if( ( deviceExtension->DevicePnPState != Working) ||
- deviceExtension->bIsOpen )
- {
- status = STATUS_INVALID_DEVICE_STATE;
- return CompleteRequest(Irp, status, 0);
- }
- deviceExtension->bIsOpen = TRUE;
- SampleIoIncrement ( deviceExtension );
- return CompleteRequest(Irp, status, 0);
- } // SampleCreate
- NTSTATUS SampleClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
- { // SampleClose
- NTSTATUS status;
- PDEVICE_EXTENSION deviceExtension;
- PAGED_CODE();
- status = STATUS_SUCCESS;
- deviceExtension = DeviceObject->DeviceExtension;
- DbgPrint("--- IRP_MJ_CLOSEn");
- deviceExtension->bIsOpen = FALSE;
- SampleIoDecrement ( deviceExtension );
- return CompleteRequest(Irp, STATUS_SUCCESS, 0);
- } // SampleClose
- NTSTATUS SampleCleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
- {
- NTSTATUS status;
- PIO_STACK_LOCATION IrpStack;
- PDEVICE_EXTENSION deviceExtension;
- KIRQL oldIrql;
- PAGED_CODE();
- deviceExtension = DeviceObject->DeviceExtension;
- DbgPrint("Entering IRP_MJ_CLEANUPn");
- status = STATUS_SUCCESS;
- IrpStack = IoGetCurrentIrpStackLocation(Irp);
- KeAcquireSpinLock ( &deviceExtension->ThreadSpinLock, &oldIrql );
- if( deviceExtension->WaitOnMaskIrp ){ // 取消上一次的WAIT_ON_MASK Irp
- *((ULONG *)deviceExtension->WaitOnMaskIrp->AssociatedIrp.SystemBuffer) = 0;
- CompleteRequest( deviceExtension->WaitOnMaskIrp, STATUS_SUCCESS, sizeof( ULONG ));
- SampleIoDecrement ( deviceExtension );
- deviceExtension->WaitOnMaskIrp = NULL;
- }
- KeReleaseSpinLock ( &deviceExtension->ThreadSpinLock, oldIrql );
- return CompleteRequest( Irp, status, 0 );
- }
- NTSTATUS
- SamplePowerDispatch(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp
- )
- /*++
- Routine Description:
- This routine is the dispatch routine for power irps.
- Arguments:
- DeviceObject - Pointer to the device object.
- Irp - Pointer to the request packet.
- Return Value:
- NT Status code
- --*/
- {
- NTSTATUS status;
- PDEVICE_EXTENSION deviceExtension;
- PAGED_CODE ();
- DebugPrint(("Enter DispatchPower routine...n"));
- deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
- PoStartNextPowerIrp(Irp);
- IoSkipCurrentIrpStackLocation(Irp);
- DebugPrint(("NextLowerDriver: 0x%xn", deviceExtension->NextLowerDriver ));
- status = PoCallDriver(deviceExtension->NextLowerDriver, Irp);
- DebugPrint(("-Exit Powern") );
- return status;
- }