ReactOS  0.4.14-dev-293-g2b39b42
event.c
Go to the documentation of this file.
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  */
23 NTAPI
24 VideoPortCreateEvent(IN PVOID HwDeviceExtension,
25  IN ULONG EventFlag,
26  IN PVOID Unused,
27  OUT PEVENT *Event)
28 {
30  PVIDEO_PORT_EVENT EngEvent;
31 
32  /* Allocate memory for the event structure */
34  sizeof(VIDEO_PORT_EVENT) + sizeof(KEVENT),
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) ?
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");
59  }
60 
61  /* Return result */
62  return Result;
63 }
64 
65 /*
66  * @implemented
67  */
69 NTAPI
70 VideoPortDeleteEvent(IN PVOID HwDeviceExtension,
71  IN PEVENT Event)
72 {
73  /* Handle error cases */
74  if (!Event) return ERROR_INVALID_PARAMETER;
76  if (!Event->pKEvent) return ERROR_INVALID_PARAMETER;
77 
78  /* Free storage */
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
113  IN PVOID Event,
115 {
116  PVIDEO_PORT_EVENT EngEvent = Event;
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 */
143 }
144 
145 /* EOF */
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_Must_inspect_result_ typedef _In_ PVOID Unused
Definition: iotypes.h:1129
#define IN
Definition: typedefs.h:38
#define TAG_VIDEO_PORT
Definition: videoprt.h:35
#define INITIAL_EVENT_STATE_MASK
Definition: video.h:111
LONG NTAPI VideoPortSetEvent(IN PVOID HwDeviceExtension, IN PEVENT Event)
Definition: event.c:90
struct _ENG_EVENT * PEVENT
Definition: ntddvdeo.h:548
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
VP_STATUS NTAPI VideoPortDeleteEvent(IN PVOID HwDeviceExtension, IN PEVENT Event)
Definition: event.c:70
VP_STATUS NTAPI VideoPortWaitForSingleObject(IN PVOID HwDeviceExtension, IN PVOID Event, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: event.c:112
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
long LONG
Definition: pedump.c:60
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
VOID NTAPI VideoPortClearEvent(IN PVOID HwDeviceExtension, IN PEVENT Event)
Definition: event.c:101
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define EVENT_TYPE_MASK
Definition: video.h:107
static ULONG Timeout
Definition: ping.c:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VP_STATUS NTAPI VideoPortCreateEvent(IN PVOID HwDeviceExtension, IN ULONG EventFlag, IN PVOID Unused, OUT PEVENT *Event)
Definition: event.c:24
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
LONG VP_STATUS
Definition: video.h:153
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68