-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// See http://www.salome-platform.org/
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
// File : SALOMEDS_StudyManager_i.cxx
// Author : Sergey RUIN
// Module : SALOME
-
+//
#include "utilities.h"
#include "SALOME_LifeCycleCORBA.hxx"
#include "SALOMEDS_StudyManager_i.hxx"
#include "SALOMEDSImpl_SComponent.hxx"
#include "SALOMEDSImpl_AttributeIOR.hxx"
-#include <TColStd_HArray1OfCharacter.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TCollection_AsciiString.hxx>
-
#include "Utils_CorbaException.hxx"
+#include "Utils_ExceptHandlers.hxx"
+#include "Basics_Utils.hxx"
+#include "SALOME_GenericObj_i.hh"
-#include <strstream>
+#include <sstream>
+#include <vector>
#include <map>
-using namespace std;
#ifdef WIN32
#include <process.h>
#include <unistd.h>
#endif
-#include "OpUtil.hxx"
-
-#include "SALOME_GenericObj_i.hh"
-
-#include "Utils_ExceptHandlers.hxx"
-
UNEXPECT_CATCH(SalomeException,SALOME::SALOME_Exception);
UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection);
-static SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb);
+static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
static std::map<int, PortableServer::POA_ptr> _mapOfPOA;
{
// Destroy directory to register open studies
_name_service->Destroy_Directory("/Study");
+ delete _name_service;
delete _factory;
+ delete _impl;
}
//============================================================================
* context name
*/
//============================================================================
-void SALOMEDS_StudyManager_i::register_name(char * name)
+void SALOMEDS_StudyManager_i::register_name(const char * name)
{
SALOMEDS::StudyManager_var aManager(_this());
_name_service->Register(aManager.in(), name);
{
SALOMEDS::Locker lock;
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->NewStudy(TCollection_AsciiString((char*)study_name));
- if(aStudyImpl.IsNull()) {
+ SALOMEDSImpl_Study* aStudyImpl = _impl->NewStudy(study_name);
+ if(!aStudyImpl) {
MESSAGE("NewStudy : Error : " << _impl->GetErrorCode());
return SALOMEDS::Study::_nil();
}
MESSAGE("NewStudy : Creating the CORBA servant holding it... ");
- SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
- SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
+ SALOMEDS_Study_i *Study_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+ PortableServer::ObjectId_var servantid = _poa->activate_object(Study_servant); // to use poa registered in _mapOfPOA
+ SALOMEDS::Study_var Study = Study_servant->_this();
// Register study in the naming service
// Path to acces the study
_name_service->Register(Study, study_name);
// Assign the value of the IOR in the study->root
- const char* IORStudy = _orb->object_to_string(Study);
+ CORBA::String_var IORStudy = _orb->object_to_string(Study);
- aStudyImpl->SetTransientReference((char*)IORStudy);
+ aStudyImpl->SetTransientReference((char*)IORStudy.in());
_mapOfPOA[Study->StudyId()] = _poa;
- return Study;
+ return Study._retn();
}
//============================================================================
Unexpect aCatch(SalomeException);
MESSAGE("Begin of SALOMEDS_StudyManager_i::Open");
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->Open(TCollection_AsciiString((char*)aUrl));
+ SALOMEDSImpl_Study* aStudyImpl = _impl->Open(std::string(aUrl));
+
+ if ( !aStudyImpl )
+ THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
MESSAGE("Open : Creating the CORBA servant holding it... ");
// Temporary aStudyUrl in place of study name
- SALOMEDS_Study_i * Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
- SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
+ SALOMEDS_Study_i * Study_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+ PortableServer::ObjectId_var servantid = _poa->activate_object(Study_servant); // to use poa register in _mapOfPOA
+ SALOMEDS::Study_var Study = Study_servant->_this();
// Assign the value of the IOR in the study->root
CORBA::String_var IORStudy = _orb->object_to_string(Study);
- aStudyImpl->SetTransientReference((char*)IORStudy);
+ aStudyImpl->SetTransientReference((char*)IORStudy.in());
+
+ _mapOfPOA[Study->StudyId()] = _poa;
// Register study in the naming service
// Path to acces the study
if(!_name_service->Change_Directory("/Study")) MESSAGE( "Unable to access the study directory" )
- else _name_service->Register(Study, CORBA::string_dup(aStudyImpl->Name().ToCString()));
+ else _name_service->Register(Study, CORBA::string_dup(aStudyImpl->Name().c_str()));
- return Study;
+ return Study._retn();
}
SALOMEDS::unlock();
aStudy->Close();
SALOMEDS::lock();
+
+ //remove study servant
+ PortableServer::POA_ptr poa=GetPOA(aStudy);
+ PortableServer::ServantBase* aservant=poa->reference_to_servant(aStudy);
+ PortableServer::ObjectId_var anObjectId = poa->servant_to_id(aservant);
+ poa->deactivate_object(anObjectId.in());
+ aservant->_remove_ref(); // decrement for the call to reference_to_servant
+ aservant->_remove_ref(); // to delete the object
}
//============================================================================
return false;
}
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
return _impl->Save(aStudyImpl, _factory, theMultiFile);
}
return false;
}
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
return _impl->SaveASCII(aStudyImpl, _factory, theMultiFile);
}
return false;
}
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
- return _impl->SaveAs(TCollection_AsciiString((char*)aUrl), aStudyImpl, _factory, theMultiFile);
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ return _impl->SaveAs(std::string(aUrl), aStudyImpl, _factory, theMultiFile);
}
CORBA::Boolean SALOMEDS_StudyManager_i::SaveAsASCII(const char* aUrl, SALOMEDS::Study_ptr aStudy, CORBA::Boolean theMultiFile)
return false;
}
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
- return _impl->SaveAsASCII(TCollection_AsciiString((char*)aUrl), aStudyImpl, _factory, theMultiFile);
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ return _impl->SaveAsASCII(std::string(aUrl), aStudyImpl, _factory, theMultiFile);
}
//============================================================================
{
SALOMEDS::Locker lock;
- Handle(TColStd_HSequenceOfTransient) anOpened = _impl->GetOpenStudies();
- int aLength = anOpened->Length();
+ std::vector<SALOMEDSImpl_Study*> anOpened = _impl->GetOpenStudies();
+ int aLength = anOpened.size();
SALOMEDS::ListOfOpenStudies_var _list_open_studies = new SALOMEDS::ListOfOpenStudies;
_list_open_studies->length(aLength);
}
else
{
- for (unsigned int ind=1; ind <= aLength; ind++)
- {
- Handle(SALOMEDSImpl_Study) aStudy = Handle(SALOMEDSImpl_Study)::DownCast(anOpened->Value(ind));
- _list_open_studies[ind-1] = CORBA::string_dup(aStudy->Name().ToCString());
- SCRUTE(_list_open_studies[ind-1]) ;
- }
+ for (unsigned int ind=0; ind < aLength; ind++)
+ {
+ _list_open_studies[ind] = CORBA::string_dup(anOpened[ind]->Name().c_str());
+ SCRUTE(_list_open_studies[ind]) ;
+ }
}
return _list_open_studies._retn();
}
{
SALOMEDS::Locker lock;
- Handle(SALOMEDSImpl_Study) aStudyImpl =
- _impl->GetStudyByName(TCollection_AsciiString((char*)aStudyName));
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByName(std::string(aStudyName));
- if (aStudyImpl.IsNull())
+ if (!aStudyImpl)
{
- MESSAGE(_impl->GetErrorCode().ToCString());
+ MESSAGE(_impl->GetErrorCode().c_str());
return SALOMEDS::Study::_nil();
}
- SALOMEDS_Study_i* aStudy_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
- SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(aStudy_servant->_this());
-
- return aStudy._retn();
+ SALOMEDS_Study_i* aStudy_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+ return aStudy_servant->_this();
}
//============================================================================
{
SALOMEDS::Locker lock;
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudyID);
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudyID);
- if (aStudyImpl.IsNull())
+ if (!aStudyImpl)
{
- MESSAGE(_impl->GetErrorCode().ToCString());
+ MESSAGE(_impl->GetErrorCode().c_str());
return SALOMEDS::Study::_nil();
}
- SALOMEDS_Study_i* aStudy_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
- SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(aStudy_servant->_this());
-
- return aStudy._retn();
+ SALOMEDS_Study_i* aStudy_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+ return aStudy_servant->_this();
}
SALOMEDS::Locker lock;
SALOMEDS::Study_var aStudy = theObject->GetStudy();
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
- Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID());
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ CORBA::String_var anID = theObject->GetID();
+ SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
bool ret = _impl->CanCopy(anObject, aDriver);
SALOMEDS::Locker lock;
SALOMEDS::Study_var aStudy = theObject->GetStudy();
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
- Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID());
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ CORBA::String_var anID = theObject->GetID();
+ SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
bool ret = _impl->Copy(anObject, aDriver);
SALOMEDS::Locker lock;
SALOMEDS::Study_var aStudy = theObject->GetStudy();
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
- Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID());
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ CORBA::String_var anID = theObject->GetID();
+ SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
bool ret = _impl->CanPaste(anObject, aDriver);
Unexpect aCatch(LockProtection);
SALOMEDS::Study_var aStudy = theObject->GetStudy();
- Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
- Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID());
- Handle(SALOMEDSImpl_SObject) aNewSO;
+ SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
+ CORBA::String_var anID = theObject->GetID();
+ SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
+ SALOMEDSImpl_SObject aNewSO;
try {
SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
}
-SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb)
+SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
{
SALOMEDS_Driver_i* driver = NULL;
- Handle(SALOMEDSImpl_SComponent) aSCO = theObject->GetFatherComponent();
+ SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
if(!aSCO.IsNull()) {
- TCollection_AsciiString IOREngine = aSCO->GetIOR();
- if(!IOREngine.IsEmpty()) {
- CORBA::Object_var obj = orb->string_to_object(IOREngine.ToCString());
+ std::string IOREngine = aSCO.GetIOR();
+ if(!IOREngine.empty()) {
+ CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
SALOMEDS::Driver_var Engine = SALOMEDS::Driver::_narrow(obj) ;
driver = new SALOMEDS_Driver_i(Engine, orb);
}
return PortableServer::POA::_nil();
}
+CORBA::Long SALOMEDS_StudyManager_i::getPID()
+{
+#ifdef WIN32
+ return (CORBA::Long)_getpid();
+#else
+ return (CORBA::Long)getpid();
+#endif
+}
+
+void SALOMEDS_StudyManager_i::ShutdownWithExit()
+{
+ exit( EXIT_SUCCESS );
+}
+
//===========================================================================
// PRIVATE FUNCTIONS
//===========================================================================
-CORBA::Long SALOMEDS_StudyManager_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
+CORBA::LongLong SALOMEDS_StudyManager_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
{
#ifdef WIN32
long pid = (long)_getpid();
#else
long pid = (long)getpid();
#endif
- isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
- SALOMEDSImpl_StudyManager* aManager = _impl.operator->();
- return ((long)aManager);
+ isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
+ return reinterpret_cast<CORBA::LongLong>(_impl);
}
//===========================================================================
namespace SALOMEDS
{
-/*
- CORBA::Object_var
- GetObject(const TDF_Label& theLabel, CORBA::ORB_ptr theORB)
- {
- try {
- Handle(SALOMEDS_IORAttribute) anAttr;
- if(theLabel.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr))
- return theORB->string_to_object(TCollection_AsciiString(anAttr->Get()).ToCString());
- }catch(...){
- }
- return CORBA::Object::_nil();
- }
-*/
-
PortableServer::ServantBase_var
GetServant(CORBA::Object_ptr theObject, PortableServer::POA_ptr thePOA)
{