1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
// **********************************************************************
//
// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#ifndef ICE_ASYNC_RESULT_H
#define ICE_ASYNC_RESULT_H
#include <IceUtil/Monitor.h>
#include <IceUtil/Mutex.h>
#include <IceUtil/UniquePtr.h>
#include <Ice/LocalObject.h>
#include <Ice/CommunicatorF.h>
#include <Ice/ConnectionF.h>
#include <Ice/ProxyF.h>
#include <Ice/InstanceF.h>
#include <Ice/RequestHandlerF.h>
#include <Ice/AsyncResultF.h>
#include <Ice/ObserverHelper.h>
#include <Ice/InputStream.h>
#include <Ice/VirtualShared.h>
namespace IceInternal
{
class CallbackBase;
ICE_DEFINE_PTR(CallbackBasePtr, CallbackBase);
}
namespace Ice
{
class ICE_API AsyncResult : private IceUtil::noncopyable,
#ifdef ICE_CPP11_MAPPING
public ::std::enable_shared_from_this<::Ice::AsyncResult>
#else
public Ice::LocalObject
#endif
{
public:
#ifdef ICE_CPP11_MAPPING
AsyncResult(const CommunicatorPtr&, const IceInternal::InstancePtr&, const std::string&,
const IceInternal::CallbackBasePtr&);
#else
AsyncResult(const CommunicatorPtr&, const IceInternal::InstancePtr&, const std::string&,
const IceInternal::CallbackBasePtr&, const LocalObjectPtr&);
#endif
virtual ~AsyncResult(); // Must be heap-allocated
void cancel();
Int getHash() const;
CommunicatorPtr getCommunicator() const;
virtual ConnectionPtr getConnection() const;
virtual ObjectPrxPtr getProxy() const;
bool isCompleted() const;
void waitForCompleted();
bool isSent() const;
void waitForSent();
void throwLocalException() const;
bool sentSynchronously() const;
#ifndef ICE_CPP11_MAPPING
LocalObjectPtr getCookie() const;
#endif
const std::string& getOperation() const;
::Ice::InputStream* __startReadParams()
{
_is.startEncapsulation();
return &_is;
}
void __endReadParams()
{
_is.endEncapsulation();
}
void __readEmptyParams()
{
_is.skipEmptyEncapsulation();
}
void __readParamEncaps(const ::Ice::Byte*& encaps, ::Ice::Int& sz)
{
_is.readEncapsulation(encaps, sz);
}
void __throwUserException();
bool __wait();
static void __check(const AsyncResultPtr&, const ::IceProxy::Ice::Object*, const ::std::string&);
static void __check(const AsyncResultPtr&, const Connection*, const ::std::string&);
static void __check(const AsyncResultPtr&, const Communicator*, const ::std::string&);
protected:
static void __check(const AsyncResultPtr&, const ::std::string&);
bool sent(bool);
bool finished(bool);
bool finished(const Exception&);
void invokeSentAsync();
void invokeCompletedAsync();
void invokeSent();
void invokeCompleted();
void cancel(const LocalException&);
virtual void cancelable(const IceInternal::CancellationHandlerPtr&);
void checkCanceled();
void warning(const std::exception&) const;
void warning() const;
//
// This virtual method is necessary for the communicator flush
// batch requests implementation.
//
virtual IceInternal::InvocationObserver& getObserver()
{
return _observer;
}
const IceInternal::InstancePtr _instance;
IceInternal::InvocationObserver _observer;
Ice::ConnectionPtr _cachedConnection;
bool _sentSynchronously;
Ice::InputStream _is;
IceUtil::Monitor<IceUtil::Mutex> _monitor;
private:
const CommunicatorPtr _communicator;
const std::string& _operation;
const IceInternal::CallbackBasePtr _callback;
const LocalObjectPtr _cookie;
#ifdef ICE_CPP11_MAPPING
std::exception_ptr _exception;
#else
IceUtil::UniquePtr<Exception> _exception;
#endif
IceInternal::CancellationHandlerPtr _cancellationHandler;
#ifdef ICE_CPP11_MAPPING
std::exception_ptr _cancellationException;
#else
IceUtil::UniquePtr<Ice::LocalException> _cancellationException;
#endif
static const unsigned char OK;
static const unsigned char Done;
static const unsigned char Sent;
static const unsigned char EndCalled;
static const unsigned char Canceled;
unsigned char _state;
};
}
namespace IceInternal
{
//
// Base class for all callbacks.
//
class ICE_API CallbackBase : public Ice::EnableSharedFromThis<CallbackBase>
{
public:
void checkCallback(bool, bool);
virtual void completed(const ::Ice::AsyncResultPtr&) const = 0;
#ifndef ICE_CPP11_MAPPING
virtual CallbackBasePtr verify(const ::Ice::LocalObjectPtr&) = 0;
#endif
virtual void sent(const ::Ice::AsyncResultPtr&) const = 0;
virtual bool hasSentCallback() const = 0;
};
//
// Base class for generic callbacks.
//
class ICE_API GenericCallbackBase : public virtual CallbackBase
{
};
//
// See comments in OutgoingAsync.cpp
//
extern ICE_API CallbackBasePtr __dummyCallback;
//
// Generic callback template that requires the caller to down-cast the
// proxy and the cookie that are obtained from the AsyncResult.
//
template<class T>
class AsyncCallback : public GenericCallbackBase
{
public:
typedef T callback_type;
typedef IceUtil::Handle<T> TPtr;
typedef void (T::*Callback)(const ::Ice::AsyncResultPtr&);
AsyncCallback(const TPtr& instance, Callback cb, Callback sentcb = 0) :
_callback(instance), _completed(cb), _sent(sentcb)
{
checkCallback(instance, cb != 0);
}
virtual void completed(const ::Ice::AsyncResultPtr& result) const
{
(_callback.get()->*_completed)(result);
}
virtual CallbackBasePtr verify(const ::Ice::LocalObjectPtr&)
{
return this; // Nothing to do, the cookie is not type-safe.
}
virtual void sent(const ::Ice::AsyncResultPtr& result) const
{
if(_sent)
{
(_callback.get()->*_sent)(result);
}
}
virtual bool hasSentCallback() const
{
return _sent != 0;
}
private:
TPtr _callback;
Callback _completed;
Callback _sent;
};
}
namespace Ice
{
#ifndef ICE_CPP11_MAPPING
typedef IceUtil::Handle< ::IceInternal::GenericCallbackBase> CallbackPtr;
template<class T> CallbackPtr
newCallback(const IceUtil::Handle<T>& instance,
void (T::*cb)(const AsyncResultPtr&),
void (T::*sentcb)(const AsyncResultPtr&) = 0)
{
return new ::IceInternal::AsyncCallback<T>(instance, cb, sentcb);
}
template<class T> CallbackPtr
newCallback(T* instance,
void (T::*cb)(const AsyncResultPtr&),
void (T::*sentcb)(const AsyncResultPtr&) = 0)
{
return new ::IceInternal::AsyncCallback<T>(instance, cb, sentcb);
}
#endif
}
//
// Operation callbacks are specified in Proxy.h
//
#endif
|