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