diff options
Diffstat (limited to 'cpp/src/Ice/Proxy.cpp')
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 462 |
1 files changed, 408 insertions, 54 deletions
diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index e13ea2ef1ab..893ae34fc39 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -39,6 +39,8 @@ const string ice_ping_name = "ice_ping"; const string ice_ids_name = "ice_ids"; const string ice_id_name = "ice_id"; const string ice_isA_name = "ice_isA"; +const string ice_invoke_name = "ice_invoke"; +const string ice_flushBatchRequests_name = "ice_flushBatchRequests"; } @@ -133,22 +135,68 @@ IceProxy::Ice::Object::ice_isA(const string& typeId, const Context* context) } catch(const LocalExceptionWrapper& __ex) { - __handleExceptionWrapperRelaxed(__del, __ex, 0, __cnt); + __handleExceptionWrapperRelaxed(__del, __ex, true, __cnt); } catch(const LocalException& __ex) { - __handleException(__del, __ex, 0, __cnt); + __handleException(__del, __ex, true, __cnt); } } } +Ice::AsyncResultPtr +IceProxy::Ice::Object::begin_ice_isA(const string& typeId, + const Context* ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_isA_name, del, cookie); + try + { + __checkTwowayOnly(ice_isA_name); + __result->__prepare(ice_isA_name, Normal, ctx); + IceInternal::BasicStream* __os = __result->__getOs(); + __os->write(typeId); + __os->endWriteEncaps(); + __result->__send(true); + } + catch(const LocalException& __ex) + { + __result->__exceptionAsync(__ex); + } + return __result; +} + +bool +IceProxy::Ice::Object::end_ice_isA(const AsyncResultPtr& __result) +{ + AsyncResult::__check(__result, this, ice_isA_name); + if(!__result->__wait()) + { + try + { + __result->__throwUserException(); + } + catch(const UserException& __ex) + { + throw UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + } + } + bool __ret; + IceInternal::BasicStream* __is = __result->__getIs(); + __is->startReadEncaps(); + __is->read(__ret); + __is->endReadEncaps(); + return __ret; +} + void IceProxy::Ice::Object::ice_ping(const Context* context) { int __cnt = 0; while(true) { - Handle< ::IceDelegate::Ice::Object> __del; + Handle<IceDelegate::Ice::Object> __del; try { __del = __getDelegate(false); @@ -157,22 +205,48 @@ IceProxy::Ice::Object::ice_ping(const Context* context) } catch(const LocalExceptionWrapper& __ex) { - __handleExceptionWrapperRelaxed(__del, __ex, 0, __cnt); + __handleExceptionWrapperRelaxed(__del, __ex, true, __cnt); } catch(const LocalException& __ex) { - __handleException(__del, __ex, 0, __cnt); + __handleException(__del, __ex, true, __cnt); } } } +AsyncResultPtr +IceProxy::Ice::Object::begin_ice_ping(const Context* ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_ping_name, del, cookie); + try + { + __result->__prepare(ice_ping_name, Normal, ctx); + IceInternal::BasicStream* __os = __result->__getOs(); + __os->endWriteEncaps(); + __result->__send(true); + } + catch(const LocalException& __ex) + { + __result->__exceptionAsync(__ex); + } + return __result; +} + +void +IceProxy::Ice::Object::end_ice_ping(const AsyncResultPtr& __result) +{ + __end(__result, ice_ping_name); +} + vector<string> IceProxy::Ice::Object::ice_ids(const Context* context) { int __cnt = 0; while(true) { - Handle< ::IceDelegate::Ice::Object> __del; + Handle<IceDelegate::Ice::Object> __del; try { __checkTwowayOnly(ice_ids_name); @@ -181,11 +255,11 @@ IceProxy::Ice::Object::ice_ids(const Context* context) } catch(const LocalExceptionWrapper& __ex) { - __handleExceptionWrapperRelaxed(__del, __ex, 0, __cnt); + __handleExceptionWrapperRelaxed(__del, __ex, true, __cnt); } catch(const LocalException& __ex) { - __handleException(__del, __ex, 0, __cnt); + __handleException(__del, __ex, true, __cnt); } } } @@ -196,7 +270,7 @@ IceProxy::Ice::Object::ice_id(const Context* context) int __cnt = 0; while(true) { - Handle< ::IceDelegate::Ice::Object> __del; + Handle<IceDelegate::Ice::Object> __del; try { __checkTwowayOnly(ice_id_name); @@ -205,15 +279,102 @@ IceProxy::Ice::Object::ice_id(const Context* context) } catch(const LocalExceptionWrapper& __ex) { - __handleExceptionWrapperRelaxed(__del, __ex, 0, __cnt); + __handleExceptionWrapperRelaxed(__del, __ex, true, __cnt); } catch(const LocalException& __ex) { - __handleException(__del, __ex, 0, __cnt); + __handleException(__del, __ex, true, __cnt); + } + } +} + +AsyncResultPtr +IceProxy::Ice::Object::begin_ice_ids(const Context* ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_ids_name, del, cookie); + try + { + __checkTwowayOnly(ice_ids_name); + __result->__prepare(ice_ids_name, Normal, ctx); + IceInternal::BasicStream* __os = __result->__getOs(); + __os->endWriteEncaps(); + __result->__send(true); + } + catch(const LocalException& __ex) + { + __result->__exceptionAsync(__ex); + } + return __result; +} + +vector<string> +IceProxy::Ice::Object::end_ice_ids(const AsyncResultPtr& __result) +{ + AsyncResult::__check(__result, this, ice_ids_name); + if(!__result->__wait()) + { + try + { + __result->__throwUserException(); } + catch(const UserException& __ex) + { + throw UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + } + } + vector<string> __ret; + IceInternal::BasicStream* __is = __result->__getIs(); + __is->startReadEncaps(); + __is->read(__ret); + __is->endReadEncaps(); + return __ret; +} + +AsyncResultPtr +IceProxy::Ice::Object::begin_ice_id(const Context* ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_id_name, del, cookie); + try + { + __checkTwowayOnly(ice_id_name); + __result->__prepare(ice_id_name, Normal, ctx); + IceInternal::BasicStream* __os = __result->__getOs(); + __os->endWriteEncaps(); + __result->__send(true); + } + catch(const LocalException& __ex) + { + __result->__exceptionAsync(__ex); } + return __result; } +string +IceProxy::Ice::Object::end_ice_id(const AsyncResultPtr& __result) +{ + AsyncResult::__check(__result, this, ice_id_name); + if(!__result->__wait()) + { + try + { + __result->__throwUserException(); + } + catch(const UserException& __ex) + { + throw UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + } + } + string __ret; + IceInternal::BasicStream* __is = __result->__getIs(); + __is->startReadEncaps(); + __is->read(__ret); + __is->endReadEncaps(); + return __ret; +} bool IceProxy::Ice::Object::ice_invoke(const string& operation, @@ -237,6 +398,92 @@ IceProxy::Ice::Object::ice_invoke(const string& operation, bool +IceProxy::Ice::Object::ice_invoke_async(const AMI_Object_ice_invokePtr& cb, + const string& operation, + OperationMode mode, + const vector<Byte>& inParams) +{ + Callback_Object_ice_invokePtr del; + if(dynamic_cast< ::Ice::AMISentCallback*>(cb.get())) + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Object_ice_invoke::__response, + &AMI_Object_ice_invoke::__exception, + &AMI_Object_ice_invoke::__sent); + } + else + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Object_ice_invoke::__response, + &AMI_Object_ice_invoke::__exception); + } + ::Ice::AsyncResultPtr result = begin_ice_invoke(operation, mode, inParams, del); + return result->sentSynchronously(); +} + +bool +IceProxy::Ice::Object::ice_invoke_async(const AMI_Object_ice_invokePtr& cb, + const string& operation, + OperationMode mode, + const vector<Byte>& inParams, + const Context& context) +{ + Callback_Object_ice_invokePtr del; + if(dynamic_cast< ::Ice::AMISentCallback*>(cb.get())) + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Object_ice_invoke::__response, + &AMI_Object_ice_invoke::__exception, + &AMI_Object_ice_invoke::__sent); + } + else + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Object_ice_invoke::__response, + &AMI_Object_ice_invoke::__exception); + } + ::Ice::AsyncResultPtr result = begin_ice_invoke(operation, mode, inParams, context, del); + return result->sentSynchronously(); +} + +AsyncResultPtr +IceProxy::Ice::Object::begin_ice_invoke(const string& operation, + OperationMode mode, + const vector<Byte>& inParams, + const Context* ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + pair<const Byte*, const Byte*> inPair; + if(inParams.size() == 0) + { + inPair.first = inPair.second = 0; + } + else + { + inPair.first = &inParams[0]; + inPair.second = inPair.first + inParams.size(); + } + return begin_ice_invoke(operation, mode, inPair, ctx, del, cookie); +} + +bool +IceProxy::Ice::Object::end_ice_invoke(const AsyncResultPtr& __result, vector<Byte>& outParams) +{ + AsyncResult::__check(__result, this, ice_invoke_name); + bool ok = __result->__wait(); + if(_reference->getMode() == Reference::ModeTwoway) + { + IceInternal::BasicStream* __is = __result->__getIs(); + __is->startReadEncaps(); + Int sz = __is->getReadEncapsSize(); + __is->readBlob(outParams, sz); + __is->endReadEncaps(); + } + return ok; +} + +bool IceProxy::Ice::Object::ice_invoke(const string& operation, OperationMode mode, const pair<const Byte*, const Byte*>& inParams, @@ -257,56 +504,108 @@ IceProxy::Ice::Object::ice_invoke(const string& operation, bool canRetry = mode == Nonmutating || mode == Idempotent; if(canRetry) { - __handleExceptionWrapperRelaxed(__del, __ex, 0, __cnt); + __handleExceptionWrapperRelaxed(__del, __ex, true, __cnt); } else { - __handleExceptionWrapper(__del, __ex, 0); + __handleExceptionWrapper(__del, __ex); } } catch(const LocalException& __ex) { - __handleException(__del, __ex, 0, __cnt); + __handleException(__del, __ex, true, __cnt); } } } bool -IceProxy::Ice::Object::ice_invoke_async(const AMI_Object_ice_invokePtr& cb, +IceProxy::Ice::Object::ice_invoke_async(const AMI_Array_Object_ice_invokePtr& cb, const string& operation, OperationMode mode, - const vector<Byte>& inParams) + const pair<const Byte*, const Byte*>& inParams) { - return cb->__invoke(this, operation, mode, inParams, 0); + Callback_Object_ice_invokePtr del; + if(dynamic_cast< ::Ice::AMISentCallback*>(cb.get())) + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Array_Object_ice_invoke::__response, + &AMI_Array_Object_ice_invoke::__exception, + &AMI_Array_Object_ice_invoke::__sent); + } + else + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Array_Object_ice_invoke::__response, + &AMI_Array_Object_ice_invoke::__exception); + } + ::Ice::AsyncResultPtr result = begin_ice_invoke(operation, mode, inParams, del); + return result->sentSynchronously(); } bool -IceProxy::Ice::Object::ice_invoke_async(const AMI_Object_ice_invokePtr& cb, +IceProxy::Ice::Object::ice_invoke_async(const AMI_Array_Object_ice_invokePtr& cb, const string& operation, OperationMode mode, - const vector<Byte>& inParams, + const pair<const Byte*, const Byte*>& inParams, const Context& context) { - return cb->__invoke(this, operation, mode, inParams, &context); + Callback_Object_ice_invokePtr del; + if(dynamic_cast< ::Ice::AMISentCallback*>(cb.get())) + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Array_Object_ice_invoke::__response, + &AMI_Array_Object_ice_invoke::__exception, + &AMI_Array_Object_ice_invoke::__sent); + } + else + { + del = newCallback_Object_ice_invoke(cb, + &AMI_Array_Object_ice_invoke::__response, + &AMI_Array_Object_ice_invoke::__exception); + } + ::Ice::AsyncResultPtr result = begin_ice_invoke(operation, mode, inParams, context, del); + return result->sentSynchronously(); } -bool -IceProxy::Ice::Object::ice_invoke_async(const AMI_Array_Object_ice_invokePtr& cb, - const string& operation, +AsyncResultPtr +IceProxy::Ice::Object::begin_ice_invoke(const string& operation, OperationMode mode, - const pair<const Byte*, const Byte*>& inParams) + const pair<const Byte*, const Byte*>& inParams, + const Context* ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) { - return cb->__invoke(this, operation, mode, inParams, 0); + OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_invoke_name, del, cookie); + try + { + __result->__prepare(operation, mode, ctx); + BasicStream* __os = __result->__getOs(); + __os->writeBlob(inParams.first, static_cast<Int>(inParams.second - inParams.first)); + __os->endWriteEncaps(); + __result->__send(true); + } + catch(const LocalException& __ex) + { + __result->__exceptionAsync(__ex); + } + return __result; } bool -IceProxy::Ice::Object::ice_invoke_async(const AMI_Array_Object_ice_invokePtr& cb, - const string& operation, - OperationMode mode, - const pair<const Byte*, const Byte*>& inParams, - const Context& context) +IceProxy::Ice::Object::end_ice_invoke(const AsyncResultPtr& __result, pair<const Byte*, const Byte*>& outParams) { - return cb->__invoke(this, operation, mode, inParams, &context); + AsyncResult::__check(__result, this, ice_invoke_name); + bool ok = __result->__wait(); + if(_reference->getMode() == Reference::ModeTwoway) + { + IceInternal::BasicStream* __is = __result->__getIs(); + __is->startReadEncaps(); + Int sz = __is->getReadEncapsSize(); + __is->readBlob(outParams.first, sz); + outParams.second = outParams.first + sz; + __is->endReadEncaps(); + } + return ok; } Identity @@ -769,7 +1068,7 @@ IceProxy::Ice::Object::ice_getConnection() } catch(const LocalException& __ex) { - __handleException(__del, __ex, 0, __cnt); + __handleException(__del, __ex, true, __cnt); } } } @@ -812,14 +1111,54 @@ IceProxy::Ice::Object::ice_flushBatchRequests() } catch(const LocalException& __ex) { - __handleException(__del, __ex, 0, __cnt); + __handleException(__del, __ex, true, __cnt); } } bool IceProxy::Ice::Object::ice_flushBatchRequests_async(const AMI_Object_ice_flushBatchRequestsPtr& cb) { - return cb->__invoke(this); + ::Ice::AsyncResultPtr result = begin_ice_flushBatchRequests(newCallback(cb)); + return result->sentSynchronously(); +} + +::Ice::AsyncResultPtr +IceProxy::Ice::Object::begin_ice_flushBatchRequests(const ::Ice::Context* /* unused */, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + ::IceInternal::BatchOutgoingAsyncPtr __result = + new ::IceInternal::ProxyBatchOutgoingAsync(this, ice_flushBatchRequests_name, del, cookie); + try + { + // + // We don't automatically retry if ice_flushBatchRequests fails. Otherwise, if some batch + // requests were queued with the connection, they would be lost without being noticed. + // + Handle<IceDelegate::Ice::Object> delegate; + int cnt = -1; // Don't retry. + try + { + delegate = __getDelegate(true); + delegate->__getRequestHandler()->flushAsyncBatchRequests(__result); + } + catch(const ::Ice::LocalException& ex) + { + __handleException(delegate, ex, 0, cnt); + } + } + catch(const LocalException& __ex) + { + __result->__exceptionAsync(__ex); + } + return __result; +} + +void +IceProxy::Ice::Object::end_ice_flushBatchRequests(const AsyncResultPtr& __result) +{ + AsyncResult::__check(__result, this, ice_flushBatchRequests_name); + __result->__wait(); } ReferencePtr @@ -876,10 +1215,10 @@ IceProxy::Ice::Object::__copyFrom(const ObjectPrx& from) } } -void +int IceProxy::Ice::Object::__handleException(const ::IceInternal::Handle< ::IceDelegate::Ice::Object>& delegate, const LocalException& ex, - ::IceInternal::OutgoingAsync* out, + bool sleep, int& cnt) { // @@ -900,7 +1239,7 @@ IceProxy::Ice::Object::__handleException(const ::IceInternal::Handle< ::IceDeleg try { - _reference->getInstance()->proxyFactory()->checkRetryAfterException(ex, _reference, out, cnt); + return _reference->getInstance()->proxyFactory()->checkRetryAfterException(ex, _reference, sleep, cnt); } catch(const CommunicatorDestroyedException&) { @@ -909,12 +1248,12 @@ IceProxy::Ice::Object::__handleException(const ::IceInternal::Handle< ::IceDeleg // ex.ice_throw(); } + return 0; // Keep the compiler happy. } -void +int IceProxy::Ice::Object::__handleExceptionWrapper(const ::IceInternal::Handle< ::IceDelegate::Ice::Object>& delegate, - const LocalExceptionWrapper& ex, - IceInternal::OutgoingAsync* out) + const LocalExceptionWrapper& ex) { { IceUtil::Mutex::Lock sync(*this); @@ -929,21 +1268,18 @@ IceProxy::Ice::Object::__handleExceptionWrapper(const ::IceInternal::Handle< ::I ex.get()->ice_throw(); } - if(out) - { - out->__send(); - } + return 0; } -void +int IceProxy::Ice::Object::__handleExceptionWrapperRelaxed(const ::IceInternal::Handle< ::IceDelegate::Ice::Object>& del, const LocalExceptionWrapper& ex, - ::IceInternal::OutgoingAsync* out, + bool sleep, int& cnt) { if(!ex.retry()) { - __handleException(del, *ex.get(), out, cnt); + return __handleException(del, *ex.get(), sleep, cnt); } else { @@ -955,10 +1291,7 @@ IceProxy::Ice::Object::__handleExceptionWrapperRelaxed(const ::IceInternal::Hand } } - if(out) - { - out->__send(); - } + return 0; } } @@ -966,10 +1299,8 @@ void IceProxy::Ice::Object::__checkTwowayOnly(const string& name) const { // - // No mutex lock necessary, there is nothing mutable in this - // operation. + // No mutex lock necessary, there is nothing mutable in this operation. // - if(!ice_isTwoway()) { TwowayOnlyException ex(__FILE__, __LINE__); @@ -978,6 +1309,29 @@ IceProxy::Ice::Object::__checkTwowayOnly(const string& name) const } } +void +IceProxy::Ice::Object::__end(const ::Ice::AsyncResultPtr& __result, const std::string& operation) const +{ + AsyncResult::__check(__result, this, operation); + bool ok = __result->__wait(); + if(_reference->getMode() == Reference::ModeTwoway) + { + if(!ok) + { + try + { + __result->__throwUserException(); + } + catch(const UserException& __ex) + { + throw UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + } + } + IceInternal::BasicStream* __is = __result->__getIs(); + __is->skipEmptyEncaps(); + } +} + ostream& operator<<(ostream& os, const ::IceProxy::Ice::Object& p) { |