Author: janderwald
Date: Thu Jul 30 11:43:54 2009
New Revision: 42298
URL:
http://svn.reactos.org/svn/reactos?rev=42298&view=rev
Log:
- Implement KsFreeEventList, KsDisableEvent
Modified:
trunk/reactos/drivers/ksfilter/ks/event.c
trunk/reactos/drivers/ksfilter/ks/kstypes.h
Modified: trunk/reactos/drivers/ksfilter/ks/event.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/event.…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/event.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/event.c [iso-8859-1] Thu Jul 30 11:43:54 2009
@@ -7,6 +7,69 @@
*/
#include "priv.h"
+
+BOOLEAN
+KspSynchronizedEventRoutine(
+ IN KSEVENTS_LOCKTYPE EventsFlags,
+ IN PVOID EventsLock,
+ IN PKSEVENT_SYNCHRONIZED_ROUTINE SynchronizedRoutine,
+ IN PKSEVENT_CTX Ctx)
+{
+ BOOLEAN Result = FALSE;
+ KIRQL OldLevel;
+
+ if (EventsFlags == KSEVENTS_NONE)
+ {
+ /* no synchronization required */
+ Result = SynchronizedRoutine(Ctx);
+ }
+ else if (EventsFlags == KSEVENTS_SPINLOCK)
+ {
+ /* use spin lock */
+ KeAcquireSpinLock((PKSPIN_LOCK)EventsLock, &OldLevel);
+ Result = SynchronizedRoutine(Ctx);
+ KeReleaseSpinLock((PKSPIN_LOCK)EventsLock, OldLevel);
+ }
+ else if (EventsFlags == KSEVENTS_MUTEX)
+ {
+ /* use a mutex */
+ KeWaitForSingleObject(EventsLock, Executive, KernelMode, FALSE, NULL);
+ Result = SynchronizedRoutine(Ctx);
+ KeReleaseMutex((PRKMUTEX)EventsLock, FALSE);
+ }
+ else if (EventsFlags == KSEVENTS_FMUTEX)
+ {
+ /* use a fast mutex */
+ ExAcquireFastMutex((PFAST_MUTEX)EventsLock);
+ Result = SynchronizedRoutine(Ctx);
+ ExReleaseFastMutex((PFAST_MUTEX)EventsLock);
+ }
+ else if (EventsFlags == KSEVENTS_FMUTEXUNSAFE)
+ {
+ /* acquire fast mutex unsafe */
+ KeEnterCriticalRegion();
+ ExAcquireFastMutexUnsafe((PFAST_MUTEX)EventsLock);
+ Result = SynchronizedRoutine(Ctx);
+ ExReleaseFastMutexUnsafe((PFAST_MUTEX)EventsLock);
+ KeLeaveCriticalRegion();
+ }
+ else if (EventsFlags == KSEVENTS_INTERRUPT)
+ {
+ /* use interrupt for locking */
+ Result = KeSynchronizeExecution((PKINTERRUPT)EventsLock,
(PKSYNCHRONIZE_ROUTINE)SynchronizedRoutine, (PVOID)Ctx);
+ }
+ else if (EventsFlags == KSEVENTS_ERESOURCE)
+ {
+ /* use an eresource */
+ KeEnterCriticalRegion();
+ ExAcquireResourceExclusiveLite((PERESOURCE)EventsLock, TRUE);
+ Result = SynchronizedRoutine(Ctx);
+ ExReleaseResourceLite((PERESOURCE)EventsLock);
+ KeLeaveCriticalRegion();
+ }
+
+ return Result;
+}
/*
@@ -47,9 +110,53 @@
return STATUS_UNSUCCESSFUL;
}
-
-/*
- @unimplemented
+BOOLEAN
+NTAPI
+KspDisableEvent(
+ IN PKSEVENT_CTX Ctx)
+{
+ PIO_STACK_LOCATION IoStack;
+ PKSEVENTDATA EventData;
+ PKSEVENT_ENTRY EventEntry;
+ PLIST_ENTRY Entry;
+
+ /* get current irp stack location */
+ IoStack = IoGetCurrentIrpStackLocation(Ctx->Irp);
+
+ /* get event data */
+ EventData = (PKSEVENTDATA)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
+
+ if (!Ctx || !Ctx->List || !Ctx->FileObject || !Ctx->Irp)
+ {
+ /* invalid parameter */
+ return FALSE;
+ }
+
+ /* point to first entry */
+ Entry = Ctx->List->Flink;
+
+ while(Entry != Ctx->List)
+ {
+ /* get event entry */
+ EventEntry = (PKSEVENT_ENTRY)CONTAINING_RECORD(Entry, KSEVENT_ENTRY, ListEntry);
+
+ if (EventEntry->EventData == EventData && EventEntry->FileObject ==
Ctx->FileObject)
+ {
+ /* found the entry */
+ RemoveEntryList(&EventEntry->ListEntry);
+ Ctx->EventEntry = EventEntry;
+ return TRUE;
+ }
+
+ /* move to next item */
+ Entry = Entry->Flink;
+ }
+ /* entry not found */
+ return TRUE;
+}
+
+/*
+ @implemented
*/
KSDDKAPI
NTSTATUS
@@ -60,8 +167,46 @@
IN KSEVENTS_LOCKTYPE EventsFlags,
IN PVOID EventsLock)
{
- UNIMPLEMENTED;
- return STATUS_UNSUCCESSFUL;
+ PIO_STACK_LOCATION IoStack;
+ KSEVENT_CTX Ctx;
+
+ /* get current irp stack location */
+ IoStack = IoGetCurrentIrpStackLocation(Irp);
+
+ /* is there a event entry */
+ if (IoStack->Parameters.DeviceIoControl.InputBufferLength <
sizeof(KSEVENTDATA))
+ {
+ if (IoStack->Parameters.DeviceIoControl.InputBufferLength == 0)
+ {
+ /* caller wants to free event items */
+ KsFreeEventList(IoStack->FileObject, EventsList, EventsFlags,
EventsLock);
+ return STATUS_SUCCESS;
+ }
+ /* invalid parameter */
+ return STATUS_INVALID_BUFFER_SIZE;
+ }
+
+ /* setup event ctx */
+ Ctx.List = EventsList;
+ Ctx.FileObject = IoStack->FileObject;
+ Ctx.Irp = Irp;
+ Ctx.EventEntry = NULL;
+
+ if (KspSynchronizedEventRoutine(EventsFlags, EventsLock, KspDisableEvent, &Ctx))
+ {
+ /* was the event entry found */
+ if (Ctx.EventEntry)
+ {
+ /* discard event */
+ KsDiscardEvent(Ctx.EventEntry);
+ return STATUS_SUCCESS;
+ }
+ /* event was not found */
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ /* invalid parameters */
+ return STATUS_INVALID_PARAMETER;
}
/*
@@ -77,8 +222,38 @@
}
-/*
- @unimplemented
+BOOLEAN
+NTAPI
+KspFreeEventList(
+ IN PKSEVENT_CTX Ctx)
+{
+ PLIST_ENTRY Entry;
+ PKSEVENT_ENTRY EventEntry;
+
+ /* check valid input */
+ if (!Ctx || !Ctx->List)
+ return FALSE;
+
+ /* remove first entry */
+ Entry = RemoveHeadList(Ctx->List);
+ if (!Entry)
+ {
+ /* list is empty, bye-bye */
+ return FALSE;
+ }
+
+ /* get event entry */
+ EventEntry = (PKSEVENT_ENTRY)CONTAINING_RECORD(Entry, KSEVENT_ENTRY, ListEntry);
+
+ /* store event entry */
+ Ctx->EventEntry = EventEntry;
+ /* return success */
+ return TRUE;
+}
+
+
+/*
+ @implemented
*/
KSDDKAPI
VOID
@@ -89,7 +264,20 @@
IN KSEVENTS_LOCKTYPE EventsFlags,
IN PVOID EventsLock)
{
- UNIMPLEMENTED;
+ KSEVENT_CTX Ctx;
+
+ /* setup event ctx */
+ Ctx.List = EventsList;
+ Ctx.FileObject = FileObject;
+ Ctx.EventEntry = NULL;
+
+ while(KspSynchronizedEventRoutine(EventsFlags, EventsLock, KspFreeEventList,
&Ctx))
+ {
+ if (Ctx.EventEntry)
+ {
+ KsDiscardEvent(Ctx.EventEntry);
+ }
+ }
}
@@ -153,7 +341,7 @@
}
/*
- @unimplemented
+ @implemented
*/
NTSTATUS
NTAPI
Modified: trunk/reactos/drivers/ksfilter/ks/kstypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/kstype…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/kstypes.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/kstypes.h [iso-8859-1] Thu Jul 30 11:43:54 2009
@@ -122,4 +122,14 @@
KEVENT Event;
}KSREMOVE_BUS_INTERFACE_CTX, *PKSREMOVE_BUS_INTERFACE_CTX;
+typedef struct
+{
+ PLIST_ENTRY List;
+ PFILE_OBJECT FileObject;
+ PKSEVENT_ENTRY EventEntry;
+ PIRP Irp;
+}KSEVENT_CTX, *PKSEVENT_CTX;
+
+typedef BOOLEAN (NTAPI *PKSEVENT_SYNCHRONIZED_ROUTINE)(PKSEVENT_CTX Context);
+
#endif