[IBBUS] __iou/port_was_hibernated() change NTSTATUS --> ib_api_status_t to be consist...
[mirror/winof/.git] / core / winmad / user / wm_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 _WM_PROVIDER_H_\r
33 #define _WM_PROVIDER_H_\r
34 \r
35 #include <iba\winmad.h>\r
36 \r
37 extern volatile LONG WmRef;\r
38 \r
39 class CWMProvider : IWMProvider\r
40 {\r
41 public:\r
42         // IUnknown methods\r
43         STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
44         STDMETHODIMP_(ULONG) AddRef();\r
45         STDMETHODIMP_(ULONG) Release();\r
46 \r
47         // IWVProvider methods\r
48         STDMETHODIMP CancelOverlappedRequests();\r
49         STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
50                                                                          DWORD *pNumberOfBytesTransferred, BOOL bWait);\r
51 \r
52         STDMETHODIMP_(HANDLE) GetFileHandle();\r
53         STDMETHODIMP Register(WM_REGISTER *pAttributes, UINT64 *pId);\r
54         STDMETHODIMP Deregister(UINT64 Id);\r
55         STDMETHODIMP Send(WM_MAD *pMad, OVERLAPPED *pOverlapped);\r
56         STDMETHODIMP Receive(WM_MAD *pMad, SIZE_T BufferSize, OVERLAPPED *pOverlapped);\r
57 \r
58         CWMProvider();\r
59         STDMETHODIMP Init();\r
60         ~CWMProvider();\r
61         void Delete() {delete this;}\r
62         static STDMETHODIMP CreateInstance(IWMProvider** ppProvider)\r
63         {\r
64                 HRESULT hr;\r
65                 CWMProvider *wm;\r
66 \r
67                 wm = new CWMProvider;\r
68                 if (wm == NULL) {\r
69                         hr = E_OUTOFMEMORY;\r
70                         goto err1;\r
71                 }\r
72 \r
73                 hr = wm->Init();\r
74                 if (FAILED(hr)) {\r
75                         goto err2;\r
76                 }\r
77 \r
78                 wm->m_hFile = CreateFileW(L"\\\\.\\WinMad", GENERIC_READ | GENERIC_WRITE,\r
79                                                                   FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,\r
80                                                                   OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);\r
81                 if (wm->m_hFile == INVALID_HANDLE_VALUE) {\r
82                         hr = HRESULT_FROM_WIN32(GetLastError());\r
83                         goto err2;\r
84                 }\r
85                 *ppProvider = wm;\r
86                 return NOERROR;\r
87 \r
88         err2:\r
89                 wm->Release();\r
90         err1:\r
91                 *ppProvider = NULL;\r
92                 return hr;\r
93         }\r
94 \r
95         HANDLE                                  m_hFile;\r
96         volatile LONG                   m_nRef;\r
97 protected:\r
98         STDMETHODIMP_(BOOL) WmDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,\r
99                                                                                   LPVOID lpInBuffer, DWORD nInBufferSize,\r
100                                                                                   LPVOID lpOutBuffer, DWORD nOutBufferSize,\r
101                                                                                   LPDWORD lpBytesReturned,\r
102                                                                                   LPOVERLAPPED lpOverlapped);\r
103         STDMETHODIMP_(BOOL) WmReadFile(HANDLE hFile, LPVOID lpBuffer,\r
104                                                                    DWORD nNumberOfBytesToRead,\r
105                                                                    LPDWORD lpNumberOfBytesRead,\r
106                                                                    LPOVERLAPPED lpOverlapped);\r
107         STDMETHODIMP_(BOOL) WmWriteFile(HANDLE hFile, LPVOID lpBuffer,\r
108                                                                         DWORD nNumberIfBytesToWrite,\r
109                                                                         LPDWORD lpNumberOfBytesWritten,\r
110                                                                         LPOVERLAPPED lpOverlapped);\r
111 \r
112         OVERLAPPED                              m_OverlapWrite;\r
113         OVERLAPPED                              m_OverlapRead;\r
114         CRITICAL_SECTION                m_CritSecWrite;\r
115         CRITICAL_SECTION                m_CritSecRead;\r
116 };\r
117 \r
118 #endif // _WM_PROVIDER_H_