BazisLib::DDK::Device Class Reference

Represents a DDK device. Suitable for both legacy, WDM and filter devices. More...

#include <device.h>

Inherited by BazisLib::DDK::PNPDevice [protected].

Collaboration diagram for BazisLib::DDK::Device:

Collaboration graph
[legend]

List of all members.

Classes

struct  Extension

Public Member Functions

 Device (DEVICE_TYPE DeviceType=FILE_DEVICE_UNKNOWN, const wchar_t *pwszDeviceName=NULL, ULONG DeviceCharacteristics=FILE_DEVICE_SECURE_OPEN, bool bExclusive=false, ULONG AdditionalDeviceFlags=DO_POWER_PAGABLE)
NTSTATUS RegisterDevice (Driver *pDriver, bool bCompleteInitialization=true, const wchar_t *pwszLinkPath=NULL)
void CompleteInitialization ()
NTSTATUS AttachToDeviceStack (PDEVICE_OBJECT DeviceObject)
NTSTATUS AttachToDevice (string &DevicePath)
NTSTATUS RegisterInterface (IN CONST GUID *pGuid, IN PCUNICODE_STRING ReferenceString=NULL)
NTSTATUS EnableInterface ()
NTSTATUS DisableInterface ()
NTSTATUS DetachDevice ()
NTSTATUS DeleteDevice (bool FromIRPHandler)
bool Valid ()
virtual ~Device ()

Protected Member Functions

void DeleteThisAfterLastRequest ()
bool ReportInitializationError (NTSTATUS status)
PDEVICE_OBJECT GetDeviceObject ()
PDEVICE_OBJECT GetNextDevice ()
PDEVICE_OBJECT GetUnderlyingPDO ()
PCUNICODE_STRING GetInterfaceName ()
DriverGetDriver ()
const wchar_t * GetShortDeviceName ()
bool SetShortDeviceName (const wchar_t *pwszNewName)
void OnPendingIRPCompleted (IN PIRP Irp)
NTSTATUS WaitForStopEvent (bool FromIRPHandler)
NTSTATUS CallNextDriverSynchronously (IN IncomingIrp *Irp)
NTSTATUS CreateDeviceRequestQueue ()
NTSTATUS EnqueuePacket (IN IncomingIrp *Irp)
virtual NTSTATUS DispatchRoutine (IN IncomingIrp *Irp, IO_STACK_LOCATION *IrpSp)

Static Protected Member Functions

static NTSTATUS EventSettingCompletionRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
static NTSTATUS IrpCompletingCompletionRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)

Protected Attributes

const char * m_pszDeviceDebugName

Private Member Functions

void IncrementIOCount ()
void DecrementIOCount ()
NTSTATUS ProcessIRP (IN PIRP Irp, bool bIsPowerIrp)
NTSTATUS PostProcessIRP (IncomingIrp *pIrp, NTSTATUS ProcessingStatus, bool FromDispatcherThread)
NTSTATUS ForwardPacketToNextDriver (IN IncomingIrp *Irp)
NTSTATUS ForwardPacketToNextDriverWithIrpCompletion (IN IncomingIrp *Irp)

Static Private Member Functions

static void RequestDispatcherThreadBody (IN PVOID pParam)

Private Attributes

DEVICE_TYPE m_DeviceType
ULONG m_DeviceCharacteristics
ULONG m_AdditionalDeviceFlags
bool m_bExclusive
const wchar_t * m_pwszDeviceName
Driverm_pDriver
bool m_bDeletePending
long m_OutstandingIORequestCount
KEvent m_DeleteAllowed
KEvent m_StopAllowed
bool m_bDestroyObjectAfterLastRequest
class IrpQueuem_pDeviceQueue
HANDLE m_hServiceThread
NTSTATUS m_InitializationStatus
PDEVICE_OBJECT m_pDeviceObject
PDEVICE_OBJECT m_pNextDevice
PDEVICE_OBJECT m_pUnderlyingPDO
UNICODE_STRING m_InterfaceName
string m_LinkName
bool m_bInterfaceEnabled

Friends

class Driver


Detailed Description

Represents a DDK device. Suitable for both legacy, WDM and filter devices.

Constructor & Destructor Documentation

BazisLib::DDK::Device::Device ( DEVICE_TYPE  DeviceType = FILE_DEVICE_UNKNOWN,
const wchar_t *  pwszDeviceName = NULL,
ULONG  DeviceCharacteristics = FILE_DEVICE_SECURE_OPEN,
bool  bExclusive = false,
ULONG  AdditionalDeviceFlags = DO_POWER_PAGABLE 
)

Prepares a new device for creation. Does not call IoCreateDevice().

Parameters:
DeviceType Contains the type for device
pwszDeviceName Contains the name for the device (without \Device prefix)
DeviceCharacteristics Contains device characteristics passed to IoCreateDevice()
bExclusive Exclusiveness flag passed to IoCreateDevice()
AdditionalDeviceFlags Flags that are set in DEVICE_OBJECT::Flags immediately after device creation.

virtual BazisLib::DDK::Device::~Device (  )  [virtual]


Member Function Documentation

NTSTATUS BazisLib::DDK::Device::AttachToDevice ( string DevicePath  ) 

Attaches the device to another device. If the device is already attached to another device, this method returns STATUS_INVALID_DEVICE_STATE.

NTSTATUS BazisLib::DDK::Device::AttachToDeviceStack ( PDEVICE_OBJECT  DeviceObject  ) 

Attaches the device to the highest device object in the chain. If the device is already attached to another device, or CompleteInitialization() was called, this method returns STATUS_INVALID_DEVICE_STATE.

NTSTATUS BazisLib::DDK::Device::CallNextDriverSynchronously ( IN IncomingIrp Irp  )  [protected]

Sends an IRP to the next device (returned by the IoAttachDeviceToDeviceStack() call) and waits for the next driver to process request.

Remarks:
If the device was not attached to another device, this routine can be safely called and will always return STATUS_INVALID_DEVICE_REQUEST.

Please avoid using this method as a default handler for IRP types you do not want to handle. Use __super::DispatchRoutine() instead.

void BazisLib::DDK::Device::CompleteInitialization (  ) 

Completes the initialization process by clearing the DO_DEVICE_INITIALIZING flag.

NTSTATUS BazisLib::DDK::Device::CreateDeviceRequestQueue (  )  [protected]

Creates a device request queue allowing subsequent EnqueuePacket() calls. Also creates a dispatcher thread that dequeues IRPs from the queue and processes them. The thread is automatically stopped on device deletion.

Remarks:
This method is not thread-safe. Two simultanious calls to CreateDeviceQueue() may cause the system to start losing packets. It is highly recommended to call this method from your device object constructor.

void BazisLib::DDK::Device::DecrementIOCount (  )  [private]

NTSTATUS BazisLib::DDK::Device::DeleteDevice ( bool  FromIRPHandler  ) 

Deletes the device from system, previously detaching it from another device, if it was attached. Note that this routine also shuts down the request processing thread, if one has been started. That way, it should be called even if the object is being deleted without calling to IoCreateDevice().

void BazisLib::DDK::Device::DeleteThisAfterLastRequest (  )  [inline, protected]

NTSTATUS BazisLib::DDK::Device::DetachDevice (  ) 

Detaches the device from another device, if it was previously attached. If not, returns an error.

NTSTATUS BazisLib::DDK::Device::DisableInterface (  ) 

virtual NTSTATUS BazisLib::DDK::Device::DispatchRoutine ( IN IncomingIrp Irp,
IO_STACK_LOCATION *  IrpSp 
) [inline, protected, virtual]

Device::DispatchRoutine actually does nothing and returns the IoStatus.Status field of the IRP. All IRP handling functionality is defined in child classes.

Reimplemented in BazisLib::DDK::IODevice, BazisLib::DDK::IODeviceFilter, BazisLib::DDK::PNPDevice, and BazisLib::DDK::BasicStorageVolume.

NTSTATUS BazisLib::DDK::Device::EnableInterface (  ) 

NTSTATUS BazisLib::DDK::Device::EnqueuePacket ( IN IncomingIrp Irp  )  [protected]

Enqueues an incoming IRP in the device queue. If the device queue was not previously created using the Device::CreateDeviceRequestQueue() call, this method returns STATUS_INTERNAL_ERROR.

Returns:
If the method succeeds, it returns STATUS_PENDING.
Remarks:
See comments in the beginning of IRP.H for use example.

static NTSTATUS BazisLib::DDK::Device::EventSettingCompletionRoutine ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
) [static, protected]

NTSTATUS BazisLib::DDK::Device::ForwardPacketToNextDriver ( IN IncomingIrp Irp  )  [private]

Skips current stack location and calls the next driver in chain. If no such driver exists, the routine completes IRP and returns the value of Irp->IoStatus.Status.

Remarks:
Please avoid using this method as a default handler for IRP types you do not want to handle. Use __super::DispatchRoutine() instead.

Note that if you cannot use this routine in the following way:

							return ForwardPacketToNextDriver(Irp);		//!!!BAD!!!
				
If this routine returns STATUS_PENDING, your method will also return STATUS_PENDING and nobody will be responsible for decrementing outstanding I/O operation count.

This method is fully PowerIRP-aware.

NTSTATUS BazisLib::DDK::Device::ForwardPacketToNextDriverWithIrpCompletion ( IN IncomingIrp Irp  )  [private]

Sends an IRP to the next device (returned by the IoAttachDeviceToDeviceStack() call) and completes the IRP using IoCompleteRequest() call. This routine is used for completing dequeued IRPs.

Remarks:
If the device was not attached to another device, this routine can be safely called and will always return STATUS_INVALID_DEVICE_REQUEST.

Please avoid using this method as a default handler for IRP types you do not want to handle. Use __super::DispatchRoutine() instead.

PDEVICE_OBJECT BazisLib::DDK::Device::GetDeviceObject (  )  [inline, protected]

Reimplemented in BazisLib::DDK::BusPDO.

Driver* BazisLib::DDK::Device::GetDriver (  )  [inline, protected]

PCUNICODE_STRING BazisLib::DDK::Device::GetInterfaceName (  )  [inline, protected]

PDEVICE_OBJECT BazisLib::DDK::Device::GetNextDevice (  )  [inline, protected]

const wchar_t* BazisLib::DDK::Device::GetShortDeviceName (  )  [inline, protected]

PDEVICE_OBJECT BazisLib::DDK::Device::GetUnderlyingPDO (  )  [inline, protected]

void BazisLib::DDK::Device::IncrementIOCount (  )  [private]

static NTSTATUS BazisLib::DDK::Device::IrpCompletingCompletionRoutine ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
) [static, protected]

void BazisLib::DDK::Device::OnPendingIRPCompleted ( IN PIRP  Irp  )  [inline, protected]

Here is the call graph for this function:

NTSTATUS BazisLib::DDK::Device::PostProcessIRP ( IncomingIrp pIrp,
NTSTATUS  ProcessingStatus,
bool  FromDispatcherThread 
) [private]

NTSTATUS BazisLib::DDK::Device::ProcessIRP ( IN PIRP  Irp,
bool  bIsPowerIrp 
) [private]

NTSTATUS BazisLib::DDK::Device::RegisterDevice ( Driver pDriver,
bool  bCompleteInitialization = true,
const wchar_t *  pwszLinkPath = NULL 
)

Creates and registers the system device using IoCreateDevice()

Parameters:
CreateDosDevicesLink Specifies whether to create a symbollic link in
CompleteInitialization Specifies whether to mark device as initialized
pDriver Specifies the driver object used in device creation, or NULL to use the main driver.
Remarks:
Note that as long as the device is marked as initialized, no more registration-based actions are allowed for the device. For more details, see the CompleteInitialization() method.

NTSTATUS BazisLib::DDK::Device::RegisterInterface ( IN CONST GUID pGuid,
IN PCUNICODE_STRING  ReferenceString = NULL 
)

bool BazisLib::DDK::Device::ReportInitializationError ( NTSTATUS  status  )  [protected]

static void BazisLib::DDK::Device::RequestDispatcherThreadBody ( IN PVOID  pParam  )  [static, private]

bool BazisLib::DDK::Device::SetShortDeviceName ( const wchar_t *  pwszNewName  )  [protected]

bool BazisLib::DDK::Device::Valid (  ) 

NTSTATUS BazisLib::DDK::Device::WaitForStopEvent ( bool  FromIRPHandler  )  [protected]


Friends And Related Function Documentation

friend class Driver [friend]


Member Data Documentation

DEVICE_TYPE BazisLib::DDK::Device::m_DeviceType [private]

Reimplemented in BazisLib::DDK::BusPDO.

UNICODE_STRING BazisLib::DDK::Device::m_InterfaceName [private]

PDEVICE_OBJECT BazisLib::DDK::Device::m_pDeviceObject [private]

PDEVICE_OBJECT BazisLib::DDK::Device::m_pNextDevice [private]

PDEVICE_OBJECT BazisLib::DDK::Device::m_pUnderlyingPDO [private]

const wchar_t* BazisLib::DDK::Device::m_pwszDeviceName [private]


The documentation for this class was generated from the following file:
SourceForge.net Logo