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( 25 _In_ PVOID HwDeviceExtension, 26 _In_ ULONG EventFlag, 27 _In_ PVOID Unused, 28 _Out_ PEVENT* pEvent) 29 { 30 VP_STATUS Result = NO_ERROR; 31 PVIDEO_PORT_EVENT EngEvent; 32 33 /* Allocate memory for the event structure */ 34 EngEvent = ExAllocatePoolWithTag(NonPagedPool, 35 sizeof(VIDEO_PORT_EVENT) + sizeof(KEVENT), 36 TAG_VIDEO_PORT); 37 if (EngEvent) 38 { 39 /* Zero flags */ 40 EngEvent->fFlags = 0; 41 42 /* Set KEVENT pointer */ 43 EngEvent->pKEvent = EngEvent + 1; 44 45 /* Initialize the kernel event */ 46 KeInitializeEvent(EngEvent->pKEvent, 47 (EventFlag & EVENT_TYPE_MASK) ? 48 NotificationEvent : SynchronizationEvent, 49 EventFlag & INITIAL_EVENT_STATE_MASK); 50 51 /* Pass pointer to our structure to the caller */ 52 *pEvent = (PEVENT)EngEvent; 53 DPRINT("VideoPortCreateEvent() created %p\n", EngEvent); 54 } 55 else 56 { 57 /* Out of memory */ 58 DPRINT("VideoPortCreateEvent() failed\n"); 59 Result = ERROR_NOT_ENOUGH_MEMORY; 60 } 61 62 /* Return result */ 63 return Result; 64 } 65 66 /* 67 * @implemented 68 */ 69 VP_STATUS 70 NTAPI 71 VideoPortDeleteEvent( 72 _In_ PVOID HwDeviceExtension, 73 _In_ PEVENT Event) 74 { 75 /* Handle error cases */ 76 if (!Event) return ERROR_INVALID_PARAMETER; 77 if (Event->fFlags & ENG_EVENT_USERMAPPED) return ERROR_INVALID_PARAMETER; 78 if (!Event->pKEvent) return ERROR_INVALID_PARAMETER; 79 80 /* Free storage */ 81 ExFreePoolWithTag(Event, TAG_VIDEO_PORT); 82 83 /* Indicate success */ 84 return NO_ERROR; 85 } 86 87 /* 88 * @implemented 89 */ 90 LONG 91 NTAPI 92 VideoPortSetEvent( 93 _In_ PVOID HwDeviceExtension, 94 _In_ PEVENT Event) 95 { 96 ASSERT(Event); 97 return KeSetEvent(Event->pKEvent, IO_NO_INCREMENT, FALSE); 98 } 99 100 /* 101 * @implemented 102 */ 103 VOID 104 NTAPI 105 VideoPortClearEvent( 106 _In_ PVOID HwDeviceExtension, 107 _In_ PEVENT Event) 108 { 109 ASSERT(Event); 110 KeClearEvent(Event->pKEvent); 111 } 112 113 /* 114 * @implemented 115 */ 116 LONG 117 NTAPI 118 VideoPortReadStateEvent( 119 _In_ PVOID HwDeviceExtension, 120 _In_ PEVENT Event) 121 { 122 ASSERT(Event); 123 return KeReadStateEvent(Event->pKEvent); 124 } 125 126 /* 127 * @implemented 128 */ 129 VP_STATUS 130 NTAPI 131 VideoPortWaitForSingleObject( 132 _In_ PVOID HwDeviceExtension, 133 _In_ PVOID Event, 134 _In_opt_ PLARGE_INTEGER Timeout) 135 { 136 PVIDEO_PORT_EVENT EngEvent = Event; 137 NTSTATUS Status; 138 139 /* Handle error cases */ 140 if (!EngEvent) return ERROR_INVALID_PARAMETER; 141 if (!EngEvent->pKEvent) return ERROR_INVALID_PARAMETER; 142 if (EngEvent->fFlags & ENG_EVENT_USERMAPPED) return ERROR_INVALID_PARAMETER; 143 144 /* Do the actual wait */ 145 Status = KeWaitForSingleObject(EngEvent->pKEvent, 146 Executive, 147 KernelMode, 148 FALSE, 149 Timeout); 150 if (Status == STATUS_TIMEOUT) 151 { 152 /* Convert to wait timeout, otherwise NT_SUCCESS would return NO_ERROR */ 153 return WAIT_TIMEOUT; 154 } 155 else if (NT_SUCCESS(Status)) 156 { 157 /* All other success codes are Win32 success */ 158 return NO_ERROR; 159 } 160 161 /* Otherwise, return default Win32 failure */ 162 return ERROR_INVALID_PARAMETER; 163 } 164 165 /* EOF */ 166