ReactOS 0.4.16-dev-1109-gd06d9f3
event.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for event.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static VOID ProcessTargetDeviceEvent (_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
 
static VOID ProcessDeviceClassChangeEvent (_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
 
static VOID ProcessDeviceInstallEvent (_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
 
DWORD WINAPI PnpEventThread (_In_ LPVOID lpParameter)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 33 of file event.c.

Function Documentation

◆ PnpEventThread()

DWORD WINAPI PnpEventThread ( _In_ LPVOID  lpParameter)

Definition at line 238 of file event.c.

240{
241 PLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData = {0, 0, 0, 0};
242 DWORD dwRet = ERROR_SUCCESS;
244 PPLUGPLAY_EVENT_BLOCK PnpEvent, NewPnpEvent;
245 ULONG PnpEventSize;
246
247 UNREFERENCED_PARAMETER(lpParameter);
248
249 PnpEventSize = 0x1000;
250 PnpEvent = HeapAlloc(GetProcessHeap(), 0, PnpEventSize);
251 if (PnpEvent == NULL)
252 return ERROR_OUTOFMEMORY;
253
254 for (;;)
255 {
256 DPRINT("Calling NtGetPlugPlayEvent()\n");
257
258 /* Wait for the next PnP event */
259 Status = NtGetPlugPlayEvent(0, 0, PnpEvent, PnpEventSize);
260
261 /* Resize the buffer for the PnP event if it's too small */
263 {
264 PnpEventSize += 0x400;
265 NewPnpEvent = HeapReAlloc(GetProcessHeap(), 0, PnpEvent, PnpEventSize);
266 if (NewPnpEvent == NULL)
267 {
268 dwRet = ERROR_OUTOFMEMORY;
269 break;
270 }
271 PnpEvent = NewPnpEvent;
272 continue;
273 }
274
275 if (!NT_SUCCESS(Status))
276 {
277 DPRINT1("NtGetPlugPlayEvent() failed (Status 0x%08lx)\n", Status);
278 break;
279 }
280
281 /* Process the PnP event */
282 DPRINT("Received PnP Event\n");
283 switch (PnpEvent->EventCategory)
284 {
285// case HardwareProfileChangeEvent:
286
288 ProcessTargetDeviceEvent(PnpEvent);
289 break;
290
293 break;
294
295// case CustomDeviceEvent:
296
299 break;
300
301// case DeviceArrivalEvent:
302// case PowerEvent:
303// case VetoEvent:
304// case BlockedDriverEvent:
305
306 default:
307 DPRINT1("Unsupported Event Category: %lu\n", PnpEvent->EventCategory);
308 break;
309 }
310
311 /* Dequeue the current PnP event and signal the next one */
313 &ResponseData,
314 sizeof(ResponseData));
315 if (!NT_SUCCESS(Status))
316 {
317 DPRINT1("NtPlugPlayControl(PlugPlayControlUserResponse) failed (Status 0x%08lx)\n", Status);
318 break;
319 }
320 }
321
322 HeapFree(GetProcessHeap(), 0, PnpEvent);
323
324 return dwRet;
325}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
static VOID ProcessDeviceClassChangeEvent(_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
Definition: event.c:118
static VOID ProcessTargetDeviceEvent(_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
Definition: event.c:40
static VOID ProcessDeviceInstallEvent(_In_ PPLUGPLAY_EVENT_BLOCK PnpEvent)
Definition: event.c:196
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
@ TargetDeviceChangeEvent
Definition: cmtypes.h:257
@ DeviceClassChangeEvent
Definition: cmtypes.h:258
@ DeviceInstallEvent
Definition: cmtypes.h:260
@ PlugPlayControlUserResponse
Definition: cmtypes.h:216
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
NTSTATUS NTAPI NtGetPlugPlayEvent(IN ULONG Reserved1, IN ULONG Reserved2, OUT PPLUGPLAY_EVENT_BLOCK Buffer, IN ULONG BufferSize)
Definition: plugplay.c:1364
NTSTATUS NTAPI NtPlugPlayControl(IN PLUGPLAY_CONTROL_CLASS PlugPlayControlClass, IN OUT PVOID Buffer, IN ULONG BufferLength)
Definition: plugplay.c:1494
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:73
PLUGPLAY_EVENT_CATEGORY EventCategory
Definition: cmtypes.h:406
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ServiceMain().

◆ ProcessDeviceClassChangeEvent()

static VOID ProcessDeviceClassChangeEvent ( _In_ PPLUGPLAY_EVENT_BLOCK  PnpEvent)
static

Definition at line 118 of file event.c.

120{
121 RPC_STATUS RpcStatus;
122 PLIST_ENTRY Current;
123 PNOTIFY_ENTRY pNotifyData;
126 DWORD dwEventType;
127
128 DPRINT("ProcessDeviceClassChangeEvent(%p)\n", PnpEvent);
129 DPRINT("SymbolicLink: %S\n", PnpEvent->DeviceClass.SymbolicLinkName);
130 DPRINT("ClassGuid: {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
131 PnpEvent->DeviceClass.ClassGuid.Data1, PnpEvent->DeviceClass.ClassGuid.Data2, PnpEvent->DeviceClass.ClassGuid.Data3,
132 PnpEvent->DeviceClass.ClassGuid.Data4[0], PnpEvent->DeviceClass.ClassGuid.Data4[1], PnpEvent->DeviceClass.ClassGuid.Data4[2],
133 PnpEvent->DeviceClass.ClassGuid.Data4[3], PnpEvent->DeviceClass.ClassGuid.Data4[4], PnpEvent->DeviceClass.ClassGuid.Data4[5],
134 PnpEvent->DeviceClass.ClassGuid.Data4[6], PnpEvent->DeviceClass.ClassGuid.Data4[7]);
135
137
138 Current = NotificationListHead.Flink;
139 while (Current != &NotificationListHead)
140 {
141 pNotifyData = CONTAINING_RECORD(Current, NOTIFY_ENTRY, ListEntry);
142 if ((pNotifyData->dwType == CLASS_NOTIFICATION) &&
143 ((pNotifyData->ulFlags & DEVICE_NOTIFY_ALL_INTERFACE_CLASSES) ||
144 (UuidEqual(&PnpEvent->DeviceClass.ClassGuid, &pNotifyData->ClassGuid, &RpcStatus))))
145 {
146 if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_INTERFACE_ARRIVAL, &RpcStatus))
147 {
148 DPRINT("Interface arrival: %S\n", PnpEvent->DeviceClass.SymbolicLinkName);
149 dwEventType = DBT_DEVICEARRIVAL;
150 }
151 else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_INTERFACE_REMOVAL, &RpcStatus))
152 {
153 DPRINT("Interface removal: %S\n", PnpEvent->DeviceClass.SymbolicLinkName);
154 dwEventType = DBT_DEVICEREMOVECOMPLETE;
155 }
156 else
157 {
158 dwEventType = 0;
159 }
160
161 dwSize = sizeof(DEV_BROADCAST_DEVICEINTERFACE_W) + wcslen(PnpEvent->DeviceClass.SymbolicLinkName) * sizeof(WCHAR);
163 if (pEventData)
164 {
165 pEventData->dbcc_size = dwSize;
167 CopyMemory(&pEventData->dbcc_classguid, &PnpEvent->DeviceClass.ClassGuid, sizeof(GUID));
168 wcscpy(pEventData->dbcc_name, PnpEvent->DeviceClass.SymbolicLinkName);
169 }
170
171 if ((pNotifyData->ulFlags & DEVICE_NOTIFY_SERVICE_HANDLE) == DEVICE_NOTIFY_WINDOW_HANDLE)
172 {
173 SendMessageW((HANDLE)pNotifyData->hRecipient, WM_DEVICECHANGE, (WPARAM)dwEventType, (LPARAM)pEventData);
174 }
175 else if ((pNotifyData->ulFlags & DEVICE_NOTIFY_SERVICE_HANDLE) == DEVICE_NOTIFY_SERVICE_HANDLE)
176 {
179 dwEventType,
180 pEventData);
181 }
182
183 if (pEventData)
184 HeapFree(GetProcessHeap(), 0, pEventData);
185 }
186
187 Current = Current->Flink;
188 }
189
191}
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
@ CLASS_NOTIFICATION
Definition: precomp.h:48
LIST_ENTRY NotificationListHead
Definition: rpcserver.c:42
RTL_RESOURCE NotificationListLock
Definition: rpcserver.c:43
wcscpy
struct _DEV_BROADCAST_DEVICEINTERFACE_W DEV_BROADCAST_DEVICEINTERFACE_W
#define DBT_DEVICEARRIVAL
Definition: dbt.h:12
#define DBT_DEVTYP_DEVICEINTERFACE
Definition: dbt.h:24
#define DBT_DEVICEREMOVECOMPLETE
Definition: dbt.h:16
#define TRUE
Definition: types.h:120
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
const GUID GUID_DEVICE_INTERFACE_ARRIVAL
Definition: deviface.c:14
const GUID GUID_DEVICE_INTERFACE_REMOVAL
Definition: deviface.c:15
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceShared(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
int WINAPI UuidEqual(UUID *Uuid1, UUID *Uuid2, RPC_STATUS *Status)
Definition: rpcrt4_main.c:252
BOOL WINAPI I_ScSendPnPMessage(_In_ SERVICE_STATUS_HANDLE hServiceStatus, _In_ DWORD dwControlCode, _In_ DWORD dwEventType, _In_ PVOID pEventData)
Definition: scm.c:1629
long RPC_STATUS
Definition: rpc.h:48
Definition: precomp.h:54
NOTIFICATION_TYPE dwType
Definition: precomp.h:56
DWORD ulFlags
Definition: precomp.h:59
DWORD_PTR hRecipient
Definition: precomp.h:58
GUID ClassGuid
Definition: precomp.h:60
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define CopyMemory
Definition: winbase.h:1741
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define SERVICE_CONTROL_DEVICEEVENT
Definition: winsvc.h:46
#define WM_DEVICECHANGE
Definition: winuser.h:1822
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by PnpEventThread().

◆ ProcessDeviceInstallEvent()

static VOID ProcessDeviceInstallEvent ( _In_ PPLUGPLAY_EVENT_BLOCK  PnpEvent)
static

Definition at line 196 of file event.c.

198{
200 DWORD len;
201 DWORD DeviceIdLength;
202// DWORD dwRecipient;
203
204 DPRINT("ProcessDeviceInstallEvent(%p)\n", PnpEvent);
205 DPRINT("Device enumerated: %S\n", PnpEvent->InstallDevice.DeviceId);
206
207 DeviceIdLength = lstrlenW(PnpEvent->InstallDevice.DeviceId);
208 if (DeviceIdLength)
209 {
210 /* Allocate a new device-install event */
211 len = FIELD_OFFSET(DeviceInstallParams, DeviceIds) + (DeviceIdLength + 1) * sizeof(WCHAR);
213 if (Params)
214 {
215 wcscpy(Params->DeviceIds, PnpEvent->InstallDevice.DeviceId);
216
217 /* Queue the event (will be dequeued by DeviceInstallThread) */
221
223
224// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
225// BroadcastSystemMessageW(BSF_POSTMESSAGE,
226// &dwRecipient,
227// WM_DEVICECHANGE,
228// DBT_DEVNODES_CHANGED,
229// 0);
231 }
232 }
233}
HANDLE hDeviceInstallListNotEmpty
Definition: install.c:46
HANDLE hDeviceInstallListMutex
Definition: install.c:44
LIST_ENTRY DeviceInstallListHead
Definition: install.c:45
#define DBT_DEVNODES_CHANGED
Definition: dbt.h:28
#define lstrlenW
Definition: compat.h:750
#define INFINITE
Definition: serial.h:102
#define InsertTailList(ListHead, Entry)
GLenum GLsizei len
Definition: glext.h:6722
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
#define HWND_BROADCAST
Definition: winuser.h:1215

Referenced by PnpEventThread().

◆ ProcessTargetDeviceEvent()

static VOID ProcessTargetDeviceEvent ( _In_ PPLUGPLAY_EVENT_BLOCK  PnpEvent)
static

Definition at line 40 of file event.c.

42{
43 RPC_STATUS RpcStatus;
44
45 DPRINT("ProcessTargetDeviceEvent(%p)\n", PnpEvent);
46
47 if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_ARRIVAL, &RpcStatus))
48 {
49// DWORD dwRecipient;
50
51 DPRINT("Device arrival: %S\n", PnpEvent->TargetDevice.DeviceIds);
52
53// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
54// BroadcastSystemMessageW(BSF_POSTMESSAGE,
55// &dwRecipient,
56// WM_DEVICECHANGE,
57// DBT_DEVNODES_CHANGED,
58// 0);
60 }
61 else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_EJECT_VETOED, &RpcStatus))
62 {
63 DPRINT1("Eject vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
64 }
65 else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_KERNEL_INITIATED_EJECT, &RpcStatus))
66 {
67 DPRINT1("Kernel initiated eject: %S\n", PnpEvent->TargetDevice.DeviceIds);
68 }
69 else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_SAFE_REMOVAL, &RpcStatus))
70 {
71// DWORD dwRecipient;
72
73 DPRINT1("Safe removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
74
75// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
76// BroadcastSystemMessageW(BSF_POSTMESSAGE,
77// &dwRecipient,
78// WM_DEVICECHANGE,
79// DBT_DEVNODES_CHANGED,
80// 0);
82 }
83 else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_SURPRISE_REMOVAL, &RpcStatus))
84 {
85// DWORD dwRecipient;
86
87 DPRINT1("Surprise removal: %S\n", PnpEvent->TargetDevice.DeviceIds);
88
89// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
90// BroadcastSystemMessageW(BSF_POSTMESSAGE,
91// &dwRecipient,
92// WM_DEVICECHANGE,
93// DBT_DEVNODES_CHANGED,
94// 0);
96 }
97 else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_REMOVAL_VETOED, &RpcStatus))
98 {
99 DPRINT1("Removal vetoed: %S\n", PnpEvent->TargetDevice.DeviceIds);
100 }
101 else if (UuidEqual(&PnpEvent->EventGuid, (UUID*)&GUID_DEVICE_REMOVE_PENDING, &RpcStatus))
102 {
103 DPRINT1("Removal pending: %S\n", PnpEvent->TargetDevice.DeviceIds);
104 }
105 else
106 {
107 DPRINT1("Unknown event, GUID {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
108 PnpEvent->EventGuid.Data1, PnpEvent->EventGuid.Data2, PnpEvent->EventGuid.Data3,
109 PnpEvent->EventGuid.Data4[0], PnpEvent->EventGuid.Data4[1], PnpEvent->EventGuid.Data4[2],
110 PnpEvent->EventGuid.Data4[3], PnpEvent->EventGuid.Data4[4], PnpEvent->EventGuid.Data4[5],
111 PnpEvent->EventGuid.Data4[6], PnpEvent->EventGuid.Data4[7]);
112 }
113}

Referenced by PnpEventThread().