Salome HOME
[EDF29093] : Quick fix resorbed
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study.cxx
index 0583c10cacbac8fc165140fbcb3cd25b51b0a0f5..8f438d9f4ea55151182b1b355dce427dcfeb514a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -53,8 +53,7 @@
 #include "SALOMEDS_Driver_i.hxx"
 #include "SALOMEDS_Study_i.hxx"
 
-#include "Utils_ORB_INIT.hxx" 
-#include "Utils_SINGLETON.hxx" 
+#include "OpUtil.hxx"
 
 #include "Basics_Utils.hxx"
 
@@ -70,6 +69,9 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDSImpl_Study* theStudy)
   _isLocal = true;
   _local_impl = theStudy;
   _corba_impl = SALOMEDS::Study::_nil();
+
+  pthread_mutex_init( &SALOMEDS_StudyBuilder::_remoteBuilderMutex, 0 );
+
   InitORB();
 }
 
@@ -81,7 +83,9 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
   long pid =  (long)getpid();
 #endif  
 
-  long addr = theStudy->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
+  pthread_mutex_init( &SALOMEDS_StudyBuilder::_remoteBuilderMutex, 0 );
+
+  CORBA::LongLong addr = theStudy->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
   if(_isLocal) {
     _local_impl = reinterpret_cast<SALOMEDSImpl_Study*>(addr);
     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
@@ -100,9 +104,7 @@ SALOMEDS_Study::~SALOMEDS_Study()
 
 void SALOMEDS_Study::InitORB()
 {
-  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
-  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
-  _orb = init(0 , 0 ) ;
+  _orb = KERNEL::GetRefToORB();
 }
 
 void SALOMEDS_Study::Init()
@@ -125,11 +127,18 @@ bool SALOMEDS_Study::Open(const std::string& theStudyUrl)
 {
   if(CORBA::is_nil(_corba_impl))
     return false;
+  std::wstring wtheStudyUrl = Kernel_Utils::decode_s( theStudyUrl );
+  
+  return _corba_impl->Open( (wchar_t*)wtheStudyUrl.c_str() );
+}
 
-  if (!_corba_impl->Open(theStudyUrl.c_str()))
+bool SALOMEDS_Study::CanOpen(const std::string& theStudyUrl)
+{
+  if(CORBA::is_nil(_corba_impl))
     return false;
-
-  return true;
+  std::wstring wtheStudyUrl = Kernel_Utils::decode_s( theStudyUrl );
+  
+  return _corba_impl->CanOpen( (wchar_t*)wtheStudyUrl.c_str() );
 }
 
 bool SALOMEDS_Study::Save(bool theMultiFile, bool theASCII)
@@ -145,7 +154,7 @@ bool SALOMEDS_Study::SaveAs(const std::string& theUrl, bool theMultiFile, bool t
   if(CORBA::is_nil(_corba_impl))
     return false;
 
-  return _corba_impl->SaveAs((char*)theUrl.c_str(), theMultiFile, theASCII);
+  return _corba_impl->SaveAs(Kernel_Utils::decode_s(theUrl), theMultiFile, theASCII);
 }
 
 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
@@ -341,7 +350,7 @@ std::vector<_PTR(SObject)> SALOMEDS_Study::FindObjectByName(const std::string& a
     SALOMEDS::Locker lock;
 
     std::vector<SALOMEDSImpl_SObject> aSeq = _local_impl->FindObjectByName(anObjectName, aComponentName);
-    aLength = aSeq.size();
+    aLength = (int)aSeq.size(); //!< TODO: conversion from size_t to int
     for (i = 0; i< aLength; i++) 
       aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
   }
@@ -497,10 +506,19 @@ std::string SALOMEDS_Study::Name()
     SALOMEDS::Locker lock;
     aName = _local_impl->Name();
   }
-  else aName = _corba_impl->Name();
+  else aName = Kernel_Utils::encode_s(_corba_impl->Name());
   return aName;
 }
 
+void SALOMEDS_Study::Name(const std::string& theName)
+{
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->Name(theName);
+  }
+  else _corba_impl->Name(Kernel_Utils::decode_s(theName));
+}
+
 bool SALOMEDS_Study::IsSaved()
 {
   bool isSaved;
@@ -549,7 +567,8 @@ std::string SALOMEDS_Study::URL()
     SALOMEDS::Locker lock;
     aURL = _local_impl->URL();
   }
-  else aURL = _corba_impl->URL();
+  else 
+      aURL = Kernel_Utils::encode_s(_corba_impl->URL());
   return aURL;
 }
 
@@ -559,7 +578,7 @@ void SALOMEDS_Study::URL(const std::string& url)
     SALOMEDS::Locker lock;
     _local_impl->URL(url);
   }
-  else _corba_impl->URL((char*)url.c_str());
+  else _corba_impl->URL(Kernel_Utils::decode_s(url));
 }
 
 std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO)
@@ -572,7 +591,7 @@ std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)&
 
     std::vector<SALOMEDSImpl_SObject> aSeq = _local_impl->FindDependances(*(aSO->GetLocalImpl()));
     if (aSeq.size()) {
-      aLength = aSeq.size();
+      aLength = (int)aSeq.size(); //!< TODO: conversion from size_t to int
       for (i = 0; i < aLength; i++) 
         aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
     }