Salome HOME
Revert "Synchronize adm files"
[modules/yacs.git] / src / engine / ComponentInstance.cxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ComponentInstance.hxx"
21 #include "Container.hxx"
22
23 #include <iostream>
24 #include <sstream>
25
26 //#define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28
29 using namespace YACS::ENGINE;
30 using namespace std;
31
32 /*! \class YACS::ENGINE::ComponentInstance
33  *  \brief Base class for all component instances.
34  *
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
39  *
40  * A component instance is used by one or more ServiceNode to execute
41  * services of this component instance
42  *
43  * \see ServiceNode
44  */
45
46 const char ComponentInstance::KIND[]="";
47 int ComponentInstance::_total = 0;
48
49
50 const char ComponentInstance::NULL_FILE_REPR[]="No repr specified for ComponentInstance";
51
52 void ComponentInstance::setContainer(Container *cont)
53 {
54   if (cont == _container) return;
55   
56   if(cont)
57     cont->checkCapabilityToDealWith(this);
58   if(_container)
59     _container->decrRef();
60   _container=cont;
61   if(_container)
62     _container->incrRef();
63 }
64
65 ComponentInstance::ComponentInstance(const std::string& name):_compoName(name),_isAttachedOnCloning(false),_container(0),_anonymous(true)
66 {
67   _numId = _total++;
68   stringstream instName;
69   instName << _compoName << "_" << _numId;
70   _instanceName = instName.str();
71 }
72
73 ComponentInstance::ComponentInstance(const ComponentInstance& other):_compoName(other._compoName),
74                                                                      _container(0),
75                                                                      _isAttachedOnCloning(other._isAttachedOnCloning),
76                                                                      _anonymous(true)
77 {
78   _numId = _total++;
79   stringstream instName;
80   instName << _compoName << "_" << _numId;
81   _instanceName = instName.str();
82   if(other._container)
83     _container=other._container->clone();
84 }
85
86 ComponentInstance::~ComponentInstance()
87 {
88   if(_container)
89     _container->decrRef();
90 }
91
92 /*!
93  * By calling this method the current container 'this' is not destined to be deeply copied on clone call.
94  */
95 void ComponentInstance::attachOnCloning() const
96 {
97   _isAttachedOnCloning=true;
98 }
99
100 //! For dump in file
101 std::string ComponentInstance::getFileRepr() const
102 {
103   return NULL_FILE_REPR;
104 }
105
106 /*!
107  * By calling this method the current container 'this' will be deeply copied on clone call.
108  */
109 void ComponentInstance::dettachOnCloning() const
110 {
111   _isAttachedOnCloning=false;
112 }
113
114 bool ComponentInstance::isAttachedOnCloning() const
115 {
116   return _isAttachedOnCloning;
117 }
118
119 //! Return the component kind
120 /*!
121  * A runtime can provide several implementations of a component instance.
122  * Each implementation has a different kind. A ComponentInstance can be 
123  * associated to a ServiceNode is they have the same kind.
124  */
125 string ComponentInstance::getKind() const
126 {
127   return KIND;
128 }
129
130 void ComponentInstance::shutdown(int level)
131 {
132 }