86d0864e57b67600f7154334980e3120e277fce2
[reactos.git] / reactos / drivers / input / mouclass / misc.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Mouse class driver
4 * FILE: drivers/input/mouclass/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 "mouclass.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 = ((PMOUCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
32 KEVENT Event;
33 NTSTATUS Status;
34
35 KeInitializeEvent(&Event, NotificationEvent, FALSE);
36 IoCopyCurrentIrpStackLocationToNext(Irp);
37
38 DPRINT("Calling lower device %p [%wZ]\n", LowerDevice, &LowerDevice->DriverObject->DriverName);
39 IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
40
41 Status = IoCallDriver(LowerDevice, Irp);
42 if (Status == STATUS_PENDING)
43 {
44 Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
45 if (NT_SUCCESS(Status))
46 Status = Irp->IoStatus.Status;
47 }
48
49 return Status;
50 }
51
52 NTSTATUS NTAPI
53 ForwardIrpAndForget(
54 IN PDEVICE_OBJECT DeviceObject,
55 IN PIRP Irp)
56 {
57 PDEVICE_OBJECT LowerDevice = ((PMOUCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
58
59 IoSkipCurrentIrpStackLocation(Irp);
60 return IoCallDriver(LowerDevice, Irp);
61 }