Revert Kdb and Keyboard strings in name to share more code with mouclass
[reactos.git] / reactos / drivers / input / kbdclass / misc.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Keyboard class driver
4 * FILE: drivers/input/kbdclass/misc.c
5 * PURPOSE: Misceallenous operations
6 *
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
8 */
9
10 #define NDEBUG
11 #include <debug.h>
12
13 #include "kbdclass.h"
14
15 static NTSTATUS NTAPI
16 ForwardIrpAndWaitCompletion(
17 IN PDEVICE_OBJECT DeviceObject,
18 IN PIRP Irp,
19 IN PVOID Context)
20 {
21 if (Irp->PendingReturned)
22 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
23 return STATUS_MORE_PROCESSING_REQUIRED;
24 }
25
26 NTSTATUS
27 ForwardIrpAndWait(
28 IN PDEVICE_OBJECT DeviceObject,
29 IN PIRP Irp)
30 {
31 PDEVICE_OBJECT LowerDevice;
32 KEVENT Event;
33 NTSTATUS Status;
34
35 ASSERT(!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO);
36 LowerDevice = ((PPORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
37
38 KeInitializeEvent(&Event, NotificationEvent, FALSE);
39 IoCopyCurrentIrpStackLocationToNext(Irp);
40
41 DPRINT("Calling lower device %p [%wZ]\n", LowerDevice, &LowerDevice->DriverObject->DriverName);
42 IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
43
44 Status = IoCallDriver(LowerDevice, Irp);
45 if (Status == STATUS_PENDING)
46 {
47 Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
48 if (NT_SUCCESS(Status))
49 Status = Irp->IoStatus.Status;
50 }
51
52 return Status;
53 }
54
55 NTSTATUS NTAPI
56 ForwardIrpAndForget(
57 IN PDEVICE_OBJECT DeviceObject,
58 IN PIRP Irp)
59 {
60 PDEVICE_OBJECT LowerDevice;
61
62 ASSERT(!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO);
63 LowerDevice = ((PPORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
64
65 IoSkipCurrentIrpStackLocation(Irp);
66 return IoCallDriver(LowerDevice, Irp);
67 }