From 9bc95008aed349790f2a7368b055ce270f68c012 Mon Sep 17 00:00:00 2001 From: srn Date: Tue, 12 Apr 2005 08:38:58 +0000 Subject: [PATCH] Added methods to get a CORBA wrappers of the SALOMEDSClient objects --- src/SALOMEDS/SALOMEDS_SComponent.cxx | 15 ++++++++++ src/SALOMEDS/SALOMEDS_SComponent.hxx | 2 ++ src/SALOMEDS/SALOMEDS_SObject.cxx | 39 +++++++++++++++++++++----- src/SALOMEDS/SALOMEDS_SObject.hxx | 14 ++++++--- src/SALOMEDS/SALOMEDS_Study.cxx | 23 ++++++++------- src/SALOMEDS/SALOMEDS_StudyBuilder.cxx | 2 +- src/SALOMEDS/SALOMEDS_StudyManager.cxx | 2 +- 7 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/SALOMEDS/SALOMEDS_SComponent.cxx b/src/SALOMEDS/SALOMEDS_SComponent.cxx index 6d51a3ba5..750123250 100644 --- a/src/SALOMEDS/SALOMEDS_SComponent.cxx +++ b/src/SALOMEDS/SALOMEDS_SComponent.cxx @@ -5,6 +5,7 @@ using namespace std; #include "SALOMEDS_SComponent.hxx" +#include "SALOMEDS_SComponent_i.hxx" #include #include @@ -47,3 +48,17 @@ bool SALOMEDS_SComponent::ComponentIOR(std::string& theID) return ret; } + +SALOMEDS::SComponent_ptr SALOMEDS_SComponent::GetSComponent() +{ + if(_isLocal) { + if(!CORBA::is_nil(_corba_impl)) return SALOMEDS::SComponent::_narrow(GetCORBAImpl()); + return SALOMEDS_SComponent_i::New(Handle(SALOMEDSImpl_SComponent)::DownCast(GetLocalImpl()), _orb); + } + else { + return SALOMEDS::SComponent::_narrow(GetCORBAImpl()); + } + + return SALOMEDS::SComponent::_nil(); +} + diff --git a/src/SALOMEDS/SALOMEDS_SComponent.hxx b/src/SALOMEDS/SALOMEDS_SComponent.hxx index cfd57e2b0..7f0d33878 100644 --- a/src/SALOMEDS/SALOMEDS_SComponent.hxx +++ b/src/SALOMEDS/SALOMEDS_SComponent.hxx @@ -23,5 +23,7 @@ public: virtual std::string ComponentDataType(); virtual bool ComponentIOR(std::string& theID); + + SALOMEDS::SComponent_ptr GetSComponent(); }; #endif diff --git a/src/SALOMEDS/SALOMEDS_SObject.cxx b/src/SALOMEDS/SALOMEDS_SObject.cxx index 5ad2e9b1b..9958da4ce 100644 --- a/src/SALOMEDS/SALOMEDS_SObject.cxx +++ b/src/SALOMEDS/SALOMEDS_SObject.cxx @@ -16,6 +16,9 @@ using namespace std; #include "SALOMEDS_Study.hxx" #include "SALOMEDSImpl_Study.hxx" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" + #ifdef WIN32 #include #else @@ -36,12 +39,14 @@ SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject) long addr = theSObject->GetLocalImpl(GetHostname().c_str(), pid, _isLocal); if(_isLocal) { _local_impl = ((SALOMEDSImpl_SObject*)(addr)); - _corba_impl = SALOMEDS::SObject::_nil(); + _corba_impl = SALOMEDS::SObject::_duplicate(theSObject); } else { _local_impl = NULL; _corba_impl = SALOMEDS::SObject::_duplicate(theSObject); } + + init_orb(); } SALOMEDS_SObject::SALOMEDS_SObject(const Handle(SALOMEDSImpl_SObject)& theSObject) @@ -49,6 +54,8 @@ SALOMEDS_SObject::SALOMEDS_SObject(const Handle(SALOMEDSImpl_SObject)& theSObjec { _corba_impl = SALOMEDS::SObject::_nil(); _local_impl = theSObject; + + init_orb(); } SALOMEDS_SObject::~SALOMEDS_SObject() @@ -217,13 +224,31 @@ int SALOMEDS_SObject::Depth() CORBA::Object_ptr SALOMEDS_SObject::GetObject() { - CORBA::Object_var obj; if(_isLocal) { std::string anIOR = GetIOR(); - SALOMEDS_Study* aStudy = dynamic_cast(GetStudy()); - obj = CORBA::Object::_duplicate(aStudy->ConvertIORToObject(anIOR)); - delete aStudy; + return _orb->string_to_object(anIOR.c_str()); + } + else return _corba_impl->GetObject(); + + return CORBA::Object::_nil(); +} + +SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject() +{ + if(_isLocal) { + if(!CORBA::is_nil(_corba_impl)) return _corba_impl; + return SALOMEDS_SObject_i::New(_local_impl, _orb); + } + else { + return _corba_impl; } - else obj = CORBA::Object::_duplicate(_corba_impl->GetObject()); - return obj._retn(); + return SALOMEDS::SObject::_nil(); +} + + +void SALOMEDS_SObject::init_orb() +{ + ORB_INIT &init = *SINGLETON_::Instance() ; + ASSERT(SINGLETON_::IsAlreadyExisting()); + _orb = init(0 , 0 ) ; } diff --git a/src/SALOMEDS/SALOMEDS_SObject.hxx b/src/SALOMEDS/SALOMEDS_SObject.hxx index 5cfb7497c..d6cf5687c 100644 --- a/src/SALOMEDS/SALOMEDS_SObject.hxx +++ b/src/SALOMEDS/SALOMEDS_SObject.hxx @@ -23,9 +23,10 @@ class SALOMEDS_SObject: public virtual SALOMEDSClient_SObject { protected: -bool _isLocal; -Handle(SALOMEDSImpl_SObject) _local_impl; -SALOMEDS::SObject_var _corba_impl; + bool _isLocal; + Handle(SALOMEDSImpl_SObject) _local_impl; + SALOMEDS::SObject_var _corba_impl; + CORBA::ORB_var _orb; public: @@ -50,8 +51,13 @@ public: virtual int Depth(); CORBA::Object_ptr GetObject(); + SALOMEDS::SObject_ptr GetSObject(); + SALOMEDS::SObject_ptr GetCORBAImpl() { return SALOMEDS::SObject::_duplicate(_corba_impl); } - Handle(SALOMEDSImpl_SObject) GetLocalImpl() { return _local_impl; } + Handle(SALOMEDSImpl_SObject) GetLocalImpl() { return _local_impl; } + +private: + void init_orb(); }; #endif diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index ac5b4c063..7f1fac0a3 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -60,7 +60,7 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy) long addr = theStudy->GetLocalImpl(GetHostname().c_str(), pid, _isLocal); if(_isLocal) { _local_impl = ((SALOMEDSImpl_Study*)(addr)); - _corba_impl = SALOMEDS::Study::_nil(); + _corba_impl = SALOMEDS::Study::_duplicate(theStudy); } else { _local_impl = NULL; @@ -133,18 +133,21 @@ SALOMEDSClient_SComponent* SALOMEDS_Study::FindComponentID(const std::string& aC SALOMEDSClient_SObject* SALOMEDS_Study::FindObject(const std::string& anObjectName) { - SALOMEDS_SObject* aSO = NULL; if(_isLocal) { Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObject((char*)anObjectName.c_str()); if(aSO_impl.IsNull()) return NULL; - aSO = new SALOMEDS_SObject(aSO_impl); + Handle(SALOMEDSImpl_SComponent) aSCO_impl = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO_impl); + if(!aSCO_impl.IsNull()) return new SALOMEDS_SComponent(aSCO_impl); + return new SALOMEDS_SObject(aSO_impl); } else { SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObject((char*)anObjectName.c_str()); if(CORBA::is_nil(aSO_impl)) return NULL; - aSO = new SALOMEDS_SObject(aSO_impl); + SALOMEDS::SComponent_var aSCO_impl = SALOMEDS::SComponent::_narrow(aSO_impl); + if(!CORBA::is_nil(aSCO_impl)) return new SALOMEDS_SComponent(aSCO_impl); + return new SALOMEDS_SObject(aSO_impl); } - return aSO; + return NULL; } std::vector SALOMEDS_Study::FindObjectByName(const std::string& anObjectName, @@ -170,18 +173,17 @@ std::vector SALOMEDS_Study::FindObjectByName(const std: SALOMEDSClient_SObject* SALOMEDS_Study::FindObjectID(const std::string& anObjectID) { - SALOMEDS_SObject* aSO = NULL; if(_isLocal) { Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectID((char*)anObjectID.c_str()); if(aSO_impl.IsNull()) return NULL; - aSO = new SALOMEDS_SObject(aSO_impl); + return new SALOMEDS_SObject(aSO_impl); } else { SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectID((char*)anObjectID.c_str()); if(CORBA::is_nil(aSO_impl)) return NULL; - aSO = new SALOMEDS_SObject(aSO_impl); + return new SALOMEDS_SObject(aSO_impl); } - return aSO; + return NULL; } SALOMEDSClient_SObject* SALOMEDS_Study::CreateObjectID(const std::string& anObjectID) @@ -530,13 +532,14 @@ CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) void SALOMEDS_Study::init_orb() { ORB_INIT &init = *SINGLETON_::Instance() ; - ASSERT(SINGLETON_::IsAlreadyExisting()) ; + ASSERT(SINGLETON_::IsAlreadyExisting()); _orb = init(0 , 0 ) ; } SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy() { if(_isLocal) { + if(!CORBA::is_nil(_corba_impl)) return _corba_impl; SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(_local_impl, _orb); SALOMEDS::Study_var Study = Study_servant->_this(); return Study; diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx index a84717d52..8e76a248e 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx @@ -415,6 +415,6 @@ void SALOMEDS_StudyBuilder::SetIOR(SALOMEDSClient_SObject* theSO, const std::str void SALOMEDS_StudyBuilder::init_orb() { ORB_INIT &init = *SINGLETON_::Instance() ; - ASSERT(SINGLETON_::IsAlreadyExisting()) ; + ASSERT(SINGLETON_::IsAlreadyExisting()); _orb = init(0 , 0 ) ; } diff --git a/src/SALOMEDS/SALOMEDS_StudyManager.cxx b/src/SALOMEDS/SALOMEDS_StudyManager.cxx index f0f189e44..181fa4c93 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager.cxx @@ -257,7 +257,7 @@ SALOMEDSClient_SObject* SALOMEDS_StudyManager::Paste(SALOMEDSClient_SObject* the void SALOMEDS_StudyManager::init_orb() { ORB_INIT &init = *SINGLETON_::Instance() ; - ASSERT(SINGLETON_::IsAlreadyExisting()) ; + ASSERT(SINGLETON_::IsAlreadyExisting()); _orb = init(0 , 0 ) ; } -- 2.39.2