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