diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Ice/Object.h | 16 | ||||
-rw-r--r-- | cpp/include/Ice/Proxy.h | 5 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyF.h | 6 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyHandle.h | 12 | ||||
-rw-r--r-- | cpp/src/Ice/Object.cpp | 108 | ||||
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 95 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 66 |
7 files changed, 179 insertions, 129 deletions
diff --git a/cpp/include/Ice/Object.h b/cpp/include/Ice/Object.h index 535831a62ab..98b7c2e1398 100644 --- a/cpp/include/Ice/Object.h +++ b/cpp/include/Ice/Object.h @@ -57,14 +57,9 @@ class ICE_API Object : virtual public ::IceUtil::Shared { public: - Object(); - virtual ~Object(); - virtual bool _isA(const std::string&); - virtual bool _hasFacet(const std::string&); virtual void _ping(); ::IceInternal::DispatchStatus ____isA(::IceInternal::Incoming&); - ::IceInternal::DispatchStatus ____hasFacet(::IceInternal::Incoming&); ::IceInternal::DispatchStatus ____ping(::IceInternal::Incoming&); virtual const char** __getClassIds() = 0; @@ -74,6 +69,17 @@ public: virtual void __write(::IceInternal::BasicStream*) const = 0; virtual void __read(::IceInternal::BasicStream*) = 0; + + void _addFacet(const ObjectPtr&, const ::std::string&); + void _removeFacet(const ::std::string&); + void _removeAllFacets(const ::std::string&); + ObjectPtr _findFacet(const ::std::string&); + +private: + + std::map<std::string, ObjectPtr> _activeFacetMap; + std::map<std::string, ObjectPtr>::iterator _activeFacetMapHint; + JTCMutex _activeFacetMapMutex; }; } diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 64ad96adec2..7d3f6c61e94 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -35,7 +35,6 @@ 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; @@ -60,7 +59,6 @@ public: ::IceInternal::ReferencePtr __reference() const; void __copyFrom(const ::Ice::ObjectPrx&); - void __copyFromWithFacet(const ::Ice::ObjectPrx&, const std::string&); void __handleException(const ::Ice::LocalException&, int&); void __rethrowException(const ::Ice::LocalException&); void __locationForward(const ::Ice::LocationForward&); @@ -90,7 +88,6 @@ 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; }; @@ -105,7 +102,6 @@ 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(); @@ -130,7 +126,6 @@ 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(); diff --git a/cpp/include/Ice/ProxyF.h b/cpp/include/Ice/ProxyF.h index 8afd5f3425d..97a5a0a4662 100644 --- a/cpp/include/Ice/ProxyF.h +++ b/cpp/include/Ice/ProxyF.h @@ -33,8 +33,10 @@ 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*, const ::std::string&, ::IceProxy::Ice::Object*&); -void ICE_API uncheckedCast(::IceProxy::Ice::Object*, const ::std::string&, ::IceProxy::Ice::Object*&); +void ICE_API checkedCast(const ProxyHandle< ::IceProxy::Ice::Object>&, const ::std::string&, + ProxyHandle< ::IceProxy::Ice::Object>&); +void ICE_API uncheckedCast(const ProxyHandle< ::IceProxy::Ice::Object>&, const ::std::string&, + ProxyHandle< ::IceProxy::Ice::Object>&); } diff --git a/cpp/include/Ice/ProxyHandle.h b/cpp/include/Ice/ProxyHandle.h index ea428e7c7e8..4b5e2055f0f 100644 --- a/cpp/include/Ice/ProxyHandle.h +++ b/cpp/include/Ice/ProxyHandle.h @@ -168,17 +168,17 @@ public: template<class Y> static ProxyHandle checkedCast(const ProxyHandle<Y>& r, const std::string& f = "") { - T* p; - ::IceInternal::checkedCast(r._ptr, f, p); - return ProxyHandle(p); + ProxyHandle p; + ::IceInternal::checkedCast(r, f, p); + return p; } template<class Y> static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r, const std::string& f = "") { - T* p; - ::IceInternal::uncheckedCast(r._ptr, f, p); - return ProxyHandle(p); + ProxyHandle p; + ::IceInternal::uncheckedCast(r, f, p); + return p; } }; diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index 7549ddbc793..e2458e9ac89 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -28,26 +28,12 @@ Ice::LocationForward::LocationForward(const ObjectPrx& p) : { } -Ice::Object::Object() -{ -} - -Ice::Object::~Object() -{ -} - bool Ice::Object::_isA(const string& s) { return s == "::Ice::Object"; } -bool -Ice::Object::_hasFacet(const string& s) -{ - return false; // TODO -} - void Ice::Object::_ping() { @@ -67,18 +53,6 @@ Ice::Object::____isA(Incoming& __in) } DispatchStatus -Ice::Object::____hasFacet(Incoming& __in) -{ - BasicStream* __is = __in.is(); - BasicStream* __os = __in.os(); - string s; - __is->read(s); - bool __ret = _hasFacet(s); - __os->write(__ret); - return DispatchOK; -} - -DispatchStatus Ice::Object::____ping(Incoming&) { _ping(); @@ -87,7 +61,6 @@ Ice::Object::____ping(Incoming&) const char* Ice::Object::__all[] = { - "_hasFacet" "_isA" "_ping" }; @@ -107,13 +80,9 @@ Ice::Object::__dispatch(Incoming& in, const string& s) { case 0: { - return ____hasFacet(in); - } - case 1: - { return ____isA(in); } - case 2: + case 1: { return ____ping(in); } @@ -132,3 +101,78 @@ Ice::Object::__isMutating(const std::string& s) // return false; } + +void +Ice::Object::_addFacet(const ObjectPtr& facet, const string& name) +{ + JTCSyncT<JTCMutex> sync(_activeFacetMapMutex); + + _activeFacetMapHint = _activeFacetMap.insert(_activeFacetMapHint, make_pair(name, facet)); +} + +void +Ice::Object::_removeFacet(const string& name) +{ + JTCSyncT<JTCMutex> sync(_activeFacetMapMutex); + + map<string, ObjectPtr>::iterator p = _activeFacetMap.end(); + + if (_activeFacetMapHint != _activeFacetMap.end()) + { + if (_activeFacetMapHint->first == name) + { + p = _activeFacetMapHint; + } + } + + if (p == _activeFacetMap.end()) + { + p = _activeFacetMap.find(name); + } + + if (p != _activeFacetMap.end()) + { + _activeFacetMap.erase(p); + _activeFacetMapHint = _activeFacetMap.end(); + } +} + +void +Ice::Object::_removeAllFacets(const string& name) +{ + JTCSyncT<JTCMutex> sync(_activeFacetMapMutex); + + _activeFacetMap.clear(); + _activeFacetMapHint = _activeFacetMap.end(); +} + +ObjectPtr +Ice::Object::_findFacet(const string& name) +{ + JTCSyncT<JTCMutex> sync(_activeFacetMapMutex); + + map<string, ObjectPtr>::iterator p = _activeFacetMap.end(); + + if (_activeFacetMapHint != _activeFacetMap.end()) + { + if (_activeFacetMapHint->first == name) + { + p = _activeFacetMapHint; + } + } + + if (p == _activeFacetMap.end()) + { + p = _activeFacetMap.find(name); + } + + if (p != _activeFacetMap.end()) + { + _activeFacetMapHint = p; + return p->second; + } + else + { + return 0; + } +} diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index a4353eca0a7..496ffb279be 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -40,48 +40,47 @@ 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, const string& f, ::IceProxy::Ice::Object*& d) +IceInternal::checkedCast(const ObjectPrx& b, const string& f, ObjectPrx& d) { - // TODO: Check facet - d = new ::IceProxy::Ice::Object; - d->__copyFromWithFacet(b, f); -} - -void -IceInternal::uncheckedCast(::IceProxy::Ice::Object* b, const string& f, ::IceProxy::Ice::Object*& d) -{ - d = new ::IceProxy::Ice::Object; - d->__copyFromWithFacet(b, f); -} - -bool -IceProxy::Ice::Object::_isA(const string& s) -{ - int __cnt = 0; - while (true) + d = 0; + if (b) { - try - { - Handle< ::IceDelegate::Ice::Object> __del = __getDelegate(); - return __del->_isA(s); - } - catch (const LocationForward& __ex) - { - __locationForward(__ex); - } - catch (const NonRepeatable& __ex) + if (f == b->_getFacet()) { - __handleException(*__ex.get(), __cnt); + d = b; } - catch (const LocalException& __ex) + else { - __handleException(__ex, __cnt); + ObjectPrx bb = b->_newFacet(f); + try + { +#ifdef NDEBUG + bb->_isA("::Ice::Object"); +#else + bool ok = bb->_isA("::Ice::Object"); + assert(ok); +#endif + d = bb; + } + catch (const FacetNotExistException&) + { + } } } } +void +IceInternal::uncheckedCast(const ObjectPrx& b, const string& f, ObjectPrx& d) +{ + d = 0; + if (b) + { + d = b->_newFacet(f); + } +} + bool -IceProxy::Ice::Object::_hasFacet(const string& s) +IceProxy::Ice::Object::_isA(const string& s) { int __cnt = 0; while (true) @@ -89,7 +88,7 @@ IceProxy::Ice::Object::_hasFacet(const string& s) try { Handle< ::IceDelegate::Ice::Object> __del = __getDelegate(); - return __del->_hasFacet(s); + return __del->_isA(s); } catch (const LocationForward& __ex) { @@ -325,12 +324,6 @@ IceProxy::Ice::Object::__copyFrom(const ObjectPrx& from) } void -IceProxy::Ice::Object::__copyFromWithFacet(const ObjectPrx& from, const string& facet) -{ - setup(from->__reference()->changeFacet(facet)); -} - -void IceProxy::Ice::Object::__handleException(const LocalException& ex, int& cnt) { JTCSyncT<JTCMutex> sync(*this); @@ -491,23 +484,6 @@ IceDelegateM::Ice::Object::_isA(const string& s) return __ret; } -bool -IceDelegateM::Ice::Object::_hasFacet(const string& s) -{ - Outgoing __out(__emitter, __reference); - BasicStream* __is = __out.is(); - BasicStream* __os = __out.os(); - __os->write("_hasFacet"); - __os->write(s); - if (!__out.invoke()) - { - throw ::Ice::UnknownUserException(__FILE__, __LINE__); - } - bool __ret; - __is->read(__ret); - return __ret; -} - void IceDelegateM::Ice::Object::_ping() { @@ -586,13 +562,6 @@ 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() { diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index e52791c97e2..f8ee945c781 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1617,7 +1617,6 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) StringList allOpNames; transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), ::IceUtil::memFun(&Operation::name)); allOpNames.push_back("_isA"); - allOpNames.push_back("_hasFacet"); allOpNames.push_back("_ping"); allOpNames.sort(); allOpNames.unique(); @@ -1628,7 +1627,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) StringList allMutatingOpNames; transform(allMutatingOps.begin(), allMutatingOps.end(), back_inserter(allMutatingOpNames), ::IceUtil::memFun(&Operation::name)); - // Don't add _isA, _hasFacet, and _ping. These operations are non-mutating. + // Don't add _isA and _ping. These operations are non-mutating. allMutatingOpNames.sort(); allMutatingOpNames.unique(); @@ -1953,10 +1952,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*, const ::std::string&, ::IceProxy" - << scoped << "*&);"; - H << nl << _dllExport << "void uncheckedCast(::IceProxy::Ice::Object*, const ::std::string&, ::IceProxy" - << scoped << "*&);"; + H << nl << _dllExport << "void checkedCast(const ::Ice::ObjectPrx&, const ::std::string&, " + << "ProxyHandle< ::IceProxy" << scoped << ">&);"; + H << nl << _dllExport << "void uncheckedCast(const ::Ice::ObjectPrx&, const ::std::string&, " + << "ProxyHandle< ::IceProxy" << scoped << ">&);"; } } @@ -1987,25 +1986,60 @@ 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, const ::std::string& f, " - << "::IceProxy" << scoped << "*& d)"; + C << nl << "void" << nl << "IceInternal::checkedCast(const ::Ice::ObjectPrx& b, const ::std::string& f, " + << scoped << "Prx& d)"; C << sb; - C << nl << "d = dynamic_cast< ::IceProxy" << scoped << "*>(b);"; + C << nl << "d = 0;"; + C << nl << "if (b)"; + C << sb; + C << nl << "if (f == b->_getFacet())"; + C << sb; + C << nl << "d = dynamic_cast< ::IceProxy" << scoped << "*>(b.get());"; C << nl << "if (!d && b->_isA(\"" << scoped << "\"))"; C << sb; - C << nl << "d = new ::IceProxy" << scoped << ';'; - C << nl << "d->__copyFromWithFacet(b, f);"; + C << nl << "d = new ::IceProxy" << scoped << ";"; + C << nl << "d->__copyFrom(b);"; + C << eb; + C << eb; + C << nl << "else"; + C << sb; + C << nl << "::Ice::ObjectPrx bb = b->_newFacet(f);"; + C << nl << "try"; + C << sb; + C << nl << "if (bb->_isA(\"" << scoped << "\"))"; + C << sb; + C << nl << "d = new ::IceProxy" << scoped << ";"; + C << nl << "d->__copyFrom(bb);"; + C << eb; + C << eb; + C << nl << "catch (const ::Ice::FacetNotExistException&)"; + C << sb; + C << eb; + C << eb; C << eb; C << eb; C << sp; - C << nl << "void" << nl << "IceInternal::uncheckedCast(::IceProxy::Ice::Object* b, const ::std::string& f, " - << "::IceProxy" << scoped << "*& d)"; + C << nl << "void" << nl << "IceInternal::uncheckedCast(const ::Ice::ObjectPrx& b, const ::std::string& f, " + << scoped << "Prx& d)"; + C << sb; + C << nl << "d = 0;"; + C << nl << "if (b)"; + C << sb; + C << nl << "if (f == b->_getFacet())"; C << sb; - C << nl << "d = dynamic_cast< ::IceProxy" << scoped << "*>(b);"; + C << nl << "d = dynamic_cast< ::IceProxy" << scoped << "*>(b.get());"; C << nl << "if (!d)"; C << sb; - C << nl << "d = new ::IceProxy" << scoped << ';'; - C << nl << "d->__copyFromWithFacet(b, f);"; + C << nl << "d = new ::IceProxy" << scoped << ";"; + C << nl << "d->__copyFrom(b);"; + C << eb; + C << eb; + C << nl << "else"; + C << sb; + C << nl << "::Ice::ObjectPrx bb = b->_newFacet(f);"; + C << nl << "d = new ::IceProxy" << scoped << ";"; + C << nl << "d->__copyFrom(bb);"; + C << eb; C << eb; C << eb; } |