summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2001-10-18 15:34:32 +0000
committerMarc Laukien <marc@zeroc.com>2001-10-18 15:34:32 +0000
commit6f32b305b09f6b975db8f6626e851e4104e3c88e (patch)
tree1f2c1df0c066433b412b7bc16a7db00611efee93 /cpp/src
parentwin fixes (diff)
downloadice-6f32b305b09f6b975db8f6626e851e4104e3c88e.tar.bz2
ice-6f32b305b09f6b975db8f6626e851e4104e3c88e.tar.xz
ice-6f32b305b09f6b975db8f6626e851e4104e3c88e.zip
more facet stuff
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Object.cpp108
-rw-r--r--cpp/src/Ice/Proxy.cpp95
-rw-r--r--cpp/src/slice2cpp/Gen.cpp66
3 files changed, 158 insertions, 111 deletions
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;
}