// ********************************************************************** // // Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. // // This copy of Ice-E is licensed to you under the terms described in the // ICEE_LICENSE file included in this distribution. // // ********************************************************************** #ifndef ICEE_PROXY_H #define ICEE_PROXY_H #include #include #include #include #include //#include // Can't include RouterF.h here, otherwise we have cyclic includes //#include // Can't include RouterF.h here, otherwise we have cyclic includes #include #include #include #include #include #ifdef ICEE_HAS_ROUTER namespace IceProxy { namespace Ice { class Router; } } namespace IceInternal { ICE_API void incRef(::IceProxy::Ice::Router*); ICE_API void decRef(::IceProxy::Ice::Router*); class LocalExceptionWrapper; } namespace Ice { typedef ::IceInternal::ProxyHandle< ::IceProxy::Ice::Router> RouterPrx; } #endif // ICEE_HAS_ROUTER #ifdef ICEE_HAS_LOCATOR namespace IceProxy { namespace Ice { class Locator; } } namespace IceInternal { ICE_API void incRef(::IceProxy::Ice::Locator*); ICE_API void decRef(::IceProxy::Ice::Locator*); } namespace Ice { typedef ::IceInternal::ProxyHandle< ::IceProxy::Ice::Locator> LocatorPrx; } #endif // ICEE_HAS_LOCATOR namespace Ice { class LocalException; typedef ::std::map< ::std::string, ::std::string> Context; class __U__Context { }; ICE_API void __write(::IceInternal::BasicStream*, const Context&, __U__Context); ICE_API void __read(::IceInternal::BasicStream*, Context&, __U__Context); } namespace IceProxy { namespace Ice { #if defined(_MSC_VER) && (_MSC_VER == 1310) // Work around for VC++ 7.1 bug typedef ::std::map< ::std::string, ::std::string> Context; #endif class Object : public ::IceUtil::Shared, private ::IceUtil::Mutex { public: ICE_API bool operator==(const Object&) const; ICE_API bool operator<(const Object&) const; ICE_DEPRECATED_API ::Ice::Int ice_hash() const { return ice_getHash(); } ICE_API ::Ice::Int ice_getHash() const; ICE_DEPRECATED_API ::Ice::CommunicatorPtr ice_communicator() const { return ice_getCommunicator(); } ICE_API ::Ice::CommunicatorPtr ice_getCommunicator() const; ICE_API ::std::string ice_toString() const; bool ice_isA(const ::std::string& typeId) { return ice_isA(typeId, 0); } bool ice_isA(const ::std::string& typeId, const ::Ice::Context& context) { return ice_isA(typeId, &context); } void ice_ping() { ice_ping(0); } void ice_ping(const ::Ice::Context& context) { ice_ping(&context); } ::std::vector< ::std::string> ice_ids() { return ice_ids(0); } ::std::vector< ::std::string> ice_ids(const ::Ice::Context& context) { return ice_ids(&context); } ::std::string ice_id() { return ice_id(0); } ::std::string ice_id(const ::Ice::Context& context) { return ice_id(&context); } ICE_API ::Ice::Identity ice_getIdentity() const; ICE_DEPRECATED_API ::Ice::ObjectPrx ice_newIdentity(const ::Ice::Identity& id) const { return ice_identity(id); } ICE_API ::Ice::ObjectPrx ice_identity(const ::Ice::Identity&) const; ICE_API ::Ice::Context ice_getContext() const; ICE_DEPRECATED_API ::Ice::ObjectPrx ice_newContext(const ::Ice::Context& ctx) const { return ice_context(ctx); } ICE_API ::Ice::ObjectPrx ice_context(const ::Ice::Context&) const; ICE_API const ::std::string& ice_getFacet() const; ICE_DEPRECATED_API ::Ice::ObjectPrx ice_newFacet(const ::std::string& facet) const { return ice_facet(facet); } ICE_API ::Ice::ObjectPrx ice_facet(const ::std::string&) const; #ifdef ICEE_HAS_ROUTER ICE_API ::Ice::ObjectPrx ice_router(const ::Ice::RouterPrx&) const; ICE_API ::Ice::RouterPrx ice_getRouter() const; #endif #ifdef ICEE_HAS_LOCATOR ICE_API ::Ice::ObjectPrx ice_adapterId(const std::string&) const; ICE_API std::string ice_getAdapterId() const; ICE_API ::Ice::ObjectPrx ice_locator(const ::Ice::LocatorPrx&) const; ICE_API ::Ice::LocatorPrx ice_getLocator() const; #endif ICE_API ::Ice::ObjectPrx ice_twoway() const; ICE_API bool ice_isTwoway() const; ICE_API ::Ice::ObjectPrx ice_oneway() const; ICE_API bool ice_isOneway() const; #ifdef ICEE_HAS_BATCH ICE_API ::Ice::ObjectPrx ice_batchOneway() const; ICE_API bool ice_isBatchOneway() const; #endif ICE_API ::Ice::ObjectPrx ice_timeout(int) const; ICE_DEPRECATED_API ::Ice::ConnectionPtr ice_connection() { return ice_getConnection(); } ICE_API ::Ice::ConnectionPtr ice_getConnection(); ICE_API ::Ice::ConnectionPtr ice_getCachedConnection() const; ::IceInternal::ReferencePtr __reference() const { return _reference; } ICE_API void __copyFrom(const ::Ice::ObjectPrx&); ICE_API void __handleException(const ::Ice::ConnectionPtr&, const ::Ice::LocalException&, int&); ICE_API void __handleExceptionWrapper(const ::Ice::ConnectionPtr&, const ::IceInternal::LocalExceptionWrapper&); ICE_API void __handleExceptionWrapperRelaxed(const ::Ice::ConnectionPtr&, const ::IceInternal::LocalExceptionWrapper&, int&); ICE_API void __checkTwowayOnly(const char*) const; protected: ::IceInternal::ReferencePtr _reference; private: ICE_API bool ice_isA(const ::std::string&, const ::Ice::Context*); ICE_API void ice_ping(const ::Ice::Context*); ICE_API ::std::vector< ::std::string> ice_ids(const ::Ice::Context*); ICE_API ::std::string ice_id(const ::Ice::Context*); void setup(const ::IceInternal::ReferencePtr& ref) { // // No need to synchronize "*this", as this operation is only // called upon initialization. // assert(!_reference); assert(!_connection); _reference = ref; } friend class ::IceInternal::ProxyFactory; ::Ice::ConnectionPtr _connection; }; } } namespace Ice { ICE_API bool proxyIdentityLess(const ObjectPrx&, const ObjectPrx&); ICE_API bool proxyIdentityEqual(const ObjectPrx&, const ObjectPrx&); ICE_API bool proxyIdentityAndFacetLess(const ObjectPrx&, const ObjectPrx&); ICE_API bool proxyIdentityAndFacetEqual(const ObjectPrx&, const ObjectPrx&); struct ProxyIdentityLess : std::binary_function { bool operator()(const ObjectPrx& lhs, const ObjectPrx& rhs) const { return proxyIdentityLess(lhs, rhs); } }; struct ProxyIdentityEqual : std::binary_function { bool operator()(const ObjectPrx& lhs, const ObjectPrx& rhs) const { return proxyIdentityEqual(lhs, rhs); } }; struct ProxyIdentityAndFacetLess : std::binary_function { bool operator()(const ObjectPrx& lhs, const ObjectPrx& rhs) const { return proxyIdentityAndFacetLess(lhs, rhs); } }; struct ProxyIdentityAndFacetEqual : std::binary_function { bool operator()(const ObjectPrx& lhs, const ObjectPrx& rhs) const { return proxyIdentityAndFacetEqual(lhs, rhs); } }; } namespace IceInternal { // // Inline comparison functions for proxies // template inline bool operator==(const ProxyHandle& lhs, const ProxyHandle& rhs) { ::IceProxy::Ice::Object* l = lhs.__upCast(); ::IceProxy::Ice::Object* r = rhs.__upCast(); if(l && r) { return *l == *r; } else { return !l && !r; } } template inline bool operator!=(const ProxyHandle& lhs, const ProxyHandle& rhs) { return !operator==(lhs, rhs); } template inline bool operator<(const ProxyHandle& lhs, const ProxyHandle& rhs) { ::IceProxy::Ice::Object* l = lhs.__upCast(); ::IceProxy::Ice::Object* r = rhs.__upCast(); if(l && r) { return *l < *r; } else { return !l && r; } } template inline bool operator<=(const ProxyHandle& lhs, const ProxyHandle& rhs) { return lhs < rhs || lhs == rhs; } template inline bool operator>(const ProxyHandle& lhs, const ProxyHandle& rhs) { return !(lhs < rhs || lhs == rhs); } template inline bool operator>=(const ProxyHandle& lhs, const ProxyHandle& rhs) { return !(lhs < rhs); } // // checkedCast and uncheckedCast functions without facet: // // // Out of line implementations // template P checkedCastImpl(const ::Ice::ObjectPrx& b) { P d = 0; if(b.get()) { typedef typename P::element_type T; d = dynamic_cast(b.get()); if(!d && b->ice_isA(T::ice_staticId())) { d = new T; d->__copyFrom(b); } } return d; } template P checkedCastImpl(const ::Ice::ObjectPrx& b, const ::Ice::Context& ctx) { P d = 0; if(b.get()) { typedef typename P::element_type T; d = dynamic_cast(b.get()); if(!d && b->ice_isA(T::ice_staticId(), ctx)) { d = new T; d->__copyFrom(b); } } return d; } template P uncheckedCastImpl(const ::Ice::ObjectPrx& b) { P d = 0; if(b) { typedef typename P::element_type T; d = dynamic_cast(b.get()); if(!d) { d = new T; d->__copyFrom(b); } } return d; } // // checkedCast and uncheckedCast with facet: // // // Helper with type ID. // ICE_API ::Ice::ObjectPrx checkedCastImpl(const ::Ice::ObjectPrx&, const std::string&, const std::string&); ICE_API ::Ice::ObjectPrx checkedCastImpl(const ::Ice::ObjectPrx&, const std::string&, const std::string&, const ::Ice::Context&); // // Specializations for P = ::Ice::ObjectPrx // We have to use inline functions for broken compilers such as VC7. // template<> inline ::Ice::ObjectPrx checkedCastImpl< ::Ice::ObjectPrx>(const ::Ice::ObjectPrx& b, const std::string& f) { return checkedCastImpl(b, f, "::Ice::Object"); } template<> inline ::Ice::ObjectPrx checkedCastImpl< ::Ice::ObjectPrx>(const ::Ice::ObjectPrx& b, const std::string& f, const ::Ice::Context& ctx) { return checkedCastImpl(b, f, "::Ice::Object", ctx); } template<> inline ::Ice::ObjectPrx uncheckedCastImpl< ::Ice::ObjectPrx>(const ::Ice::ObjectPrx& b, const std::string& f) { ::Ice::ObjectPrx d = 0; if(b) { d = b->ice_facet(f); } return d; } template P checkedCastImpl(const ::Ice::ObjectPrx& b, const std::string& f) { P d = 0; typedef typename P::element_type T; ::Ice::ObjectPrx bb = checkedCastImpl(b, f, T::ice_staticId()); if(bb) { d = new T; d->__copyFrom(bb); } return d; } template P checkedCastImpl(const ::Ice::ObjectPrx& b, const std::string& f, const ::Ice::Context& ctx) { P d = 0; typedef typename P::element_type T; ::Ice::ObjectPrx bb = checkedCastImpl(b, f, T::ice_staticId(), ctx); if(bb) { d = new T; d->__copyFrom(bb); } return d; } template P uncheckedCastImpl(const ::Ice::ObjectPrx& b, const std::string& f) { P d = 0; if(b) { typedef typename P::element_type T; ::Ice::ObjectPrx bb = b->ice_facet(f); d = new T; d->__copyFrom(bb); } return d; } } // // checkedCast and uncheckedCast functions provided in the global namespace // template inline P checkedCast(const ::IceInternal::ProxyHandle& b) { Y* tag = 0; #if defined(_MSC_VER) && (_MSC_VER < 1300) return ::IceInternal::checkedCastHelper(b, tag); #else return ::IceInternal::checkedCastHelper(b, tag); #endif } template inline P checkedCast(const ::IceInternal::ProxyHandle& b, const ::Ice::Context& ctx) { Y* tag = 0; #if defined(_MSC_VER) && (_MSC_VER < 1300) return ::IceInternal::checkedCastHelper(b, tag, ctx); #else return ::IceInternal::checkedCastHelper(b, tag, ctx); #endif } template inline P uncheckedCast(const ::IceInternal::ProxyHandle& b) { Y* tag = 0; #if defined(_MSC_VER) && (_MSC_VER < 1300) return ::IceInternal::uncheckedCastHelper(b, tag); #else return ::IceInternal::uncheckedCastHelper(b, tag); #endif } template inline P checkedCast(const ::Ice::ObjectPrx& b, const std::string& f) { return ::IceInternal::checkedCastImpl

(b, f); } template inline P checkedCast(const ::Ice::ObjectPrx& b, const std::string& f, const ::Ice::Context& ctx) { return ::IceInternal::checkedCastImpl

(b, f, ctx); } template inline P uncheckedCast(const ::Ice::ObjectPrx& b, const std::string& f) { return ::IceInternal::checkedCastImpl

(b, f); } #endif