[RPCRT4]
[reactos.git] / reactos / 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 #include "precomp.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
25
26 #define RPC_ASYNC_SIGNATURE 0x43595341
27
28 static inline BOOL valid_async_handle(PRPC_ASYNC_STATE pAsync)
29 {
30 return pAsync->Signature == RPC_ASYNC_SIGNATURE;
31 }
32
33 /***********************************************************************
34 * RpcAsyncInitializeHandle [RPCRT4.@]
35 *
36 * Initialises an asynchronous state so it can be used in other asynchronous
37 * functions and for use in asynchronous calls.
38 *
39 * PARAMS
40 * pAsync [I] Asynchronous state to initialise.
41 * Size [I] Size of the memory pointed to by pAsync.
42 *
43 * RETURNS
44 * Success: RPC_S_OK.
45 * Failure: Any error code.
46 */
47 RPC_STATUS WINAPI RpcAsyncInitializeHandle(PRPC_ASYNC_STATE pAsync, unsigned int Size)
48 {
49 TRACE("(%p, %d)\n", pAsync, Size);
50
51 if (Size != sizeof(*pAsync))
52 {
53 ERR("invalid Size %d\n", Size);
54 return ERROR_INVALID_PARAMETER;
55 }
56
57 pAsync->Size = sizeof(*pAsync);
58 pAsync->Signature = RPC_ASYNC_SIGNATURE;
59 pAsync->Lock = 0;
60 pAsync->Flags = 0;
61 pAsync->StubInfo = NULL;
62 pAsync->RuntimeInfo = NULL;
63 memset(pAsync->Reserved, 0, sizeof(*pAsync) - FIELD_OFFSET(RPC_ASYNC_STATE, Reserved));
64
65 return RPC_S_OK;
66 }
67
68 /***********************************************************************
69 * RpcAsyncGetCallStatus [RPCRT4.@]
70 *
71 * Retrieves the current status of the asynchronous call taking place.
72 *
73 * PARAMS
74 * pAsync [I] Asynchronous state to initialise.
75 *
76 * RETURNS
77 * RPC_S_OK - The call was successfully completed.
78 * RPC_S_INVALID_ASYNC_HANDLE - The asynchronous structure is not valid.
79 * RPC_S_ASYNC_CALL_PENDING - The call is still in progress and has not been completed.
80 * Any other error code - The call failed.
81 */
82 RPC_STATUS WINAPI RpcAsyncGetCallStatus(PRPC_ASYNC_STATE pAsync)
83 {
84 FIXME("(%p): stub\n", pAsync);
85 return RPC_S_INVALID_ASYNC_HANDLE;
86 }
87
88 /***********************************************************************
89 * RpcAsyncCompleteCall [RPCRT4.@]
90 *
91 * Completes a client or server asynchronous call.
92 *
93 * PARAMS
94 * pAsync [I] Asynchronous state to initialise.
95 * Reply [I] The return value of the asynchronous function.
96 *
97 * RETURNS
98 * Success: RPC_S_OK.
99 * Failure: Any error code.
100 */
101 RPC_STATUS WINAPI RpcAsyncCompleteCall(PRPC_ASYNC_STATE pAsync, void *Reply)
102 {
103 TRACE("(%p, %p)\n", pAsync, Reply);
104
105 if (!valid_async_handle(pAsync))
106 return RPC_S_INVALID_ASYNC_HANDLE;
107
108 /* FIXME: check completed */
109
110 return NdrpCompleteAsyncClientCall(pAsync, Reply);
111 }
112
113 /***********************************************************************
114 * RpcAsyncAbortCall [RPCRT4.@]
115 *
116 * Aborts the asynchronous server call taking place.
117 *
118 * PARAMS
119 * pAsync [I] Asynchronous server state to abort.
120 * ExceptionCode [I] Exception code to return to the client in a fault packet.
121 *
122 * RETURNS
123 * Success: RPC_S_OK.
124 * Failure: Any error code.
125 */
126 RPC_STATUS WINAPI RpcAsyncAbortCall(PRPC_ASYNC_STATE pAsync, ULONG ExceptionCode)
127 {
128 FIXME("(%p, %d/0x%x): stub\n", pAsync, ExceptionCode, ExceptionCode);
129 return RPC_S_INVALID_ASYNC_HANDLE;
130 }
131
132 /***********************************************************************
133 * RpcAsyncCancelCall [RPCRT4.@]
134 *
135 * Cancels the asynchronous client call taking place.
136 *
137 * PARAMS
138 * pAsync [I] Asynchronous client state to abort.
139 * fAbortCall [I] If TRUE, then send a cancel to the server, otherwise
140 * just wait for the call to complete.
141 *
142 * RETURNS
143 * Success: RPC_S_OK.
144 * Failure: Any error code.
145 */
146 RPC_STATUS WINAPI RpcAsyncCancelCall(PRPC_ASYNC_STATE pAsync, BOOL fAbortCall)
147 {
148 FIXME("(%p, %s): stub\n", pAsync, fAbortCall ? "TRUE" : "FALSE");
149 return RPC_S_INVALID_ASYNC_HANDLE;
150 }