netdirect: add winverbs ND provider
[mirror/winof/.git] / ulp / netdirect / user / nd_listen.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_LISTEN_H_\r
33 #define _ND_LISTEN_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 class CNDListen : public INDListen, public CNDBase\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         // INDOverlapped methods\r
49         STDMETHODIMP CancelOverlappedRequests();\r
50         STDMETHODIMP GetOverlappedResult(OVERLAPPED *pOverlapped,\r
51                                                                          SIZE_T *pNumberOfBytesTransferred, BOOL bWait);\r
52 \r
53         // INDListen methods\r
54         STDMETHODIMP GetConnectionRequest(INDConnector* pConnector,\r
55                                                                           OVERLAPPED* pOverlapped);\r
56 \r
57         CNDListen(CNDAdapter *pAdapter);\r
58         ~CNDListen();\r
59         void Delete() {delete this;}\r
60         static STDMETHODIMP\r
61         CreateInstance(CNDAdapter *pAdapter, SIZE_T Backlog, INT Protocol, USHORT Port,\r
62                                    USHORT* pAssignedPort, INDListen** ppListen)\r
63         {\r
64                 HRESULT hr;\r
65                 CNDListen *listener;\r
66 \r
67                 listener = new CNDListen(pAdapter);\r
68                 if (listener == NULL) {\r
69                         hr = ND_NO_MEMORY;\r
70                         goto err1;\r
71                 }\r
72 \r
73                 hr = listener->Init(Backlog, Protocol, &Port);\r
74                 if (FAILED(hr)) {\r
75                         goto err2;\r
76                 }\r
77 \r
78                 if (pAssignedPort) {\r
79                         *pAssignedPort = Port;\r
80                 }\r
81                 *ppListen = listener;\r
82                 return ND_SUCCESS;\r
83 \r
84         err2:\r
85                 listener->Release();\r
86         err1:\r
87                 *ppListen = NULL;\r
88                 return hr;\r
89         }\r
90 \r
91 protected:\r
92         CNDAdapter                      *m_pAdapter;\r
93         IWVConnectEndpoint      *m_pWvConnEp;\r
94 \r
95         STDMETHODIMP            Init(SIZE_T Backlog, INT Protocol, USHORT *pPort);\r
96 };\r
97 \r
98 #endif // _ND_LISTEN_H_\r