[ofw] [RFC] [PATCH 1/12] winverbs: add CWVBuffer class

Sean Hefty sean.hefty at intel.com
Fri Mar 14 22:56:59 PDT 2008


Code format change to match that used by MS toaster driver sample.

Add WVBuffer class that can be used for IOCTL buffers.  The class
defines a static byte array that can be used for small buffers, but
allocates larger buffers.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
This is based off of Tzachi's recommendation, with one minor change
to the interface.  I'm not thrilled with the class name or function
names, so I'm open to better ideas.  I wanted them to convey that
each instance of the class is a single data buffer.  The class should
not be shared among multiple threads.  The term 'allocator', to me
anyway, implies that multiple threads could call Allocator::Alloc()
and expect to get different data buffers.

Index: core/winverbs/user/wv_base.h
===================================================================
--- core/winverbs/user/wv_base.h	(revision 979)
+++ core/winverbs/user/wv_base.h	(working copy)
@@ -35,6 +35,7 @@
 #include <windows.h>
 
 #include <iba\ib_types.h>
+#include <iba\ib_uvp.h>
 
 __inline void* __cdecl operator new(size_t size)
 {
@@ -46,6 +47,34 @@
 	HeapFree(GetProcessHeap(), 0, pObj);
 }
 
-HRESULT ConvertIbalStatus(ib_api_status_t status);
+const int WvDefaultBufferSize = 128;
 
+class CWVBuffer
+{
+public:
+	void* Get(size_t size)
+	{
+		if (size <= WvDefaultBufferSize) {
+			pBuf = m_Buffer;
+		} else {
+			pBuf = new UINT8[size];
+		}
+		return pBuf;
+	}
+
+	void Put()
+	{
+		if (pBuf != m_Buffer) {
+			delete pBuf;
+		}
+	}
+protected:
+	UINT8 m_Buffer[WvDefaultBufferSize];
+	void *pBuf;
+};
+
+HRESULT WvConvertIbStatus(ib_api_status_t status);
+
+HRESULT WvGetUserVerbs(HMODULE hLib, uvp_interface_t *pVerbs);
+
 #endif // _WV_BASE_H_
\ No newline at end of file
Index: core/winverbs/user/wv_main.cpp
===================================================================
--- core/winverbs/user/wv_main.cpp	(revision 986)
+++ core/winverbs/user/wv_main.cpp	(working copy)
@@ -52,29 +52,33 @@
 	CWVProvider *wv;
 
 	wv = new CWVProvider;
-	if (!wv)
-	{
+	if (wv == NULL) {
 		hr = WV_NO_MEMORY;
 		goto err1;
 	}
 
 	hr = wv->QueryInterface(riid, ppvObj);
-	if (hr != WV_SUCCESS)
+	if (FAILED(hr)) {
 		goto err2;
+	}
+	wv->Release();
 
+	hr = wv->Open();
+	if (FAILED(hr)) {
+		goto err2;
+	}
 	return WV_SUCCESS;
 
 err2:
-	delete wv;
+	wv->Release();
 err1:
 	*ppvObj = NULL;
 	return hr;
 }
 
-HRESULT ConvertIbalStatus(ib_api_status_t status)
+HRESULT WvConvertIbStatus(ib_api_status_t status)
 {
-	switch (status)
-	{
+	switch (status) {
 	case IB_SUCCESS:				return WV_SUCCESS;
 	case IB_INSUFFICIENT_RESOURCES:	return WV_INSUFFICIENT_RESOURCES;
 	case IB_INSUFFICIENT_MEMORY:	return WV_NO_MEMORY;





More information about the ofw mailing list