https://git.reactos.org/?p=reactos.git;a=commitdiff;h=30b9be047f9679b7443f678f62806cc29f36c9ca

commit 30b9be047f9679b7443f678f62806cc29f36c9ca
Author:     Eric Kohl <eric.k...@reactos.org>
AuthorDate: Sun Dec 3 11:08:57 2023 +0100
Commit:     Eric Kohl <eric.k...@reactos.org>
CommitDate: Sun Dec 3 11:08:57 2023 +0100

    [UMPNPMGR] Split the notification code by event category
    
    - Move the TargetDeviceChangeEvent code into a separate function.
    - Add a new function for the DeviceClassChangeEvent category.
---
 base/services/umpnpmgr/event.c | 229 +++++++++++++++++++++++++----------------
 1 file changed, 139 insertions(+), 90 deletions(-)

diff --git a/base/services/umpnpmgr/event.c b/base/services/umpnpmgr/event.c
index 678022de61b..d9ae579cad2 100644
--- a/base/services/umpnpmgr/event.c
+++ b/base/services/umpnpmgr/event.c
@@ -35,13 +35,132 @@
 
 /* FUNCTIONS *****************************************************************/
 
-DWORD WINAPI
-PnpEventThread(LPVOID lpParameter)
+static
+VOID
+ProcessTargetDeviceEvent(
+    _In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
+{
+    RPC_STATUS RpcStatus;
+
+    if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ENUMERATED, 
&RpcStatus))
+    {
+        DeviceInstallParams* Params;
+        DWORD len;
+        DWORD DeviceIdLength;
+
+        DPRINT("Device enumerated: %S\n", PnpEvent->TargetDevice.DeviceIds);
+
+        DeviceIdLength = lstrlenW(PnpEvent->TargetDevice.DeviceIds);
+        if (DeviceIdLength)
+        {
+            /* Allocate a new device-install event */
+            len = FIELD_OFFSET(DeviceInstallParams, DeviceIds) + 
(DeviceIdLength + 1) * sizeof(WCHAR);
+            Params = HeapAlloc(GetProcessHeap(), 0, len);
+            if (Params)
+            {
+                wcscpy(Params->DeviceIds, PnpEvent->TargetDevice.DeviceIds);
+
+                /* Queue the event (will be dequeued by DeviceInstallThread) */
+                WaitForSingleObject(hDeviceInstallListMutex, INFINITE);
+                InsertTailList(&DeviceInstallListHead, &Params->ListEntry);
+                ReleaseMutex(hDeviceInstallListMutex);
+
+                SetEvent(hDeviceInstallListNotEmpty);
+            }
+        }
+    }
+    else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ARRIVAL, 
&RpcStatus))
+    {
+//        DWORD dwRecipient;
+
+        DPRINT("Device arrival: %S\n", PnpEvent->TargetDevice.DeviceIds);
+
+//       dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
+//       BroadcastSystemMessageW(BSF_POSTMESSAGE,
+//                               &dwRecipient,
+//                               WM_DEVICECHANGE,
+//                               DBT_DEVNODES_CHANGED,
+//                               0);
+        SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
+    }
+    else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_EJECT_VETOED, 
&RpcStatus))
+    {
+        DPRINT1("Eject vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
+    }
+    else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_KERNEL_INITIATED_EJECT, &RpcStatus))
+    {
+        DPRINT1("Kernel initiated eject: %S\n", 
PnpEvent->TargetDevice.DeviceIds);
+    }
+    else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_SAFE_REMOVAL, 
&RpcStatus))
+    {
+//        DWORD dwRecipient;
+
+        DPRINT1("Safe removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
+
+//        dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
+//        BroadcastSystemMessageW(BSF_POSTMESSAGE,
+//                                &dwRecipient,
+//                                WM_DEVICECHANGE,
+//                                DBT_DEVNODES_CHANGED,
+//                                0);
+        SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
+    }
+    else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_SURPRISE_REMOVAL, &RpcStatus))
+    {
+//        DWORD dwRecipient;
+
+        DPRINT1("Surprise removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
+
+//        dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
+//        BroadcastSystemMessageW(BSF_POSTMESSAGE,
+//                                &dwRecipient,
+//                                WM_DEVICECHANGE,
+//                                DBT_DEVNODES_CHANGED,
+//                                0);
+        SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
+    }
+    else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_REMOVAL_VETOED, &RpcStatus))
+    {
+        DPRINT1("Removal vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
+    }
+    else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_REMOVE_PENDING, &RpcStatus))
+    {
+        DPRINT1("Removal pending: %S\n", PnpEvent->TargetDevice.DeviceIds);
+    }
+    else
+    {
+        DPRINT1("Unknown event, GUID 
{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
+                PnpEvent->EventGuid.Data1, PnpEvent->EventGuid.Data2, 
PnpEvent->EventGuid.Data3,
+                PnpEvent->EventGuid.Data4[0], PnpEvent->EventGuid.Data4[1], 
PnpEvent->EventGuid.Data4[2],
+                PnpEvent->EventGuid.Data4[3], PnpEvent->EventGuid.Data4[4], 
PnpEvent->EventGuid.Data4[5],
+                PnpEvent->EventGuid.Data4[6], PnpEvent->EventGuid.Data4[7]);
+    }
+}
+
+
+static
+VOID
+ProcessDeviceClassChangeEvent(
+    _In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
+{
+    DPRINT("DeviceClassChangeEvent: %S\n", 
PnpEvent->DeviceClass.SymbolicLinkName);
+
+    DPRINT("ClassGuid: {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
+           PnpEvent->DeviceClass.ClassGuid.Data1, 
PnpEvent->DeviceClass.ClassGuid.Data2, PnpEvent->DeviceClass.ClassGuid.Data3,
+           PnpEvent->DeviceClass.ClassGuid.Data4[0], 
PnpEvent->DeviceClass.ClassGuid.Data4[1], 
PnpEvent->DeviceClass.ClassGuid.Data4[2],
+           PnpEvent->DeviceClass.ClassGuid.Data4[3], 
PnpEvent->DeviceClass.ClassGuid.Data4[4], 
PnpEvent->DeviceClass.ClassGuid.Data4[5],
+           PnpEvent->DeviceClass.ClassGuid.Data4[6], 
PnpEvent->DeviceClass.ClassGuid.Data4[7]);
+}
+
+
+DWORD
+WINAPI
+PnpEventThread(
+    _In_ LPVOID lpParameter)
 {
     PLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData = {0, 0, 0, 0};
     DWORD dwRet = ERROR_SUCCESS;
     NTSTATUS Status;
-    RPC_STATUS RpcStatus;
     PPLUGPLAY_EVENT_BLOCK PnpEvent, NewPnpEvent;
     ULONG PnpEventSize;
 
@@ -81,98 +200,28 @@ PnpEventThread(LPVOID lpParameter)
 
         /* Process the PnP event */
         DPRINT("Received PnP Event\n");
-        if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ENUMERATED, 
&RpcStatus))
-        {
-            DeviceInstallParams* Params;
-            DWORD len;
-            DWORD DeviceIdLength;
-
-            DPRINT("Device enumerated: %S\n", 
PnpEvent->TargetDevice.DeviceIds);
-
-            DeviceIdLength = lstrlenW(PnpEvent->TargetDevice.DeviceIds);
-            if (DeviceIdLength)
-            {
-                /* Allocate a new device-install event */
-                len = FIELD_OFFSET(DeviceInstallParams, DeviceIds) + 
(DeviceIdLength + 1) * sizeof(WCHAR);
-                Params = HeapAlloc(GetProcessHeap(), 0, len);
-                if (Params)
-                {
-                    wcscpy(Params->DeviceIds, 
PnpEvent->TargetDevice.DeviceIds);
-
-                    /* Queue the event (will be dequeued by 
DeviceInstallThread) */
-                    WaitForSingleObject(hDeviceInstallListMutex, INFINITE);
-                    InsertTailList(&DeviceInstallListHead, &Params->ListEntry);
-                    ReleaseMutex(hDeviceInstallListMutex);
-
-                    SetEvent(hDeviceInstallListNotEmpty);
-                }
-            }
-        }
-        else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ARRIVAL, 
&RpcStatus))
-        {
-//            DWORD dwRecipient;
-
-            DPRINT("Device arrival: %S\n", PnpEvent->TargetDevice.DeviceIds);
-
-//            dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
-//            BroadcastSystemMessageW(BSF_POSTMESSAGE,
-//                                    &dwRecipient,
-//                                    WM_DEVICECHANGE,
-//                                    DBT_DEVNODES_CHANGED,
-//                                    0);
-            SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, 
DBT_DEVNODES_CHANGED, 0);
-        }
-        else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_EJECT_VETOED, &RpcStatus))
+        switch (PnpEvent->EventCategory)
         {
-            DPRINT1("Eject vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
-        }
-        else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_KERNEL_INITIATED_EJECT, &RpcStatus))
-        {
-            DPRINT1("Kernel initiated eject: %S\n", 
PnpEvent->TargetDevice.DeviceIds);
-        }
-        else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_SAFE_REMOVAL, &RpcStatus))
-        {
-//            DWORD dwRecipient;
+//            case HardwareProfileChangeEvent:
 
-            DPRINT1("Safe removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
+            case TargetDeviceChangeEvent:
+                ProcessTargetDeviceEvent(PnpEvent);
+                break;
 
-//            dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
-//            BroadcastSystemMessageW(BSF_POSTMESSAGE,
-//                                    &dwRecipient,
-//                                    WM_DEVICECHANGE,
-//                                    DBT_DEVNODES_CHANGED,
-//                                    0);
-            SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, 
DBT_DEVNODES_CHANGED, 0);
-        }
-        else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_SURPRISE_REMOVAL, &RpcStatus))
-        {
-//            DWORD dwRecipient;
+            case DeviceClassChangeEvent:
+                ProcessDeviceClassChangeEvent(PnpEvent);
+                break;
 
-            DPRINT1("Surprise removal: %S\n", 
PnpEvent->TargetDevice.DeviceIds);
+//            case CustomDeviceEvent:
+//            case DeviceInstallEvent:
+//            case DeviceArrivalEvent:
+//            case PowerEvent:
+//            case VetoEvent:
+//            case BlockedDriverEvent:
 
-//            dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
-//            BroadcastSystemMessageW(BSF_POSTMESSAGE,
-//                                    &dwRecipient,
-//                                    WM_DEVICECHANGE,
-//                                    DBT_DEVNODES_CHANGED,
-//                                    0);
-            SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, 
DBT_DEVNODES_CHANGED, 0);
-        }
-        else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_REMOVAL_VETOED, &RpcStatus))
-        {
-            DPRINT1("Removal vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
-        }
-        else if (UuidEqual(&PnpEvent->EventGuid, 
(UUID*)&GUID_DEVICE_REMOVE_PENDING, &RpcStatus))
-        {
-            DPRINT1("Removal pending: %S\n", PnpEvent->TargetDevice.DeviceIds);
-        }
-        else
-        {
-            DPRINT1("Unknown event, GUID 
{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
-                PnpEvent->EventGuid.Data1, PnpEvent->EventGuid.Data2, 
PnpEvent->EventGuid.Data3,
-                PnpEvent->EventGuid.Data4[0], PnpEvent->EventGuid.Data4[1], 
PnpEvent->EventGuid.Data4[2],
-                PnpEvent->EventGuid.Data4[3], PnpEvent->EventGuid.Data4[4], 
PnpEvent->EventGuid.Data4[5],
-                PnpEvent->EventGuid.Data4[6], PnpEvent->EventGuid.Data4[7]);
+            default:
+                DPRINT1("Unsupported Event Category: %lu\n", 
PnpEvent->EventCategory);
+                break;
         }
 
         /* Dequeue the current PnP event and signal the next one */

Reply via email to