Salome HOME
Copyrights update 2015.
[modules/yacs.git] / src / engine / Test / ContainerTest.cxx
1 // Copyright (C) 2006-2015  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 "ContainerTest.hxx"
21 #include "ComponentInstance.hxx"
22 #include "ToyNode.hxx"
23 #include <sstream>
24
25 using namespace std;
26 using namespace YACS::ENGINE;
27
28 unsigned ContainerTest::_counter = 0;
29
30 const char ContainerTest::SUPPORTED_COMP_KIND[] = "TESTKIND1";
31
32 unsigned ContainerTest2::_counter = 0;
33
34 const char ContainerTest2::SUPPORTED_COMP_KIND[] = "TESTKIND2";
35
36 ContainerTest::ContainerTest():_alreadyStarted(false),_myCounter(_counter++)
37 {
38 }
39
40 std::string ContainerTest::getKind() const
41 {
42   return std::string();
43 }
44
45 std::string ContainerTest::getPlacementInfo() const
46 {
47   ostringstream stream;
48   stream << "Cont#_" << _myCounter;
49   return stream.str();
50 }
51
52 bool ContainerTest::isAlreadyStarted(const Task *askingNode) const
53 {
54   return _alreadyStarted;
55 }
56
57 void ContainerTest::start(const Task *askingNode) throw(YACS::Exception)
58 {
59   if(_alreadyStarted)
60     throw Exception("ContainerTest already started !!!!");
61   _alreadyStarted=true;
62 }
63
64 Container *ContainerTest::clone() const
65 {
66   if(_isAttachedOnCloning)
67     {
68       incrRef();
69       return (Container *) this;
70     }
71   else
72     return new ContainerTest;
73 }
74
75 Container *ContainerTest::cloneAlways() const
76 {
77   return new ContainerTest;
78 }
79
80 void ContainerTest::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
81 {
82   if(inst->getKind()!=SUPPORTED_COMP_KIND)
83     throw Exception("ContainerTest not compatible with this type of instance.");
84 }
85
86 void ContainerTest::initAllContainers()
87 {
88   _counter=0;
89 }
90
91 ContainerTest2::ContainerTest2():_alreadyStarted(false),_myCounter(_counter++)
92 {
93 }
94
95 std::string ContainerTest2::getKind() const
96 {
97   return std::string();
98 }
99
100 bool ContainerTest2::isAlreadyStarted(const Task *askingNode) const
101 {
102   return _alreadyStarted;
103 }
104
105 void ContainerTest2::start(const Task *askingNode) throw(YACS::Exception)
106 {
107   if(_alreadyStarted)
108     throw Exception("ContainerTest already started !!!!");
109   _alreadyStarted=true;
110 }
111
112 Container *ContainerTest2::clone() const
113 {
114   if(_isAttachedOnCloning)
115     {
116       incrRef();
117       return (Container *) this;
118     }
119   else
120     return new ContainerTest2;
121 }
122
123 Container *ContainerTest2::cloneAlways() const
124 {
125   return new ContainerTest2;
126 }
127
128 void ContainerTest2::initAllContainers()
129 {
130   _counter=0;
131 }
132
133 void ContainerTest2::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
134 {
135   if(inst->getKind()!=SUPPORTED_COMP_KIND)
136     throw Exception("ContainerTest not compatible with this type of instance.");
137 }