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 /cpp/src | |
parent | Freeze fixes (diff) | |
download | ice-b42a7bbf16c4495ae7b9d5108e7d726f3ebb8356.tar.bz2 ice-b42a7bbf16c4495ae7b9d5108e7d726f3ebb8356.tar.xz ice-b42a7bbf16c4495ae7b9d5108e7d726f3ebb8356.zip |
location transparency stuff
Diffstat (limited to 'cpp/src')
-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 |
5 files changed, 332 insertions, 31 deletions
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: |