-// Copyright (C) 2006-2014 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2015 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
for(pt=typeMap.begin();pt!=typeMap.end();pt++)
((*pt).second)->decrRef();
- //get rid of containers in container map
- std::map<std::string, Container*>::const_iterator it;
- for(it=containerMap.begin();it!=containerMap.end();it++)
- ((*it).second)->decrRef();
+ removeContainers();
//get rid of loggers in logger map
std::map<std::string, Logger*>::const_iterator lt;
return progress;
}
+int Proc::getGlobalProgressPercent()
+{
+ list<ProgressWeight> weightList = getProgressWeight();
+ int weightDone = 0;
+ int weightTotal = 0;
+ int progressPercent = 0;
+ for(list<ProgressWeight>::const_iterator iter=weightList.begin();iter!=weightList.end();iter++)
+ {
+ weightDone += (*iter).weightDone;
+ weightTotal += (*iter).weightTotal;
+ }
+ if (weightTotal > 0)
+ progressPercent = int(float(weightDone) / float(weightTotal) * 100);
+ return progressPercent;
+}
+
std::string Proc::getXMLState(int numId)
{
if(YACS::ENGINE::Node::idMap.count(numId) == 0)
/*!
* \param xmlSchemaFile: the file name
*/
-void Proc::saveSchema(std::string xmlSchemaFile)
+void Proc::saveSchema(const std::string& xmlSchemaFile)
{
VisitorSaveSchema vss(this);
vss.openFileSchema(xmlSchemaFile);
/*!
* \param xmlStateFile: the file name
*/
-void Proc::saveState(std::string xmlStateFile)
+void Proc::saveState(const std::string& xmlStateFile)
{
VisitorSaveState vst(this);
vst.openFileDump(xmlStateFile);
vst.closeFileDump();
}
+void Proc::removeContainers()
+{
+ //get rid of containers in container map
+ std::map<std::string, Container*>::const_iterator it;
+ for(it=containerMap.begin();it!=containerMap.end();it++)
+ ((*it).second)->decrRef();
+ containerMap.clear();
+}
+
//! Create a new Container and store it in containerMap
/*!
* \param name: the container name and key in containerMap
* \param kind: the container kind (depends on runtime)
* \return the created Container
*/
-Container* Proc::createContainer(const std::string& name,const std::string& kind)
+Container *Proc::createContainer(const std::string& name, const std::string& kind)
{
- Container* co= getRuntime()->createContainer(kind);
+ Container *co(getRuntime()->createContainer(kind));
co->setName(name);
if(containerMap.count(name)!=0)
containerMap[name]->decrRef();
{
return this;
}
+
+/*!
+ * This method is useful if this has been modified recursively and an update is needed between all the
+ * containers and components refered by children and little children and maps.
+ */
+void Proc::updateContainersAndComponents()
+{
+ std::map<std::string, Container*> myContainerMap;
+ std::map<std::string, ComponentInstance*> myComponentInstanceMap;
+ DeploymentTree treeToDup(getDeploymentTree());
+ vector<Container *> conts(treeToDup.getAllContainers());
+ for(vector<Container *>::const_iterator iterCt=conts.begin();iterCt!=conts.end();iterCt++)
+ {
+ Container *tmp(*iterCt);
+ if(tmp)
+ {
+ if(myContainerMap.find(tmp->getName())!=myContainerMap.end())
+ {
+ std::ostringstream oss; oss << "Proc::updateContainersAndComponents : more than one container instance with name \"" << tmp->getName() << "\" !";
+ throw YACS::Exception(oss.str());
+ }
+ myContainerMap[tmp->getName()]=tmp;
+ tmp->incrRef();
+ }
+ vector<ComponentInstance *> comps=treeToDup.getComponentsLinkedToContainer(*iterCt);
+ for(vector<ComponentInstance *>::iterator iterCp=comps.begin();iterCp!=comps.end();iterCp++)
+ {
+ ComponentInstance *tmp2(*iterCp);
+ if(tmp2)
+ {
+ if(myComponentInstanceMap.find(tmp2->getCompoName())!=myComponentInstanceMap.end())
+ {
+ std::ostringstream oss; oss << "Proc::updateContainersAndComponents : more than one component instance with name \"" << tmp2->getCompoName() << "\" !";
+ throw YACS::Exception(oss.str());
+ }
+ }
+ myComponentInstanceMap[tmp2->getCompoName()]=tmp2;
+ tmp2->incrRef();
+ }
+ }
+ removeContainers();
+ containerMap=myContainerMap;
+ componentInstanceMap=myComponentInstanceMap;
+}