]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
This commit was generated by cvs2git to create branch 'V2_2_0_adev'.
authoradmin <salome-admin@opencascade.com>
Tue, 25 Jan 2005 14:26:54 +0000 (14:26 +0000)
committeradmin <salome-admin@opencascade.com>
Tue, 25 Jan 2005 14:26:54 +0000 (14:26 +0000)
Cherrypick from master 2005-01-25 14:26:53 UTC apo <apo@opencascade.com> 'CEA DEN - PAL/SALOME 2005 - L1.4.1 - Polyhedral elements - access to connectivities through slice_array':
    idl/SALOME_ContainerManager.idl
    resources/CatalogResources.xml
    src/Container/SALOME_ContainerManager.cxx
    src/Container/SALOME_ContainerManager.hxx
    src/MEDWrapper/Base/MED_Structures.cxx
    src/ResourcesManager/Makefile.in
    src/ResourcesManager/SALOME_LoadRateManager.cxx
    src/ResourcesManager/SALOME_LoadRateManager.hxx
    src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx
    src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx
    src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx
    src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx
    src/ResourcesManager/SALOME_ResourcesManager.cxx
    src/ResourcesManager/SALOME_ResourcesManager.hxx

14 files changed:
idl/SALOME_ContainerManager.idl [new file with mode: 0644]
resources/CatalogResources.xml [new file with mode: 0644]
src/Container/SALOME_ContainerManager.cxx [new file with mode: 0644]
src/Container/SALOME_ContainerManager.hxx [new file with mode: 0644]
src/MEDWrapper/Base/MED_Structures.cxx [new file with mode: 0644]
src/ResourcesManager/Makefile.in [new file with mode: 0755]
src/ResourcesManager/SALOME_LoadRateManager.cxx [new file with mode: 0644]
src/ResourcesManager/SALOME_LoadRateManager.hxx [new file with mode: 0644]
src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx [new file with mode: 0755]
src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx [new file with mode: 0755]
src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx [new file with mode: 0644]
src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx [new file with mode: 0755]
src/ResourcesManager/SALOME_ResourcesManager.cxx [new file with mode: 0644]
src/ResourcesManager/SALOME_ResourcesManager.hxx [new file with mode: 0644]

diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl
new file mode 100644 (file)
index 0000000..d8a5724
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef _SALOME_CONTAINERMANAGER_IDL_
+#define _SALOME_CONTAINERMANAGER_IDL_
+
+#include "SALOME_Component.idl"
+
+module Engines
+{
+
+/*!
+    Type to describe properties of wanted resource.
+*/
+struct MachineParameters {
+  string container_name;
+  string hostname;
+  string OS;
+  long mem_mb;
+  long cpu_clock;
+  long nb_proc_per_node;
+  long nb_node;
+};
+
+/*!
+    Type to transmit list of machines.
+*/
+  typedef sequence<string> MachineList;
+
+/*! \brief Interface of the %containerManager
+    This interface is used for interaction with the unique instance of ContainerManager
+*/
+  interface ContainerManager
+  {
+    Container FindOrStartContainer( in string containerName, in MachineList possibleComputers);
+    string FindBest(in MachineList possibleComputers);
+    MachineList GetFittingResources( in MachineParameters params, in string componentName );
+    void Shutdown();
+    void ShutdownContainers();
+  } ;
+};
+  
+#endif
diff --git a/resources/CatalogResources.xml b/resources/CatalogResources.xml
new file mode 100644 (file)
index 0000000..99939a3
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE ResourcesCatalog>
+<resources>
+<machine protocol="r" nbOfNodes="1" mode="i" OS="LINUX" CPUFreqMHz="3200" userName="BS" memInMB="1024" preReqFilePath="/export/home/kloss/Salome2_2.1.0_22.12.04/env_products.sh" nbOfProcPerNode="1" alias="is111793" hostname="is111793" >
+<modules modulePath="/export/home/kloss/Salome2_2.1.0_22.12.04/CCRTTEST_INSTALL" moduleName="CCRTTEST" />
+  <modules modulePath="/export/home/kloss/Salome2_2.1.0_22.12.04/KERNEL_INSTALL" moduleName="KERNEL" /> </machine>
+ <machine protocol="r" nbOfNodes="1" mode="i" OS="LINUX" CPUFreqMHz="3200" userName="geay" memInMB="1024" preReqFilePath="/export/home/geay/SALOME_RES_MAN/env_products.sh" nbOfProcPerNode="1" alias="is111918" hostname="is111918" >
+<modules modulePath="/export/home/geay/CCRTTEST/CCRTTEST_INSTALL" moduleName="CCRTTEST" />
+  <modules modulePath="/export/home/geay/SALOME_RES_MAN/KERNEL_INSTALL" moduleName="KERNEL" /> </machine></resources>
diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx
new file mode 100644 (file)
index 0000000..d5fad0a
--- /dev/null
@@ -0,0 +1,141 @@
+#include "SALOME_ContainerManager.hxx"
+#include "SALOME_NamingService.hxx"
+#include "OpUtil.hxx"
+#include <sys/types.h>
+#include <unistd.h>
+#include <vector>
+
+#define TIME_OUT_TO_LAUNCH_CONT 21
+
+using namespace std;
+
+const char *SALOME_ContainerManager::_ContainerManagerNameInNS="/ContainerManager";
+
+SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb)
+{
+  _NS=new SALOME_NamingService(orb);
+  PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
+  PortableServer::ObjectId_var id=root_poa->activate_object(this);
+  CORBA::Object_var obj=root_poa->id_to_reference(id);
+  Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj);
+  _NS->Register(refContMan,_ContainerManagerNameInNS);
+}
+
+SALOME_ContainerManager::~SALOME_ContainerManager()
+{
+  delete _NS;
+}
+
+void SALOME_ContainerManager::Shutdown()
+{
+  ShutdownContainers();
+  PortableServer::ObjectId_var oid = _default_POA()->servant_to_id(this);
+  _default_POA()->deactivate_object(oid);
+  _remove_ref();
+  
+}
+
+void SALOME_ContainerManager::ShutdownContainers()
+{
+  _NS->Change_Directory("/Containers");
+  vector<string> vec=_NS->list_directory_recurs();
+  for(vector<string>::iterator iter=vec.begin();iter!=vec.end();iter++)
+    {
+      SCRUTE((*iter));
+      CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
+      Engines::Container_var cont=Engines::Container::_narrow(obj);
+      if(!CORBA::is_nil(cont))
+       cont->Shutdown();
+    }
+}
+
+Engines::Container_ptr SALOME_ContainerManager::FindOrStartContainer(const char *containerName, const Engines::MachineList& possibleComputers)
+{
+  Engines::Container_ptr ret=FindContainer(containerName,possibleComputers);
+  if(!CORBA::is_nil(ret))
+    return ret;
+  // Container doesn't exist try to launch it ...
+  vector<string> vector;
+  string theMachine=_LoadManager.FindBest(possibleComputers);
+  string command;
+  if(theMachine==GetHostname())
+    command=_ResManager.BuildCommandToLaunchLocalContainer(containerName);
+  else
+    command=_ResManager.BuildTempFileToLaunchRemoteContainer(theMachine,containerName);
+  _ResManager.RmTmpFile();
+  int status=system(command.c_str());
+  if (status == -1) {
+    MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status -1)");
+    return Engines::Container::_nil();
+  }
+  else if (status == 217) {
+    MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status 217)");
+    return Engines::Container::_nil();
+  }
+  else {
+    int count=TIME_OUT_TO_LAUNCH_CONT;
+    while ( CORBA::is_nil(ret) && count ) {
+      sleep( 1 ) ;
+      count-- ;
+      if ( count != 10 )
+       MESSAGE( count << ". Waiting for FactoryServer on " << theMachine);
+      string containerNameInNS=BuildContainerNameInNS(containerName,theMachine.c_str());
+      SCRUTE(containerNameInNS);
+      CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
+      ret=Engines::Container::_narrow(obj);
+    }
+    if ( CORBA::is_nil(ret) ) {
+      MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed");
+    }
+    return ret;
+  }
+}
+
+Engines::MachineList *SALOME_ContainerManager::GetFittingResources(const Engines::MachineParameters& params, const char *componentName)
+{
+  vector<string> vec=_ResManager.GetFittingResources(params,componentName);
+  Engines::MachineList *ret=new Engines::MachineList;
+  ret->length(vec.size());
+  for(unsigned int i=0;i<vec.size();i++)
+    {
+      (*ret)[i]=(vec[i]).c_str();
+    }
+  return ret;
+}
+
+char* SALOME_ContainerManager::FindBest(const Engines::MachineList& possibleComputers)
+  {
+    string theMachine=_LoadManager.FindBest(possibleComputers);
+    return CORBA::string_dup(theMachine.c_str());
+  }
+
+Engines::Container_ptr SALOME_ContainerManager::FindContainer(const char *containerName,const char *theMachine)
+{
+  string containerNameInNS(BuildContainerNameInNS(containerName,theMachine));
+  SCRUTE(containerNameInNS);
+  CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
+  if( !CORBA::is_nil(obj) )
+    return Engines::Container::_narrow(obj);
+  else
+    return Engines::Container::_nil();
+}
+
+Engines::Container_ptr SALOME_ContainerManager::FindContainer(const char *containerName,const Engines::MachineList& possibleComputers)
+{
+  for(unsigned int i=0;i<possibleComputers.length();i++)
+    {
+      Engines::Container_ptr cont=FindContainer(containerName,possibleComputers[i]);
+      if( !CORBA::is_nil(cont) )
+       return cont;
+    }
+  return Engines::Container::_nil();
+}
+
+string SALOME_ContainerManager::BuildContainerNameInNS(const char *containerName,const char *machineName)
+{
+  string containerNameInNS("/Containers/");
+  containerNameInNS+=machineName;
+  containerNameInNS+="/";
+  containerNameInNS+=containerName;
+  return containerNameInNS;
+}
diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx
new file mode 100644 (file)
index 0000000..9293f18
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef __SALOME_CONTAINERMANAGER_HXX__
+#define __SALOME_CONTAINERMANAGER_HXX__
+
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_Component)
+#include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
+#include "SALOME_ResourcesManager.hxx"
+#include "SALOME_LoadRateManager.hxx"
+
+#include <string>
+
+class SALOME_NamingService;
+
+class SALOME_ContainerManager: public POA_Engines::ContainerManager,
+                              public PortableServer::RefCountServantBase {
+private:
+  SALOME_ResourcesManager _ResManager;
+  SALOME_LoadRateManager _LoadManager;
+  SALOME_NamingService *_NS;
+public:
+  SALOME_ContainerManager(CORBA::ORB_ptr orb);
+  ~SALOME_ContainerManager();
+  Engines::Container_ptr FindOrStartContainer(const char *containerName, const Engines::MachineList& possibleComputer);
+  Engines::MachineList *GetFittingResources(const Engines::MachineParameters& params, const char *componentName);
+  char* FindBest(const Engines::MachineList& possibleComputers);
+  void Shutdown();
+  void ShutdownContainers();
+
+  static const char *_ContainerManagerNameInNS;
+private:
+  Engines::Container_ptr FindContainer(const char *containerName,const Engines::MachineList& possibleComputers);
+  Engines::Container_ptr FindContainer(const char *containerName,const char *theMachine);
+  std::string BuildContainerNameInNS(const char *containerName,const char *machineName);
+};
+
+#endif
diff --git a/src/MEDWrapper/Base/MED_Structures.cxx b/src/MEDWrapper/Base/MED_Structures.cxx
new file mode 100644 (file)
index 0000000..2418581
--- /dev/null
@@ -0,0 +1,168 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_Structure.cxx
+//  Author : Eugeny NIKOLAEV
+//  Module : VISU
+
+#include "MED_Structures.hxx"
+#include "MED_Utilities.hxx"
+using namespace MED;
+
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#endif
+
+#if defined __GNUC_2__
+#define GETINDEX(anArray,ind) anArray[ind]
+#else
+#define GETINDEX(anArray,ind) anArray.at(ind)
+#endif
+
+namespace MED{
+
+  TInt GetNbConnectivities(EGeometrieElement typmai)
+  {
+    TInt taille = typmai%100;
+    return taille;
+  }
+
+  template<>
+  TInt GetNbConn<eV2_1>(EGeometrieElement typmai,
+                       TInt mdim)
+  {
+    TInt edim = typmai / 100;
+    TInt nsup = 0;
+
+    if (mdim  == 2 || mdim == 3)
+      if (edim == 1)
+       nsup = 1;
+    
+    if (mdim == 3)
+      if (edim == 2)
+       nsup = 1;
+    
+    TInt taille = nsup+typmai%100;
+    return taille;
+  }
+
+  template<>
+  TInt GetNbConn<eV2_2>(EGeometrieElement typmai,
+                       TInt mdim)
+  {
+    TInt taille = typmai%100;
+    return taille;
+  }
+
+  std::string GetString(TInt theId, TInt theStep, 
+                       const TString& theString)
+  {
+    const char* aPos = &GETINDEX(theString,theId*theStep);
+    TInt aSize = std::min(TInt(strlen(aPos)),theStep);
+    return std::string(aPos,aSize);
+  }
+
+  void SetString(TInt theId, TInt theStep, 
+                TString& theString, 
+                const std::string& theValue)
+  {
+    TInt aSize = std::min(TInt(theValue.size()+1),theStep);
+    char* aPos = &GETINDEX(theString,theId*theStep);
+    strncpy(aPos,theValue.c_str(),aSize);
+  }
+
+}
+
+//---------------------------------------------------------------
+TInt TFamilyInfo::GetAttrId(TInt theId) const {
+  return GETINDEX(myAttrId,theId);
+}
+
+TInt TFamilyInfo::GetAttrVal(TInt theId) const {
+  return GETINDEX(myAttrVal,theId);
+}
+
+void TFamilyInfo::SetAttrId(TInt theId,TInt theVal) {
+  GETINDEX(myAttrId,theId) = theVal;
+}
+
+void TFamilyInfo::SetAttrVal(TInt theId,TInt theVal) {
+  GETINDEX(myAttrVal,theId) = theVal;
+}
+
+//---------------------------------------------------------------
+TInt TElemInfo::GetFamNum(TInt theId) const {
+  return GETINDEX(myFamNum,theId);
+}
+
+TInt TElemInfo::GetElemNum(TInt theId) const {
+  return GETINDEX(myElemNum,theId);
+}
+
+void TElemInfo::SetFamNum(TInt theId,TInt theVal) {
+  GETINDEX(myFamNum,theId) = theVal;
+}
+
+//---------------------------------------------------------------
+TFloat TNodeInfo::GetNodeCoord(TInt theId,TInt theComp) const {
+  return GETINDEX(myCoord,myMeshInfo->myDim*theId + theComp);
+}
+
+void TNodeInfo::SetNodeCoord(TInt theId,TInt theComp,TFloat theVal) {
+  GETINDEX(myCoord,myMeshInfo->myDim*theId + theComp) = theVal;
+}
+
+//---------------------------------------------------------------
+TInt TCellInfo::GetConn(TInt theElemId, TInt theConnId) const {
+  return GETINDEX(myConn,GetConnDim()*theElemId + theConnId);
+}
+
+void TCellInfo::SetConn(TInt theElemId, TInt theConnId, TInt theVal){
+  GETINDEX(myConn,GetConnDim()*theElemId + theConnId) = theVal;
+}
+
+TConstConnSlice 
+TCellInfo::GetConnSlice(TInt theElemId) const
+{
+  return TConstConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbConnectivities(myTGeom),1));
+}
+
+TConnSlice 
+TCellInfo::GetConnSlice(TInt theElemId)
+{
+  return TConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbConnectivities(myTGeom),1));
+}
+
+//---------------------------------------------------------------
+TInt TPolygoneInfo::GetNbConn(TInt theElemId) const {
+  TInt i1 = GETINDEX(myIndex,theElemId);
+  TInt i2 = GETINDEX(myIndex,theElemId+1);
+  TInt ret = i2 - i1;
+  return ret;
+}
+
+//---------------------------------------------------------------
+TFloat TTimeStampVal::GetVal(EGeometrieElement theGeom, TInt theId, 
+                            TInt theComp, TInt theGauss) const {
+  TInt aNbComp = myTimeStampInfo->myFieldInfo->myNbComp;
+  TInt aNbGauss = myTimeStampInfo->myNbGauss;
+  TInt aStep = aNbComp*aNbGauss;
+  TMeshValue::const_iterator anIter = myMeshValue.find(theGeom);
+  if(anIter != myMeshValue.end()){
+    TFloat aRet=GETINDEX(anIter->second,theId*aStep + theComp*aNbGauss + theGauss);
+    return aRet;
+  }
+  return TFloat();
+}
+
+void TTimeStampVal::SetVal(EGeometrieElement theGeom, TInt theId, 
+                          TInt theComp, TFloat theVal, TInt theGauss)
+{
+  TInt aNbComp = myTimeStampInfo->myFieldInfo->myNbComp;
+  TInt aNbGauss = myTimeStampInfo->myNbGauss;
+  TInt aStep = aNbComp*aNbGauss;
+  GETINDEX(myMeshValue[theGeom],theId*aStep + theComp*aNbGauss + theGauss) = theVal;
+}
diff --git a/src/ResourcesManager/Makefile.in b/src/ResourcesManager/Makefile.in
new file mode 100755 (executable)
index 0000000..ac30999
--- /dev/null
@@ -0,0 +1,66 @@
+#  SALOME RessourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
+#
+#  Copyright (C) 2003  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. 
+# 
+#  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+#
+#
+#
+#  File   : Makefile.in
+#  Author : Paul RASCLE, EDF
+#  Module : SALOME
+#  $Header$
+
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+EXPORT_HEADERS = \
+               SALOME_ResourcesCatalog_Parser.hxx \
+               SALOME_ResourcesManager.hxx \
+                SALOME_ResourcesCatalog_Handler.hxx \
+               SALOME_LoadRateManager.hxx \
+
+# Libraries targets
+LIB = libSalomeResourcesManager.la
+LIB_SRC = \
+                 SALOME_ResourcesCatalog_Parser.cxx \
+                 SALOME_ResourcesCatalog_Handler.cxx  \
+                 SALOME_LoadRateManager.cxx \
+                 SALOME_ResourcesManager.cxx \
+
+# Executables targets
+# trouble we have client and serveur and build don't known about this with rule
+# in fact client is a test ! So it may go away BIN !
+#BIN = test_rc2
+#SALOME_RessourcesCatalog_Server SALOME_RessourcesCatalog_Client test
+LIB_CLIENT_IDL = SALOME_ContainerManager.idl SALOME_Component.idl
+BIN_SRC = 
+BIN_SERVER_IDL = SALOME_ContainerManager.idl
+
+CPPFLAGS+= $(QT_MT_INCLUDES) -I$(srcdir)/../Container
+CXXFLAGS+= 
+LDFLAGS+= $(QT_MT_LIBS) $(OGL_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector
+
+@CONCLUDE@
+
+
diff --git a/src/ResourcesManager/SALOME_LoadRateManager.cxx b/src/ResourcesManager/SALOME_LoadRateManager.cxx
new file mode 100644 (file)
index 0000000..ab5aa4d
--- /dev/null
@@ -0,0 +1,9 @@
+#include "SALOME_LoadRateManager.hxx"
+
+using namespace std;
+
+string SALOME_LoadRateManager::FindBest(const Engines::MachineList& hosts)
+{
+  // for the moment then "maui" will be used for dynamic selection ...
+  return string(hosts[0]);
+}
diff --git a/src/ResourcesManager/SALOME_LoadRateManager.hxx b/src/ResourcesManager/SALOME_LoadRateManager.hxx
new file mode 100644 (file)
index 0000000..9a5d984
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __SALOME_LOADRATEMANAGER_HXX__
+#define __SALOME_LOADRATEMANAGER_HXX__
+
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
+#include <string>
+
+class SALOME_LoadRateManager
+{
+public:
+  std::string FindBest(const Engines::MachineList& hosts);
+};
+
+#endif
diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx
new file mode 100755 (executable)
index 0000000..2dc349b
--- /dev/null
@@ -0,0 +1,289 @@
+//  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
+//
+//  Copyright (C) 2003  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. 
+// 
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SALOME_ResourcesCatalog_Handler.cxx
+//  Author : Estelle Deville
+//  Module : SALOME
+//$Header$
+
+#include "SALOME_ResourcesCatalog_Handler.hxx"
+#include <iostream>
+#include <map>
+#include <qdom.h>
+#include "utilities.h"
+
+using namespace std;
+
+//----------------------------------------------------------------------
+//Function : SALOME_ResourcesCatalog_Handler
+//Purpose: Constructor
+//----------------------------------------------------------------------
+SALOME_ResourcesCatalog_Handler::SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):_resources_list(listOfResources)
+{
+  MESSAGE("SALOME_ResourcesCatalog_Handler creation");
+  //XML tags initialisation
+  test_machine="machine";
+  test_resources="resources";
+
+  test_hostname="hostname";
+  test_alias="alias";
+  test_protocol="protocol";
+  test_mode="mode";
+  test_user_name="userName";
+  test_modules="modules";
+  test_module_name="moduleName";
+  test_module_path="modulePath";
+  test_pre_req_file_path="preReqFilePath";
+  test_os="OS";
+  test_mem_in_mb="memInMB";
+  test_cpu_freq_mhz="CPUFreqMHz";
+  test_nb_of_nodes="nbOfNodes";
+  test_nb_of_proc_per_node="nbOfProcPerNode";
+}
+
+//----------------------------------------------------------------------
+//Function : ~SALOME_ResourcesCatalog_Handler
+//Purpose: Destructor
+//----------------------------------------------------------------------
+SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
+{
+  MESSAGE("SALOME_ResourcesCatalog_Handler destruction");
+}
+
+//----------------------------------------------------------------------
+//Function : GetResourcesAfterParsing
+//Purpose: Retrieves DS after the file parse.
+//----------------------------------------------------------------------
+const MapOfParserResourcesType& SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
+{
+  return _resources_list;
+}
+
+//----------------------------------------------------------------------
+//Function : startDocument
+//Purpose: overload handler function 
+//----------------------------------------------------------------------
+bool SALOME_ResourcesCatalog_Handler::startDocument()
+{
+  MESSAGE("Begin parse document");
+  // Empty private elements
+  _resources_list.clear();
+  return true;
+}
+
+//----------------------------------------------------------------------
+//Function : startElement
+//Purpose: overload handler function 
+//----------------------------------------------------------------------
+bool SALOME_ResourcesCatalog_Handler::startElement(const QString&, 
+                                              const QString&,
+                                              const QString& name, 
+                                              const QXmlAttributes& attrs)
+{
+  for(int i=0;i<attrs.count();i++)
+    {
+      QString qName(attrs.localName(i));
+      std::string content(attrs.value(i));
+      if((qName.compare(QString(test_hostname))==0))
+       _resource.DataForSort._hostName = content;
+      if((qName.compare(QString(test_alias))==0))
+       _resource.Alias = content;
+      if((qName.compare(QString(test_protocol))==0)){
+       switch(content[0]) {
+       case 'r':
+         _resource.Protocol = rsh;
+         break;
+       case 's':
+         _resource.Protocol = ssh;
+         break; 
+       default:
+         // If it'not in all theses cases, the protocol is affected to rsh
+         _resource.Protocol = rsh;
+         break;
+       }
+      }
+      if((qName.compare(QString(test_mode))==0))
+       {
+         switch(content[0]) {
+         case 'i':
+           _resource.Mode = interactive;
+           break;
+         case 'b':
+           _resource.Mode = batch;
+           break; 
+         default:
+           // If it'not in all theses cases, the mode is affected to interactive
+           _resource.Mode = interactive;
+           break;
+         }
+       }
+      if((qName.compare(QString(test_user_name))==0))
+       _resource.UserName = content;
+      if((qName.compare(QString(test_module_name))==0))
+       previous_module_name = content;
+      if((qName.compare(QString(test_module_path))==0))
+       previous_module_path = content;
+      if((qName.compare(QString(test_pre_req_file_path))==0))
+       _resource.PreReqFilePath = content;
+      if((qName.compare(QString(test_os))==0))
+       _resource.OS = content;
+      if((qName.compare(QString(test_mem_in_mb))==0))
+         _resource.DataForSort._memInMB = atoi(content.c_str());
+      if((qName.compare(QString(test_cpu_freq_mhz))==0))
+       _resource.DataForSort._CPUFreqMHz = atoi(content.c_str());
+      if((qName.compare(QString(test_nb_of_nodes))==0))
+       _resource.DataForSort._nbOfNodes = atoi(content.c_str());
+      if((qName.compare(QString(test_nb_of_proc_per_node))==0))
+       _resource.DataForSort._nbOfProcPerNode = atoi(content.c_str());
+    }
+  return true;
+}
+
+//----------------------------------------------------------------------
+//Function : endElement
+//Purpose: overload handler function 
+//----------------------------------------------------------------------
+bool SALOME_ResourcesCatalog_Handler::endElement(const QString&, const QString&,
+                                            const QString& qName)
+{
+  if((qName.compare(QString(test_modules))==0))
+    _resource.ModulesPath[previous_module_name] = previous_module_path;
+  if((qName.compare(QString(test_machine))==0))
+    _resources_list[_resource.DataForSort._hostName]=_resource;
+  return true;
+}
+
+//----------------------------------------------------------------------
+//Function : characters
+//Purpose: overload handler function
+//----------------------------------------------------------------------
+bool SALOME_ResourcesCatalog_Handler::characters(const QString& chars)
+{
+  content = (const char *)chars ;
+  return true;
+}
+
+//----------------------------------------------------------------------
+//Function : endDocument
+//Purpose: overload handler function 
+//----------------------------------------------------------------------
+bool SALOME_ResourcesCatalog_Handler::endDocument()
+{
+  //_resources_list
+//   for (unsigned int ind = 0; ind < _resources_list.size(); ind++)
+//     {
+//       MESSAGE("Resources name :"<<_resources_list[ind].Parsername);
+//       MESSAGE("OS :"<<_resources_list[ind].ParserOS); 
+//       MESSAGE("OS version :"<<_resources_list[ind].ParserOS_version);
+//       for (unsigned int i = 0; i < _resources_list[ind].Parserprocs.size(); i++)
+//     {
+//       MESSAGE("Proc number :" << _resources_list[ind].Parserprocs[i].Parsernumber);
+//       MESSAGE("Model name :" << _resources_list[ind].Parserprocs[i].Parsermodel_name);
+//       MESSAGE("CPU(MHz) :" << _resources_list[ind].Parserprocs[i].Parsercpu_mhz);
+//       MESSAGE("Cache :" << _resources_list[ind].Parserprocs[i].Parsercache_size);
+//     }
+//       for (unsigned int j = 0; j < _resources_list[ind].Parsercontainertype.size(); j++)
+//     MESSAGE("Container Type :" << _resources_list[ind].Parsercontainertype[j]);
+//     }
+  cout << "This is the end of document" << endl;
+  return true;
+}
+
+//----------------------------------------------------------------------
+//Function : errorProtocol
+//Purpose: overload handler function
+//----------------------------------------------------------------------
+QString SALOME_ResourcesCatalog_Handler::errorProtocol()
+{
+  cout << "error prot !!!!!!!!!!!!!!!!!" << endl;
+  return errorProt;
+}
+
+//----------------------------------------------------------------------
+//Function : fatalError
+//Purpose: overload handler function
+//----------------------------------------------------------------------
+bool 
+SALOME_ResourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
+{
+  cout << "fatal error !!!!!!!!!!!!!!!!!" << endl;
+    errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
+    .arg( exception.message() )
+    .arg( exception.lineNumber() )
+    .arg( exception.columnNumber() );
+
+  return QXmlDefaultHandler::fatalError( exception );
+}
+
+//----------------------------------------------------------------------
+//Function : FillDocument
+//Purpose: Fill the document tree in xml file, used to write in xml file.
+//----------------------------------------------------------------------
+void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(QDomDocument& doc)
+{
+  QDomElement root = doc.createElement("resources");
+  doc.appendChild(root);
+  for(map<string, ParserResourcesType>::iterator iter=_resources_list.begin();iter!=_resources_list.end();iter++)
+    {
+      QDomElement eltRoot = doc.createElement(test_machine);
+      root.appendChild( eltRoot );
+      eltRoot.setAttribute((char *)test_hostname,(*iter).first.c_str());
+      eltRoot.setAttribute((char *)test_alias,(*iter).second.Alias.c_str());
+      switch((*iter).second.Protocol)
+       {
+       case rsh:
+         eltRoot.setAttribute((char *)test_protocol,"rsh");
+         break;
+       case ssh:
+         eltRoot.setAttribute((char *)test_protocol,"ssh");
+         break;
+       default:
+         eltRoot.setAttribute((char *)test_protocol,"rsh");
+       }
+      switch((*iter).second.Mode)
+       {
+       case interactive:
+         eltRoot.setAttribute((char *)test_mode,"interactive");
+         break;
+       case batch:
+         eltRoot.setAttribute((char *)test_mode,"batch");
+         break;
+       default:
+         eltRoot.setAttribute((char *)test_mode,"interactive");
+       }
+      eltRoot.setAttribute((char *)test_user_name,(*iter).second.UserName.c_str());
+      for(map<string, string>::const_iterator iter2=(*iter).second.ModulesPath.begin();iter2!=(*iter).second.ModulesPath.end();iter2++)
+       {
+         QDomElement rootForModulesPaths=doc.createElement(test_modules);
+         rootForModulesPaths.setAttribute(test_module_name,(*iter2).first.c_str());
+         rootForModulesPaths.setAttribute(test_module_path,(*iter2).second.c_str());
+         eltRoot.appendChild(rootForModulesPaths);
+       }
+      eltRoot.setAttribute(test_pre_req_file_path,(*iter).second.PreReqFilePath.c_str());
+      eltRoot.setAttribute(test_os,(*iter).second.OS.c_str());
+      eltRoot.setAttribute(test_mem_in_mb,(*iter).second.DataForSort._memInMB);
+      eltRoot.setAttribute(test_cpu_freq_mhz,(*iter).second.DataForSort._CPUFreqMHz);
+      eltRoot.setAttribute(test_nb_of_nodes,(*iter).second.DataForSort._nbOfNodes);
+      eltRoot.setAttribute(test_nb_of_proc_per_node,(*iter).second.DataForSort._nbOfProcPerNode);
+    }
+}
diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx
new file mode 100755 (executable)
index 0000000..6e9916a
--- /dev/null
@@ -0,0 +1,137 @@
+//  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
+//
+//  Copyright (C) 2003  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. 
+// 
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SALOME_ResourcesCatalog_Handler.hxx
+//  Author : Estelle Deville
+//  Module : SALOME
+//$Header$
+
+#ifndef SALOME_RESOURCES_CATALOG_HANDLER
+#define SALOME_RESOURCES_CATALOG_HANDLER
+
+#include "SALOME_ResourcesCatalog_Parser.hxx"
+
+#include <qxml.h>
+#include <string>
+#include <vector>
+
+class QDomElement;
+class QDomDocument;
+
+class SALOME_ResourcesCatalog_Handler : public QXmlDefaultHandler
+{
+public :
+  //! standard constructor
+  SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources);
+
+  const MapOfParserResourcesType& GetResourcesAfterParsing() const;
+
+  //! standard destructor
+  virtual ~SALOME_ResourcesCatalog_Handler();
+
+  //! method to overload handler function startDocument
+  /*! is called before a xml file is parsed
+    \return true if no error was detected
+  */
+  virtual bool startDocument();
+
+  //! method to overload handler function startElement
+  /*!
+    \param QString argument by value
+    \param QString argument by value
+    \param QString qName argument by value
+    \param QXmlAttributes atts argument by value
+    \return true if no error was detected
+  */
+  virtual bool startElement(const QString& , const QString& ,
+                           const QString& name, const QXmlAttributes& attrs);
+
+ //! method to overload handler function endElement
+  /*!
+    \param QString argument by value
+    \param QString argument by value
+    \param QString qName argument by value
+    \return true if no error was detected
+  */
+  virtual bool endElement(const QString&, const QString&,
+                         const QString& qName);
+
+ //! method to overload handler function characters
+  /*!
+    \param QString chars argument by value
+    \return true if no error was detected
+  */
+  virtual bool characters(const QString& chars);
+
+ //! method to overload handler function endDocument
+  /*! is called at the end of the parsing
+    \return true if no error was detected
+  */
+  virtual bool endDocument();
+
+ //! method to overload handler function errorProtocol
+  /*!
+    \return the error message
+  */
+  virtual QString errorProtocol();
+
+//! method to overload handler function fatalError
+  /*!
+    \param QXmlParseException exception argument by value
+    \return true if no error was detected
+  */
+  virtual bool fatalError(const QXmlParseException& exception);
+
+//! method to fill the document to be writen in a file
+  void PrepareDocToXmlFile(QDomDocument& doc);
+
+private :
+  QString errorProt;
+  std::string content;
+  std::string previous_module_name;
+  std::string previous_module_path;
+
+  ParserResourcesType _resource;
+  MapOfParserResourcesType& _resources_list;
+
+  const char *test_machine;
+  const char *test_resources;
+
+  const char *test_hostname;
+  const char *test_alias;
+  const char *test_protocol;
+  const char *test_mode;
+  const char *test_user_name;
+  const char *test_modules;
+  const char *test_module_name;
+  const char *test_module_path;
+  const char *test_pre_req_file_path;
+  const char *test_os;
+  const char *test_mem_in_mb;
+  const char *test_cpu_freq_mhz;
+  const char *test_nb_of_nodes;
+  const char *test_nb_of_proc_per_node;
+
+};
+
+#endif // SALOME_RESOURCES_CATALOG_HANDLER
diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx
new file mode 100644 (file)
index 0000000..d6562be
--- /dev/null
@@ -0,0 +1,82 @@
+#include "SALOME_ResourcesCatalog_Parser.hxx"
+#include <iostream>
+
+#define NULL_VALUE 0
+
+using namespace std;
+
+unsigned int ResourceDataToSort::_nbOfNodesWanted=NULL_VALUE;
+unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted=NULL_VALUE;
+unsigned int ResourceDataToSort::_CPUFreqMHzWanted=NULL_VALUE;
+unsigned int ResourceDataToSort::_memInMBWanted=NULL_VALUE;
+
+ResourceDataToSort::ResourceDataToSort()
+{
+}
+
+ResourceDataToSort::ResourceDataToSort(const string& hostname,unsigned int nbOfNodes,unsigned int nbOfProcPerNode,unsigned int CPUFreqMHz,unsigned int memInMB):_hostName(hostname),_nbOfNodes(nbOfNodes),_nbOfProcPerNode(nbOfProcPerNode),_CPUFreqMHz(CPUFreqMHz),_memInMB(memInMB)
+{
+}
+
+//! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting
+bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
+{
+  unsigned int nbPts=GetNumberOfPoints();
+  return nbPts<other.GetNumberOfPoints();
+}
+
+unsigned int ResourceDataToSort::GetNumberOfPoints() const
+{
+  unsigned int ret=0;
+  //priority 1 : Nb of nodes
+  if(_nbOfNodesWanted!=NULL_VALUE)
+    {
+      if(_nbOfNodes==_nbOfNodesWanted)
+       ret+=3000;
+      else if(_nbOfNodes>_nbOfNodesWanted)
+       ret+=2000;
+      else
+       ret+=1000;
+    }
+  //priority 2 : Nb of proc by node
+  if(_nbOfProcPerNodeWanted!=NULL_VALUE)
+    {
+      if(_nbOfProcPerNode==_nbOfProcPerNodeWanted)
+       ret+=300;
+      else if(_nbOfProcPerNode > _nbOfProcPerNodeWanted)
+       ret+=200;
+      else
+       ret+=100;
+    }
+  //priority 3 : Cpu freq
+  if(_CPUFreqMHzWanted!=NULL_VALUE)
+    {
+      if(_CPUFreqMHz==_CPUFreqMHzWanted)
+       ret+=30;
+      else if(_CPUFreqMHz > _CPUFreqMHzWanted)
+       ret+=20;
+      else
+       ret+=10;
+    }
+  //priority 4 : memory
+  if(_memInMBWanted!=NULL_VALUE)
+    {
+      if(_memInMB==_memInMBWanted)
+       ret+=3;
+      else if(_memInMB > _memInMBWanted)
+       ret+=2;
+      else
+       ret+=1;
+    }
+  return ret;
+}
+
+//! Method used for debug
+void ResourceDataToSort::Print() const
+{
+  cout << "Nb of nodes : " << _nbOfNodes << endl;
+  cout << "Nb of proc per node : " <<  _nbOfProcPerNode << endl;
+  cout << "CPU : " << _CPUFreqMHz << endl;
+  cout << "Mem : " << _memInMB << endl;
+}
+
diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx
new file mode 100755 (executable)
index 0000000..989db2f
--- /dev/null
@@ -0,0 +1,97 @@
+//  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
+//
+//  Copyright (C) 2003  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. 
+// 
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SALOME_ResourcesCatalog_Parser.hxx
+//  Author : Estelle Deville
+//  Module : SALOME
+//$Header$
+
+#ifndef SALOME_RESOURCES_CATALOG_PARSER
+#define SALOME_RESOURCES_CATALOG_PARSER
+
+#include <string>
+#include <vector>
+#include <map>
+#include <iostream>
+
+typedef std::map<std::string, std::string> MapOfModulesPath;
+
+enum AccessProtocolType {rsh, ssh};
+
+enum AccessModeType {interactive, batch};
+
+class ResourceDataToSort {
+public:
+  std::string _hostName;
+  unsigned int _nbOfNodes;
+  unsigned int _nbOfProcPerNode;
+  unsigned int _CPUFreqMHz;
+  unsigned int _memInMB;
+  static unsigned int _nbOfNodesWanted;
+  static unsigned int _nbOfProcPerNodeWanted;
+  static unsigned int _CPUFreqMHzWanted;
+  static unsigned int _memInMBWanted;
+public:
+  ResourceDataToSort();
+  ResourceDataToSort(const std::string& hostname,unsigned int nbOfNodes,unsigned int nbOfProcPerNode,unsigned int CPUFreqMHz,unsigned int memInMB);
+  bool operator< (const ResourceDataToSort& other) const;
+  void Print() const;
+private:
+  unsigned int GetNumberOfPoints() const;
+//   friend class SALOME_ResourcesCatalog_Handler;
+//   friend class SALOME_ResourcesManager;
+//   friend struct ParserResourcesType;
+};
+
+struct ParserResourcesType {
+  ResourceDataToSort DataForSort;
+  std::string Alias;
+  AccessProtocolType Protocol;
+  AccessModeType Mode;
+  std::string UserName;
+  MapOfModulesPath ModulesPath;
+  std::string PreReqFilePath;
+  std::string OS;
+
+  void Print(){
+    std::cout << "##############*****" << std::endl; 
+    std::cout << "HostName : " << DataForSort._hostName << std::endl;
+    std::cout << "Alias : " << Alias << std::endl;
+    std::cout << "Protocol : " << Protocol << std::endl;
+    std::cout << "Mode : " << Mode << std::endl;
+    std::cout << "UserName : " << UserName << std::endl;
+    std::cout << "Modules : " << std::endl;
+    int i=1;
+    for(std::map<std::string, std::string>::iterator iter=ModulesPath.begin();iter!=ModulesPath.end();iter++)
+       {
+         std::cout << "    Module " << i++ << " called : " << (*iter).first << " with path : " << (*iter).second << std::endl;
+       }
+    std::cout << "PreReqFilePath : " << PreReqFilePath << std::endl;
+    std::cout << "OS : " << OS << std::endl;
+    DataForSort.Print();
+  }
+};
+
+typedef std::map<std::string, ParserResourcesType> MapOfParserResourcesType;
+
+#endif //SALOME_RESOURCES_CATALOG_PARSER
diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx
new file mode 100644 (file)
index 0000000..7765c78
--- /dev/null
@@ -0,0 +1,374 @@
+#include "SALOME_ResourcesManager.hxx"
+#include "SALOME_Container_i.hxx"
+#include "Utils_ExceptHandlers.hxx"
+#include "OpUtil.hxx"
+
+#include <qdom.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fstream>
+#include <iostream>
+#include <string.h>
+#include <map>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#define MAX_SIZE_FOR_HOSTNAME 256;
+
+using namespace std;
+
+//just for test
+SALOME_ResourcesManager::SALOME_ResourcesManager(const char *xmlFilePath):_path_resources(xmlFilePath)
+{
+}
+
+SALOME_ResourcesManager::SALOME_ResourcesManager()
+{
+  _path_resources=getenv("KERNEL_ROOT_DIR");
+  _path_resources+="/share/salome/resources/CatalogResources.xml";
+  ParseXmlFile();
+}
+
+SALOME_ResourcesManager::~SALOME_ResourcesManager()
+{
+}
+
+vector<string> SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params,const char *moduleName) throw(SALOME_Exception)
+{
+  vector <std::string> ret;
+  //To be sure that we search in a correct list.
+  ParseXmlFile();
+  const char *hostname=(const char *)params.hostname;
+  if(hostname[0]!='\0')
+    {
+      if(_resourcesList.find(hostname)!=_resourcesList.end())
+       // params.hostame is in the list of resources so return it.
+       ret.push_back(hostname);
+      else
+       //user specified an unknown hostame so notify to him.
+       throw SALOME_Exception("unknown host");
+    }
+  else
+    // Search for available resources sorted by priority
+    {
+      SelectOnlyResourcesWithOS(ret,params.OS);
+      KeepOnlyResourcesWithModule(ret,moduleName);
+      //set wanted parameters
+      ResourceDataToSort::_nbOfNodesWanted=params.nb_node;
+      ResourceDataToSort::_nbOfProcPerNodeWanted=params.nb_proc_per_node;
+      ResourceDataToSort::_CPUFreqMHzWanted=params.cpu_clock;
+      ResourceDataToSort::_memInMBWanted=params.mem_mb;
+      //end of set
+      list<ResourceDataToSort> li;
+      for(vector<string>::iterator iter=ret.begin();iter!=ret.end();iter++)
+       li.push_back(_resourcesList[(*iter)].DataForSort);
+      li.sort();
+      unsigned int i=0;
+      for(list<ResourceDataToSort>::iterator iter2=li.begin();iter2!=li.end();iter2++)
+       ret[i++]=(*iter2)._hostName;
+    }
+  return ret;
+}
+
+int SALOME_ResourcesManager::AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources, const map<string,string>& modulesOnNewResources,
+                                                 const char *environPathOfPrerequired,
+                                                 const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception)
+{
+  map<string,string>::const_iterator iter=modulesOnNewResources.find("KERNEL");
+  if(iter!=modulesOnNewResources.end())
+    {
+      ParserResourcesType newElt;
+      newElt.DataForSort._hostName=paramsOfNewResources.hostname;
+      newElt.Alias=alias;
+      newElt.Protocol=prot;
+      newElt.Mode=mode;
+      newElt.UserName=userName;
+      newElt.ModulesPath=modulesOnNewResources;
+      newElt.PreReqFilePath=environPathOfPrerequired;
+      newElt.OS=paramsOfNewResources.OS;
+      newElt.DataForSort._memInMB=paramsOfNewResources.mem_mb;
+      newElt.DataForSort._CPUFreqMHz=paramsOfNewResources.cpu_clock;
+      newElt.DataForSort._nbOfNodes=paramsOfNewResources.nb_node;
+      newElt.DataForSort._nbOfProcPerNode=paramsOfNewResources.nb_proc_per_node;
+      _resourcesList[newElt.DataForSort._hostName]=newElt;
+      return 0;
+    }
+  else
+    throw SALOME_Exception("KERNEL is not present in this resource");
+}
+
+void SALOME_ResourcesManager::DeleteResourceInCatalog(const char *hostname)
+{
+  _resourcesList.erase(hostname);
+}
+
+void SALOME_ResourcesManager::WriteInXmlFile()
+{
+  QDomDocument doc("ResourcesCatalog");
+  SALOME_ResourcesCatalog_Handler* handler = new SALOME_ResourcesCatalog_Handler(_resourcesList);
+  handler->PrepareDocToXmlFile(doc);
+  delete handler;
+  QFile file( _path_resources );
+  if( !file.open( IO_WriteOnly ) )
+    cout << "WRITING ERROR !!!" << endl;
+
+  QTextStream ts( &file );
+  ts << doc.toString();
+
+  file.close();
+  cout << "WRITING DONE!!!" << endl;
+}
+
+const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() 
+{
+  SALOME_ResourcesCatalog_Handler* handler = new SALOME_ResourcesCatalog_Handler(_resourcesList);
+  QFile xmlFile(_path_resources);
+
+  QXmlInputSource source(xmlFile);
+
+  QXmlSimpleReader reader;
+  reader.setContentHandler( handler );
+  reader.setErrorHandler( handler );
+  reader.parse( source );
+  xmlFile.close();
+  delete handler;
+  return _resourcesList;
+}
+
+bool SALOME_ResourcesManager::_verify_resources(MapOfParserResourcesType resourceslist)
+{
+//     bool _return_value = true;
+//     bool _bool = false ;
+//     vector<string> _machine_list;
+//     _machine_list.resize(0);
+
+//   // Fill a list of all computers indicated in the resources list
+//   for (unsigned int ind = 0; ind < resourceslist.size(); ind++)
+//           _machine_list.push_back(resourceslist[ind].HostName);   
+
+//   // Parse if a computer name is twice in the list of computers
+//   for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
+//     {
+//      for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
+//        {
+//          if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
+//            {
+//              MESSAGE("The computer " << _machine_list[ind] << " is indicated more than once in the resources list")
+//              _return_value = false;
+//           }
+//        }
+//     }
+
+//    return _return_value;
+  return true;
+}
+
+const MapOfParserResourcesType& SALOME_ResourcesManager::GetList() const
+{
+  return _resourcesList;
+}
+
+string SALOME_ResourcesManager::FindBest(const Engines::MachineList& listOfMachines)
+{
+  return _dynamicResourcesSelecter.FindBest(listOfMachines);
+}
+
+string SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer(const string& machine,const char *containerName)
+{
+  _TmpFileName=BuildTemporaryFileName();
+  ofstream tempOutputFile;
+  tempOutputFile.open(_TmpFileName.c_str(),ofstream::out );
+  const ParserResourcesType& resInfo=_resourcesList[machine];
+  tempOutputFile << "#! /bin/sh" << endl;
+  //set env vars
+  for(map<string,string>::const_iterator iter=resInfo.ModulesPath.begin();iter!=resInfo.ModulesPath.end();iter++)
+    {
+      string curModulePath((*iter).second);
+      tempOutputFile << (*iter).first << "_ROOT_DIR="<< curModulePath << endl;
+      tempOutputFile << "export " << (*iter).first << "_ROOT_DIR" << endl;
+      tempOutputFile << "LD_LIBRARY_PATH=" << curModulePath << "/lib/salome" << ":${LD_LIBRARY_PATH}" << endl;
+      tempOutputFile << "PYTHONPATH=" << curModulePath << "/bin/salome:" << curModulePath << "/lib/python2.2/site-packages/salome:";
+      tempOutputFile << curModulePath << "/lib/python2.2/site-packages/salome/shared_modules:${PYTHONPATH}" << endl;
+    }
+  tempOutputFile << "export LD_LIBRARY_PATH" << endl;
+  tempOutputFile << "export PYTHONPATH" << endl;
+  tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
+  // ! env vars
+  tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second << "/bin/salome/";
+  if(Engines_Container_i::isPythonContainer(containerName))
+    tempOutputFile << "SALOME_ContainerPy.py ";
+  else
+    tempOutputFile << "SALOME_Container ";
+  tempOutputFile << containerName << " -";
+  AddOmninamesParams(tempOutputFile);
+  tempOutputFile << " > /tmp/" << "/" << containerName << "_" << machine << ".log 2>&1 &" << endl;//" &" << endl;
+  //tempOutputFile << "EOF" << endl;
+  //tempOutputFile << "&" << endl;
+  tempOutputFile.flush();
+  tempOutputFile.close();
+  chmod(_TmpFileName.c_str(),0x1ED);
+  //Build command
+  string command;
+  if(resInfo.Protocol==rsh)
+    {
+      command = "rsh ";
+      string commandRcp="rcp ";
+      commandRcp+=_TmpFileName;
+      commandRcp+=" ";
+      commandRcp+=machine;
+      commandRcp+=":";
+      commandRcp+=_TmpFileName;
+      system(commandRcp.c_str());
+    }
+  else if(resInfo.Protocol==ssh)
+    command = "ssh ";
+  else
+    throw SALOME_Exception("Unknown protocol");
+  command+=machine;
+  _CommandForRemAccess=command;
+  command+=" ";
+  command+=_TmpFileName;
+  command+=" & ";
+  cout << "Command is ... " << command << endl;
+  return command;
+}
+
+string SALOME_ResourcesManager::BuildCommandToLaunchLocalContainer(const char *containerName)
+{
+  _TmpFileName="";
+  string command;
+  if(Engines_Container_i::isPythonContainer(containerName))
+    command="SALOME_ContainerPy.py ";
+  else
+    command="SALOME_Container ";
+  command+=containerName;
+  command+=" -";
+  AddOmninamesParams(command);
+  command+=" > /tmp/";
+  command+=containerName;
+  command += "_";
+  command += GetHostname();
+  command += ".log 2>&1 &" ;
+  cout << "Command is ... " << command << endl << flush;
+  return command;
+}
+
+void SALOME_ResourcesManager::RmTmpFile()
+{
+  if(_TmpFileName!="")
+    {
+      string command="rm ";
+      command+=_TmpFileName;
+      system(command.c_str());
+    }
+}
+
+string SALOME_ResourcesManager::BuildCommand(const string& machine,const char *containerName)
+{
+// rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 &
+  const ParserResourcesType& resInfo=_resourcesList[machine];
+  bool pyCont=Engines_Container_i::isPythonContainer(containerName);
+  string command;
+  if(resInfo.Protocol==rsh)
+    command = "rsh -n " ;
+  else if(resInfo.Protocol==ssh)
+    command = "ssh -f -n ";
+  else
+    throw SALOME_Exception("Not implemented yet...");
+      command += machine;
+  command += " ";
+  string path = (*(resInfo.ModulesPath.find("KERNEL"))).second;
+  command +=path;
+  command += "/bin/salome/";
+  if ( pyCont )
+    command += "SALOME_ContainerPy.py ";
+  else
+    command += "SALOME_Container ";
+  command += containerName;
+  command += " -";
+  AddOmninamesParams(command);
+  command += " > /tmp/";
+  command += containerName;
+  command += "_";
+  command += machine;
+  command += ".log 2>&1 &" ;
+  SCRUTE( command );
+  return command;
+}
+
+// Warning need an updated parsed list : _resourcesList
+void SALOME_ResourcesManager::SelectOnlyResourcesWithOS(vector<string>& hosts,const char *OS) const throw(SALOME_Exception)
+{
+  string base(OS);
+  for(map<string, ParserResourcesType>::const_iterator iter=_resourcesList.begin();iter!=_resourcesList.end();iter++)
+    if((*iter).second.OS==base)
+      hosts.push_back((*iter).first);
+}
+
+//Warning need an updated parsed list : _resourcesList
+void SALOME_ResourcesManager::KeepOnlyResourcesWithModule(vector<string>& hosts,const char *moduleName) const throw(SALOME_Exception)
+{
+   for(vector<string>::iterator iter=hosts.begin();iter!=hosts.end();iter++)
+     {
+       MapOfParserResourcesType::const_iterator it=_resourcesList.find(*iter);
+       const map<string,string>& mapOfModulesOfCurrentHost=(((*it).second).ModulesPath);
+       if(mapOfModulesOfCurrentHost.find(moduleName)==mapOfModulesOfCurrentHost.end())
+        {
+          hosts.erase(iter);
+        }
+     }
+}
+
+void SALOME_ResourcesManager::AddOmninamesParams(string& command) const
+{
+  string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ;
+  ifstream omniORBfile( omniORBcfg.c_str() ) ;
+  char ORBInitRef[12] ;
+  char nameservice[132] ;
+  omniORBfile >> ORBInitRef ;
+  command += ORBInitRef ;
+  command += " " ;
+  omniORBfile >> nameservice ;
+  omniORBfile.close() ;
+  char * bsn = strchr( nameservice , '\n' ) ;
+  if ( bsn ) {
+    bsn[ 0 ] = '\0' ;
+  }
+  command += nameservice ;
+}
+
+void SALOME_ResourcesManager::AddOmninamesParams(ofstream& fileStream) const
+{
+  string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ;
+  ifstream omniORBfile( omniORBcfg.c_str() ) ;
+  char ORBInitRef[12] ;
+  char nameservice[132] ;
+  omniORBfile >> ORBInitRef ;
+  fileStream << ORBInitRef;
+  fileStream << " ";
+  omniORBfile >> nameservice ;
+  omniORBfile.close() ;
+  char * bsn = strchr( nameservice , '\n' ) ;
+  if ( bsn ) {
+    bsn[ 0 ] = '\0' ;
+  }
+  fileStream << nameservice;
+}
+
+string SALOME_ResourcesManager::BuildTemporaryFileName() const
+{
+  //build more complex file name to support multiple salome session
+  string command( "/tmp/" );
+  char *temp=new char[14];
+  strcpy(temp,"command");
+  strcat(temp,"XXXXXX");
+  mkstemp(temp);
+  command += temp;
+  delete [] temp;
+  command += ".sh";
+  return command;
+}
+
+
diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx
new file mode 100644 (file)
index 0000000..c0b6ef3
--- /dev/null
@@ -0,0 +1,99 @@
+#ifndef __SALOME_RESOURCESMANAGER_HXX__
+#define __SALOME_RESOURCESMANAGER_HXX__
+
+#include "Utils_SALOME_Exception.hxx"
+#include "utilities.h"
+#include <SALOMEconfig.h>
+#include "SALOME_ResourcesCatalog_Handler.hxx"
+#include "SALOME_LoadRateManager.hxx"
+#include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
+#include <string>
+#include <fstream>
+#include <vector>
+
+//WARNING the call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done in a critical section to be sure to be clean.
+//Only one thread should use the SALOME_ResourcesManager class in a SALOME session.
+
+class SALOME_ResourcesManager
+{
+public:
+  //! standard constructor
+  SALOME_ResourcesManager();
+
+  //!just for test
+  SALOME_ResourcesManager(const char *xmlFilePath);
+  
+  //! standard destructor
+  ~SALOME_ResourcesManager();
+
+  //! method to get the list of name of ressources fitting for the specified module.
+  std::vector<std::string> GetFittingResources(const Engines::MachineParameters& params,const char *moduleName) throw(SALOME_Exception);
+
+  //! method to dynamically obtain the best machines
+  std::string FindBest(const Engines::MachineList& listOfMachines);
+
+  //! method that builds in a temporary file the script to be launched
+  std::string BuildTempFileToLaunchRemoteContainer(const std::string& machine,const char *containerName);
+
+  //! method that builds the command to be launched.
+  std::string BuildCommandToLaunchLocalContainer(const char *containerName);
+
+  //! method that remove the generated temporary file in case of a remote launch.
+  void RmTmpFile();
+
+  //! method that builds the script to be launched
+  std::string BuildCommand(const std::string& machine,const char *containerName);
+
+  //! add an entry in the ressources catalog  xml file. Return 1 if OK. Return 0 if the ressource with the same hostname already exists.
+  int AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources, const std::map<std::string,std::string>& modulesOnNewResources,
+                          const char *environPathOfPrerequired,
+                          const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception);
+  
+  //! delete a ressource from the Catalog.
+  void DeleteResourceInCatalog(const char *hostname);
+
+  //! write the current data in memory in file.
+  void WriteInXmlFile();
+
+  //! method to parse the data type catalog
+  const MapOfParserResourcesType& ParseXmlFile();
+
+  //! to consult the content of the list
+  const MapOfParserResourcesType& GetList() const;
+
+private:
+
+  //! method to verify ressources catalog content - return true if verfication is OK
+  bool _verify_resources(MapOfParserResourcesType resourceslist);
+
+  //! method that fill hosts with only resources in xml files that are on the specified OS
+  void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,const char *OS) const throw(SALOME_Exception);
+
+  //! method that keep from hosts only those having component of name moduleName.
+  void KeepOnlyResourcesWithModule(std::vector<std::string>& hosts,const char *moduleName) const throw(SALOME_Exception);
+
+  //! methode that add to command all options relative to naming service.
+  void AddOmninamesParams(std::string& command) const;
+
+  //! method that add to command all options relative to naming service.
+  void AddOmninamesParams(std::ofstream& fileStream) const;
+
+  //! method that generate a file name in /tmp directory
+  std::string BuildTemporaryFileName() const;
+
+  // will contain the path to the ressources catalog
+  QString _path_resources;
+
+  //! attribute that contains current tmp files generated
+  std::string _TmpFileName;
+
+  //! attribute that contains the rsh or ssh command to access directly to machine. Only used by this->RmTmpFile in case of a remote launch.
+  std::string _CommandForRemAccess;
+  
+  //will contain the informations on the data type catalog(after parsing)
+  MapOfParserResourcesType _resourcesList;
+
+  SALOME_LoadRateManager _dynamicResourcesSelecter;
+};
+
+#endif // RESSOURCESCATALOG_IMPL_H