diff options
author | Marc Laukien <marc@zeroc.com> | 2001-09-27 18:58:55 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-09-27 18:58:55 +0000 |
commit | b42a7bbf16c4495ae7b9d5108e7d726f3ebb8356 (patch) | |
tree | faaf559e36cb8a03427618ce0cff4ecf9dbd260b | |
parent | Freeze fixes (diff) | |
download | ice-b42a7bbf16c4495ae7b9d5108e7d726f3ebb8356.tar.bz2 ice-b42a7bbf16c4495ae7b9d5108e7d726f3ebb8356.tar.xz ice-b42a7bbf16c4495ae7b9d5108e7d726f3ebb8356.zip |
location transparency stuff
-rw-r--r-- | cpp/include/Ice/Direct.h | 43 | ||||
-rw-r--r-- | cpp/include/Ice/Object.h | 4 | ||||
-rw-r--r-- | cpp/include/Ice/Proxy.h | 37 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyF.h | 4 | ||||
-rw-r--r-- | cpp/src/Ice/Direct.cpp | 82 | ||||
-rw-r--r-- | cpp/src/Ice/Makefile | 1 | ||||
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 59 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 199 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.h | 22 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/Collocated.cpp | 1 | ||||
-rw-r--r-- | cpp/test/Ice/inheritance/Collocated.cpp | 1 | ||||
-rw-r--r-- | cpp/test/Ice/operations/Collocated.cpp | 1 | ||||
-rw-r--r-- | cpp/test/IcePack/simple/Collocated.cpp | 1 |
13 files changed, 419 insertions, 36 deletions
diff --git a/cpp/include/Ice/Direct.h b/cpp/include/Ice/Direct.h new file mode 100644 index 00000000000..e6f65b7cbe2 --- /dev/null +++ b/cpp/include/Ice/Direct.h @@ -0,0 +1,43 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef ICE_DIRECT_H +#define ICE_DIRECT_H + +#include <Ice/ObjectAdapterF.h> +#include <Ice/ReferenceF.h> +#include <Ice/ObjectF.h> +#include <Ice/LocalObjectF.h> + +namespace IceInternal +{ + +class ICE_API Direct : public ::IceUtil::noncopyable +{ +public: + + Direct(const ::Ice::ObjectAdapterPtr&, const ReferencePtr&, const char*); + ~Direct(); + + const ::Ice::ObjectPtr& servant(); + +private: + + const ::Ice::ObjectAdapterPtr& _adapter; + const ReferencePtr& _reference; + const char* _operation; + ::Ice::ObjectPtr _servant; + ::Ice::ServantLocatorPtr _locator; + ::Ice::LocalObjectPtr _cookie; +}; + +} + +#endif diff --git a/cpp/include/Ice/Object.h b/cpp/include/Ice/Object.h index 1ee34b1e58a..603ccdbc402 100644 --- a/cpp/include/Ice/Object.h +++ b/cpp/include/Ice/Object.h @@ -13,7 +13,7 @@ #include <IceUtil/Shared.h> #include <Ice/ObjectF.h> -#include <Ice/Proxy.h> +#include <Ice/ProxyF.h> namespace IceInternal { @@ -67,7 +67,7 @@ protected: ObjectPtr _ptr; }; -class ICE_API Object : virtual public ::IceDelegate::Ice::Object +class ICE_API Object : public ::IceUtil::Shared { public: diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 2309cec94d3..ec12c6ee5c5 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -15,6 +15,8 @@ #include <Ice/ProxyF.h> #include <Ice/ProxyFactoryF.h> #include <Ice/EmitterF.h> +#include <Ice/ObjectF.h> +#include <Ice/ObjectAdapterF.h> #include <Ice/ReferenceF.h> namespace Ice @@ -102,7 +104,7 @@ public: virtual bool _isA(const std::string&) = 0; virtual void _ping() = 0; - virtual void _flush(); + virtual void _flush() = 0; protected: @@ -112,7 +114,7 @@ protected: private: - virtual void setup(const ::IceInternal::ReferencePtr&); + virtual void setup(const ::IceInternal::ReferencePtr&) = 0; }; } } @@ -134,10 +136,39 @@ protected: virtual ~Object(); friend class ::IceProxy::Ice::Object; + ::IceInternal::EmitterPtr __emitter; + ::IceInternal::ReferencePtr __reference; + +private: + virtual void setup(const ::IceInternal::ReferencePtr&); +}; - ::IceInternal::EmitterPtr __emitter; +} } + +namespace IceDelegateD { namespace Ice +{ + +class ICE_API Object : virtual public ::IceDelegate::Ice::Object +{ +public: + + virtual bool _isA(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: + + virtual void setup(const ::IceInternal::ReferencePtr&); }; } } diff --git a/cpp/include/Ice/ProxyF.h b/cpp/include/Ice/ProxyF.h index dd4d34af5e7..8001b4bf06b 100644 --- a/cpp/include/Ice/ProxyF.h +++ b/cpp/include/Ice/ProxyF.h @@ -16,6 +16,7 @@ namespace IceProxy { namespace Ice { class Object; } } namespace IceDelegate { namespace Ice { class Object; } } namespace IceDelegateM { namespace Ice { class Object; } } +namespace IceDelegateD { namespace Ice { class Object; } } namespace IceInternal { @@ -29,6 +30,9 @@ void ICE_API decRef(::IceDelegate::Ice::Object*); void ICE_API incRef(::IceDelegateM::Ice::Object*); 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*, diff --git a/cpp/src/Ice/Direct.cpp b/cpp/src/Ice/Direct.cpp new file mode 100644 index 00000000000..f88987a7d45 --- /dev/null +++ b/cpp/src/Ice/Direct.cpp @@ -0,0 +1,82 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Direct.h> +#include <Ice/ObjectAdapter.h> +#include <Ice/Reference.h> +#include <Ice/Object.h> +#include <Ice/LocalException.h> + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +IceInternal::Direct::Direct(const ObjectAdapterPtr& adapter, const ReferencePtr& ref, const char* operation) : + _adapter(adapter), + _reference(ref), + _operation(operation) +{ + _servant = _adapter->identityToServant(_reference->identity); + + try + { + if (!_servant) + { + _locator = _adapter->getServantLocator(); + if (_locator) + { + _servant = _locator->locate(_adapter, _reference->identity, _operation, _cookie); + } + } + + if(!_servant) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + } + catch(const LocationForward&) + { + if (_locator && _servant) + { + _locator->finished(_adapter, _reference->identity, _servant, _operation, _cookie); + } + throw; + } + catch(const LocalException&) + { + if (_locator && _servant) + { + _locator->finished(_adapter, _reference->identity, _servant, _operation, _cookie); + } + throw; + } + catch(...) + { + if (_locator && _servant) + { + _locator->finished(_adapter, _reference->identity, _servant, _operation, _cookie); + } + throw UnknownException(__FILE__, __LINE__); + } +} + +IceInternal::Direct::~Direct() +{ + if (_locator && _servant) + { + _locator->finished(_adapter, _reference->identity, _servant, _operation, _cookie); + } +} + +const ObjectPtr& +IceInternal::Direct::servant() +{ + return _servant; +} diff --git a/cpp/src/Ice/Makefile b/cpp/src/Ice/Makefile index 14632f1000f..d4d19d3d408 100644 --- a/cpp/src/Ice/Makefile +++ b/cpp/src/Ice/Makefile @@ -46,6 +46,7 @@ OBJS = Application.o \ Proxy.o \ Outgoing.o \ Incoming.o \ + Direct.o \ Emitter.o \ Collector.o \ Network.o \ diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 8e73188486a..22b18a98695 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -10,8 +10,8 @@ #include <Ice/Proxy.h> #include <Ice/Object.h> -#include <Ice/ObjectAdapterFactory.h> #include <Ice/Outgoing.h> +#include <Ice/Direct.h> #include <Ice/Reference.h> #include <Ice/Endpoint.h> #include <Ice/Instance.h> @@ -36,6 +36,9 @@ void IceInternal::decRef(::IceDelegate::Ice::Object* p) { p->__decRef(); } void IceInternal::incRef(::IceDelegateM::Ice::Object* p) { p->__incRef(); } void IceInternal::decRef(::IceDelegateM::Ice::Object* p) { p->__decRef(); } +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) { @@ -405,6 +408,7 @@ IceProxy::Ice::Object::__getDelegate() JTCSyncT<JTCMutex> sync(*this); if (!_delegate) { +/* ObjectPtr obj = _reference->instance->objectAdapterFactory()->proxyToServant(this); if (obj) @@ -413,6 +417,7 @@ IceProxy::Ice::Object::__getDelegate() } else { +*/ _delegate = __createDelegateM(); try { @@ -423,7 +428,7 @@ IceProxy::Ice::Object::__getDelegate() _delegate = 0; throw; } - } +// } } return _delegate; @@ -445,12 +450,6 @@ IceProxy::Ice::Object::setup(const ReferencePtr& reference) _reference = reference; } -void -IceDelegate::Ice::Object::_flush() -{ - // Do nothing -} - IceDelegate::Ice::Object::Object() { } @@ -459,11 +458,6 @@ IceDelegate::Ice::Object::~Object() { } -void -IceDelegate::Ice::Object::setup(const ReferencePtr&) -{ -} - bool IceDelegateM::Ice::Object::_isA(const string& s) { @@ -561,3 +555,42 @@ IceDelegateM::Ice::Object::setup(const ReferencePtr& reference) __emitter = factory->create(endpoints); assert(__emitter); } + +bool +IceDelegateD::Ice::Object::_isA(const string& s) +{ + Direct __direct(__adapter, __reference, "_isA"); + return __direct.servant()->_isA(s); +} + +void +IceDelegateD::Ice::Object::_ping() +{ + Direct __direct(__adapter, __reference, "_isA"); + __direct.servant()->_ping(); +} + +void +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& reference) +{ + // + // No need to synchronize, as this operation is only called + // upon initial initialization. + // + __reference = reference; +} + diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index a2f63a4e788..cbf12353d14 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -21,7 +21,7 @@ struct ToIfdef char operator()(char c) { if (!isalnum(c)) - { + { return '_'; } else @@ -116,6 +116,7 @@ Slice::Gen::generate(const UnitPtr& unit) H << "\n#include <Ice/Object.h>"; H << "\n#include <Ice/Outgoing.h>"; H << "\n#include <Ice/Incoming.h>"; + H << "\n#include <Ice/Direct.h>"; H << "\n#include <Ice/LocalException.h>"; } else @@ -182,6 +183,9 @@ Slice::Gen::generate(const UnitPtr& unit) DelegateMVisitor delegateMVisitor(H, C, _dllExport); unit->visit(&delegateMVisitor); + DelegateDVisitor delegateDVisitor(H, C, _dllExport); + unit->visit(&delegateDVisitor); + ObjectVisitor objectVisitor(H, C, _dllExport); unit->visit(&objectVisitor); } @@ -905,19 +909,16 @@ Slice::Gen::DelegateVisitor::visitOperation(const OperationPtr& p) TypeStringList::const_iterator q; string params = "("; - string args = "("; for (q = inParams.begin(); q != inParams.end(); ++q) { if (q != inParams.begin()) { params += ", "; - args += ", "; } string typeString = inputTypeToString(q->first); params += typeString; - args += q->second; } for (q = outParams.begin(); q != outParams.end(); ++q) @@ -925,16 +926,13 @@ Slice::Gen::DelegateVisitor::visitOperation(const OperationPtr& p) if (q != outParams.begin() || !inParams.empty()) { params += ", "; - args += ", "; } string typeString = outputTypeToString(q->first); params += typeString; - args += q->second; } params += ')'; - args += ')'; TypeList throws = p->throws(); @@ -1043,7 +1041,6 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) { string name = p->name(); string scoped = p->scoped(); -// string scope = p->scope(); TypePtr ret = p->returnType(); string retS = returnTypeToString(ret); @@ -1054,7 +1051,6 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) string params = "("; string paramsDecl = "("; // With declarators - string args = "("; for (q = inParams.begin(); q != inParams.end(); ++q) { @@ -1062,7 +1058,6 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) { params += ", "; paramsDecl += ", "; - args += ", "; } string typeString = inputTypeToString(q->first); @@ -1070,7 +1065,6 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) paramsDecl += typeString; paramsDecl += ' '; paramsDecl += q->second; - args += q->second; } for (q = outParams.begin(); q != outParams.end(); ++q) @@ -1079,7 +1073,6 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) { params += ", "; paramsDecl += ", "; - args += ", "; } string typeString = outputTypeToString(q->first); @@ -1087,12 +1080,10 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) paramsDecl += typeString; paramsDecl += ' '; paramsDecl += q->second; - args += q->second; } params += ')'; paramsDecl += ')'; - args += ')'; TypeList throws = p->throws(); @@ -1154,6 +1145,182 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) C << eb; } +Slice::Gen::DelegateDVisitor::DelegateDVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) +{ +} + +bool +Slice::Gen::DelegateDVisitor::visitUnitStart(const UnitPtr& p) +{ + if (!p->hasProxies()) + { + return false; + } + + H << sp; + H << nl << "namespace IceDelegateD" << nl << '{'; + + return true; +} + +void +Slice::Gen::DelegateDVisitor::visitUnitEnd(const UnitPtr& p) +{ + H << sp; + H << nl << '}'; +} + +bool +Slice::Gen::DelegateDVisitor::visitModuleStart(const ModulePtr& p) +{ + if (!p->hasProxies()) + { + return false; + } + + string name = p->name(); + + H << sp; + H << nl << "namespace " << name << nl << '{'; + + return true; +} + +void +Slice::Gen::DelegateDVisitor::visitModuleEnd(const ModulePtr& p) +{ + H << sp; + H << nl << '}'; +} + +bool +Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p) +{ + if (p->isLocal()) + { + return false; + } + + string name = p->name(); + string scoped = p->scoped(); + ClassList bases = p->bases(); + + H << sp; + H << nl << "class " << _dllExport << name << " : "; + H.useCurrentPosAsIndent(); + H << "virtual public ::IceDelegate" << scoped << ','; + if (bases.empty()) + { + H << nl << "virtual public ::IceDelegateD::Ice::Object"; + } + else + { + ClassList::const_iterator q = bases.begin(); + while (q != bases.end()) + { + H << nl << "virtual public ::IceDelegateD" << (*q)->scoped(); + if (++q != bases.end()) + { + H << ','; + } + } + } + H.restoreIndent(); + H << sb; + H.dec(); + H << nl << "public: "; + H.inc(); + + return true; +} + +void +Slice::Gen::DelegateDVisitor::visitClassDefEnd(const ClassDefPtr& p) +{ + H << eb << ';'; +} + +void +Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p) +{ + ContainerPtr container = p->container(); + ClassDefPtr cl = ClassDefPtr::dynamicCast(container); + + string name = p->name(); + string scoped = p->scoped(); + + TypePtr ret = p->returnType(); + string retS = returnTypeToString(ret); + + TypeStringList inParams = p->inputParameters(); + TypeStringList outParams = p->outputParameters(); + TypeStringList::const_iterator q; + + string params = "("; + string paramsDecl = "("; // With declarators + string args = "("; + + for (q = inParams.begin(); q != inParams.end(); ++q) + { + if (q != inParams.begin()) + { + params += ", "; + paramsDecl += ", "; + args += ", "; + } + + string typeString = inputTypeToString(q->first); + params += typeString; + paramsDecl += typeString; + paramsDecl += ' '; + paramsDecl += q->second; + args += q->second; + } + + for (q = outParams.begin(); q != outParams.end(); ++q) + { + if (q != outParams.begin() || !inParams.empty()) + { + params += ", "; + paramsDecl += ", "; + args += ", "; + } + + string typeString = outputTypeToString(q->first); + params += typeString; + paramsDecl += typeString; + paramsDecl += ' '; + paramsDecl += q->second; + args += q->second; + } + + params += ')'; + paramsDecl += ')'; + args += ')'; + + TypeList throws = p->throws(); + + H << sp; + H << nl << "virtual " << retS << ' ' << name << params << ';'; + C << sp; + C << nl << retS << nl << "IceDelegateD" << scoped << paramsDecl; + C << sb; + C << nl << "::IceInternal::Direct __direct(__adapter, __reference, \"" << name << "\");"; + C << nl << cl->scoped() << "* __servant = dynamic_cast< " << cl->scoped() << "*>(__direct.servant().get());"; + C << nl << "if (!__servant)"; + C << sb; + C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__);"; + C << eb; + C << nl; + if (ret) + { + C << "return "; + } + C << "__servant->" << name << args << ';'; + C << eb; +} + Slice::Gen::ObjectDeclVisitor::ObjectDeclVisitor(Output& h, Output& c, const string& dllExport) : H(h), C(c), _dllExport(dllExport) { @@ -1373,10 +1540,6 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) } } } - if (!p->isLocal()) - { - H << ',' << nl << "virtual public ::IceDelegate" << scoped; - } H.restoreIndent(); H << sb; H.dec(); diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index cddd62692aa..693f064df50 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -156,6 +156,28 @@ private: std::string _dllExport; }; + class DelegateDVisitor : public ::IceUtil::noncopyable, public ParserVisitor + { + public: + + DelegateDVisitor(Output&, Output&, const std::string&); + + virtual bool visitUnitStart(const UnitPtr&); + virtual void visitUnitEnd(const UnitPtr&); + virtual bool visitModuleStart(const ModulePtr&); + virtual void visitModuleEnd(const ModulePtr&); + virtual bool visitClassDefStart(const ClassDefPtr&); + virtual void visitClassDefEnd(const ClassDefPtr&); + virtual void visitOperation(const OperationPtr&); + + private: + + Output& H; + Output& C; + + std::string _dllExport; + }; + class ObjectDeclVisitor : public ::IceUtil::noncopyable, public ParserVisitor { public: diff --git a/cpp/test/Ice/exceptions/Collocated.cpp b/cpp/test/Ice/exceptions/Collocated.cpp index 63a8fda6ccf..6be6fa2a6e3 100644 --- a/cpp/test/Ice/exceptions/Collocated.cpp +++ b/cpp/test/Ice/exceptions/Collocated.cpp @@ -20,6 +20,7 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("TestAdapter", endpts); Ice::ObjectPtr object = new ThrowerI(adapter); adapter->add(object, "thrower"); + adapter->activate(); ThrowerPrx allTests(const Ice::CommunicatorPtr&); allTests(communicator); diff --git a/cpp/test/Ice/inheritance/Collocated.cpp b/cpp/test/Ice/inheritance/Collocated.cpp index 63b9d8ffb00..36bda26e114 100644 --- a/cpp/test/Ice/inheritance/Collocated.cpp +++ b/cpp/test/Ice/inheritance/Collocated.cpp @@ -20,6 +20,7 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("TestAdapter", endpts); Ice::ObjectPtr object = new InitialI(adapter); adapter->add(object, "initial"); + adapter->activate(); InitialPrx allTests(const Ice::CommunicatorPtr&); allTests(communicator); diff --git a/cpp/test/Ice/operations/Collocated.cpp b/cpp/test/Ice/operations/Collocated.cpp index a266c7bdf0b..25963719269 100644 --- a/cpp/test/Ice/operations/Collocated.cpp +++ b/cpp/test/Ice/operations/Collocated.cpp @@ -20,6 +20,7 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("TestAdapter", endpts); Ice::ObjectPtr object = new MyDerivedClassI(adapter, "test"); adapter->add(object, "test"); + adapter->activate(); Test::MyClassPrx allTests(const Ice::CommunicatorPtr&); allTests(communicator); diff --git a/cpp/test/IcePack/simple/Collocated.cpp b/cpp/test/IcePack/simple/Collocated.cpp index eba91ca4924..3c63eec9414 100644 --- a/cpp/test/IcePack/simple/Collocated.cpp +++ b/cpp/test/IcePack/simple/Collocated.cpp @@ -20,6 +20,7 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("TestAdapter", endpts); Ice::ObjectPtr object = new TestI(adapter); adapter->add(object, "test"); + adapter->activate(); TestPrx allTests(const Ice::CommunicatorPtr&); allTests(communicator); |