[ofw] [PATCH] winverbs: add framework for allocating device object
Sean Hefty
sean.hefty at intel.com
Thu Mar 6 00:08:52 PST 2008
Allow allocating and destroying the device object. Only the structure
is allocated. The device is not associated with any specific RDMA
device.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Test app has been updated as well.
Index: winverbs/core/winverbs/user/wv_device.cpp
===================================================================
--- winverbs/core/winverbs/user/wv_device.cpp (revision 974)
+++ winverbs/core/winverbs/user/wv_device.cpp (working copy)
@@ -33,22 +33,32 @@
STDMETHODIMP CWVDevice::
QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
{
- UNREFERENCED_PARAMETER(riid);
- UNREFERENCED_PARAMETER(ppvObj);
+ if (riid != IID_IUnknown && riid != IID_IWVDevice)
+ {
+ *ppvObj = NULL;
+ return E_NOINTERFACE;
+ }
- return E_NOTIMPL;
+ *ppvObj = this;
+ InterlockedIncrement(&m_nRef);
+ return WV_SUCCESS;
}
STDMETHODIMP_(ULONG) CWVDevice::
AddRef(void)
{
- return 0;
+ return InterlockedIncrement(&m_nRef);
}
STDMETHODIMP_(ULONG) CWVDevice::
Release(void)
{
- return 0;
+ ULONG ref;
+
+ ref = (ULONG) InterlockedDecrement(&m_nRef);
+ if (ref == 0)
+ delete this;
+ return ref;
}
STDMETHODIMP CWVDevice::
@@ -68,6 +78,14 @@
return E_NOTIMPL;
}
+STDMETHODIMP CWVDevice::
+Open(UINT64 Guid)
+{
+ UNREFERENCED_PARAMETER(Guid);
+
+ return E_NOTIMPL;
+}
+
//static void
//SetDeviceCap(DWORD *pFlags, ib_ca_attr_t *pCaAttr)
//{
Index: winverbs/core/winverbs/user/wv_device.h
===================================================================
--- winverbs/core/winverbs/user/wv_device.h (revision 974)
+++ winverbs/core/winverbs/user/wv_device.h (working copy)
@@ -55,6 +55,23 @@
STDMETHODIMP CreateCompletionQueue(SIZE_T *pEntries, IWVCompletionQueue** ppCq);
STDMETHODIMP AllocateProtectionDomain(IWVProtectionDomain** ppPd);
STDMETHODIMP Notify(OVERLAPPED* pOverlapped, WV_EVENT* pEvent);
+
+ CWVDevice(IWVProvider *pProvider)
+ {
+ pProvider->AddRef();
+ m_pProvider = pProvider;
+ m_nRef = 0;
+ }
+ ~CWVDevice()
+ {
+ m_pProvider->Release();
+ }
+
+ STDMETHODIMP Open(UINT64 Guid);
+
+private:
+ volatile LONG m_nRef;
+ IWVProvider *m_pProvider;
};
#endif // __WV_DEVICE_H_
Index: winverbs/core/winverbs/user/wv_provider.cpp
===================================================================
--- winverbs/core/winverbs/user/wv_provider.cpp (revision 980)
+++ winverbs/core/winverbs/user/wv_provider.cpp (working copy)
@@ -29,6 +29,7 @@
#include "wv_base.h"
#include "wv_provider.h"
+#include "wv_device.h"
STDMETHODIMP CWVProvider::
QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
@@ -73,10 +74,17 @@
STDMETHODIMP CWVProvider::
QueryDevice(UINT64 Guid, WV_DEVICE_ATTRIBUTES* pAttributes)
{
- UNREFERENCED_PARAMETER(Guid);
- UNREFERENCED_PARAMETER(pAttributes);
+ IWVDevice *dev;
+ HRESULT hr;
- return E_NOTIMPL;
+ hr = OpenDevice(Guid, &dev);
+ if (hr != WV_SUCCESS)
+ goto out;
+
+ hr = dev->Query(pAttributes);
+ dev->Release();
+out:
+ return hr;
}
STDMETHODIMP CWVProvider::
@@ -91,10 +99,29 @@
STDMETHODIMP CWVProvider::
OpenDevice(UINT64 Guid, IWVDevice** ppDevice)
{
- UNREFERENCED_PARAMETER(Guid);
- UNREFERENCED_PARAMETER(ppDevice);
+ HRESULT hr;
+ CWVDevice *dev;
- return E_NOTIMPL;
+ dev = new CWVDevice(this);
+ if (!dev)
+ {
+ hr = WV_NO_MEMORY;
+ goto err1;
+ }
+
+ dev->QueryInterface(IID_IWVDevice, (LPVOID*) ppDevice);
+
+ hr = dev->Open(Guid);
+ if (hr != WV_SUCCESS)
+ goto err2;
+
+ return WV_SUCCESS;
+
+err2:
+ dev->Release();
+err1:
+ *ppDevice = NULL;
+ return hr;
}
STDMETHODIMP CWVProvider::
More information about the ofw
mailing list