netdirect: add winverbs ND provider
[mirror/winof/.git] / ulp / netdirect / user / nd_connect.h
1 /*\r
2  * Copyright (c) 2009 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 AND\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 _ND_CONNECTOR_H_\r
33 #define _ND_CONNECTOR_H_\r
34 \r
35 #include <initguid.h>\r
36 #include <ndspi.h>\r
37 #include "nd_base.h"\r
38 #include "nd_adapter.h"\r
39 \r
40 \r
41 #define ND_PRIVATE_DATA_SIZE    56\r
42 \r
43 \r
44 class CNDConnector : public INDConnector, public CNDBase\r
45 {\r
46 public:\r
47         // IUnknown methods\r
48         STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppvObj);\r
49         STDMETHODIMP_(ULONG) AddRef();\r
50         STDMETHODIMP_(ULONG) Release();\r
51 \r
52         // INDOverlapped methods\r
53         STDMETHODIMP CancelOverlappedRequests();\r
54         STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
55                                                                          SIZE_T *pNumberOfBytesTransferred, BOOL bWait);\r
56 \r
57         // INDConnector methods\r
58         STDMETHODIMP CreateEndpoint(INDCompletionQueue* pInboundCq,\r
59                                                                 INDCompletionQueue* pOutboundCq,\r
60                                                                 SIZE_T nInboundEntries, SIZE_T nOutboundEntries,\r
61                                                                 SIZE_T nInboundSge, SIZE_T nOutboundSge,\r
62                                                                 SIZE_T InboundReadLimit, SIZE_T OutboundReadLimit,\r
63                                                                 SIZE_T* pMaxInlineData, INDEndpoint** ppEndpoint);\r
64         STDMETHODIMP Connect(INDEndpoint* pEndpoint, \r
65                                                  const struct sockaddr* pAddress, SIZE_T AddressLength,\r
66                                                  INT Protocol, USHORT LocalPort,\r
67                                                  const void* pPrivateData, SIZE_T PrivateDataLength,\r
68                                                  OVERLAPPED* pOverlapped);\r
69         STDMETHODIMP CompleteConnect(OVERLAPPED* pOverlapped);\r
70         STDMETHODIMP Accept(INDEndpoint* pEndpoint,\r
71                                                 const void* pPrivateData, SIZE_T PrivateDataLength,\r
72                                                 OVERLAPPED* pOverlapped);\r
73         STDMETHODIMP Reject(const void* pPrivateData, SIZE_T PrivateDataLength);\r
74         STDMETHODIMP GetConnectionData(SIZE_T* pInboundReadLimit,\r
75                                                                    SIZE_T* pOutboundReadLimit,\r
76                                                                    void* pPrivateData, SIZE_T* pPrivateDataLength);\r
77         STDMETHODIMP GetLocalAddress(struct sockaddr* pAddress, SIZE_T* pAddressLength);\r
78         STDMETHODIMP GetPeerAddress(struct sockaddr* pAddress, SIZE_T* pAddressLength);\r
79         STDMETHODIMP NotifyDisconnect(OVERLAPPED* pOverlapped);\r
80         STDMETHODIMP Disconnect(OVERLAPPED* pOverlapped);\r
81 \r
82         CNDConnector(CNDAdapter *pAdapter);\r
83         ~CNDConnector();\r
84         void Delete() {delete this;}\r
85         static STDMETHODIMP\r
86         CreateInstance(CNDAdapter *pAdapter, INDConnector** ppConnector)\r
87         {\r
88                 HRESULT hr;\r
89                 CNDConnector *conn;\r
90 \r
91                 conn = new CNDConnector(pAdapter);\r
92                 if (conn == NULL) {\r
93                         hr = ND_NO_MEMORY;\r
94                         goto err1;\r
95                 }\r
96 \r
97                 hr = conn->Init();\r
98                 if (FAILED(hr)) {\r
99                         goto err2;\r
100                 }\r
101 \r
102                 *ppConnector = conn;\r
103                 return ND_SUCCESS;\r
104 \r
105         err2:\r
106                 conn->Release();\r
107         err1:\r
108                 *ppConnector = NULL;\r
109                 return hr;\r
110         }\r
111 \r
112         IWVConnectEndpoint      *m_pWvConnEp;\r
113         CNDAdapter                      *m_pAdapter;\r
114 \r
115 protected:\r
116         STDMETHODIMP            Init();\r
117 };\r
118 \r
119 #endif // _ND_CONNECTOR_H_\r