diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Ice/Proxy.h | 28 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyF.h | 6 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyHandle.h | 90 | ||||
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 103 | ||||
-rw-r--r-- | cpp/src/Ice/TraceUtil.cpp | 3 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 20 |
6 files changed, 153 insertions, 97 deletions
diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 49175e134c0..623c22e94a1 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -35,6 +35,7 @@ class ICE_API Object : public ::IceUtil::Shared, JTCMutex public: bool _isA(const std::string&); + bool _hasFacet(const std::string&); void _ping(); bool operator==(const Object&) const; @@ -58,17 +59,14 @@ public: void _flush(); // Flush batch messages ::IceInternal::ReferencePtr __reference() const; - void __copyTo(::IceProxy::Ice::Object*) const; + void __copyFrom(const ::IceProxy::Ice::Object*); + void __copyFromWithFacet(const ::IceProxy::Ice::Object*, const std::string&); void __handleException(const ::Ice::LocalException&, int&); void __rethrowException(const ::Ice::LocalException&); void __locationForward(const ::Ice::LocationForward&); protected: - Object(); - virtual ~Object(); - friend class ::IceInternal::ProxyFactory; - ::IceInternal::Handle< ::IceDelegate::Ice::Object> __getDelegate(); virtual ::IceInternal::Handle< ::IceDelegateM::Ice::Object> __createDelegateM(); virtual ::IceInternal::Handle< ::IceDelegateD::Ice::Object> __createDelegateD(); @@ -76,6 +74,7 @@ protected: private: void setup(const ::IceInternal::ReferencePtr&); + friend ::IceInternal::ProxyFactory; ::IceInternal::ReferencePtr _reference; ::IceInternal::Handle< ::IceDelegate::Ice::Object> _delegate; @@ -91,14 +90,9 @@ class ICE_API Object : public ::IceUtil::Shared public: virtual bool _isA(const std::string&) = 0; + virtual bool _hasFacet(const std::string&) = 0; virtual void _ping() = 0; virtual void _flush() = 0; - -protected: - - Object(); - virtual ~Object(); - friend class ::IceProxy::Ice::Object; }; } } @@ -111,21 +105,19 @@ class ICE_API Object : virtual public ::IceDelegate::Ice::Object public: virtual bool _isA(const std::string&); + virtual bool _hasFacet(const std::string&); virtual void _ping(); virtual void _flush(); protected: - Object(); - virtual ~Object(); - friend class ::IceProxy::Ice::Object; - ::IceInternal::EmitterPtr __emitter; ::IceInternal::ReferencePtr __reference; private: void setup(const ::IceInternal::ReferencePtr&); + friend class ::IceProxy::Ice::Object; }; } } @@ -138,21 +130,19 @@ class ICE_API Object : virtual public ::IceDelegate::Ice::Object public: virtual bool _isA(const std::string&); + virtual bool _hasFacet(const std::string&); virtual void _ping(); virtual void _flush(); protected: - Object(); - virtual ~Object(); - friend class ::IceProxy::Ice::Object; - ::Ice::ObjectAdapterPtr __adapter; ::IceInternal::ReferencePtr __reference; private: void setup(const ::IceInternal::ReferencePtr&, const ::Ice::ObjectAdapterPtr&); + friend class ::IceProxy::Ice::Object; }; } } diff --git a/cpp/include/Ice/ProxyF.h b/cpp/include/Ice/ProxyF.h index 8001b4bf06b..8afd5f3425d 100644 --- a/cpp/include/Ice/ProxyF.h +++ b/cpp/include/Ice/ProxyF.h @@ -33,10 +33,8 @@ void ICE_API decRef(::IceDelegateM::Ice::Object*); void ICE_API incRef(::IceDelegateD::Ice::Object*); void ICE_API decRef(::IceDelegateD::Ice::Object*); -void ICE_API checkedCast(::IceProxy::Ice::Object*, - ::IceProxy::Ice::Object*&); -void ICE_API uncheckedCast(::IceProxy::Ice::Object*, - ::IceProxy::Ice::Object*&); +void ICE_API checkedCast(::IceProxy::Ice::Object*, const ::std::string&, ::IceProxy::Ice::Object*&); +void ICE_API uncheckedCast(::IceProxy::Ice::Object*, const ::std::string&, ::IceProxy::Ice::Object*&); } diff --git a/cpp/include/Ice/ProxyHandle.h b/cpp/include/Ice/ProxyHandle.h index eb0880a01fb..ea428e7c7e8 100644 --- a/cpp/include/Ice/ProxyHandle.h +++ b/cpp/include/Ice/ProxyHandle.h @@ -11,8 +11,8 @@ #ifndef ICE_PROXY_HANDLE_H #define ICE_PROXY_HANDLE_H +#include <IceUtil/Handle.h> #include <Ice/Config.h> -#include <algorithm> namespace IceInternal { @@ -23,23 +23,40 @@ namespace IceInternal // dynamicCast(). // template<typename T> -class ProxyHandle +class ProxyHandle : public ::IceUtil::HandleBase<T> { public: ProxyHandle(T* p = 0) - : _ptr(p) { + _ptr = p; + if (_ptr) + { incRef(_ptr); + } } template<typename Y> ProxyHandle(const ProxyHandle<Y>& r) - : _ptr(r._ptr) { + _ptr = r._ptr; + + if (_ptr) + { + incRef(_ptr); + } + } + + template<typename Y> + ProxyHandle(const ::IceUtil::Handle<Y>& r) + { + _ptr = r._ptr; + if (_ptr) + { incRef(_ptr); + } } #ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? @@ -48,16 +65,21 @@ public: #else ProxyHandle(const ProxyHandle& r) #endif - : _ptr(r._ptr) { + _ptr = r._ptr; + if (_ptr) + { incRef(_ptr); + } } ~ProxyHandle() { if (_ptr) + { decRef(_ptr); + } } ProxyHandle& operator=(T* p) @@ -65,10 +87,14 @@ public: if (_ptr != p) { if (p) + { incRef(p); + } if (_ptr) + { decRef(_ptr); + } _ptr = p; } @@ -81,10 +107,34 @@ public: if (_ptr != r._ptr) { if (r._ptr) + { incRef(r._ptr); + } if (_ptr) + { decRef(_ptr); + } + + _ptr = r._ptr; + } + return *this; + } + + template<typename Y> + ProxyHandle& operator=(const ::IceUtil::Handle<Y>& r) + { + if (_ptr != r._ptr) + { + if (r._ptr) + { + incRef(r._ptr); + } + + if (_ptr) + { + decRef(_ptr); + } _ptr = r._ptr; } @@ -101,10 +151,14 @@ public: if (_ptr != r._ptr) { if (r._ptr) + { incRef(r._ptr); + } if (_ptr) + { decRef(_ptr); + } _ptr = r._ptr; } @@ -112,38 +166,20 @@ public: } template<class Y> - static ProxyHandle checkedCast(const ProxyHandle<Y>& r) + static ProxyHandle checkedCast(const ProxyHandle<Y>& r, const std::string& f = "") { T* p; - ::IceInternal::checkedCast(r._ptr, p); + ::IceInternal::checkedCast(r._ptr, f, p); return ProxyHandle(p); } template<class Y> - static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r) + static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r, const std::string& f = "") { T* p; - ::IceInternal::uncheckedCast(r._ptr, p); + ::IceInternal::uncheckedCast(r._ptr, f, p); return ProxyHandle(p); } - - typedef T element_type; - - T* get() const { return _ptr; } - T* operator->() const { return _ptr; } - operator bool() const { return _ptr ? true : false; } - - void swap(ProxyHandle& other) { std::swap(_ptr, other._ptr); } - -#ifndef WIN32 // COMPILERBUG: VC++ 6.0 doesn't understand this - - template<typename Y> friend class ProxyHandle; - -protected: - -#endif - - T* _ptr; }; template<typename T, typename U> diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 4e6ec8120ba..9957c3b4353 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -40,15 +40,18 @@ void IceInternal::incRef(::IceDelegateD::Ice::Object* p) { p->__incRef(); } void IceInternal::decRef(::IceDelegateD::Ice::Object* p) { p->__decRef(); } void -IceInternal::checkedCast(::IceProxy::Ice::Object* b, ::IceProxy::Ice::Object*& d) +IceInternal::checkedCast(::IceProxy::Ice::Object* b, const string& f, ::IceProxy::Ice::Object*& d) { - d = b; + // TODO: Check facet + d = new ::IceProxy::Ice::Object; + d->__copyFromWithFacet(b, f); } void -IceInternal::uncheckedCast(::IceProxy::Ice::Object* b, ::IceProxy::Ice::Object*& d) +IceInternal::uncheckedCast(::IceProxy::Ice::Object* b, const string& f, ::IceProxy::Ice::Object*& d) { - d = b; + d = new ::IceProxy::Ice::Object; + d->__copyFromWithFacet(b, f); } bool @@ -77,6 +80,32 @@ IceProxy::Ice::Object::_isA(const string& s) } } +bool +IceProxy::Ice::Object::_hasFacet(const string& s) +{ + int __cnt = 0; + while (true) + { + try + { + Handle< ::IceDelegate::Ice::Object> __del = __getDelegate(); + return __del->_hasFacet(s); + } + catch (const LocationForward& __ex) + { + __locationForward(__ex); + } + catch (const NonRepeatable& __ex) + { + __handleException(*__ex.get(), __cnt); + } + catch (const LocalException& __ex) + { + __handleException(__ex, __cnt); + } + } +} + void IceProxy::Ice::Object::_ping() { @@ -290,9 +319,15 @@ IceProxy::Ice::Object::__reference() const } void -IceProxy::Ice::Object::__copyTo(::IceProxy::Ice::Object* to) const +IceProxy::Ice::Object::__copyFrom(const ::IceProxy::Ice::Object* from) { - to->setup(_reference); + setup(from->__reference()); +} + +void +IceProxy::Ice::Object::__copyFromWithFacet(const ::IceProxy::Ice::Object* from, const string& facet) +{ + setup(from->__reference()->changeFacet(facet)); } void @@ -393,14 +428,6 @@ IceProxy::Ice::Object::__rethrowException(const LocalException& ex) ex._throw(); } -IceProxy::Ice::Object::Object() -{ -} - -IceProxy::Ice::Object::~Object() -{ -} - Handle< ::IceDelegate::Ice::Object> IceProxy::Ice::Object::__getDelegate() { @@ -447,21 +474,30 @@ IceProxy::Ice::Object::setup(const ReferencePtr& ref) _reference = ref; } -IceDelegate::Ice::Object::Object() -{ -} - -IceDelegate::Ice::Object::~Object() +bool +IceDelegateM::Ice::Object::_isA(const string& s) { + Outgoing __out(__emitter, __reference); + BasicStream* __is = __out.is(); + BasicStream* __os = __out.os(); + __os->write("_isA"); + __os->write(s); + if (!__out.invoke()) + { + throw ::Ice::UnknownUserException(__FILE__, __LINE__); + } + bool __ret; + __is->read(__ret); + return __ret; } bool -IceDelegateM::Ice::Object::_isA(const string& s) +IceDelegateM::Ice::Object::_hasFacet(const string& s) { Outgoing __out(__emitter, __reference); BasicStream* __is = __out.is(); BasicStream* __os = __out.os(); - __os->write("_isA"); + __os->write("_hasFacet"); __os->write(s); if (!__out.invoke()) { @@ -490,14 +526,6 @@ IceDelegateM::Ice::Object::_flush() __emitter->flushBatchRequest(); } -IceDelegateM::Ice::Object::Object() -{ -} - -IceDelegateM::Ice::Object::~Object() -{ -} - void IceDelegateM::Ice::Object::setup(const ReferencePtr& ref) { @@ -558,10 +586,17 @@ IceDelegateD::Ice::Object::_isA(const string& s) return __direct.servant()->_isA(s); } +bool +IceDelegateD::Ice::Object::_hasFacet(const string& s) +{ + Direct __direct(__adapter, __reference, "_hasFacet"); + return __direct.servant()->_hasFacet(s); +} + void IceDelegateD::Ice::Object::_ping() { - Direct __direct(__adapter, __reference, "_isA"); + Direct __direct(__adapter, __reference, "_ping"); __direct.servant()->_ping(); } @@ -571,14 +606,6 @@ IceDelegateD::Ice::Object::_flush() // Nothing to do for direct delegates } -IceDelegateD::Ice::Object::Object() -{ -} - -IceDelegateD::Ice::Object::~Object() -{ -} - void IceDelegateD::Ice::Object::setup(const ReferencePtr& ref, const ObjectAdapterPtr& adapter) { diff --git a/cpp/src/Ice/TraceUtil.cpp b/cpp/src/Ice/TraceUtil.cpp index 0707a7ffcb5..4f3b9a7e0db 100644 --- a/cpp/src/Ice/TraceUtil.cpp +++ b/cpp/src/Ice/TraceUtil.cpp @@ -104,6 +104,9 @@ IceInternal::traceRequest(const char* heading, const BasicStream& str, const ::I string identity; stream.read(identity); s << "\nidentity = " << identity; + string facet; + stream.read(facet); + s << "\nfacet = " << facet; string operation; stream.read(operation); s << "\noperation name = " << operation; diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 19e1c1f2d35..1ad8d17faea 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1953,8 +1953,10 @@ Slice::Gen::IceVisitor::visitClassDecl(const ClassDeclPtr& p) H << nl << _dllExport << "void incRef(::IceProxy" << scoped << "*);"; H << nl << _dllExport << "void decRef(::IceProxy" << scoped << "*);"; H << sp; - H << nl << _dllExport << "void checkedCast(::IceProxy::Ice::Object*, ::IceProxy" << scoped << "*&);"; - H << nl << _dllExport << "void uncheckedCast(::IceProxy::Ice::Object*, ::IceProxy" << scoped << "*&);"; + H << nl << _dllExport << "void checkedCast(::IceProxy::Ice::Object*, const ::std::string&, ::IceProxy" + << scoped << "*&);"; + H << nl << _dllExport << "void uncheckedCast(::IceProxy::Ice::Object*, const ::std::string&, ::IceProxy" + << scoped << "*&);"; } } @@ -1985,25 +1987,25 @@ Slice::Gen::IceVisitor::visitClassDefStart(const ClassDefPtr& p) C << nl << "p->__decRef();"; C << eb; C << sp; - C << nl << "void" << nl << "IceInternal::checkedCast(::IceProxy::Ice::Object* b, ::IceProxy" << scoped - << "*& d)"; + C << nl << "void" << nl << "IceInternal::checkedCast(::IceProxy::Ice::Object* b, const ::std::string& f, " + << "::IceProxy" << scoped << "*& d)"; C << sb; C << nl << "d = dynamic_cast< ::IceProxy" << scoped << "*>(b);"; C << nl << "if (!d && b->_isA(\"" << scoped << "\"))"; C << sb; C << nl << "d = new ::IceProxy" << scoped << ';'; - C << nl << "b->__copyTo(d);"; + C << nl << "d->__copyFromWithFacet(b, f);"; C << eb; C << eb; C << sp; - C << nl << "void" << nl << "IceInternal::uncheckedCast(::IceProxy::Ice::Object* b, ::IceProxy" << scoped - << "*& d)"; + C << nl << "void" << nl << "IceInternal::uncheckedCast(::IceProxy::Ice::Object* b, const ::std::string& f, " + << "::IceProxy" << scoped << "*& d)"; C << sb; C << nl << "d = dynamic_cast< ::IceProxy" << scoped << "*>(b);"; C << nl << "if (!d)"; C << sb; C << nl << "d = new ::IceProxy" << scoped << ';'; - C << nl << "b->__copyTo(d);"; + C << nl << "d->__copyFromWithFacet(b, f);"; C << eb; C << eb; } @@ -2085,7 +2087,7 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) C << nl << "else"; C << sb; C << nl << "v = new ::IceProxy" << scoped << ';'; - C << nl << "proxy->__copyTo(v.get());"; + C << nl << "v->__copyFrom(proxy.get());"; C << eb; C << eb; |