diff options
Diffstat (limited to 'cpp/src/Ice/Proxy.cpp')
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 1339 |
1 files changed, 567 insertions, 772 deletions
diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index f69594a8cc4..6744c4c277c 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -19,16 +19,23 @@ #include <Ice/Instance.h> #include <Ice/RouterInfo.h> #include <Ice/LocatorInfo.h> -#include <Ice/BasicStream.h> +#include <Ice/OutputStream.h> +#include <Ice/InputStream.h> #include <Ice/LocalException.h> #include <Ice/ConnectionI.h> // To convert from ConnectionIPtr to ConnectionPtr in ice_getConnection(). -#include <Ice/Stream.h> #include <Ice/ImplicitContextI.h> using namespace std; using namespace Ice; using namespace IceInternal; +namespace Ice +{ + +const Context noExplicitContext; + +} + namespace { @@ -42,98 +49,111 @@ const string ice_flushBatchRequests_name = "ice_flushBatchRequests"; } -::Ice::ObjectPrx -IceInternal::checkedCastImpl(const ObjectPrx& b, const string& f, const string& typeId, const Context* context) +#ifdef ICE_CPP11_MAPPING // C++11 mapping + +bool +Ice::ObjectPrx::operator==(const ObjectPrx& r) const { - if(b) - { - ObjectPrx bb = b->ice_facet(f); - try - { - if(context == 0 ? bb->ice_isA(typeId) : bb->ice_isA(typeId, *context)) - { - return bb; - } -#ifndef NDEBUG - else - { - assert(typeId != "::Ice::Object"); - } -#endif - } - catch(const FacetNotExistException&) - { - } - } - return 0; + return _reference == r._reference; } -#ifdef ICE_CPP11 +bool +Ice::ObjectPrx::operator!=(const ObjectPrx& r) const +{ + return _reference != r._reference; +} -IceInternal::Cpp11FnCallbackNC::Cpp11FnCallbackNC(const ::std::function<void (const ::Ice::Exception&)>& excb, - const ::std::function<void (bool)>& sentcb) : - _exception(excb), - _sent(sentcb) +bool +Ice::ObjectPrx::operator<(const ObjectPrx& r) const { + return _reference < r._reference; } -IceInternal::CallbackBasePtr -IceInternal::Cpp11FnCallbackNC::verify(const ::Ice::LocalObjectPtr&) +void +Ice::ObjectPrx::__ice_isA(const shared_ptr<IceInternal::OutgoingAsyncT<bool>>& outAsync, + const string& typeId, + const Context& ctx) { - return this; + __checkAsyncTwowayOnly("__ice_isA"); + outAsync->invoke(ice_isA_name, OperationMode::Nonmutating, DefaultFormat, ctx, + [&](Ice::OutputStream* os) + { + os->write(typeId); + }, + nullptr); } void -IceInternal::Cpp11FnCallbackNC::sent(const ::Ice::AsyncResultPtr& result) const +Ice::ObjectPrx::__ice_ping(const shared_ptr<IceInternal::OutgoingAsyncT<void>>& outAsync, const Context& ctx) { - if(_sent != nullptr) - { - _sent(result->sentSynchronously()); - } + outAsync->invoke(ice_ping_name, OperationMode::Nonmutating, DefaultFormat, ctx, nullptr, nullptr); } -bool -IceInternal::Cpp11FnCallbackNC::hasSentCallback() const +void +Ice::ObjectPrx::__ice_ids(const shared_ptr<IceInternal::OutgoingAsyncT<vector<string>>>& outAsync, const Context& ctx) { - return _sent != nullptr; + __checkAsyncTwowayOnly("__ice_ids"); + outAsync->invoke(ice_ids_name, OperationMode::Nonmutating, DefaultFormat, ctx, nullptr, nullptr); } void -IceInternal::Cpp11FnCallbackNC::exception(const ::Ice::AsyncResultPtr&, const ::Ice::Exception& ex) const +Ice::ObjectPrx::__ice_id(const shared_ptr<IceInternal::OutgoingAsyncT<string>>& outAsync, const Context& ctx) { - if(_exception != nullptr) - { - _exception(ex); - } + __checkAsyncTwowayOnly("__ice_id"); + outAsync->invoke(ice_id_name, OperationMode::Nonmutating, DefaultFormat, ctx, nullptr, nullptr); } -IceInternal::Cpp11FnOnewayCallbackNC::Cpp11FnOnewayCallbackNC(const ::std::function<void ()>& cb, - const ::std::function<void (const ::Ice::Exception&)>& excb, - const ::std::function<void (bool)>& sentcb) : - Cpp11FnCallbackNC(excb, sentcb), - _cb(cb) +void +Ice::ObjectPrx::__ice_getConnection(const shared_ptr<IceInternal::ProxyGetConnection>& outAsync) { - CallbackBase::checkCallback(true, cb || excb != nullptr); + outAsync->invoke(ice_getConnection_name); } void -IceInternal::Cpp11FnOnewayCallbackNC::completed(const ::Ice::AsyncResultPtr& result) const +Ice::ObjectPrx::__ice_flushBatchRequests(const shared_ptr<IceInternal::ProxyFlushBatchAsync>& outAsync) { - try - { - result->getProxy()->__end(result, result->getOperation()); - } - catch(const ::Ice::Exception& ex) - { - Cpp11FnCallbackNC::exception(result, ex); - return; - } - if(_cb != nullptr) + outAsync->invoke(ice_flushBatchRequests_name); +} + +shared_ptr<ObjectPrx> +Ice::ObjectPrx::__newInstance() const +{ + return createProxy<ObjectPrx>(); +} + +ostream& +Ice::operator<<(ostream& os, const Ice::ObjectPrx& p) +{ + return os << p.ice_toString(); +} + +#else // C++98 mapping + +::Ice::ObjectPrxPtr +IceInternal::checkedCastImpl(const ObjectPrxPtr& b, const string& f, const string& typeId, const Context& context) +{ + if(b != ICE_NULLPTR) { - _cb(); + ObjectPrxPtr bb = b->ice_facet(f); + try + { + if(bb->ice_isA(typeId, context)) + { + return bb; + } +#ifndef NDEBUG + else + { + assert(typeId != "::Ice::Object"); + } +#endif + } + catch(const FacetNotExistException&) + { + } } + return ICE_NULLPTR; } -#endif bool IceProxy::Ice::Object::operator==(const Object& r) const @@ -153,32 +173,14 @@ IceProxy::Ice::Object::operator<(const Object& r) const return _reference < r._reference; } -CommunicatorPtr -IceProxy::Ice::Object::ice_getCommunicator() const -{ - return _reference->getCommunicator(); -} - -string -IceProxy::Ice::Object::ice_toString() const -{ - // - // Returns the stringified proxy. There's no need to convert the - // string to a native string: a stringified proxy only contains - // printable ASCII which is a subset of all native character sets. - // - return _reference->toString(); -} - - bool -IceProxy::Ice::Object::ice_isA(const string& typeId, const Context* context) +IceProxy::Ice::Object::ice_isA(const string& typeId, const Context& context) { __checkTwowayOnly(ice_isA_name); Outgoing __og(this, ice_isA_name, ::Ice::Nonmutating, context); try { - BasicStream* __os = __og.startWriteParams(DefaultFormat); + OutputStream* __os = __og.startWriteParams(DefaultFormat); __os->write(typeId, false); __og.endWriteParams(); } @@ -194,31 +196,31 @@ IceProxy::Ice::Object::ice_isA(const string& typeId, const Context* context) } catch(const ::Ice::UserException& __ex) { - throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_id()); } } bool __ret; - BasicStream* __is = __og.startReadParams(); + InputStream* __is = __og.startReadParams(); __is->read(__ret); __og.endReadParams(); return __ret; } Ice::AsyncResultPtr -IceProxy::Ice::Object::begin_ice_isA(const string& typeId, - const Context* ctx, - const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) +IceProxy::Ice::Object::__begin_ice_isA(const string& typeId, + const Context& ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) { __checkAsyncTwowayOnly(ice_isA_name); - OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_isA_name, del, cookie); + OutgoingAsyncPtr __result = new CallbackOutgoing(this, ice_isA_name, del, cookie); try { __result->prepare(ice_isA_name, Nonmutating, ctx); - IceInternal::BasicStream* __os = __result->startWriteParams(DefaultFormat); + ::Ice::OutputStream* __os = __result->startWriteParams(DefaultFormat); __os->write(typeId); __result->endWriteParams(); - __result->invoke(); + __result->invoke(ice_isA_name); } catch(const Exception& __ex) { @@ -227,293 +229,6 @@ IceProxy::Ice::Object::begin_ice_isA(const string& typeId, return __result; } -#ifdef ICE_CPP11 - -Ice::AsyncResultPtr -IceProxy::Ice::Object::__begin_ice_isA(const ::std::string& typeId, - const ::Ice::Context* ctx, - const ::IceInternal::Function<void (bool)>& response, - const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception, - const ::IceInternal::Function<void (bool)>& sent) -{ - class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC - { - public: - - Cpp11CB(const ::std::function<void (bool)>& responseFunc, - const ::std::function<void (const ::Ice::Exception&)>& exceptionFunc, - const ::std::function<void (bool)>& sentFunc) : - ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), - _response(responseFunc) - { - CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); - } - - virtual void completed(const ::Ice::AsyncResultPtr& __result) const - { - ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); - bool __ret; - try - { - __ret = __proxy->end_ice_isA(__result); - } - catch(const ::Ice::Exception& ex) - { - Cpp11FnCallbackNC::exception(__result, ex); - return; - } - if(_response != nullptr) - { - _response(__ret); - } - } - - private: - - ::std::function<void (bool)> _response; - }; - - return begin_ice_isA(typeId, ctx, new Cpp11CB(response, exception, sent), 0); -} - -Ice::AsyncResultPtr -IceProxy::Ice::Object::__begin_ice_id(const ::Ice::Context* ctx, - const ::IceInternal::Function<void (const ::std::string&)>& response, - const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception, - const ::IceInternal::Function<void (bool)>& sent) -{ - class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC - { - public: - - Cpp11CB(const ::std::function<void (const ::std::string&)>& responseFunc, - const ::std::function<void (const ::Ice::Exception&)>& exceptionFunc, - const ::std::function<void (bool)>& sentFunc) : - ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), - _response(responseFunc) - { - CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); - } - - virtual void completed(const ::Ice::AsyncResultPtr& __result) const - { - ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); - ::std::string __ret; - try - { - __ret = __proxy->end_ice_id(__result); - } - catch(const ::Ice::Exception& ex) - { - Cpp11FnCallbackNC::exception(__result, ex); - return; - } - if(_response != nullptr) - { - _response(__ret); - } - } - - private: - - ::std::function<void (const ::std::string&)> _response; - }; - return begin_ice_id(ctx, new Cpp11CB(response, exception, sent), 0); -} - -Ice::AsyncResultPtr -IceProxy::Ice::Object::__begin_ice_ids( - const ::Ice::Context* ctx, - const ::IceInternal::Function<void (const ::std::vector< ::std::string>&)>& response, - const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception, - const ::IceInternal::Function<void (bool)>& sent) -{ - class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC - { - public: - - Cpp11CB(const ::std::function<void (const ::std::vector< ::std::string>&)>& responseFunc, - const ::std::function<void (const ::Ice::Exception&)>& exceptionFunc, - const ::std::function<void (bool)>& sentFunc) : - ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), - _response(responseFunc) - { - CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); - } - - virtual void completed(const ::Ice::AsyncResultPtr& __result) const - { - ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); - ::std::vector< ::std::string> __ret; - try - { - __ret = __proxy->end_ice_ids(__result); - } - catch(const ::Ice::Exception& ex) - { - Cpp11FnCallbackNC::exception(__result, ex); - return; - } - if(_response != nullptr) - { - _response(__ret); - } - } - - private: - - ::std::function<void (const ::std::vector< ::std::string>&)> _response; - }; - return begin_ice_ids(ctx, new Cpp11CB(response, exception, sent), 0); -} - -Ice::AsyncResultPtr -IceProxy::Ice::Object::__begin_ice_invoke( - const ::std::string& operation, - ::Ice::OperationMode mode, - const ::std::vector< ::Ice::Byte>& inParams, - const ::Ice::Context* ctx, - const ::IceInternal::Function<void (bool, const ::std::vector< ::Ice::Byte>&)>& response, - const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception, - const ::IceInternal::Function<void (bool)>& sent) -{ - class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC - { - public: - - Cpp11CB(const ::std::function<void (bool, const ::std::vector< ::Ice::Byte>&)>& responseFunc, - const ::std::function<void (const ::Ice::Exception&)>& exceptionFunc, - const ::std::function<void (bool)>& sentFunc) : - ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), - _response(responseFunc) - { - CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); - } - - virtual void completed(const ::Ice::AsyncResultPtr& __result) const - { - ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); - bool __ret; - ::std::vector< ::Ice::Byte> p1; - try - { - __ret = __proxy->end_ice_invoke(p1, __result); - } - catch(const ::Ice::Exception& ex) - { - Cpp11FnCallbackNC::exception(__result, ex); - return; - } - if(_response != nullptr) - { - _response(__ret, p1); - } - } - - private: - - ::std::function<void (bool, const ::std::vector< ::Ice::Byte>&)> _response; - }; - - return begin_ice_invoke(operation, mode, inParams, ctx, new Cpp11CB(response, exception, sent), 0); -} - -Ice::AsyncResultPtr -IceProxy::Ice::Object::__begin_ice_invoke( - const ::std::string& operation, - ::Ice::OperationMode mode, - const ::std::pair<const ::Ice::Byte*, const ::Ice::Byte*>& inParams, - const ::Ice::Context* ctx, - const ::IceInternal::Function<void (bool, const ::std::pair<const ::Ice::Byte*, const ::Ice::Byte*>&)>& response, - const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception, - const ::IceInternal::Function<void (bool)>& sent) -{ - class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC - { - public: - - Cpp11CB(const ::std::function<void (bool, const ::std::pair<const ::Ice::Byte*, - const ::Ice::Byte*>&)>& responseFunc, - const ::std::function<void (const ::Ice::Exception&)>& exceptionFunc, - const ::std::function<void (bool)>& sentFunc) : - ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc), - _response(responseFunc) - { - CallbackBase::checkCallback(true, _response || _exception != nullptr); - } - - virtual void completed(const ::Ice::AsyncResultPtr& __result) const - { - bool __ret; - ::std::pair<const ::Ice::Byte*, const ::Ice::Byte*> p1; - try - { - __ret = __result->getProxy()->___end_ice_invoke(p1, __result); - } - catch(const ::Ice::Exception& ex) - { - Cpp11FnCallbackNC::exception(__result, ex); - return; - } - if(_response != nullptr) - { - _response(__ret, p1); - } - } - - private: - - ::std::function<void (bool, const ::std::pair<const ::Ice::Byte*, const ::Ice::Byte*>&)> _response; - }; - return begin_ice_invoke(operation, mode, inParams, ctx, new Cpp11CB(response, exception, sent), 0); -} - -Ice::AsyncResultPtr -IceProxy::Ice::Object::begin_ice_getConnection( - const ::IceInternal::Function<void (const ::Ice::ConnectionPtr&)>& response, - const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception) -{ - class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC - { - public: - - Cpp11CB(const ::std::function<void (const ::Ice::ConnectionPtr&)>& responseFunc, - const ::std::function<void (const ::Ice::Exception&)>& exceptionFunc) : - ::IceInternal::Cpp11FnCallbackNC(exceptionFunc, nullptr), - _response(responseFunc) - { - CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr); - } - - virtual void completed(const ::Ice::AsyncResultPtr& __result) const - { - ::Ice::ObjectPrx __proxy = ::Ice::ObjectPrx::uncheckedCast(__result->getProxy()); - ::Ice::ConnectionPtr __ret; - try - { - __ret = __proxy->end_ice_getConnection(__result); - } - catch(const ::Ice::Exception& ex) - { - Cpp11FnCallbackNC::exception(__result, ex); - return; - } - if(_response != nullptr) - { - _response(__ret); - } - } - - private: - - ::std::function<void (const ::Ice::ConnectionPtr&)> _response; - }; - return begin_ice_getConnectionInternal(new Cpp11CB(response, exception), 0); -} - -#endif - - bool IceProxy::Ice::Object::end_ice_isA(const AsyncResultPtr& __result) { @@ -527,18 +242,18 @@ IceProxy::Ice::Object::end_ice_isA(const AsyncResultPtr& __result) } catch(const UserException& __ex) { - throw UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + throw UnknownUserException(__FILE__, __LINE__, __ex.ice_id()); } } bool __ret; - IceInternal::BasicStream* __is = __result->__startReadParams(); + ::Ice::InputStream* __is = __result->__startReadParams(); __is->read(__ret); __result->__endReadParams(); return __ret; } void -IceProxy::Ice::Object::ice_ping(const Context* context) +IceProxy::Ice::Object::ice_ping(const Context& context) { Outgoing __og(this, ice_ping_name, ::Ice::Nonmutating, context); __og.writeEmptyParams(); @@ -553,7 +268,7 @@ IceProxy::Ice::Object::ice_ping(const Context* context) } catch(const ::Ice::UserException& __ex) { - throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_id()); } } __og.readEmptyParams(); @@ -561,16 +276,16 @@ IceProxy::Ice::Object::ice_ping(const Context* context) } AsyncResultPtr -IceProxy::Ice::Object::begin_ice_ping(const Context* ctx, - const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) +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); + OutgoingAsyncPtr __result = new CallbackOutgoing(this, ice_ping_name, del, cookie); try { __result->prepare(ice_ping_name, Nonmutating, ctx); __result->writeEmptyParams(); - __result->invoke(); + __result->invoke(ice_ping_name); } catch(const Exception& __ex) { @@ -586,7 +301,7 @@ IceProxy::Ice::Object::end_ice_ping(const AsyncResultPtr& __result) } vector<string> -IceProxy::Ice::Object::ice_ids(const Context* context) +IceProxy::Ice::Object::ice_ids(const Context& context) { __checkTwowayOnly(ice_ids_name); Outgoing __og(this, ice_ids_name, ::Ice::Nonmutating, context); @@ -599,18 +314,18 @@ IceProxy::Ice::Object::ice_ids(const Context* context) } catch(const ::Ice::UserException& __ex) { - throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_id()); } } vector<string> __ret; - BasicStream* __is = __og.startReadParams(); + InputStream* __is = __og.startReadParams(); __is->read(__ret, false); __og.endReadParams(); return __ret; } string -IceProxy::Ice::Object::ice_id(const Context* context) +IceProxy::Ice::Object::ice_id(const Context& context) { __checkTwowayOnly(ice_id_name); Outgoing __og(this, ice_id_name, ::Ice::Nonmutating, context); @@ -623,28 +338,28 @@ IceProxy::Ice::Object::ice_id(const Context* context) } catch(const ::Ice::UserException& __ex) { - throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_id()); } } string __ret; - BasicStream* __is = __og.startReadParams(); + InputStream* __is = __og.startReadParams(); __is->read(__ret, false); __og.endReadParams(); return __ret; } AsyncResultPtr -IceProxy::Ice::Object::begin_ice_ids(const Context* ctx, - const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) +IceProxy::Ice::Object::__begin_ice_ids(const Context& ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) { __checkAsyncTwowayOnly(ice_ids_name); - OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_ids_name, del, cookie); + OutgoingAsyncPtr __result = new CallbackOutgoing(this, ice_ids_name, del, cookie); try { __result->prepare(ice_ids_name, Nonmutating, ctx); __result->writeEmptyParams(); - __result->invoke(); + __result->invoke(ice_ids_name); } catch(const Exception& __ex) { @@ -666,28 +381,28 @@ IceProxy::Ice::Object::end_ice_ids(const AsyncResultPtr& __result) } catch(const UserException& __ex) { - throw UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + throw UnknownUserException(__FILE__, __LINE__, __ex.ice_id()); } } vector<string> __ret; - IceInternal::BasicStream* __is = __result->__startReadParams(); + ::Ice::InputStream* __is = __result->__startReadParams(); __is->read(__ret); __result->__endReadParams(); return __ret; } AsyncResultPtr -IceProxy::Ice::Object::begin_ice_id(const Context* ctx, - const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) +IceProxy::Ice::Object::__begin_ice_id(const Context& ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) { __checkAsyncTwowayOnly(ice_id_name); - OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_id_name, del, cookie); + OutgoingAsyncPtr __result = new CallbackOutgoing(this, ice_id_name, del, cookie); try { __result->prepare(ice_id_name, Nonmutating, ctx); __result->writeEmptyParams(); - __result->invoke(); + __result->invoke(ice_id_name); } catch(const Exception& __ex) { @@ -709,11 +424,11 @@ IceProxy::Ice::Object::end_ice_id(const AsyncResultPtr& __result) } catch(const UserException& __ex) { - throw UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + throw UnknownUserException(__FILE__, __LINE__, __ex.ice_id()); } } string __ret; - IceInternal::BasicStream* __is = __result->__startReadParams(); + ::Ice::InputStream* __is = __result->__startReadParams(); __is->read(__ret); __result->__endReadParams(); return __ret; @@ -724,7 +439,7 @@ IceProxy::Ice::Object::ice_invoke(const string& operation, OperationMode mode, const vector<Byte>& inEncaps, vector<Byte>& outEncaps, - const Context* context) + const Context& context) { pair<const Byte*, const Byte*> inPair; if(inEncaps.empty()) @@ -740,12 +455,12 @@ IceProxy::Ice::Object::ice_invoke(const string& operation, } AsyncResultPtr -IceProxy::Ice::Object::begin_ice_invoke(const string& operation, - OperationMode mode, - const vector<Byte>& inEncaps, - const Context* ctx, - const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) +IceProxy::Ice::Object::__begin_ice_invoke(const string& operation, + OperationMode mode, + const vector<Byte>& inEncaps, + const Context& ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) { pair<const Byte*, const Byte*> inPair; if(inEncaps.empty()) @@ -757,7 +472,7 @@ IceProxy::Ice::Object::begin_ice_invoke(const string& operation, inPair.first = &inEncaps[0]; inPair.second = inPair.first + inEncaps.size(); } - return begin_ice_invoke(operation, mode, inPair, ctx, del, cookie); + return __begin_ice_invoke(operation, mode, inPair, ctx, del, cookie); } bool @@ -780,7 +495,7 @@ IceProxy::Ice::Object::ice_invoke(const string& operation, OperationMode mode, const pair<const Byte*, const Byte*>& inEncaps, vector<Byte>& outEncaps, - const Context* context) + const Context& context) { Outgoing __og(this, operation, mode, context); try @@ -803,19 +518,19 @@ IceProxy::Ice::Object::ice_invoke(const string& operation, } AsyncResultPtr -IceProxy::Ice::Object::begin_ice_invoke(const string& operation, - OperationMode mode, - const pair<const Byte*, const Byte*>& inEncaps, - const Context* ctx, - const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) -{ - OutgoingAsyncPtr __result = new OutgoingAsync(this, ice_invoke_name, del, cookie); +IceProxy::Ice::Object::__begin_ice_invoke(const string& operation, + OperationMode mode, + const pair<const Byte*, const Byte*>& inEncaps, + const Context& ctx, + const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + OutgoingAsyncPtr __result = new CallbackOutgoing(this, ice_invoke_name, del, cookie); try { __result->prepare(operation, mode, ctx); __result->writeParamEncaps(inEncaps.first, static_cast<Int>(inEncaps.second - inEncaps.first)); - __result->invoke(); + __result->invoke(operation); } catch(const Exception& __ex) { @@ -838,14 +553,256 @@ IceProxy::Ice::Object::___end_ice_invoke(pair<const Byte*, const Byte*>& outEnca return ok; } +::Ice::AsyncResultPtr +IceProxy::Ice::Object::begin_ice_flushBatchRequestsInternal(const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + class ProxyFlushBatchAsyncWithCallback : public ProxyFlushBatchAsync, public CallbackCompletion + { + public: + + ProxyFlushBatchAsyncWithCallback(const ::Ice::ObjectPrx& proxy, + const CallbackBasePtr& cb, + const ::Ice::LocalObjectPtr& cookie) : + ProxyFlushBatchAsync(proxy), CallbackCompletion(cb, cookie) + { + _cookie = cookie; + } + + virtual const std::string& + getOperation() const + { + return ice_flushBatchRequests_name; + } + }; + + ProxyFlushBatchAsyncPtr result = new ProxyFlushBatchAsyncWithCallback(this, del, cookie); + try + { + result->invoke(ice_flushBatchRequests_name); + } + catch(const Exception& ex) + { + result->abort(ex); + } + return result; +} + +void +IceProxy::Ice::Object::end_ice_flushBatchRequests(const AsyncResultPtr& result) +{ + AsyncResult::__check(result, this, ice_flushBatchRequests_name); + result->__wait(); +} + +void +IceProxy::Ice::Object::__invoke(Outgoing& __og) const +{ + // + // Helper for operations without out/return parameters and user + // exceptions. + // + + bool __ok = __og.invoke(); + if(__og.hasResponse()) + { + if(!__ok) + { + try + { + __og.throwUserException(); + } + catch(const ::Ice::UserException& __ex) + { + ::Ice::UnknownUserException __uue(__FILE__, __LINE__, __ex.ice_id()); + throw __uue; + } + } + __og.readEmptyParams(); + } +} + +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_id()); + } + } + __result->__readEmptyParams(); + } +} + +namespace IceProxy +{ + +namespace Ice +{ + +ostream& +operator<<(ostream& os, const ::IceProxy::Ice::Object& p) +{ + return os << p.ice_toString(); +} + +} + +} + +IceProxy::Ice::Object* +IceProxy::Ice::Object::__newInstance() const +{ + return new Object; +} + +ConnectionPtr +IceProxy::Ice::Object::ice_getConnection() +{ + InvocationObserver observer(this, "ice_getConnection", ::Ice::noExplicitContext); + int cnt = 0; + while(true) + { + RequestHandlerPtr handler; + try + { + handler = __getRequestHandler(); + return handler->waitForConnection(); // Wait for the connection to be established. + } + catch(const IceInternal::RetryException&) + { + __updateRequestHandler(handler, 0); // Clear request handler and retry. + } + catch(const Exception& ex) + { + try + { + int interval = __handleException(ex, handler, ICE_ENUM(OperationMode, Idempotent), false, cnt); + observer.retried(); + if(interval > 0) + { + IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(interval)); + } + } + catch(const Exception& exc) + { + observer.failed(exc.ice_id()); + throw; + } + } + } +} + +AsyncResultPtr +IceProxy::Ice::Object::begin_ice_getConnectionInternal(const ::IceInternal::CallbackBasePtr& del, + const ::Ice::LocalObjectPtr& cookie) +{ + class ProxyGetConnectionWithCallback : public ProxyGetConnection, public CallbackCompletion + { + public: + + ProxyGetConnectionWithCallback(const ::Ice::ObjectPrx& proxy, + const ::IceInternal::CallbackBasePtr& cb, + const ::Ice::LocalObjectPtr& cookie) : + ProxyGetConnection(proxy), CallbackCompletion(cb, cookie) + { + _cookie = cookie; + } + + virtual const std::string& + getOperation() const + { + return ice_getConnection_name; + } + }; + + ProxyGetConnectionPtr result = new ProxyGetConnectionWithCallback(this, del, cookie); + try + { + result->invoke(ice_getConnection_name); + } + catch(const Exception& ex) + { + result->abort(ex); + } + return result; +} + +ConnectionPtr +IceProxy::Ice::Object::end_ice_getConnection(const AsyncResultPtr& __result) +{ + AsyncResult::__check(__result, this, ice_getConnection_name); + __result->__wait(); + return ice_getCachedConnection(); +} + +void +IceProxy::Ice::Object::ice_flushBatchRequests() +{ + ProxyFlushBatch og(ICE_SHARED_FROM_THIS, ice_flushBatchRequests_name); + og.invoke(); +} + +void +IceProxy::Ice::Object::__checkTwowayOnly(const string& name) const +{ + // + // No mutex lock necessary, there is nothing mutable in this operation. + // + if(!ice_isTwoway()) + { + TwowayOnlyException ex(__FILE__, __LINE__); + ex.operation = name; + throw ex; + } +} + +#endif + +#ifdef ICE_CPP11_MAPPING +# define ICE_OBJECT_PRX Ice::ObjectPrx +# define CONST_POINTER_CAST_OBJECT_PRX const_pointer_cast<ObjectPrx>(shared_from_this()) +#else +# define ICE_OBJECT_PRX IceProxy::Ice::Object +# define CONST_POINTER_CAST_OBJECT_PRX ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)) +#endif + +// +// methods common for both C++11/C++98 mappings +// + +void +ICE_OBJECT_PRX::__checkAsyncTwowayOnly(const string& name) const +{ + // + // No mutex lock necessary, there is nothing mutable in this operation. + // + if(!ice_isTwoway()) + { + throw IceUtil::IllegalArgumentException(__FILE__, + __LINE__, + "`" + name + "' can only be called with a twoway proxy"); + } +} + Identity -IceProxy::Ice::Object::ice_getIdentity() const +ICE_OBJECT_PRX::ice_getIdentity() const { return _reference->getIdentity(); } -ObjectPrx -IceProxy::Ice::Object::ice_identity(const Identity& newIdentity) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_identity(const Identity& newIdentity) const { if(newIdentity.name.empty()) { @@ -853,113 +810,121 @@ IceProxy::Ice::Object::ice_identity(const Identity& newIdentity) const } if(newIdentity == _reference->getIdentity()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = new Object; +#ifdef ICE_CPP11_MAPPING + auto proxy = createProxy<ObjectPrx>(); +#else + ObjectPrxPtr proxy = new IceProxy::Ice::Object; +#endif proxy->setup(_reference->changeIdentity(newIdentity)); return proxy; } } Context -IceProxy::Ice::Object::ice_getContext() const +ICE_OBJECT_PRX::ice_getContext() const { return _reference->getContext()->getValue(); } -ObjectPrx -IceProxy::Ice::Object::ice_context(const Context& newContext) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_context(const Context& newContext) const { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeContext(newContext)); return proxy; } const string& -IceProxy::Ice::Object::ice_getFacet() const +ICE_OBJECT_PRX::ice_getFacet() const { return _reference->getFacet(); } -ObjectPrx -IceProxy::Ice::Object::ice_facet(const string& newFacet) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_facet(const string& newFacet) const { if(newFacet == _reference->getFacet()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = new Object; +#ifdef ICE_CPP11_MAPPING + auto proxy = createProxy<ObjectPrx>(); +#else + ObjectPrx proxy = new IceProxy::Ice::Object; +#endif proxy->setup(_reference->changeFacet(newFacet)); return proxy; } } string -IceProxy::Ice::Object::ice_getAdapterId() const +ICE_OBJECT_PRX::ice_getAdapterId() const { return _reference->getAdapterId(); } -ObjectPrx -IceProxy::Ice::Object::ice_adapterId(const string& newAdapterId) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_adapterId(const string& newAdapterId) const { if(newAdapterId == _reference->getAdapterId()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeAdapterId(newAdapterId)); return proxy; } } EndpointSeq -IceProxy::Ice::Object::ice_getEndpoints() const +ICE_OBJECT_PRX::ice_getEndpoints() const { vector<EndpointIPtr> endpoints = _reference->getEndpoints(); EndpointSeq retSeq; for(vector<EndpointIPtr>::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { - retSeq.push_back(EndpointPtr::dynamicCast(*p)); + retSeq.push_back(ICE_DYNAMIC_CAST(Endpoint, *p)); } return retSeq; } -ObjectPrx -IceProxy::Ice::Object::ice_endpoints(const EndpointSeq& newEndpoints) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_endpoints(const EndpointSeq& newEndpoints) const { vector<EndpointIPtr> endpoints; for(EndpointSeq::const_iterator p = newEndpoints.begin(); p != newEndpoints.end(); ++p) { - endpoints.push_back(EndpointIPtr::dynamicCast(*p)); + endpoints.push_back(ICE_DYNAMIC_CAST(EndpointI, *p)); } if(endpoints == _reference->getEndpoints()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeEndpoints(endpoints)); return proxy; } } Int -IceProxy::Ice::Object::ice_getLocatorCacheTimeout() const +ICE_OBJECT_PRX::ice_getLocatorCacheTimeout() const { return _reference->getLocatorCacheTimeout(); } -ObjectPrx -IceProxy::Ice::Object::ice_locatorCacheTimeout(Int newTimeout) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_locatorCacheTimeout(Int newTimeout) const { if(newTimeout < -1) { @@ -969,196 +934,204 @@ IceProxy::Ice::Object::ice_locatorCacheTimeout(Int newTimeout) const } if(newTimeout == _reference->getLocatorCacheTimeout()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeLocatorCacheTimeout(newTimeout)); return proxy; } } bool -IceProxy::Ice::Object::ice_isConnectionCached() const +ICE_OBJECT_PRX::ice_isConnectionCached() const { return _reference->getCacheConnection(); } -ObjectPrx -IceProxy::Ice::Object::ice_connectionCached(bool newCache) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_connectionCached(bool newCache) const { if(newCache == _reference->getCacheConnection()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeCacheConnection(newCache)); return proxy; } } EndpointSelectionType -IceProxy::Ice::Object::ice_getEndpointSelection() const +ICE_OBJECT_PRX::ice_getEndpointSelection() const { return _reference->getEndpointSelection(); } -ObjectPrx -IceProxy::Ice::Object::ice_endpointSelection(EndpointSelectionType newType) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_endpointSelection(EndpointSelectionType newType) const { if(newType == _reference->getEndpointSelection()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeEndpointSelection(newType)); return proxy; } } bool -IceProxy::Ice::Object::ice_isSecure() const +ICE_OBJECT_PRX::ice_isSecure() const { return _reference->getSecure(); } -ObjectPrx -IceProxy::Ice::Object::ice_secure(bool b) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_secure(bool b) const { if(b == _reference->getSecure()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeSecure(b)); return proxy; } } ::Ice::EncodingVersion -IceProxy::Ice::Object::ice_getEncodingVersion() const +ICE_OBJECT_PRX::ice_getEncodingVersion() const { return _reference->getEncoding(); } -ObjectPrx -IceProxy::Ice::Object::ice_encodingVersion(const ::Ice::EncodingVersion& encoding) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_encodingVersion(const ::Ice::EncodingVersion& encoding) const { if(encoding == _reference->getEncoding()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeEncoding(encoding)); return proxy; } } bool -IceProxy::Ice::Object::ice_isPreferSecure() const +ICE_OBJECT_PRX::ice_isPreferSecure() const { return _reference->getPreferSecure(); } -ObjectPrx -IceProxy::Ice::Object::ice_preferSecure(bool b) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_preferSecure(bool b) const { if(b == _reference->getPreferSecure()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changePreferSecure(b)); return proxy; } } -RouterPrx -IceProxy::Ice::Object::ice_getRouter() const +RouterPrxPtr +ICE_OBJECT_PRX::ice_getRouter() const { RouterInfoPtr ri = _reference->getRouterInfo(); - return ri ? ri->getRouter() : RouterPrx(); +#ifdef ICE_CPP11_MAPPING + return ri ? ri->getRouter() : nullptr; +#else + return ri ? ri->getRouter() : RouterPrxPtr(); +#endif } -ObjectPrx -IceProxy::Ice::Object::ice_router(const RouterPrx& router) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_router(const RouterPrxPtr& router) const { ReferencePtr ref = _reference->changeRouter(router); if(ref == _reference) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(ref); return proxy; } } -LocatorPrx -IceProxy::Ice::Object::ice_getLocator() const +LocatorPrxPtr +ICE_OBJECT_PRX::ice_getLocator() const { LocatorInfoPtr ri = _reference->getLocatorInfo(); - return ri ? ri->getLocator() : LocatorPrx(); +#ifdef ICE_CPP11_MAPPING + return ri ? ri->getLocator() : nullptr; +#else + return ri ? ri->getLocator() : LocatorPrxPtr(); +#endif } -ObjectPrx -IceProxy::Ice::Object::ice_locator(const LocatorPrx& locator) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_locator(const LocatorPrxPtr& locator) const { ReferencePtr ref = _reference->changeLocator(locator); if(ref == _reference) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(ref); return proxy; } } bool -IceProxy::Ice::Object::ice_isCollocationOptimized() const +ICE_OBJECT_PRX::ice_isCollocationOptimized() const { return _reference->getCollocationOptimized(); } -ObjectPrx -IceProxy::Ice::Object::ice_collocationOptimized(bool b) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_collocationOptimized(bool b) const { if(b == _reference->getCollocationOptimized()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeCollocationOptimized(b)); return proxy; } } Int -IceProxy::Ice::Object::ice_getInvocationTimeout() const +ICE_OBJECT_PRX::ice_getInvocationTimeout() const { return _reference->getInvocationTimeout(); } -ObjectPrx -IceProxy::Ice::Object::ice_invocationTimeout(Int newTimeout) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_invocationTimeout(Int newTimeout) const { if(newTimeout < 1 && newTimeout != -1 && newTimeout != -2) { @@ -1168,139 +1141,139 @@ IceProxy::Ice::Object::ice_invocationTimeout(Int newTimeout) const } if(newTimeout == _reference->getInvocationTimeout()) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeInvocationTimeout(newTimeout)); return proxy; } } -ObjectPrx -IceProxy::Ice::Object::ice_twoway() const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_twoway() const { if(_reference->getMode() == Reference::ModeTwoway) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeMode(Reference::ModeTwoway)); return proxy; } } bool -IceProxy::Ice::Object::ice_isTwoway() const +ICE_OBJECT_PRX::ice_isTwoway() const { return _reference->getMode() == Reference::ModeTwoway; } -ObjectPrx -IceProxy::Ice::Object::ice_oneway() const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_oneway() const { if(_reference->getMode() == Reference::ModeOneway) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeMode(Reference::ModeOneway)); return proxy; } } bool -IceProxy::Ice::Object::ice_isOneway() const +ICE_OBJECT_PRX::ice_isOneway() const { return _reference->getMode() == Reference::ModeOneway; } -ObjectPrx -IceProxy::Ice::Object::ice_batchOneway() const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_batchOneway() const { if(_reference->getMode() == Reference::ModeBatchOneway) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeMode(Reference::ModeBatchOneway)); return proxy; } } bool -IceProxy::Ice::Object::ice_isBatchOneway() const +ICE_OBJECT_PRX::ice_isBatchOneway() const { return _reference->getMode() == Reference::ModeBatchOneway; } -ObjectPrx -IceProxy::Ice::Object::ice_datagram() const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_datagram() const { if(_reference->getMode() == Reference::ModeDatagram) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeMode(Reference::ModeDatagram)); return proxy; } } bool -IceProxy::Ice::Object::ice_isDatagram() const +ICE_OBJECT_PRX::ice_isDatagram() const { return _reference->getMode() == Reference::ModeDatagram; } -ObjectPrx -IceProxy::Ice::Object::ice_batchDatagram() const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_batchDatagram() const { if(_reference->getMode() == Reference::ModeBatchDatagram) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(_reference->changeMode(Reference::ModeBatchDatagram)); return proxy; } } bool -IceProxy::Ice::Object::ice_isBatchDatagram() const +ICE_OBJECT_PRX::ice_isBatchDatagram() const { return _reference->getMode() == Reference::ModeBatchDatagram; } -ObjectPrx -IceProxy::Ice::Object::ice_compress(bool b) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_compress(bool b) const { ReferencePtr ref = _reference->changeCompress(b); if(ref == _reference) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(ref); return proxy; } } -ObjectPrx -IceProxy::Ice::Object::ice_timeout(int t) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_timeout(int t) const { if(t < 1 && t != -1) { @@ -1311,101 +1284,40 @@ IceProxy::Ice::Object::ice_timeout(int t) const ReferencePtr ref = _reference->changeTimeout(t); if(ref == _reference) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(ref); return proxy; } } -ObjectPrx -IceProxy::Ice::Object::ice_connectionId(const string& id) const +ObjectPrxPtr +ICE_OBJECT_PRX::ice_connectionId(const string& id) const { ReferencePtr ref = _reference->changeConnectionId(id); if(ref == _reference) { - return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + return CONST_POINTER_CAST_OBJECT_PRX; } else { - ObjectPrx proxy = __newInstance(); + ObjectPrxPtr proxy = __newInstance(); proxy->setup(ref); return proxy; } } string -IceProxy::Ice::Object::ice_getConnectionId() const +ICE_OBJECT_PRX::ice_getConnectionId() const { return _reference->getConnectionId(); } ConnectionPtr -IceProxy::Ice::Object::ice_getConnection() -{ - InvocationObserver observer(this, "ice_getConnection", 0); - int cnt = 0; - while(true) - { - RequestHandlerPtr handler; - try - { - handler = __getRequestHandler(); - return handler->waitForConnection(); // Wait for the connection to be established. - } - catch(const IceInternal::RetryException&) - { - __updateRequestHandler(handler, 0); // Clear request handler and retry. - } - catch(const Exception& ex) - { - try - { - int interval = __handleException(ex, handler, Idempotent, false, cnt); - observer.retried(); - if(interval > 0) - { - IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(interval)); - } - } - catch(const Exception& exc) - { - observer.failed(exc.ice_name()); - throw; - } - } - } -} - -AsyncResultPtr -IceProxy::Ice::Object::begin_ice_getConnectionInternal(const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) -{ - ProxyGetConnectionPtr result = new ProxyGetConnection(this, ice_getConnection_name, del, cookie); - try - { - result->invoke(); - } - catch(const Exception& ex) - { - result->abort(ex); - } - return result; -} - -ConnectionPtr -IceProxy::Ice::Object::end_ice_getConnection(const AsyncResultPtr& __result) -{ - AsyncResult::__check(__result, this, ice_getConnection_name); - __result->__wait(); - return ice_getCachedConnection(); -} - -ConnectionPtr -IceProxy::Ice::Object::ice_getCachedConnection() const +ICE_OBJECT_PRX::ice_getCachedConnection() const { RequestHandlerPtr __handler; { @@ -1427,51 +1339,21 @@ IceProxy::Ice::Object::ice_getCachedConnection() const } void -IceProxy::Ice::Object::ice_flushBatchRequests() -{ - ProxyFlushBatch og(this, ice_flushBatchRequests_name); - og.invoke(); -} - -::Ice::AsyncResultPtr -IceProxy::Ice::Object::begin_ice_flushBatchRequestsInternal(const ::IceInternal::CallbackBasePtr& del, - const ::Ice::LocalObjectPtr& cookie) -{ - ProxyFlushBatchAsyncPtr result = new ProxyFlushBatchAsync(this, ice_flushBatchRequests_name, del, cookie); - try - { - result->invoke(); - } - catch(const Exception& ex) - { - result->abort(ex); - } - return result; -} - -void -IceProxy::Ice::Object::end_ice_flushBatchRequests(const AsyncResultPtr& result) +ICE_OBJECT_PRX::setup(const ReferencePtr& ref) { - AsyncResult::__check(result, this, ice_flushBatchRequests_name); - result->__wait(); -} + // + // No need to synchronize "*this", as this operation is only + // called upon initialization. + // -Int -IceProxy::Ice::Object::__hash() const -{ - return _reference->hash(); -} + assert(!_reference); + assert(!_requestHandler); -void -IceProxy::Ice::Object::__copyFrom(const ObjectPrx& from) -{ - IceUtil::Mutex::Lock sync(from->_mutex); - _reference = from->_reference; - _requestHandler = from->_requestHandler; + _reference = ref; } int -IceProxy::Ice::Object::__handleException(const Exception& ex, +ICE_OBJECT_PRX::__handleException(const Exception& ex, const RequestHandlerPtr& handler, OperationMode mode, bool sent, @@ -1496,7 +1378,7 @@ IceProxy::Ice::Object::__handleException(const Exception& ex, // const LocalException* localEx = dynamic_cast<const LocalException*>(&ex); if(localEx && (!sent || - mode == Nonmutating || mode == Idempotent || + mode == ICE_ENUM(OperationMode, Nonmutating) || mode == ICE_ENUM(OperationMode, Idempotent) || dynamic_cast<const CloseConnectionException*>(&ex) || dynamic_cast<const ObjectNotExistException*>(&ex))) { @@ -1519,101 +1401,8 @@ IceProxy::Ice::Object::__handleException(const Exception& ex, return 0; // Keep the compiler happy. } -void -IceProxy::Ice::Object::__checkTwowayOnly(const string& name) const -{ - // - // No mutex lock necessary, there is nothing mutable in this operation. - // - if(!ice_isTwoway()) - { - TwowayOnlyException ex(__FILE__, __LINE__); - ex.operation = name; - throw ex; - } -} - -void -IceProxy::Ice::Object::__checkAsyncTwowayOnly(const string& name) const -{ - // - // No mutex lock necessary, there is nothing mutable in this operation. - // - if(!ice_isTwoway()) - { - throw IceUtil::IllegalArgumentException(__FILE__, - __LINE__, - "`" + name + "' can only be called with a twoway proxy"); - } -} - -void -IceProxy::Ice::Object::__invoke(Outgoing& __og) const -{ - // - // Helper for operations without out/return parameters and user - // exceptions. - // - - bool __ok = __og.invoke(); - if(__og.hasResponse()) - { - if(!__ok) - { - try - { - __og.throwUserException(); - } - catch(const ::Ice::UserException& __ex) - { - ::Ice::UnknownUserException __uue(__FILE__, __LINE__, __ex.ice_name()); - throw __uue; - } - } - __og.readEmptyParams(); - } -} - -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()); - } - } - __result->__readEmptyParams(); - } -} - -namespace IceProxy -{ - -namespace Ice -{ - -ostream& -operator<<(ostream& os, const ::IceProxy::Ice::Object& p) -{ - return os << p.ice_toString(); -} - -} - -} - ::IceInternal::RequestHandlerPtr -IceProxy::Ice::Object::__getRequestHandler() +ICE_OBJECT_PRX::__getRequestHandler() { RequestHandlerPtr handler; if(_reference->getCacheConnection()) @@ -1624,11 +1413,11 @@ IceProxy::Ice::Object::__getRequestHandler() return _requestHandler; } } - return _reference->getRequestHandler(this); + return _reference->getRequestHandler(ICE_SHARED_FROM_THIS); } IceInternal::BatchRequestQueuePtr -IceProxy::Ice::Object::__getBatchRequestQueue() +ICE_OBJECT_PRX::__getBatchRequestQueue() { IceUtil::Mutex::Lock sync(_mutex); if(!_batchRequestQueue) @@ -1639,7 +1428,7 @@ IceProxy::Ice::Object::__getBatchRequestQueue() } ::IceInternal::RequestHandlerPtr -IceProxy::Ice::Object::__setRequestHandler(const ::IceInternal::RequestHandlerPtr& handler) +ICE_OBJECT_PRX::__setRequestHandler(const ::IceInternal::RequestHandlerPtr& handler) { if(_reference->getCacheConnection()) { @@ -1654,7 +1443,7 @@ IceProxy::Ice::Object::__setRequestHandler(const ::IceInternal::RequestHandlerPt } void -IceProxy::Ice::Object::__updateRequestHandler(const ::IceInternal::RequestHandlerPtr& previous, +ICE_OBJECT_PRX::__updateRequestHandler(const ::IceInternal::RequestHandlerPtr& previous, const ::IceInternal::RequestHandlerPtr& handler) { if(_reference->getCacheConnection() && previous) @@ -1674,28 +1463,46 @@ IceProxy::Ice::Object::__updateRequestHandler(const ::IceInternal::RequestHandle } } -IceProxy::Ice::Object* -IceProxy::Ice::Object::__newInstance() const +void +ICE_OBJECT_PRX::__copyFrom(const ObjectPrxPtr& from) { - return new Object; + IceUtil::Mutex::Lock sync(from->_mutex); + _reference = from->_reference; + _requestHandler = from->_requestHandler; } -void -IceProxy::Ice::Object::setup(const ReferencePtr& ref) +CommunicatorPtr +ICE_OBJECT_PRX::ice_getCommunicator() const +{ + return _reference->getCommunicator(); +} + +string +ICE_OBJECT_PRX::ice_toString() const { // - // No need to synchronize "*this", as this operation is only - // called upon initialization. + // Returns the stringified proxy. There's no need to convert the + // string to a native string: a stringified proxy only contains + // printable ASCII which is a subset of all native character sets. // + return _reference->toString(); +} - assert(!_reference); - assert(!_requestHandler); +Int +ICE_OBJECT_PRX::__hash() const +{ + return _reference->hash(); +} - _reference = ref; +void +ICE_OBJECT_PRX::__write(OutputStream& os) const +{ + os.write(__reference()->getIdentity()); + __reference()->streamWrite(&os); } bool -Ice::proxyIdentityLess(const ObjectPrx& lhs, const ObjectPrx& rhs) +Ice::proxyIdentityLess(const ObjectPrxPtr& lhs, const ObjectPrxPtr& rhs) { if(!lhs && !rhs) { @@ -1716,7 +1523,7 @@ Ice::proxyIdentityLess(const ObjectPrx& lhs, const ObjectPrx& rhs) } bool -Ice::proxyIdentityEqual(const ObjectPrx& lhs, const ObjectPrx& rhs) +Ice::proxyIdentityEqual(const ObjectPrxPtr& lhs, const ObjectPrxPtr& rhs) { if(!lhs && !rhs) { @@ -1737,7 +1544,7 @@ Ice::proxyIdentityEqual(const ObjectPrx& lhs, const ObjectPrx& rhs) } bool -Ice::proxyIdentityAndFacetLess(const ObjectPrx& lhs, const ObjectPrx& rhs) +Ice::proxyIdentityAndFacetLess(const ObjectPrxPtr& lhs, const ObjectPrxPtr& rhs) { if(!lhs && !rhs) { @@ -1782,7 +1589,7 @@ Ice::proxyIdentityAndFacetLess(const ObjectPrx& lhs, const ObjectPrx& rhs) } bool -Ice::proxyIdentityAndFacetEqual(const ObjectPrx& lhs, const ObjectPrx& rhs) +Ice::proxyIdentityAndFacetEqual(const ObjectPrxPtr& lhs, const ObjectPrxPtr& rhs) { if(!lhs && !rhs) { @@ -1815,15 +1622,3 @@ Ice::proxyIdentityAndFacetEqual(const ObjectPrx& lhs, const ObjectPrx& rhs) return false; } } - -void -Ice::ice_writeObjectPrx(const OutputStreamPtr& out, const ObjectPrx& v) -{ - out->write(v); -} - -void -Ice::ice_readObjectPrx(const InputStreamPtr& in, ObjectPrx& v) -{ - in->read(v); -} |