UsbDk: CUsbDkFilterDevice: introduce children list

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit is contained in:
Dmitry Fleytman 2014-02-17 16:03:40 +02:00
parent 7ae3eaf31b
commit c06e5461f3
2 changed files with 49 additions and 39 deletions

View file

@ -1,7 +1,6 @@
#include "FilterDevice.h"
#include "trace.h"
#include "FilterDevice.tmh"
#include "Public.h"
#include "DeviceAccess.h"
#include "ControlDevice.h"
@ -121,59 +120,62 @@ UsbDkClonePdo(WDFDEVICE ParentDevice)
return ClonePdo;
}
//TODO: Temporary function, printouts only
VOID UsbDkDumpHWIds(CDeviceAccess* devAcc)
{
CObjHolder<CRegText> IDs(devAcc->GetHardwareIDs());
if (!IDs || IDs->empty())
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No HW IDs read");
}
else
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! HW IDs read");
IDs->Dump();
}
CObjHolder<CRegText> DevIDs(devAcc->GetDeviceID());
if (!DevIDs || DevIDs->empty())
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No Device IDs read");
}
else
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! Device IDs read");
DevIDs->Dump();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
void CUsbDkFilterDevice::ClearChildrenList()
{
m_ChildDevices.ForEachDetached([] (CUsbDkChildDevice* Child) { delete Child; });
}
void CUsbDkFilterDevice::QDRPostProcessWi()
{
ASSERT(m_QDRIrp != NULL);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Entry");
PDEVICE_RELATIONS Relations = (PDEVICE_RELATIONS) m_QDRIrp->IoStatus.Information;
ClearChildrenList();
auto Relations = (PDEVICE_RELATIONS) m_QDRIrp->IoStatus.Information;
if (Relations)
{
for (ULONG i = 0; i < Relations->Count; i++)
{
CObjHolder<CDeviceAccess> pdoAccess(CDeviceAccess::GetDeviceAccess(Relations->Objects[i]));
CObjHolder<CRegText> DevID(pdoAccess->GetDeviceID());
if (!DevID || DevID->empty())
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No Device IDs read");
continue;
}
CObjHolder<CRegText> InstanceID(pdoAccess->GetInstanceID());
if (!InstanceID || InstanceID->empty())
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! No Instance ID read");
continue;
}
CUsbDkChildDevice *Device = new CUsbDkChildDevice(DevID, InstanceID);
if (Device == nullptr)
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! Cannot allocate child device instance");
continue;
}
DevID.detach();
InstanceID.detach();
m_ChildDevices.PushBack(Device);
}
if (Relations->Count > 0)
{
m_ClonedPdo = Relations->Objects[0];
{
//TEMPORARY: To verify we see HW ids of PDO to be cloned
CObjHolder<CDeviceAccess> pdoAccess(CDeviceAccess::GetDeviceAccess(m_ClonedPdo));
if (pdoAccess)
{
UsbDkDumpHWIds(pdoAccess);
}
}
WDFDEVICE PdoClone = UsbDkClonePdo(m_Device);
if (PdoClone != WDF_NO_HANDLE)
@ -202,6 +204,7 @@ void CUsbDkFilterDevice::QDRPostProcessWi()
CUsbDkFilterDevice::~CUsbDkFilterDevice()
{
ClearChildrenList();
if (m_ControlDevice != nullptr)
{
m_ControlDevice->UnregisterFilter(*this);

View file

@ -61,6 +61,10 @@ public:
NTSTATUS Create(PWDFDEVICE_INIT DevInit, WDFDRIVER Driver);
NTSTATUS CreateFilterDevice(PWDFDEVICE_INIT DevInit);
template <typename TFunctor>
void EnumerateChildren(TFunctor Functor)
{ m_ChildDevices.ForEach(Functor); }
PLIST_ENTRY GetListEntry()
{ return &m_ListEntry; }
static CUsbDkFilterDevice *GetByListEntry(PLIST_ENTRY entry)
@ -82,6 +86,7 @@ private:
void CUsbDkFilterDevice::QDRPostProcessWi();
bool ShouldAttach();
void ClearChildrenList();
CWdfWorkitem m_QDRCompletionWorkItem;
@ -89,6 +94,8 @@ private:
PDEVICE_OBJECT m_ClonedPdo = nullptr;
CUsbDkControlDevice *m_ControlDevice = nullptr;
CWdmList<CUsbDkChildDevice, CLockedAccess, CNonCountingObject> m_ChildDevices;
LIST_ENTRY m_ListEntry;
CUsbDkFilterDevice(const CUsbDkFilterDevice&) = delete;