summaryrefslogtreecommitdiff
path: root/gpio/samples/simdeviceumdf/queue.h
diff options
context:
space:
mode:
authorDave Wilson <[email protected]>2015-03-17 19:50:07 -0700
committerDave Wilson <[email protected]>2015-03-17 19:50:07 -0700
commit97cf5197cf5b882b2c689d8dc2b555f2edf8f418 (patch)
tree46f3701832d70b420eb0fc0eb93261f9da45db3f /gpio/samples/simdeviceumdf/queue.h
parentef1905bf1e8825bb31120dfb27e0daf3154d859a (diff)
Initial publish
Diffstat (limited to 'gpio/samples/simdeviceumdf/queue.h')
-rw-r--r--gpio/samples/simdeviceumdf/queue.h211
1 files changed, 211 insertions, 0 deletions
diff --git a/gpio/samples/simdeviceumdf/queue.h b/gpio/samples/simdeviceumdf/queue.h
new file mode 100644
index 00000000..108299a4
--- /dev/null
+++ b/gpio/samples/simdeviceumdf/queue.h
@@ -0,0 +1,211 @@
+/*++
+
+Copyright (c) Microsoft Corporation, All Rights Reserved
+
+Module Name:
+
+ queue.h
+
+Abstract:
+
+ This file defines the queue callback interface.
+
+Environment:
+
+ Windows User-Mode Driver Framework (WUDF)
+
+--*/
+
+#pragma once
+
+// Set max write length for testing
+#define MAX_WRITE_LENGTH (40*1024)
+
+// Set timer period in ms
+#define TIMER_PERIOD 100
+
+//
+// Queue Callback Object.
+//
+
+class CSimdeviceQueue :
+ public IQueueCallbackDeviceIoControl,
+ public IQueueCallbackRead,
+ public IQueueCallbackWrite,
+ public CUnknown
+{
+ PVOID m_Buffer; // Current buffer
+ ULONG m_Length; // Length of the buffer
+ SIZE_T m_XferredBytes; // Amount of bytes transferred for the current request
+ IWDFIoRequest2 *m_CurrentRequest; // Current request
+ CRITICAL_SECTION m_Crit; // Lock to protect updates to CSimdeviceQueue fields
+ BOOLEAN m_ExitThread; // If TRUE Terminate thread.
+ BOOLEAN m_InitCritSec; // If TRUE lock initialized
+
+ IWDFIoQueue *m_FxQueue;
+
+ CSimdeviceQueue() :
+ m_Buffer(NULL),
+ m_Length (0),
+ m_CurrentRequest(NULL),
+ m_XferredBytes(0),
+ m_ExitThread(FALSE),
+ m_InitCritSec(FALSE),
+ m_FxQueue(NULL)
+ {
+ }
+
+ virtual ~CSimdeviceQueue();
+
+ __inline
+ void
+ Lock(
+ )
+ {
+ ::EnterCriticalSection(&m_Crit);
+ }
+
+ __inline
+ void
+ Unlock(
+ )
+ {
+ ::LeaveCriticalSection(&m_Crit);
+ }
+
+ HRESULT
+ Initialize(
+ _In_ IWDFDevice *FxDevice
+ );
+
+public:
+
+ //
+ // Completion thread routine.
+ //
+
+ static DWORD CompletionThread( PVOID ThreadParameter);
+
+ //
+ // Sets the flag to make thread exit
+ //
+
+ void
+ SetExitThread()
+ {
+ m_ExitThread = TRUE;
+ }
+
+ static
+ HRESULT
+ CreateInstance(
+ _In_ IWDFDevice *FxDevice,
+ _Out_ PCSimdeviceQueue *Queue
+ );
+
+ HRESULT
+ Configure(
+ VOID
+ )
+ {
+ return S_OK;
+ }
+
+
+ IQueueCallbackDeviceIoControl *
+ QueryIQueueCallbackDeviceIoControl(
+ VOID
+ )
+ {
+ AddRef();
+ return static_cast<IQueueCallbackDeviceIoControl *>(this);
+ }
+
+ IQueueCallbackRead *
+ QueryIQueueCallbackRead(
+ VOID
+ )
+ {
+ AddRef();
+ return static_cast<IQueueCallbackRead *>(this);
+ }
+
+ IQueueCallbackWrite *
+ QueryIQueueCallbackWrite(
+ VOID
+ )
+ {
+ AddRef();
+ return static_cast<IQueueCallbackWrite *>(this);
+ }
+
+ //
+ // IUnknown
+ //
+
+ virtual
+ ULONG
+ STDMETHODCALLTYPE
+ AddRef(
+ VOID
+ ) {
+ return CUnknown::AddRef();
+ }
+
+ __drv_arg(this, __drv_freesMem(object))
+ virtual
+ ULONG
+ STDMETHODCALLTYPE
+ Release(
+ VOID
+ ) {
+ return CUnknown::Release();
+ }
+
+ virtual
+ HRESULT
+ STDMETHODCALLTYPE
+ QueryInterface(
+ _In_ REFIID InterfaceId,
+ _Out_ PVOID *Object
+ );
+
+ //
+ // Wdf Callbacks
+ //
+
+ // IQueueCallbackDeviceIoControl
+ //
+ virtual
+ VOID
+ STDMETHODCALLTYPE
+ OnDeviceIoControl(
+ _In_ IWDFIoQueue *pWdfQueue,
+ _In_ IWDFIoRequest *pWdfRequest,
+ _In_ ULONG ControlCode,
+ _In_ SIZE_T InputBufferSizeInBytes,
+ _In_ SIZE_T OutputBufferSizeInBytes
+ );
+
+ // IQueueCallbackWrite
+ //
+ virtual
+ VOID
+ STDMETHODCALLTYPE
+ OnWrite(
+ _In_ IWDFIoQueue *pWdfQueue,
+ _In_ IWDFIoRequest *pWdfRequest,
+ _In_ SIZE_T NumOfBytesToWrite
+ );
+
+ // IQueueCallbackRead
+ //
+ virtual
+ VOID
+ STDMETHODCALLTYPE
+ OnRead(
+ _In_ IWDFIoQueue *pWdfQueue,
+ _In_ IWDFIoRequest *pWdfRequest,
+ _In_ SIZE_T NumOfBytesToRead
+ );
+};