ReactOS 0.4.15-dev-8002-gbbb3b00
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 175 of file event.c.

177{
178 PLUGPLAY_CONTROL_USER_RESPONSE_DATA ResponseData = {0, 0, 0, 0};
179 DWORD dwRet = ERROR_SUCCESS;
181 PPLUGPLAY_EVENT_BLOCK PnpEvent, NewPnpEvent;
182 ULONG PnpEventSize;
183
184 UNREFERENCED_PARAMETER(lpParameter);
185
186 PnpEventSize = 0x1000;
187 PnpEvent = HeapAlloc(GetProcessHeap(), 0, PnpEventSize);
188 if (PnpEvent == NULL)
189 return ERROR_OUTOFMEMORY;
190
191 for (;;)
192 {
193 DPRINT("Calling NtGetPlugPlayEvent()\n");
194
195 /* Wait for the next PnP event */
196 Status = NtGetPlugPlayEvent(0, 0, PnpEvent, PnpEventSize);
197
198 /* Resize the buffer for the PnP event if it's too small */
200 {
201 PnpEventSize += 0x400;
202 NewPnpEvent = HeapReAlloc(GetProcessHeap(), 0, PnpEvent, PnpEventSize);
203 if (NewPnpEvent == NULL)
204 {
205 dwRet = ERROR_OUTOFMEMORY;
206 break;
207 }
208 PnpEvent = NewPnpEvent;
209 continue;
210 }
211
212 if (!NT_SUCCESS(Status))
213 {
214 DPRINT1("NtGetPlugPlayEvent() failed (Status 0x%08lx)\n", Status);
215 break;
216 }
217
218 /* Process the PnP event */
219 DPRINT("Received PnP Event\n");
220 switch (PnpEvent->EventCategory)
221 {
222// case HardwareProfileChangeEvent:
223
225 ProcessTargetDeviceEvent(PnpEvent);
226 break;
227
230 break;
231
232// case CustomDeviceEvent:
233
236 break;
237
238// case DeviceArrivalEvent:
239// case PowerEvent:
240// case VetoEvent:
241// case BlockedDriverEvent:
242
243 default:
244 DPRINT1("Unsupported Event Category: %lu\n", PnpEvent->EventCategory);
245 break;
246 }
247
248 /* Dequeue the current PnP event and signal the next one */
250 &ResponseData,
251 sizeof(ResponseData));
252 if (!NT_SUCCESS(Status))
253 {
254 DPRINT1("NtPlugPlayControl(PlugPlayControlUserResponse) failed (Status 0x%08lx)\n", Status);
255 break;
256 }
257 }
258
259 HeapFree(GetProcessHeap(), 0, PnpEvent);
260
261 return dwRet;
262}
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:133
#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:32
#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:317
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:71
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 DPRINT("ProcessDeviceClassChangeEvent(%p)\n", PnpEvent);
122 DPRINT("SymbolicLink: %S\n", PnpEvent->DeviceClass.SymbolicLinkName);
123 DPRINT("ClassGuid: {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\n",
124 PnpEvent->DeviceClass.ClassGuid.Data1, PnpEvent->DeviceClass.ClassGuid.Data2, PnpEvent->DeviceClass.ClassGuid.Data3,
125 PnpEvent->DeviceClass.ClassGuid.Data4[0], PnpEvent->DeviceClass.ClassGuid.Data4[1], PnpEvent->DeviceClass.ClassGuid.Data4[2],
126 PnpEvent->DeviceClass.ClassGuid.Data4[3], PnpEvent->DeviceClass.ClassGuid.Data4[4], PnpEvent->DeviceClass.ClassGuid.Data4[5],
127 PnpEvent->DeviceClass.ClassGuid.Data4[6], PnpEvent->DeviceClass.ClassGuid.Data4[7]);
128}

Referenced by PnpEventThread().

◆ ProcessDeviceInstallEvent()

static VOID ProcessDeviceInstallEvent ( _In_ PPLUGPLAY_EVENT_BLOCK  PnpEvent)
static

Definition at line 133 of file event.c.

135{
137 DWORD len;
138 DWORD DeviceIdLength;
139// DWORD dwRecipient;
140
141 DPRINT("ProcessDeviceInstallEvent(%p)\n", PnpEvent);
142 DPRINT("Device enumerated: %S\n", PnpEvent->InstallDevice.DeviceId);
143
144 DeviceIdLength = lstrlenW(PnpEvent->InstallDevice.DeviceId);
145 if (DeviceIdLength)
146 {
147 /* Allocate a new device-install event */
148 len = FIELD_OFFSET(DeviceInstallParams, DeviceIds) + (DeviceIdLength + 1) * sizeof(WCHAR);
150 if (Params)
151 {
152 wcscpy(Params->DeviceIds, PnpEvent->InstallDevice.DeviceId);
153
154 /* Queue the event (will be dequeued by DeviceInstallThread) */
158
160
161// dwRecipient = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
162// BroadcastSystemMessageW(BSF_POSTMESSAGE,
163// &dwRecipient,
164// WM_DEVICECHANGE,
165// DBT_DEVNODES_CHANGED,
166// 0);
168 }
169 }
170}
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
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
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:1204
#define WM_DEVICECHANGE
Definition: winuser.h:1811
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180

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}
int WINAPI UuidEqual(UUID *Uuid1, UUID *Uuid2, RPC_STATUS *Status)
Definition: rpcrt4_main.c:252
long RPC_STATUS
Definition: rpc.h:52

Referenced by PnpEventThread().