- Create KD branch. All debugging support is removed in this branch (no symbols,...
[reactos.git] / reactos / ntoskrnl / po / events.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/po/events.c
5 * PURPOSE: Power Manager
6 *
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
8 */
9
10 #include <ntoskrnl.h>
11 //#define NDEBUG
12 #include <internal/debug.h>
13
14 NTSTATUS CALLBACK
15 PopAddRemoveSysCapsCallback(
16 IN PVOID NotificationStructure,
17 IN PVOID Context)
18 {
19 PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification;
20 OBJECT_ATTRIBUTES ObjectAttributes;
21 HANDLE DeviceHandle;
22 IO_STATUS_BLOCK IoStatusBlock;
23 BOOLEAN Arrival;
24 ULONG Caps;
25 NTSTATUS Status;
26
27 DPRINT("PopAddRemoveSysCapsCallback(%p %p)\n",
28 NotificationStructure, Context);
29
30 Notification = (PDEVICE_INTERFACE_CHANGE_NOTIFICATION)NotificationStructure;
31 if (Notification->Version != 1)
32 return STATUS_REVISION_MISMATCH;
33 if (Notification->Size != sizeof(DEVICE_INTERFACE_CHANGE_NOTIFICATION))
34 return STATUS_INVALID_PARAMETER;
35 if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_ARRIVAL, sizeof(GUID) == sizeof(GUID)))
36 Arrival = TRUE;
37 else if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_REMOVAL, sizeof(GUID) == sizeof(GUID)))
38 Arrival = FALSE;
39 else
40 return STATUS_INVALID_PARAMETER;
41
42 if (Arrival)
43 {
44 DPRINT("Arrival of %wZ\n", Notification->SymbolicLinkName);
45
46 /* Open device */
47 InitializeObjectAttributes(
48 &ObjectAttributes,
49 Notification->SymbolicLinkName,
50 OBJ_KERNEL_HANDLE,
51 NULL,
52 NULL);
53 Status = ZwOpenFile(
54 &DeviceHandle,
55 FILE_READ_DATA,
56 &ObjectAttributes,
57 &IoStatusBlock,
58 FILE_SHARE_READ | FILE_SHARE_WRITE,
59 0);
60 if (!NT_SUCCESS(Status))
61 {
62 DPRINT("ZwOpenFile() failed with status 0x%08lx\n", Status);
63 return Status;
64 }
65
66 /* Send IOCTL_GET_SYS_BUTTON_CAPS to get new caps */
67 Status = ZwDeviceIoControlFile(
68 DeviceHandle,
69 NULL,
70 NULL,
71 NULL,
72 &IoStatusBlock,
73 IOCTL_GET_SYS_BUTTON_CAPS,
74 NULL,
75 0,
76 &Caps,
77 sizeof(Caps));
78 if (!NT_SUCCESS(Status))
79 {
80 DPRINT("ZwDeviceIoControlFile(IOCTL_GET_SYS_BUTTON_CAPS) failed with status 0x%08lx\n", Status);
81 ZwClose(DeviceHandle);
82 return Status;
83 }
84 /* FIXME: What do do with this? */
85 DPRINT1("Device capabilities: 0x%lx\n", Caps);
86
87 /* Send IOCTL_GET_SYS_BUTTON_CAPS to get current caps */
88 /* FIXME: Set a IO completion routine on it to be able to send a new one */
89 DPRINT1("Send a IOCTL_GET_SYS_BUTTON_EVENT\n");
90 return ZwClose(DeviceHandle);
91 }
92 else
93 {
94 DPRINT1("Removal of a power capable device not implemented\n");
95 return STATUS_NOT_IMPLEMENTED;
96 }
97 }