+// Copyright (C) 2006-2019 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// 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
+//
+
//#define REFCNT
+//
#ifdef REFCNT
#define private public
#define protected public
#include "RuntimeSALOME.hxx"
#include "SalomeContainer.hxx"
#include "SalomeComponent.hxx"
+#include "ServiceNode.hxx"
+#include "Proc.hxx"
#include "SALOME_NamingService.hxx"
#include "SALOME_LifeCycleCORBA.hxx"
#include "SALOME_ContainerManager.hxx"
+#include "Basics_Utils.hxx"
+#include "OpUtil.hxx"
#include <sstream>
#include <iostream>
+#ifdef WIN32
+#include <process.h>
+#define getpid _getpid
+#endif
+
//#define _DEVDEBUG_
#include "YacsTrace.hxx"
using namespace YACS::ENGINE;
using namespace std;
-SalomeContainer::SalomeContainer():_trueCont(Engines::Container::_nil())
+const char SalomeContainer::KIND[]="Salome";
+
+const char SalomeContainer::TYPE_PROPERTY_STR[]="type";
+
+SalomeContainer::SalomeContainer():_launchModeType(new SalomeContainerMonoHelper),_shutdownLevel(999)
{
}
-SalomeContainer::SalomeContainer(const SalomeContainer& other):Container(other),_trueCont(Engines::Container::_nil())
+SalomeContainer::SalomeContainer(const SalomeContainer& other)
+: Container(other),_componentNames(other._componentNames),
+ _launchModeType(other._launchModeType->deepCpyOnlyStaticInfo()),
+ _shutdownLevel(other._shutdownLevel),
+ _sct(other._sct)
{
}
+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()
{
+ _launchModeType->decrRef();
}
void SalomeContainer::lock()
void SalomeContainer::unLock()
{
- _mutex.unlock();
+ _mutex.unLock();
}
-bool SalomeContainer::isAlreadyStarted() const
+std::string SalomeContainer::getKind() const
{
- if(CORBA::is_nil(_trueCont))
- return false;
- else
- return true;
-}
-
-void SalomeContainer::start() throw (Exception)
-{
- CORBA::ORB_ptr orb=getSALOMERuntime()->getOrb();
- SALOME_NamingService ns(orb);
- CORBA::Object_var obj=ns.Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
- Engines::ContainerManager_var contManager=Engines::ContainerManager::_narrow(obj);
- SALOME_LifeCycleCORBA LCC(&ns);
- Engines::MachineParameters params;
- LCC.preSet(params);
- params.hostname=CORBA::string_dup("");
- std::ostringstream stream;
- stream << (void *)(this);
- params.container_name=CORBA::string_dup(stream.str().c_str());
- try
- {
- std::string policy=getProperty("policy");
- if(policy=="best")
- _trueCont=contManager->StartContainer(params,Engines::P_BEST);
- else if(policy=="first")
- _trueCont=contManager->StartContainer(params,Engines::P_FIRST);
- else
- _trueCont=contManager->StartContainer(params,Engines::P_CYCL);
- }
- catch(CORBA::COMM_FAILURE&)
- {
- throw Exception("SalomeContainer::start : Unable to launch container in Salome : CORBA Comm failure detected");
- }
- catch(CORBA::Exception&)
- {
- throw Exception("SalomeContainer::start : Unable to launch container in Salome : Unexpected CORBA failure detected");
- }
- if(CORBA::is_nil(_trueCont))
- throw Exception("SalomeContainer::start : Unable to launch container in Salome");
-#ifdef REFCNT
- DEBTRACE(_trueCont->_PR_getobj()->pd_refCount );
-#endif
+ return KIND;
}
Container *SalomeContainer::clone() const
return new SalomeContainer(*this);
}
-std::string SalomeContainer::getPlacementId() const
+Container *SalomeContainer::cloneAlways() const
{
- if(isAlreadyStarted())
+ return new SalomeContainer(*this);
+}
+
+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.");
+}
+
+void SalomeContainer::setProperty(const std::string& name, const std::string& value)
+{
+ 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)
+ {
+ _launchModeType->decrRef();
+ _launchModeType=new SalomeContainerMonoHelper;
+ }
+ else if (value == SalomeContainerMultiHelper::TYPE_NAME)
+ {
+ _launchModeType->decrRef();
+ _launchModeType=new SalomeContainerMultiHelper;
+ }
+ else
+ throw Exception("SalomeContainer::setProperty : type value is not correct (mono or multi): " + value);
+ }
+ _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)
{
- const char *what="/";
- char *corbaStr=_trueCont->name();
- string ret(corbaStr);
- CORBA::string_free(corbaStr);
- //Salome FOREVER ...
- std::string::size_type i=ret.find_first_of(what,0);
- i=ret.find_first_of(what, i==std::string::npos ? i:i+1);
- if(i!=std::string::npos)
- return ret.substr(i+1);
- return ret;
+ int reti(_isAttachedOnCloning);
+ std::ostringstream oss; oss << reti;
+ return oss.str();
}
+ return _sct.getProperty(name);
+}
+
+void SalomeContainer::clearProperties()
+{
+ _sct.clearProperties();
+}
+
+void SalomeContainer::addComponentName(const std::string& name)
+{
+ _componentNames.push_back(name);
+}
+
+void SalomeContainer::addToResourceList(const std::string& name)
+{
+ _sct.addToResourceList(name);
+}
+
+//! Load a component instance in this container
+/*!
+ * \param inst the component instance to load
+ */
+CORBA::Object_ptr SalomeContainer::loadComponent(Task *askingNode)
+{
+ return SalomeContainerTools::LoadComponent(_launchModeType,this,askingNode);
+}
+
+//! Get the container placement id for a component instance
+/*!
+ * \param inst the component instance
+ * \return the placement id
+ */
+std::string SalomeContainer::getPlacementId(const Task *askingNode) const
+{
+ return SalomeContainerTools::GetPlacementId(_launchModeType,this,askingNode);
+}
+
+//! Get the container full path for a component instance
+/*!
+ * \param inst the component instance
+ * \return the full placement id
+ */
+std::string SalomeContainer::getFullPlacementId(const Task *askingNode) const
+{
+ return SalomeContainerTools::GetFullPlacementId(_launchModeType,this,askingNode);
+}
+
+//! Check if the component instance container is already started
+/*!
+ * \param inst the component instance
+ * \return true, if the container is already started, else false
+ */
+bool SalomeContainer::isAlreadyStarted(const Task *askingNode) const
+{
+ return _launchModeType->isAlreadyStarted(askingNode);
+}
+
+Engines::Container_ptr SalomeContainer::getContainerPtr(const Task *askingNode) const
+{
+ return Engines::Container::_duplicate(_launchModeType->getContainer(askingNode));
+}
+
+//! Start a salome container (true salome container not yacs one) with given ContainerParameters (_params)
+/*!
+ * \param inst the component instance
+ */
+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())
+ {
+ SalomeContainerTools tempSct = _sct;
+ tempSct.setProperty("name", resource_name);
+ tempSct.setProperty("container_name", container_name);
+ SalomeContainerTools::Start(_componentNames,_launchModeType,tempSct,_shutdownLevel,this,askingNode);
+ }
else
- return "Not placed yet !!!";
+ start(askingNode);
}
-void SalomeContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw (Exception)
+bool SalomeContainer::canAcceptImposedResource()
{
- if(inst->getKind()!=SalomeComponent::KIND)
- throw Exception("SalomeContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
+ return _launchModeType->getType() == SalomeContainerMultiHelper::TYPE_NAME;
}
+void SalomeContainer::shutdown(int level)
+{
+ DEBTRACE("SalomeContainer::shutdown: " << _name << "," << level << "," << _shutdownLevel);
+ if(level < _shutdownLevel)
+ return;
+
+ _shutdownLevel=999;
+ //shutdown the SALOME containers
+ _launchModeType->shutdown();
+}
+
+std::map<std::string,std::string> SalomeContainer::getResourceProperties(const std::string& name) const
+{
+ return _sct.getResourceProperties(name);
+}
+
+std::map<std::string,std::string> SalomeContainer::getProperties() const
+{
+ return _sct.getProperties();
+}