6
6
#define ICE_OUTGOING_ASYNC_H
7
7
8
8
#include < IceUtil/Timer.h>
9
- #include < Ice/OutgoingAsyncF.h>
10
9
#include < Ice/CommunicatorF.h>
11
10
#include < Ice/ConnectionIF.h>
12
11
#include < Ice/ObjectAdapterF.h>
23
22
namespace IceInternal
24
23
{
25
24
25
+ class OutgoingAsyncBase ;
26
26
class RetryException ;
27
27
class CollocatedRequestHandler ;
28
28
@@ -136,6 +136,8 @@ class ICE_API OutgoingAsyncBase : public virtual OutgoingAsyncCompletionCallback
136
136
static const unsigned char Sent;
137
137
};
138
138
139
+ using OutgoingAsyncBasePtr = ::std::shared_ptr<OutgoingAsyncBase>;
140
+
139
141
//
140
142
// Base class for proxy based invocations. This class handles the
141
143
// retry for proxy invocations. It also ensures the child observer is
@@ -164,7 +166,7 @@ class ICE_API ProxyOutgoingAsyncBase : public OutgoingAsyncBase,
164
166
165
167
protected:
166
168
167
- ProxyOutgoingAsyncBase (const Ice::ObjectPrx& );
169
+ ProxyOutgoingAsyncBase (Ice::ObjectPrx);
168
170
~ProxyOutgoingAsyncBase ();
169
171
170
172
void invokeImpl (bool );
@@ -184,14 +186,16 @@ class ICE_API ProxyOutgoingAsyncBase : public OutgoingAsyncBase,
184
186
bool _sent;
185
187
};
186
188
189
+ using ProxyOutgoingAsyncBasePtr = ::std::shared_ptr<ProxyOutgoingAsyncBase>;
190
+
187
191
//
188
192
// Class for handling Slice operation invocations
189
193
//
190
194
class ICE_API OutgoingAsync : public ProxyOutgoingAsyncBase
191
195
{
192
196
public:
193
197
194
- OutgoingAsync (const Ice::ObjectPrx& , bool );
198
+ OutgoingAsync (Ice::ObjectPrx, bool );
195
199
196
200
void prepare (const std::string&, Ice::OperationMode, const Ice::Context&);
197
201
@@ -220,7 +224,7 @@ class ICE_API OutgoingAsync : public ProxyOutgoingAsyncBase
220
224
{
221
225
_os.writeEmptyEncapsulation (_encoding);
222
226
}
223
- void writeParamEncaps (const ::Ice::Byte * encaps, :: std::int32_t size)
227
+ void writeParamEncaps (const ::Ice::Byte * encaps, std::int32_t size)
224
228
{
225
229
if (size == 0 )
226
230
{
@@ -239,16 +243,13 @@ class ICE_API OutgoingAsync : public ProxyOutgoingAsyncBase
239
243
bool _synchronous;
240
244
};
241
245
242
- }
243
-
244
- namespace IceInternal
245
- {
246
+ using OutgoingAsyncPtr = ::std::shared_ptr<OutgoingAsync>;
246
247
247
248
class ICE_API LambdaInvoke : public virtual OutgoingAsyncCompletionCallback
248
249
{
249
250
public:
250
251
251
- LambdaInvoke (std::function<void (:: std::exception_ptr)> exception , std::function<void (bool )> sent) :
252
+ LambdaInvoke (std::function<void (std::exception_ptr)> exception , std::function<void (bool )> sent) :
252
253
_exception (std::move(exception )), _sent(std::move(sent))
253
254
{
254
255
}
@@ -263,25 +264,21 @@ class ICE_API LambdaInvoke : public virtual OutgoingAsyncCompletionCallback
263
264
virtual void handleInvokeException (std::exception_ptr, OutgoingAsyncBase*) const override ;
264
265
virtual void handleInvokeResponse (bool , OutgoingAsyncBase*) const override ;
265
266
266
- std::function<void (:: std::exception_ptr)> _exception;
267
+ std::function<void (std::exception_ptr)> _exception;
267
268
std::function<void (bool )> _sent;
268
269
std::function<void (bool )> _response;
269
270
};
270
271
271
- template <typename Promise >
272
+ template <typename R >
272
273
class PromiseInvoke : public virtual OutgoingAsyncCompletionCallback
273
274
{
274
275
public:
275
276
276
- auto
277
- getFuture () -> decltype (std::declval<Promise>().get_future())
278
- {
279
- return _promise.get_future ();
280
- }
277
+ std::future<R> getFuture () { return _promise.get_future (); }
281
278
282
279
protected:
283
280
284
- Promise _promise;
281
+ std::promise<R> _promise;
285
282
std::function<void (bool )> _response;
286
283
287
284
private:
@@ -388,11 +385,11 @@ class LambdaOutgoing : public OutgoingAsyncT<R>, public LambdaInvoke
388
385
{
389
386
public:
390
387
391
- LambdaOutgoing (const Ice::ObjectPrx& proxy,
388
+ LambdaOutgoing (Ice::ObjectPrx proxy,
392
389
std::function<void (R)> response,
393
- std::function<void (:: std::exception_ptr)> ex,
390
+ std::function<void (std::exception_ptr)> ex,
394
391
std::function<void (bool )> sent) :
395
- OutgoingAsyncT<R>(proxy, false ), LambdaInvoke(std::move(ex), std::move(sent))
392
+ OutgoingAsyncT<R>(std::move( proxy) , false ), LambdaInvoke(std::move(ex), std::move(sent))
396
393
{
397
394
_response = [this , response = std::move (response)](bool ok)
398
395
{
@@ -424,11 +421,11 @@ class LambdaOutgoing<void> : public OutgoingAsyncT<void>, public LambdaInvoke
424
421
{
425
422
public:
426
423
427
- LambdaOutgoing (const Ice::ObjectPrx& proxy,
424
+ LambdaOutgoing (Ice::ObjectPrx proxy,
428
425
std::function<void ()> response,
429
- std::function<void (:: std::exception_ptr)> ex,
426
+ std::function<void (std::exception_ptr)> ex,
430
427
std::function<void (bool )> sent) :
431
- OutgoingAsyncT<void >(proxy, false ), LambdaInvoke(std::move(ex), std::move(sent))
428
+ OutgoingAsyncT<void >(std::move( proxy) , false ), LambdaInvoke(std::move(ex), std::move(sent))
432
429
{
433
430
_response = [this , response = std::move (response)](bool ok)
434
431
{
@@ -460,11 +457,11 @@ class CustomLambdaOutgoing : public OutgoingAsync, public LambdaInvoke
460
457
{
461
458
public:
462
459
463
- CustomLambdaOutgoing (const Ice::ObjectPrx& proxy,
460
+ CustomLambdaOutgoing (Ice::ObjectPrx proxy,
464
461
std::function<void (Ice::InputStream*)> read,
465
- std::function<void (:: std::exception_ptr)> ex,
462
+ std::function<void (std::exception_ptr)> ex,
466
463
std::function<void (bool )> sent) :
467
- OutgoingAsync (proxy, false ), LambdaInvoke(std::move(ex), std::move(sent))
464
+ OutgoingAsync (std::move( proxy) , false ), LambdaInvoke(std::move(ex), std::move(sent))
468
465
{
469
466
_response = [this , read = std::move (read )](bool ok)
470
467
{
@@ -495,13 +492,13 @@ class CustomLambdaOutgoing : public OutgoingAsync, public LambdaInvoke
495
492
}
496
493
};
497
494
498
- template <typename P, typename R>
499
- class PromiseOutgoing : public OutgoingAsyncT <R>, public PromiseInvoke<P >
495
+ template <typename R>
496
+ class PromiseOutgoing : public OutgoingAsyncT <R>, public PromiseInvoke<R >
500
497
{
501
498
public:
502
499
503
- PromiseOutgoing (const Ice::ObjectPrx& proxy, bool sync) :
504
- OutgoingAsyncT<R>(proxy, sync)
500
+ PromiseOutgoing (Ice::ObjectPrx proxy, bool sync) :
501
+ OutgoingAsyncT<R>(std::move( proxy) , sync)
505
502
{
506
503
this ->_response = [this ](bool ok)
507
504
{
@@ -521,13 +518,13 @@ class PromiseOutgoing : public OutgoingAsyncT<R>, public PromiseInvoke<P>
521
518
}
522
519
};
523
520
524
- template <typename P >
525
- class PromiseOutgoing <P, void > : public OutgoingAsyncT<void >, public PromiseInvoke<P >
521
+ template <>
522
+ class PromiseOutgoing <void > : public OutgoingAsyncT<void >, public PromiseInvoke<void >
526
523
{
527
524
public:
528
525
529
- PromiseOutgoing (const Ice::ObjectPrx& proxy, bool sync) :
530
- OutgoingAsyncT<void >(proxy, sync)
526
+ PromiseOutgoing (Ice::ObjectPrx proxy, bool sync) :
527
+ OutgoingAsyncT<void >(std::move( proxy) , sync)
531
528
{
532
529
this ->_response = [&](bool ok)
533
530
{
@@ -556,12 +553,28 @@ class PromiseOutgoing<P, void> : public OutgoingAsyncT<void>, public PromiseInvo
556
553
{
557
554
if (done)
558
555
{
559
- PromiseInvoke<P >::_promise.set_value ();
556
+ PromiseInvoke<void >::_promise.set_value ();
560
557
}
561
558
return false ;
562
559
}
563
560
};
564
561
562
+ template <typename R, typename Obj, typename Fn, typename ... Args>
563
+ inline std::future<R> makePromiseOutgoing (bool sync, Obj obj, Fn fn, Args&&... args)
564
+ {
565
+ auto outAsync = std::make_shared<PromiseOutgoing<R>>(*obj, sync );
566
+ (obj->*fn)(outAsync, std::forward<Args>(args)...);
567
+ return outAsync->getFuture ();
568
+ }
569
+
570
+ template <typename R, typename Re, typename E, typename S, typename Obj, typename Fn, typename ... Args>
571
+ inline std::function<void ()> makeLambdaOutgoing (Re r, E e, S s, Obj obj, Fn fn, Args&&... args)
572
+ {
573
+ auto outAsync = std::make_shared<LambdaOutgoing<R>>(*obj, std::move (r), std::move (e), std::move (s));
574
+ (obj->*fn)(outAsync, std::forward<Args>(args)...);
575
+ return [outAsync]() { outAsync->cancel (); };
576
+ }
577
+
565
578
}
566
579
567
580
#endif
0 commit comments