1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ComponentInstance.hxx"
21 #include "Container.hxx"
27 #include "YacsTrace.hxx"
29 using namespace YACS::ENGINE;
32 /*! \class YACS::ENGINE::ComponentInstance
33 * \brief Base class for all component instances.
35 * This is an abstract class that must be specialized in runtime.
36 * Specialized classes must provide implementation for loading of
37 * a component (load method) unloading (unload method) and an
38 * information method (isLoaded) about the state of the component
40 * A component instance is used by one or more ServiceNode to execute
41 * services of this component instance
46 const char ComponentInstance::KIND[]="";
47 int ComponentInstance::_total = 0;
50 const char ComponentInstance::NULL_FILE_REPR[]="No repr specified for ComponentInstance";
52 bool ComponentInstance::setContainer(Container *cont)
54 if (cont == _container) return false;
57 cont->checkCapabilityToDealWith(this);
59 _container->decrRef();
62 _container->incrRef();
66 ComponentInstance::ComponentInstance(const std::string& name):_compoName(name),_isAttachedOnCloning(false),_container(0),_anonymous(true)
69 stringstream instName;
70 instName << _compoName << "_" << _numId;
71 _instanceName = instName.str();
74 ComponentInstance::ComponentInstance(const ComponentInstance& other):_compoName(other._compoName),
76 _isAttachedOnCloning(other._isAttachedOnCloning),
80 stringstream instName;
81 instName << _compoName << "_" << _numId;
82 _instanceName = instName.str();
84 _container=other._container->clone();
87 ComponentInstance::~ComponentInstance()
90 _container->decrRef();
94 * By calling this method the current container 'this' is not destined to be deeply copied on clone call.
96 void ComponentInstance::attachOnCloning() const
98 _isAttachedOnCloning=true;
102 std::string ComponentInstance::getFileRepr() const
104 return NULL_FILE_REPR;
108 * By calling this method the current container 'this' will be deeply copied on clone call.
110 void ComponentInstance::dettachOnCloning() const
112 _isAttachedOnCloning=false;
115 bool ComponentInstance::isAttachedOnCloning() const
117 return _isAttachedOnCloning;
120 //! Return the component kind
122 * A runtime can provide several implementations of a component instance.
123 * Each implementation has a different kind. A ComponentInstance can be
124 * associated to a ServiceNode is they have the same kind.
126 string ComponentInstance::getKind() const
131 std::string ComponentInstance::getKindForNode() const
136 void ComponentInstance::shutdown(int level)