Salome HOME
CCAR: remove some memory leaks in non local SALOMEDS
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study.cxx
index 0aa3a240d9f6135a436e0d09dcb9b17ed9826450..e97694d1beb658dc67c90a1a082d706a648f1547 100644 (file)
@@ -1,28 +1,28 @@
-// 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-2008  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/ or email : webmaster.salome@opencascade.com
+//  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_Study.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
-
-
+//
 #include "utilities.h" 
 
 #include "SALOMEDS_Study.hxx"
@@ -44,6 +44,7 @@
 #include "SALOMEDSImpl_SComponentIterator.hxx"
 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
 #include "SALOMEDSImpl_AttributeParameter.hxx"
+#include "SALOMEDSImpl_GenericVariable.hxx"
 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
 
 #include "SALOMEDS_Driver_i.hxx"
@@ -52,6 +53,8 @@
 #include "Utils_ORB_INIT.hxx" 
 #include "Utils_SINGLETON.hxx" 
 
+#include "Basics_Utils.hxx"
+
 #ifdef WIN32
 #include <process.h>
 #else
@@ -59,8 +62,6 @@
 #include <unistd.h>
 #endif
 
-#include "OpUtil.hxx"
-
 using namespace std; 
 
 SALOMEDS_Study::SALOMEDS_Study(SALOMEDSImpl_Study* theStudy)
@@ -79,9 +80,9 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
   long pid =  (long)getpid();
 #endif  
 
-  long addr = theStudy->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
+  long addr = theStudy->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
   if(_isLocal) {
-    _local_impl = ((SALOMEDSImpl_Study*)(addr));
+    _local_impl = reinterpret_cast<SALOMEDSImpl_Study*>(addr);
     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
   }
   else {
@@ -679,6 +680,203 @@ vector<string> SALOMEDS_Study::GetLockerID()
   return aVector;
 }
 
+
+void SALOMEDS_Study::SetReal(const string& theVarName, const double theValue)
+{
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->SetVariable(theVarName,
+                             theValue,
+                             SALOMEDSImpl_GenericVariable::REAL_VAR);
+  }
+  else 
+    _corba_impl->SetReal((char*)theVarName.c_str(),theValue);
+}
+
+void SALOMEDS_Study::SetInteger(const string& theVarName, const int theValue)
+{
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->SetVariable(theVarName,
+                             theValue,
+                             SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+  }
+  else 
+    _corba_impl->SetInteger((char*)theVarName.c_str(),theValue);
+}
+
+void SALOMEDS_Study::SetBoolean(const string& theVarName, const bool theValue)
+{
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->SetVariable(theVarName,
+                             theValue,
+                             SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+  }
+  else 
+    _corba_impl->SetBoolean((char*)theVarName.c_str(),theValue);
+}
+
+double SALOMEDS_Study::GetReal(const string& theVarName)
+{
+  double aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->GetVariableValue(theVarName);
+  }
+  else 
+    aResult = _corba_impl->GetReal((char*)theVarName.c_str());
+  return aResult;
+}
+
+int SALOMEDS_Study::GetInteger(const string& theVarName)
+{
+  int aResult;  
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = (int) _local_impl->GetVariableValue(theVarName);
+  }
+  else 
+    aResult = _corba_impl->GetInteger((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::GetBoolean(const string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = (bool) _local_impl->GetVariableValue(theVarName);
+  }
+  else 
+    aResult = _corba_impl->GetBoolean((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsReal(const string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsTypeOf(theVarName, 
+                                   SALOMEDSImpl_GenericVariable::REAL_VAR);
+  }
+  else
+    aResult = _corba_impl->IsReal((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsInteger(const string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsTypeOf(theVarName, 
+                                   SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+  }
+  else
+    aResult = _corba_impl->IsInteger((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsBoolean(const string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsTypeOf(theVarName, 
+                                   SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+  }
+  else
+    aResult = _corba_impl->IsBoolean((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsVariable(const string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsVariable(theVarName);
+  }
+  else
+    aResult = _corba_impl->IsVariable((char*)theVarName.c_str());
+  return aResult;
+}
+
+vector<string> SALOMEDS_Study::GetVariableNames()
+{
+  vector<string> aVector;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aVector = _local_impl->GetVariableNames();
+  }
+  else {
+    SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetVariableNames();
+    int aLength = aSeq->length();
+    for (int i = 0; i < aLength; i++) 
+      aVector.push_back( string(aSeq[i].in()) );
+  }
+  return aVector;
+}
+
+bool SALOMEDS_Study::RemoveVariable(const string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->RemoveVariable(theVarName);
+  }
+  else
+    aResult = _corba_impl->RemoveVariable((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::RenameVariable(const string& theVarName, const string& theNewVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->RenameVariable(theVarName, theNewVarName);
+  }
+  else
+    aResult = _corba_impl->RenameVariable((char*)theVarName.c_str(), (char*)theNewVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsVariableUsed(const string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsVariableUsed(theVarName);
+  }
+  else
+    aResult = _corba_impl->IsVariableUsed((char*)theVarName.c_str());
+  return aResult;
+}
+
+vector< vector<string> > SALOMEDS_Study::ParseVariables(const string& theVars)
+{
+  vector< vector<string> > aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->ParseVariables(theVars);
+  }
+  else {
+    SALOMEDS::ListOfListOfStrings_var aSeq = _corba_impl->ParseVariables(theVars.c_str());
+    for (int i = 0, n = aSeq->length(); i < n; i++) {
+      vector<string> aVector;
+      SALOMEDS::ListOfStrings aSection = aSeq[i];
+      for (int j = 0, m = aSection.length(); j < m; j++) {
+       aVector.push_back( string(aSection[j].in()) );
+      }
+      aResult.push_back( aVector );
+    }
+  }
+  return aResult;
+}
+
 std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) 
 {
   return _orb->object_to_string(theObject);