Skip to content

Commit 30b9be0

Browse files
committed
[UMPNPMGR] Split the notification code by event category
- Move the TargetDeviceChangeEvent code into a separate function. - Add a new function for the DeviceClassChangeEvent category.
1 parent 75cf692 commit 30b9be0

File tree

1 file changed

+139
-90
lines changed

1 file changed

+139
-90
lines changed

base/services/umpnpmgr/event.c

Lines changed: 139 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,132 @@
3535

3636
/* FUNCTIONS *****************************************************************/
3737

38-
DWORD WINAPI
39-
PnpEventThread(LPVOID lpParameter)
38+
static
39+
VOID
40+
ProcessTargetDeviceEvent(
41+
_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
42+
{
43+
RPC_STATUS RpcStatus;
44+
45+
if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ENUMERATED, &RpcStatus))
46+
{
47+
DeviceInstallParams* Params;
48+
DWORD len;
49+
DWORD DeviceIdLength;
50+
51+
DPRINT("Device enumerated: %S\n", PnpEvent->TargetDevice.DeviceIds);
52+
53+
DeviceIdLength = lstrlenW(PnpEvent->TargetDevice.DeviceIds);
54+
if (DeviceIdLength)
55+
{
56+
/* Allocate a new device-install event */
57+
len = FIELD_OFFSET(DeviceInstallParams, DeviceIds) + (DeviceIdLength + 1) * sizeof(WCHAR);
58+
Params = HeapAlloc(GetProcessHeap(), 0, len);
59+
if (Params)
60+
{
61+
wcscpy(Params->DeviceIds, PnpEvent->TargetDevice.DeviceIds);
62+
63+
/* Queue the event (will be dequeued by DeviceInstallThread) */
64+
WaitForSingleObject(hDeviceInstallListMutex, INFINITE);
65+
InsertTailList(&DeviceInstallListHead, &Params->ListEntry);
66+
ReleaseMutex(hDeviceInstallListMutex);
67+
68+
SetEvent(hDeviceInstallListNotEmpty);
69+
}
70+
}
71+
}
72+
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ARRIVAL, &RpcStatus))
73+
{
74+
// DWORD dwRecipient;
75+
76+
DPRINT("Device arrival: %S\n", PnpEvent->TargetDevice.DeviceIds);
77+
78+
// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
79+
// BroadcastSystemMessageW(BSF_POSTMESSAGE,
80+
// &dwRecipient,
81+
// WM_DEVICECHANGE,
82+
// DBT_DEVNODES_CHANGED,
83+
// 0);
84+
SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
85+
}
86+
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_EJECT_VETOED, &RpcStatus))
87+
{
88+
DPRINT1("Eject vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
89+
}
90+
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_KERNEL_INITIATED_EJECT, &RpcStatus))
91+
{
92+
DPRINT1("Kernel initiated eject: %S\n", PnpEvent->TargetDevice.DeviceIds);
93+
}
94+
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_SAFE_REMOVAL, &RpcStatus))
95+
{
96+
// DWORD dwRecipient;
97+
98+
DPRINT1("Safe removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
99+
100+
// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
101+
// BroadcastSystemMessageW(BSF_POSTMESSAGE,
102+
// &dwRecipient,
103+
// WM_DEVICECHANGE,
104+
// DBT_DEVNODES_CHANGED,
105+
// 0);
106+
SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
107+
}
108+
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_SURPRISE_REMOVAL, &RpcStatus))
109+
{
110+
// DWORD dwRecipient;
111+
112+
DPRINT1("Surprise removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
113+
114+
// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
115+
// BroadcastSystemMessageW(BSF_POSTMESSAGE,
116+
// &dwRecipient,
117+
// WM_DEVICECHANGE,
118+
// DBT_DEVNODES_CHANGED,
119+
// 0);
120+
SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
121+
}
122+
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_REMOVAL_VETOED, &RpcStatus))
123+
{
124+
DPRINT1("Removal vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
125+
}
126+
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_REMOVE_PENDING, &RpcStatus))
127+
{
128+
DPRINT1("Removal pending: %S\n", PnpEvent->TargetDevice.DeviceIds);
129+
}
130+
else
131+
{
132+
DPRINT1("Unknown event, GUID {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
133+
PnpEvent->EventGuid.Data1, PnpEvent->EventGuid.Data2, PnpEvent->EventGuid.Data3,
134+
PnpEvent->EventGuid.Data4[0], PnpEvent->EventGuid.Data4[1], PnpEvent->EventGuid.Data4[2],
135+
PnpEvent->EventGuid.Data4[3], PnpEvent->EventGuid.Data4[4], PnpEvent->EventGuid.Data4[5],
136+
PnpEvent->EventGuid.Data4[6], PnpEvent->EventGuid.Data4[7]);
137+
}
138+
}
139+
140+
141+
static
142+
VOID
143+
ProcessDeviceClassChangeEvent(
144+
_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
145+
{
146+
DPRINT("DeviceClassChangeEvent: %S\n", PnpEvent->DeviceClass.SymbolicLinkName);
147+
148+
DPRINT("ClassGuid: {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
149+
PnpEvent->DeviceClass.ClassGuid.Data1, PnpEvent->DeviceClass.ClassGuid.Data2, PnpEvent->DeviceClass.ClassGuid.Data3,
150+
PnpEvent->DeviceClass.ClassGuid.Data4[0], PnpEvent->DeviceClass.ClassGuid.Data4[1], PnpEvent->DeviceClass.ClassGuid.Data4[2],
151+
PnpEvent->DeviceClass.ClassGuid.Data4[3], PnpEvent->DeviceClass.ClassGuid.Data4[4], PnpEvent->DeviceClass.ClassGuid.Data4[5],
152+
PnpEvent->DeviceClass.ClassGuid.Data4[6], PnpEvent->DeviceClass.ClassGuid.Data4[7]);
153+
}
154+
155+
156+
DWORD
157+
WINAPI
158+
PnpEventThread(
159+
_In_ LPVOID lpParameter)
40160
{
41161
PLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData = {0, 0, 0, 0};
42162
DWORD dwRet = ERROR_SUCCESS;
43163
NTSTATUS Status;
44-
RPC_STATUS RpcStatus;
45164
PPLUGPLAY_EVENT_BLOCK PnpEvent, NewPnpEvent;
46165
ULONG PnpEventSize;
47166

@@ -81,98 +200,28 @@ PnpEventThread(LPVOID lpParameter)
81200

82201
/* Process the PnP event */
83202
DPRINT("Received PnP Event\n");
84-
if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ENUMERATED, &RpcStatus))
85-
{
86-
DeviceInstallParams* Params;
87-
DWORD len;
88-
DWORD DeviceIdLength;
89-
90-
DPRINT("Device enumerated: %S\n", PnpEvent->TargetDevice.DeviceIds);
91-
92-
DeviceIdLength = lstrlenW(PnpEvent->TargetDevice.DeviceIds);
93-
if (DeviceIdLength)
94-
{
95-
/* Allocate a new device-install event */
96-
len = FIELD_OFFSET(DeviceInstallParams, DeviceIds) + (DeviceIdLength + 1) * sizeof(WCHAR);
97-
Params = HeapAlloc(GetProcessHeap(), 0, len);
98-
if (Params)
99-
{
100-
wcscpy(Params->DeviceIds, PnpEvent->TargetDevice.DeviceIds);
101-
102-
/* Queue the event (will be dequeued by DeviceInstallThread) */
103-
WaitForSingleObject(hDeviceInstallListMutex, INFINITE);
104-
InsertTailList(&DeviceInstallListHead, &Params->ListEntry);
105-
ReleaseMutex(hDeviceInstallListMutex);
106-
107-
SetEvent(hDeviceInstallListNotEmpty);
108-
}
109-
}
110-
}
111-
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ARRIVAL, &RpcStatus))
112-
{
113-
// DWORD dwRecipient;
114-
115-
DPRINT("Device arrival: %S\n", PnpEvent->TargetDevice.DeviceIds);
116-
117-
// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
118-
// BroadcastSystemMessageW(BSF_POSTMESSAGE,
119-
// &dwRecipient,
120-
// WM_DEVICECHANGE,
121-
// DBT_DEVNODES_CHANGED,
122-
// 0);
123-
SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
124-
}
125-
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_EJECT_VETOED, &RpcStatus))
203+
switch (PnpEvent->EventCategory)
126204
{
127-
DPRINT1("Eject vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
128-
}
129-
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_KERNEL_INITIATED_EJECT, &RpcStatus))
130-
{
131-
DPRINT1("Kernel initiated eject: %S\n", PnpEvent->TargetDevice.DeviceIds);
132-
}
133-
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_SAFE_REMOVAL, &RpcStatus))
134-
{
135-
// DWORD dwRecipient;
205+
// case HardwareProfileChangeEvent:
136206

137-
DPRINT1("Safe removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
207+
case TargetDeviceChangeEvent:
208+
ProcessTargetDeviceEvent(PnpEvent);
209+
break;
138210

139-
// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
140-
// BroadcastSystemMessageW(BSF_POSTMESSAGE,
141-
// &dwRecipient,
142-
// WM_DEVICECHANGE,
143-
// DBT_DEVNODES_CHANGED,
144-
// 0);
145-
SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
146-
}
147-
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_SURPRISE_REMOVAL, &RpcStatus))
148-
{
149-
// DWORD dwRecipient;
211+
case DeviceClassChangeEvent:
212+
ProcessDeviceClassChangeEvent(PnpEvent);
213+
break;
150214

151-
DPRINT1("Surprise removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
215+
// case CustomDeviceEvent:
216+
// case DeviceInstallEvent:
217+
// case DeviceArrivalEvent:
218+
// case PowerEvent:
219+
// case VetoEvent:
220+
// case BlockedDriverEvent:
152221

153-
// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
154-
// BroadcastSystemMessageW(BSF_POSTMESSAGE,
155-
// &dwRecipient,
156-
// WM_DEVICECHANGE,
157-
// DBT_DEVNODES_CHANGED,
158-
// 0);
159-
SendMessageW(HWND_BROADCAST, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0);
160-
}
161-
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_REMOVAL_VETOED, &RpcStatus))
162-
{
163-
DPRINT1("Removal vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
164-
}
165-
else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_REMOVE_PENDING, &RpcStatus))
166-
{
167-
DPRINT1("Removal pending: %S\n", PnpEvent->TargetDevice.DeviceIds);
168-
}
169-
else
170-
{
171-
DPRINT1("Unknown event, GUID {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
172-
PnpEvent->EventGuid.Data1, PnpEvent->EventGuid.Data2, PnpEvent->EventGuid.Data3,
173-
PnpEvent->EventGuid.Data4[0], PnpEvent->EventGuid.Data4[1], PnpEvent->EventGuid.Data4[2],
174-
PnpEvent->EventGuid.Data4[3], PnpEvent->EventGuid.Data4[4], PnpEvent->EventGuid.Data4[5],
175-
PnpEvent->EventGuid.Data4[6], PnpEvent->EventGuid.Data4[7]);
222+
default:
223+
DPRINT1("Unsupported Event Category: %lu\n", PnpEvent->EventCategory);
224+
break;
176225
}
177226

178227
/* Dequeue the current PnP event and signal the next one */

0 commit comments

Comments
 (0)