ReactOS  0.4.15-dev-320-g2dc9f0a
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
25  _In_ PVOID HwDeviceExtension,
26  _In_ ULONG EventFlag,
28  _Out_ PEVENT* pEvent)
29 {
31  PVIDEO_PORT_EVENT EngEvent;
32 
33  /* Allocate memory for the event structure */
35  sizeof(VIDEO_PORT_EVENT) + sizeof(KEVENT),
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) ?
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");
60  }
61 
62  /* Return result */
63  return Result;
64 }
65 
66 /*
67  * @implemented
68  */
70 NTAPI
72  _In_ PVOID HwDeviceExtension,
74 {
75  /* Handle error cases */
76  if (!Event) return ERROR_INVALID_PARAMETER;
78  if (!Event->pKEvent) return ERROR_INVALID_PARAMETER;
79 
80  /* Free storage */
82 
83  /* Indicate success */
84  return NO_ERROR;
85 }
86 
87 /*
88  * @implemented
89  */
90 LONG
91 NTAPI
93  _In_ PVOID HwDeviceExtension,
95 {
96  ASSERT(Event);
97  return KeSetEvent(Event->pKEvent, IO_NO_INCREMENT, FALSE);
98 }
99 
100 /*
101  * @implemented
102  */
103 VOID
104 NTAPI
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
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
132  _In_ PVOID HwDeviceExtension,
133  _In_ PVOID Event,
135 {
136  PVIDEO_PORT_EVENT EngEvent = Event;
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 */
163 }
164 
165 /* EOF */
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_Must_inspect_result_ typedef _In_ PVOID Unused
Definition: iotypes.h:1129
#define TAG_VIDEO_PORT
Definition: videoprt.h:38
#define INITIAL_EVENT_STATE_MASK
Definition: video.h:111
VP_STATUS NTAPI VideoPortCreateEvent(_In_ PVOID HwDeviceExtension, _In_ ULONG EventFlag, _In_ PVOID Unused, _Out_ PEVENT *pEvent)
Definition: event.c:24
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
#define _In_opt_
Definition: no_sal2.h:213
#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
LONG NTAPI VideoPortSetEvent(_In_ PVOID HwDeviceExtension, _In_ PEVENT Event)
Definition: event.c:92
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
_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
#define _Out_
Definition: no_sal2.h:323
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI VideoPortClearEvent(_In_ PVOID HwDeviceExtension, _In_ PEVENT Event)
Definition: event.c:105
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define WAIT_TIMEOUT
Definition: dderror.h:14
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VP_STATUS NTAPI VideoPortWaitForSingleObject(_In_ PVOID HwDeviceExtension, _In_ PVOID Event, _In_opt_ PLARGE_INTEGER Timeout)
Definition: event.c:131
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
#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 VideoPortDeleteEvent(_In_ PVOID HwDeviceExtension, _In_ PEVENT Event)
Definition: event.c:71
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
LONG VP_STATUS
Definition: video.h:153
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
LONG NTAPI VideoPortReadStateEvent(_In_ PVOID HwDeviceExtension, _In_ PEVENT Event)
Definition: event.c:118