reactos/win32ss/drivers/videoprt/event.c

166 lines
3.8 KiB
C
Raw Normal View History

/*
* PROJECT: ReactOS Video Port Driver
* LICENSE: BSD - See COPYING.ARM in the top level directory
* FILE: win32ss/drivers/videoprt/event.c
* PURPOSE: Event Support Routines
* PROGRAMMERS: ReactOS Portable Systems Group
*/
/* INCLUDES *******************************************************************/
#include "videoprt.h"
#include "../../gdi/eng/engevent.h"
#define NDEBUG
#include <debug.h>
/* PUBLIC FUNCTIONS ***********************************************************/
/*
* @implemented
*/
VP_STATUS
NTAPI
2019-11-24 23:29:36 +00:00
VideoPortCreateEvent(
_In_ PVOID HwDeviceExtension,
_In_ ULONG EventFlag,
_In_ PVOID Unused,
_Out_ PEVENT* pEvent)
{
VP_STATUS Result = NO_ERROR;
PVIDEO_PORT_EVENT EngEvent;
/* Allocate memory for the event structure */
EngEvent = ExAllocatePoolWithTag(NonPagedPool,
sizeof(VIDEO_PORT_EVENT) + sizeof(KEVENT),
TAG_VIDEO_PORT);
if (EngEvent)
{
/* Zero flags */
EngEvent->fFlags = 0;
/* Set KEVENT pointer */
EngEvent->pKEvent = EngEvent + 1;
2019-11-24 23:29:36 +00:00
/* Initialize the kernel event */
KeInitializeEvent(EngEvent->pKEvent,
(EventFlag & EVENT_TYPE_MASK) ?
NotificationEvent : SynchronizationEvent,
EventFlag & INITIAL_EVENT_STATE_MASK);
/* Pass pointer to our structure to the caller */
2019-11-24 23:29:36 +00:00
*pEvent = (PEVENT)EngEvent;
DPRINT("VideoPortCreateEvent() created %p\n", EngEvent);
}
else
{
/* Out of memory */
2019-11-24 23:29:36 +00:00
DPRINT("VideoPortCreateEvent() failed\n");
Result = ERROR_NOT_ENOUGH_MEMORY;
}
/* Return result */
return Result;
}
/*
* @implemented
*/
VP_STATUS
NTAPI
2019-11-24 23:29:36 +00:00
VideoPortDeleteEvent(
_In_ PVOID HwDeviceExtension,
_In_ PEVENT Event)
{
/* Handle error cases */
if (!Event) return ERROR_INVALID_PARAMETER;
if (Event->fFlags & ENG_EVENT_USERMAPPED) return ERROR_INVALID_PARAMETER;
if (!Event->pKEvent) return ERROR_INVALID_PARAMETER;
/* Free storage */
ExFreePoolWithTag(Event, TAG_VIDEO_PORT);
/* Indicate success */
return NO_ERROR;
}
/*
* @implemented
*/
LONG
NTAPI
2019-11-24 23:29:36 +00:00
VideoPortSetEvent(
_In_ PVOID HwDeviceExtension,
_In_ PEVENT Event)
{
ASSERT(Event);
return KeSetEvent(Event->pKEvent, IO_NO_INCREMENT, FALSE);
}
/*
* @implemented
*/
VOID
NTAPI
2019-11-24 23:29:36 +00:00
VideoPortClearEvent(
_In_ PVOID HwDeviceExtension,
_In_ PEVENT Event)
{
ASSERT(Event);
KeClearEvent(Event->pKEvent);
}
/*
* @implemented
*/
LONG
NTAPI
VideoPortReadStateEvent(
_In_ PVOID HwDeviceExtension,
_In_ PEVENT Event)
{
ASSERT(Event);
return KeReadStateEvent(Event->pKEvent);
}
/*
* @implemented
*/
VP_STATUS
NTAPI
2019-11-24 23:29:36 +00:00
VideoPortWaitForSingleObject(
_In_ PVOID HwDeviceExtension,
_In_ PVOID Event,
_In_opt_ PLARGE_INTEGER Timeout)
{
PVIDEO_PORT_EVENT EngEvent = Event;
NTSTATUS Status;
2019-11-24 23:29:36 +00:00
/* Handle error cases */
if (!EngEvent) return ERROR_INVALID_PARAMETER;
if (!EngEvent->pKEvent) return ERROR_INVALID_PARAMETER;
if (EngEvent->fFlags & ENG_EVENT_USERMAPPED) return ERROR_INVALID_PARAMETER;
2019-11-24 23:29:36 +00:00
/* Do the actual wait */
Status = KeWaitForSingleObject(EngEvent->pKEvent,
Executive,
KernelMode,
FALSE,
Timeout);
if (Status == STATUS_TIMEOUT)
{
/* Convert to wait timeout, otherwise NT_SUCCESS would return NO_ERROR */
return WAIT_TIMEOUT;
}
else if (NT_SUCCESS(Status))
{
/* All other success codes are Win32 success */
return NO_ERROR;
}
2019-11-24 23:29:36 +00:00
/* Otherwise, return default Win32 failure */
return ERROR_INVALID_PARAMETER;
}
/* EOF */