Sunc with trunk revision 58971.
[reactos.git] / dll / win32 / rpcrt4 / rpc_async.c
1 /*
2 * Asynchronous Call Support Functions
3 *
4 * Copyright 2007 Robert Shearman (for CodeWeavers)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 */
21
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24
25 #include <stdarg.h>
26
27 #include <windef.h>
28 #include <winbase.h>
29 #include <rpc.h>
30 #include <rpcndr.h>
31 //#include "rpcasync.h"
32
33 #include <wine/debug.h>
34
35 //#include "rpc_binding.h"
36 //#include "rpc_message.h"
37 #include "ndr_stubless.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
40
41 #define RPC_ASYNC_SIGNATURE 0x43595341
42
43 static inline BOOL valid_async_handle(PRPC_ASYNC_STATE pAsync)
44 {
45 return pAsync->Signature == RPC_ASYNC_SIGNATURE;
46 }
47
48 /***********************************************************************
49 * RpcAsyncInitializeHandle [RPCRT4.@]
50 *
51 * Initialises an asynchronous state so it can be used in other asynchronous
52 * functions and for use in asynchronous calls.
53 *
54 * PARAMS
55 * pAsync [I] Asynchronous state to initialise.
56 * Size [I] Size of the memory pointed to by pAsync.
57 *
58 * RETURNS
59 * Success: RPC_S_OK.
60 * Failure: Any error code.
61 */
62 RPC_STATUS WINAPI RpcAsyncInitializeHandle(PRPC_ASYNC_STATE pAsync, unsigned int Size)
63 {
64 TRACE("(%p, %d)\n", pAsync, Size);
65
66 if (Size != sizeof(*pAsync))
67 {
68 ERR("invalid Size %d\n", Size);
69 return ERROR_INVALID_PARAMETER;
70 }
71
72 pAsync->Size = sizeof(*pAsync);
73 pAsync->Signature = RPC_ASYNC_SIGNATURE;
74 pAsync->Lock = 0;
75 pAsync->Flags = 0;
76 pAsync->StubInfo = NULL;
77 pAsync->RuntimeInfo = NULL;
78 memset(pAsync->Reserved, 0, sizeof(*pAsync) - FIELD_OFFSET(RPC_ASYNC_STATE, Reserved));
79
80 return RPC_S_OK;
81 }
82
83 /***********************************************************************
84 * RpcAsyncGetCallStatus [RPCRT4.@]
85 *
86 * Retrieves the current status of the asynchronous call taking place.
87 *
88 * PARAMS
89 * pAsync [I] Asynchronous state to initialise.
90 *
91 * RETURNS
92 * RPC_S_OK - The call was successfully completed.
93 * RPC_S_INVALID_ASYNC_HANDLE - The asynchronous structure is not valid.
94 * RPC_S_ASYNC_CALL_PENDING - The call is still in progress and has not been completed.
95 * Any other error code - The call failed.
96 */
97 RPC_STATUS WINAPI RpcAsyncGetCallStatus(PRPC_ASYNC_STATE pAsync)
98 {
99 FIXME("(%p): stub\n", pAsync);
100 return RPC_S_INVALID_ASYNC_HANDLE;
101 }
102
103 /***********************************************************************
104 * RpcAsyncCompleteCall [RPCRT4.@]
105 *
106 * Completes a client or server asynchronous call.
107 *
108 * PARAMS
109 * pAsync [I] Asynchronous state to initialise.
110 * Reply [I] The return value of the asynchronous function.
111 *
112 * RETURNS
113 * Success: RPC_S_OK.
114 * Failure: Any error code.
115 */
116 RPC_STATUS WINAPI RpcAsyncCompleteCall(PRPC_ASYNC_STATE pAsync, void *Reply)
117 {
118 TRACE("(%p, %p)\n", pAsync, Reply);
119
120 if (!valid_async_handle(pAsync))
121 return RPC_S_INVALID_ASYNC_HANDLE;
122
123 /* FIXME: check completed */
124
125 return NdrpCompleteAsyncClientCall(pAsync, Reply);
126 }
127
128 /***********************************************************************
129 * RpcAsyncAbortCall [RPCRT4.@]
130 *
131 * Aborts the asynchronous server call taking place.
132 *
133 * PARAMS
134 * pAsync [I] Asynchronous server state to abort.
135 * ExceptionCode [I] Exception code to return to the client in a fault packet.
136 *
137 * RETURNS
138 * Success: RPC_S_OK.
139 * Failure: Any error code.
140 */
141 RPC_STATUS WINAPI RpcAsyncAbortCall(PRPC_ASYNC_STATE pAsync, ULONG ExceptionCode)
142 {
143 FIXME("(%p, %d/0x%x): stub\n", pAsync, ExceptionCode, ExceptionCode);
144 return RPC_S_INVALID_ASYNC_HANDLE;
145 }
146
147 /***********************************************************************
148 * RpcAsyncCancelCall [RPCRT4.@]
149 *
150 * Cancels the asynchronous client call taking place.
151 *
152 * PARAMS
153 * pAsync [I] Asynchronous client state to abort.
154 * fAbortCall [I] If TRUE, then send a cancel to the server, otherwise
155 * just wait for the call to complete.
156 *
157 * RETURNS
158 * Success: RPC_S_OK.
159 * Failure: Any error code.
160 */
161 RPC_STATUS WINAPI RpcAsyncCancelCall(PRPC_ASYNC_STATE pAsync, BOOL fAbortCall)
162 {
163 FIXME("(%p, %s): stub\n", pAsync, fAbortCall ? "TRUE" : "FALSE");
164 return RPC_S_INVALID_ASYNC_HANDLE;
165 }