[PORTCLS]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Sat, 15 May 2010 17:17:05 +0000 (17:17 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Sat, 15 May 2010 17:17:05 +0000 (17:17 +0000)
- Pass subdevice interface to PcNewRegistryKey
- Fix multiple bugs in PcNewRegistryKey such as
- If key type is GeneralRegistryKey, the function is supposed to create a new key
- If key type is HwProfileRegistryKey, the type must be or'd with PLUGPLAY_REGKEY_DEVICE
- Implement opening keys of type DeviceInterfaceRegistryKey
- Free key handle if there is not enough memory to create a registry key object
- Add more comments

svn path=/trunk/; revision=47222

reactos/drivers/wdm/audio/backpln/portcls/port_dmus.cpp
reactos/drivers/wdm/audio/backpln/portcls/port_topology.cpp
reactos/drivers/wdm/audio/backpln/portcls/port_wavecyclic.cpp
reactos/drivers/wdm/audio/backpln/portcls/port_wavepci.cpp
reactos/drivers/wdm/audio/backpln/portcls/port_wavert.cpp
reactos/drivers/wdm/audio/backpln/portcls/private.hpp
reactos/drivers/wdm/audio/backpln/portcls/registry.cpp

index 8c08b1f..3f4fb91 100644 (file)
@@ -340,7 +340,7 @@ CPortDMus::NewRegistryKey(
                             RegistryKeyType,
                             DesiredAccess,
                             m_pDeviceObject,
-                            NULL,//FIXME
+                            (ISubdevice*)this,
                             ObjectAttributes,
                             CreateOptions,
                             Disposition);
index 2c80a43..ab4322a 100644 (file)
@@ -299,7 +299,7 @@ CPortTopology::NewRegistryKey(
                             RegistryKeyType,
                             DesiredAccess,
                             m_pDeviceObject,
-                            NULL,//FIXME
+                            (ISubdevice*)this,
                             ObjectAttributes,
                             CreateOptions,
                             Disposition);
index 23bfba9..6566fe6 100644 (file)
@@ -340,7 +340,7 @@ CPortWaveCyclic::NewRegistryKey(
         DPRINT("IPortWaveCyclic_fnNewRegistryKey called w/o initialized\n");
         return STATUS_UNSUCCESSFUL;
     }
-    return PcNewRegistryKey(OutRegistryKey, OuterUnknown, RegistryKeyType, DesiredAccess, m_pDeviceObject, NULL /*FIXME*/, ObjectAttributes, CreateOptions, Disposition);
+    return PcNewRegistryKey(OutRegistryKey, OuterUnknown, RegistryKeyType, DesiredAccess, m_pDeviceObject, (ISubdevice*)this, ObjectAttributes, CreateOptions, Disposition);
 }
 
 
index 81d6ed9..986ffcf 100644 (file)
@@ -359,7 +359,7 @@ CPortWavePci::NewRegistryKey(
                             RegistryKeyType,
                             DesiredAccess,
                             m_pDeviceObject,
-                            NULL,//FIXME
+                            (ISubdevice*)this,
                             ObjectAttributes,
                             CreateOptions,
                             Disposition);
index 8910dc1..305d097 100644 (file)
@@ -329,7 +329,7 @@ CPortWaveRT::NewRegistryKey(
         DPRINT("IPortWaveRT_fnNewRegistryKey called w/o initialized\n");
         return STATUS_UNSUCCESSFUL;
     }
-    return PcNewRegistryKey(OutRegistryKey, OuterUnknown, RegistryKeyType, DesiredAccess, m_pDeviceObject, NULL /*FIXME*/, ObjectAttributes, CreateOptions, Disposition);
+    return PcNewRegistryKey(OutRegistryKey, OuterUnknown, RegistryKeyType, DesiredAccess, m_pDeviceObject, (ISubdevice*)this, ObjectAttributes, CreateOptions, Disposition);
 }
 //---------------------------------------------------------------
 // ISubdevice interface
index 17adc4c..874d226 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <ntddk.h>
 #include <portcls.h>
-#define NDEBUG
+#define YDEBUG
 #include <debug.h>
 
 #include <dmusicks.h>
index eadcc89..86c2d3f 100644 (file)
@@ -270,6 +270,9 @@ PcNewRegistryKey(
     NTSTATUS Status = STATUS_UNSUCCESSFUL;
     CRegistryKey * RegistryKey;
     PPCLASS_DEVICE_EXTENSION DeviceExt;
+    PSUBDEVICE_DESCRIPTOR SubDeviceDescriptor;
+    ISubdevice * Device;
+    PSYMBOLICLINK_ENTRY SymEntry;
 
     DPRINT("PcNewRegistryKey entered\n");
 
@@ -294,8 +297,8 @@ PcNewRegistryKey(
             // object attributes is mandatory
             return STATUS_INVALID_PARAMETER;
         }
-        // try to open the key
-        Status = ZwOpenKey(&hHandle, DesiredAccess, ObjectAttributes);
+        // try to create the key
+        Status = ZwCreateKey(&hHandle, DesiredAccess, ObjectAttributes, 0, NULL, CreateOptions, Disposition);
     }
     else if (RegistryKeyType == DeviceRegistryKey ||
              RegistryKeyType == DriverRegistryKey ||
@@ -305,7 +308,7 @@ PcNewRegistryKey(
         if (RegistryKeyType == HwProfileRegistryKey)
         {
              // IoOpenDeviceRegistryKey used different constant
-            RegistryKeyType = PLUGPLAY_REGKEY_CURRENT_HWPROFILE;
+            RegistryKeyType = PLUGPLAY_REGKEY_CURRENT_HWPROFILE | PLUGPLAY_REGKEY_DEVICE;
         }
 
         // obtain the new device extension
@@ -315,24 +318,71 @@ PcNewRegistryKey(
     }
     else if (RegistryKeyType == DeviceInterfaceRegistryKey)
     {
-        // FIXME
-        UNIMPLEMENTED
-        DbgBreakPoint();
+        if (SubDevice == NULL)
+        {
+            // invalid parameter
+            return STATUS_INVALID_PARAMETER;
+        }
+
+        // look up our undocumented interface
+        Status = ((PUNKNOWN)SubDevice)->QueryInterface(IID_ISubdevice, (LPVOID*)&Device);
+
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT("No ISubdevice interface\n");
+            // invalid parameter
+            return STATUS_INVALID_PARAMETER;
+        }
+
+        // get the subdevice descriptor
+        Status = Device->GetDescriptor(&SubDeviceDescriptor);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT("Failed to get subdevice descriptor %x\n", Status);
+            ((PUNKNOWN)SubDevice)->Release();
+            return STATUS_UNSUCCESSFUL;
+        }
+
+        // is there an registered device interface
+        if (IsListEmpty(&SubDeviceDescriptor->SymbolicLinkList))
+        {
+            DPRINT("No device interface registered\n");
+            ((PUNKNOWN)SubDevice)->Release();
+            return STATUS_UNSUCCESSFUL;
+        }
+
+        // get the first symbolic link
+        SymEntry = (PSYMBOLICLINK_ENTRY)CONTAINING_RECORD(SubDeviceDescriptor->SymbolicLinkList.Flink, SYMBOLICLINK_ENTRY, Entry);
+
+        // open device interface
+        Status = IoOpenDeviceInterfaceRegistryKey(&SymEntry->SymbolicLink, DesiredAccess, &hHandle);
+
+        // release subdevice interface
+        ((PUNKNOWN)SubDevice)->Release();
     }
 
+    // check for success
     if (!NT_SUCCESS(Status))
     {
+        DPRINT1("PcNewRegistryKey failed with %lx\n", Status);
         return Status;
     }
 
+    // allocate new registry key object
     RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hHandle);
     if (!RegistryKey)
+    {
+        // not enough memory
+        ZwClose(hHandle);
         return STATUS_INSUFFICIENT_RESOURCES;
+    }
 
+    // query for interface
     Status = RegistryKey->QueryInterface(IID_IRegistryKey, (PVOID*)OutRegistryKey);
 
     if (!NT_SUCCESS(Status))
     {
+        // out of memory
         delete RegistryKey;
     }