winverbs: fixes to support OFED compatibility libraries and ND
[mirror/winof/.git] / core / winverbs / user / wv_provider.h
1 /*\r
2  * Copyright (c) 2008 Intel Corporation. All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  */\r
29 \r
30 #pragma once\r
31 \r
32 #ifndef _WV_PROVIDER_H_\r
33 #define _WV_PROVIDER_H_\r
34 \r
35 #include <rdma\winverbs.h>\r
36 #include "wv_base.h"\r
37 \r
38 extern volatile LONG WvRef;\r
39 \r
40 class CWVProvider : IWVProvider, public CWVBase\r
41 {\r
42 public:\r
43         // IUnknown methods\r
44         STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
45         STDMETHODIMP_(ULONG) AddRef();\r
46         STDMETHODIMP_(ULONG) Release();\r
47 \r
48         // IWVProvider methods\r
49         STDMETHODIMP_(HANDLE) GetFileHandle();\r
50         STDMETHODIMP QueryDeviceList(NET64* pGuidList, SIZE_T* pBufferSize);\r
51         STDMETHODIMP QueryDevice(NET64 Guid, WV_DEVICE_ATTRIBUTES* pAttributes);\r
52         STDMETHODIMP TranslateAddress(const SOCKADDR* pAddress,\r
53                                                                   WV_DEVICE_ADDRESS* pDeviceAddress);\r
54 \r
55         STDMETHODIMP OpenDevice(NET64 Guid, IWVDevice** ppDevice);\r
56 \r
57         STDMETHODIMP CreateConnectEndpoint(IWVConnectEndpoint** ppConnectEndpoint);\r
58         STDMETHODIMP CreateDatagramEndpoint(IWVDatagramEndpoint** ppDatagramEndpoint);\r
59 \r
60         CWVProvider();\r
61         ~CWVProvider();\r
62         void Delete() {delete this;}\r
63         static STDMETHODIMP CreateInstance(IWVProvider** ppProvider)\r
64         {\r
65                 WSADATA wsadata;\r
66                 HRESULT hr;\r
67                 CWVProvider *wv;\r
68 \r
69                 if (WvRef == 0) {\r
70                         hr = WSAStartup(MAKEWORD(2, 2), &wsadata);\r
71                         if (FAILED(hr)) {\r
72                                 return hr;\r
73                         }\r
74                 }\r
75 \r
76                 wv = new CWVProvider;\r
77                 if (wv == NULL) {\r
78                         hr = WV_NO_MEMORY;\r
79                         goto err1;\r
80                 }\r
81 \r
82                 hr = wv->Init();\r
83                 if (FAILED(hr)) {\r
84                         goto err2;\r
85                 }\r
86 \r
87                 wv->m_hFile = CreateFileW(L"\\\\.\\WinVerbs", GENERIC_READ | GENERIC_WRITE,\r
88                                                                   FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,\r
89                                                                   OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);\r
90                 if (wv->m_hFile == INVALID_HANDLE_VALUE) {\r
91                         hr = HRESULT_FROM_WIN32(GetLastError());\r
92                         goto err2;\r
93                 }\r
94                 *ppProvider = wv;\r
95                 return WV_SUCCESS;\r
96 \r
97         err2:\r
98                 wv->Release();\r
99         err1:\r
100                 *ppProvider = NULL;\r
101                 return hr;\r
102         }\r
103 };\r
104 \r
105 #endif // _WV_PROVIDER_H_