Salome HOME
Some tests are modified to work in session less mode.
[modules/yacs.git] / src / runtime / SalomeContainer.cxx
index 38ec232357b5274e0f2199b8d7900c4123c295ac..65ed0ed67208e26b408088d5babcc5ff9cbca150 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -32,7 +32,6 @@
 #include "ServiceNode.hxx"
 #include "Proc.hxx"
 
-#include "SALOME_NamingService.hxx"
 #include "SALOME_LifeCycleCORBA.hxx"
 #include "SALOME_ContainerManager.hxx"
 #include "Basics_Utils.hxx"
 using namespace YACS::ENGINE;
 using namespace std;
 
+const char SalomeContainer::KIND[]="Salome";
+
+const char SalomeContainer::TYPE_PROPERTY_STR[]="type";
+
 SalomeContainer::SalomeContainer():_launchModeType(new SalomeContainerMonoHelper),_shutdownLevel(999)
 {
 }
@@ -64,9 +67,17 @@ SalomeContainer::SalomeContainer(const SalomeContainer& other)
 {
 }
 
+SalomeContainer::SalomeContainer(const Container& other, const SalomeContainerTools& sct, const SalomeContainerHelper *lmt,
+                                 const std::vector<std::string>& componentNames, int shutdownLev):Container(other),_componentNames(componentNames),
+                                     _launchModeType(const_cast<SalomeContainerHelper *>(lmt)),_shutdownLevel(shutdownLev),_sct(sct)
+{
+  if(lmt)
+    lmt->incrRef();
+}
+
 SalomeContainer::~SalomeContainer()
 {
-  delete _launchModeType;
+  _launchModeType->decrRef();
 }
 
 void SalomeContainer::lock()
@@ -76,7 +87,12 @@ void SalomeContainer::lock()
 
 void SalomeContainer::unLock()
 {
-  _mutex.unlock();
+  _mutex.unLock();
+}
+
+std::string SalomeContainer::getKind() const
+{
+  return KIND;
 }
 
 Container *SalomeContainer::clone() const
@@ -95,7 +111,7 @@ Container *SalomeContainer::cloneAlways() const
   return new SalomeContainer(*this);
 }
 
-void SalomeContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
+void SalomeContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const
 {
   if(inst->getKind()!=SalomeComponent::KIND)
     throw Exception("SalomeContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
@@ -103,27 +119,41 @@ void SalomeContainer::checkCapabilityToDealWith(const ComponentInstance *inst) c
 
 void SalomeContainer::setProperty(const std::string& name, const std::string& value)
 {
-  if (name == "type")
+  if (name == AOC_ENTRY)
+    {
+      std::istringstream iss(value);
+      int val;
+      iss >> val;
+      setAttachOnCloningStatus((bool)val);
+    }
+  else if (name == TYPE_PROPERTY_STR)
     {
       if (value == SalomeContainerMonoHelper::TYPE_NAME)
         {
-          delete _launchModeType;
+          _launchModeType->decrRef();
           _launchModeType=new SalomeContainerMonoHelper;
         }
       else if (value == SalomeContainerMultiHelper::TYPE_NAME)
         {
-          delete _launchModeType;
+          _launchModeType->decrRef();
           _launchModeType=new SalomeContainerMultiHelper;
         }
       else
         throw Exception("SalomeContainer::setProperty : type value is not correct (mono or multi): " + value);
-      return ;
     }
   _sct.setProperty(name,value);
 }
 
 std::string SalomeContainer::getProperty(const std::string& name) const
 {
+  if (name == TYPE_PROPERTY_STR)
+    return _launchModeType->getType();
+  if (name==AOC_ENTRY)
+    {
+      int reti(_isAttachedOnCloning);
+      std::ostringstream oss; oss << reti;
+      return oss.str();
+    }
   return _sct.getProperty(name);
 }
 
@@ -190,11 +220,35 @@ Engines::Container_ptr SalomeContainer::getContainerPtr(const Task *askingNode)
 /*!
  * \param inst the component instance
  */
-void SalomeContainer::start(const Task *askingNode) throw(YACS::Exception)
+void SalomeContainer::start(const Task *askingNode)
 {
   SalomeContainerTools::Start(_componentNames,_launchModeType,_sct,_shutdownLevel,this,askingNode);
 }
 
+void SalomeContainer::start(const Task *askingNode,
+                            const std::string& resource_name,
+                            const std::string& container_name)
+{
+  if(canAcceptImposedResource()
+    && askingNode != nullptr
+    && askingNode->hasImposedResource())
+  {
+    SalomeContainerTools tempSct = _sct;
+    tempSct.setProperty("name", resource_name);
+    tempSct.setProperty("container_name", container_name);
+    // components are not supported yet on this kind of start
+    std::vector<std::string> noComponentNames;
+    SalomeContainerTools::Start(noComponentNames,_launchModeType,tempSct,_shutdownLevel,this,askingNode);
+  }
+  else
+    start(askingNode);
+}
+
+bool SalomeContainer::canAcceptImposedResource()
+{
+  return _launchModeType->getType() == SalomeContainerMultiHelper::TYPE_NAME;
+}
+
 void SalomeContainer::shutdown(int level)
 {
   DEBTRACE("SalomeContainer::shutdown: " << _name << "," << level << "," << _shutdownLevel);