7f14c46ad6748a642c486924e17526e5f4b240fe
[reactos.git] / reactos / win32ss / drivers / videoprt / event.c
1 /*
2 * PROJECT: ReactOS Video Port Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/video/videoprt/event.c
5 * PURPOSE: Event Support Routines
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "videoprt.h"
12 #include "../../gdi/eng/engevent.h"
13
14 /* PUBLIC FUNCTIONS ***********************************************************/
15
16 /*
17 * @implemented
18 */
19 VP_STATUS
20 NTAPI
21 VideoPortCreateEvent(IN PVOID HwDeviceExtension,
22 IN ULONG EventFlag,
23 IN PVOID Unused,
24 OUT PEVENT *Event)
25 {
26 VP_STATUS Result = NO_ERROR;
27 PVIDEO_PORT_EVENT EngEvent;
28
29 /* Allocate memory for the event structure */
30 EngEvent = ExAllocatePoolWithTag(NonPagedPool,
31 sizeof(VIDEO_PORT_EVENT) + sizeof(KEVENT),
32 TAG_VIDEO_PORT);
33 if (EngEvent)
34 {
35 /* Set KEVENT pointer */
36 EngEvent->pKEvent = EngEvent + 1;
37
38 /* Initialize the kernel event */
39 KeInitializeEvent(EngEvent->pKEvent,
40 (EventFlag & EVENT_TYPE_MASK) ?
41 NotificationEvent : SynchronizationEvent,
42 EventFlag & INITIAL_EVENT_STATE_MASK);
43
44 /* Pass pointer to our structure to the caller */
45 *Event = (PEVENT)EngEvent;
46 DPRINT("VideoPortCreateEvent() created %p\n", EngEvent);
47 }
48 else
49 {
50 /* Out of memory */
51 DPRINT("VideoPortCreateEvent() failed\n");
52 Result = ERROR_NOT_ENOUGH_MEMORY;
53 }
54
55 /* Return result */
56 return Result;
57 }
58
59 /*
60 * @implemented
61 */
62 VP_STATUS
63 NTAPI
64 VideoPortDeleteEvent(IN PVOID HwDeviceExtension,
65 IN PEVENT Event)
66 {
67 /* Handle error cases */
68 if (!Event) return ERROR_INVALID_PARAMETER;
69 if (Event->fFlags & ENG_EVENT_USERMAPPED) return ERROR_INVALID_PARAMETER;
70 if (!Event->pKEvent) return ERROR_INVALID_PARAMETER;
71
72 /* Free storage */
73 ExFreePool(Event);
74
75 /* Indicate success */
76 return NO_ERROR;
77 }
78
79 /*
80 * @implemented
81 */
82 LONG
83 NTAPI
84 VideoPortSetEvent(IN PVOID HwDeviceExtension,
85 IN PEVENT Event)
86 {
87 return KeSetEvent(Event->pKEvent, IO_NO_INCREMENT, FALSE);
88 }
89
90 /*
91 * @implemented
92 */
93 VOID
94 NTAPI
95 VideoPortClearEvent(IN PVOID HwDeviceExtension,
96 IN PEVENT Event)
97 {
98 KeClearEvent(Event->pKEvent);
99 }
100
101 /*
102 * @implemented
103 */
104 VP_STATUS
105 NTAPI
106 VideoPortWaitForSingleObject(IN PVOID HwDeviceExtension,
107 IN PVOID Event,
108 IN PLARGE_INTEGER Timeout OPTIONAL)
109 {
110 PVIDEO_PORT_EVENT EngEvent = Event;
111 NTSTATUS Status;
112
113 /* Handle error cases */
114 if (!EngEvent) return ERROR_INVALID_PARAMETER;
115 if (!EngEvent->pKEvent) return ERROR_INVALID_PARAMETER;
116 if (EngEvent->fFlags & ENG_EVENT_USERMAPPED) return ERROR_INVALID_PARAMETER;
117
118 /* Do the actual wait */
119 Status = KeWaitForSingleObject(EngEvent->pKEvent,
120 Executive,
121 KernelMode,
122 FALSE,
123 Timeout);
124 if (Status == STATUS_TIMEOUT)
125 {
126 /* Convert to wait timeout, otherwise NT_SUCCESS would return NO_ERROR */
127 return WAIT_TIMEOUT;
128 }
129 else if (NT_SUCCESS(Status))
130 {
131 /* All other success codes are Win32 success */
132 return NO_ERROR;
133 }
134
135 /* Otherwise, return default Win32 failure */
136 return ERROR_INVALID_PARAMETER;
137 }
138
139 /* EOF */
140