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
|
// **********************************************************************
//
// Copyright (c) 2003-2016 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.
//
// **********************************************************************
#include <Ice/Ice.h>
#include <BlobjectI.h>
using namespace std;
#ifndef ICE_CPP11_MAPPING
class Callback : public IceUtil::Shared
{
public:
Callback(const Ice::AMD_Object_ice_invokePtr& cb, bool twoway) :
_cb(cb), _twoway(twoway)
{
}
void response(bool ok, const vector<Ice::Byte>& encaps)
{
_cb->ice_response(ok, encaps);
}
void exception(const Ice::Exception& ex)
{
_cb->ice_exception(ex);
}
void sent(bool)
{
if(!_twoway)
{
_cb->ice_response(true, vector<Ice::Byte>());
}
}
private:
Ice::AMD_Object_ice_invokePtr _cb;
bool _twoway;
};
typedef IceUtil::Handle<Callback> CallbackPtr;
#endif
BlobjectI::BlobjectI() :
_startBatch(false)
{
}
void
BlobjectI::startBatch()
{
assert(!_batchProxy);
_startBatch = true;
}
void
BlobjectI::flushBatch()
{
assert(_batchProxy);
_batchProxy->ice_flushBatchRequests();
_batchProxy = 0;
}
#ifdef ICE_CPP11_MAPPING
void
BlobjectI::ice_invokeAsync(std::vector<Ice::Byte> inEncaps,
std::function<void(bool, std::vector<Ice::Byte>)> response,
std::function<void(std::exception_ptr)> ex,
const Ice::Current& current)
{
const bool twoway = current.requestId > 0;
auto obj = current.con->createProxy(current.id);
if(!twoway)
{
if(_startBatch)
{
_startBatch = false;
_batchProxy = obj->ice_batchOneway();
}
if(_batchProxy)
{
obj = _batchProxy;
}
if(!current.facet.empty())
{
obj = obj->ice_facet(current.facet);
}
if(_batchProxy)
{
vector<Ice::Byte> out;
obj->ice_invoke(current.operation, current.mode, inEncaps, out, current.ctx);
response(true, vector<Ice::Byte>());
}
else
{
obj->ice_oneway()->ice_invokeAsync(current.operation, current.mode, inEncaps,
[](bool, std::vector<Ice::Byte>) { assert(0); },
ex,
[&](bool) { response(true, vector<Ice::Byte>()); },
current.ctx);
}
}
else
{
if(!current.facet.empty())
{
obj = obj->ice_facet(current.facet);
}
obj->ice_invokeAsync(current.operation, current.mode, inEncaps, response, ex, nullptr, current.ctx);
}
}
#else
void
BlobjectI::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& amdCb, const vector<Ice::Byte>& inEncaps,
const Ice::Current& current)
{
const bool twoway = current.requestId > 0;
Ice::ObjectPrx obj = current.con->createProxy(current.id);
if(!twoway)
{
if(_startBatch)
{
_startBatch = false;
_batchProxy = obj->ice_batchOneway();
}
if(_batchProxy)
{
obj = _batchProxy;
}
if(!current.facet.empty())
{
obj = obj->ice_facet(current.facet);
}
if(_batchProxy)
{
vector<Ice::Byte> out;
obj->ice_invoke(current.operation, current.mode, inEncaps, out, current.ctx);
amdCb->ice_response(true, vector<Ice::Byte>());
}
else
{
CallbackPtr cb = new Callback(amdCb, false);
Ice::Callback_Object_ice_invokePtr del =
Ice::newCallback_Object_ice_invoke(cb, &Callback::response, &Callback::exception, &Callback::sent);
obj->ice_oneway()->begin_ice_invoke(current.operation, current.mode, inEncaps, current.ctx, del);
}
}
else
{
if(!current.facet.empty())
{
obj = obj->ice_facet(current.facet);
}
CallbackPtr cb = new Callback(amdCb, true);
Ice::Callback_Object_ice_invokePtr del =
Ice::newCallback_Object_ice_invoke(cb, &Callback::response, &Callback::exception, &Callback::sent);
obj->begin_ice_invoke(current.operation, current.mode, inEncaps, current.ctx, del);
}
}
#endif
|