Version: 8.3.0
SalomeContainerHelper.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 
21 
22 #include "ServiceNode.hxx"
23 #include "YacsTrace.hxx"
24 
25 #include <sstream>
26 #include <iostream>
27 
28 using namespace YACS::ENGINE;
29 using namespace std;
30 
31 const char SalomeContainerMonoHelper::TYPE_NAME[]="mono";
32 
34 
35 const char SalomeContainerMultiHelper::TYPE_NAME[]="multi";
36 
37 const char SalomeContainerMultiHelper::DFT_LAUNCH_MODE[]="getorstart";
38 
40 {
41 }
42 
44 {
45 
46 }
47 
49 {
50  return TYPE_NAME;
51 }
52 
54 {
55  return std::string(DFT_LAUNCH_MODE);
56 }
57 
59 {
60  return new SalomeContainerMonoHelper;
61 }
62 
63 Engines::Container_var SalomeContainerMonoHelper::getContainer(const Task *askingNode) const
64 {
65  return _trueCont;
66 }
67 
69 {
70  if(CORBA::is_nil(_trueCont))
71  return false;
72  else
73  return true;
74 }
75 
76 void SalomeContainerMonoHelper::setContainer(const Task *askingNode, Engines::Container_var cont)
77 {
78  _trueCont=cont;
79 #ifdef REFCNT
80  DEBTRACE(_trueCont->_PR_getobj()->pd_refCount );
81 #endif
82 }
83 
85 {
86  try
87  {
88  DEBTRACE("shutdown SALOME container: " );
89  CORBA::String_var containerName=_trueCont->name();
90  DEBTRACE(containerName);
91  _trueCont->Shutdown();
92  std::cerr << "shutdown SALOME container: " << containerName << std::endl;
93  }
94  catch(...)
95  {
96  DEBTRACE("Unknown exception ignored." );
97  }
98  _trueCont=Engines::Container::_nil();
99 }
100 
102 {
103 }
104 
106 {
107  return TYPE_NAME;
108 }
109 
111 {
112  return std::string(DFT_LAUNCH_MODE);
113 }
114 
116 {
117  return new SalomeContainerMultiHelper;
118 }
119 
120 Engines::Container_var SalomeContainerMultiHelper::getContainer(const Task *askingNode) const
121 {
122  const ComponentInstance *inst(askingNode?askingNode->getComponent():0);
123  std::map<const ComponentInstance *,Engines::Container_var>::const_iterator it(_trueContainers.find(inst));
124  if(it!=_trueContainers.end())
125  return (*it).second;
126  else
127  return Engines::Container::_nil();
128 }
129 
131 {
132  const ComponentInstance *inst(askingNode?askingNode->getComponent():0);
133  if(_trueContainers.count(inst)==0)
134  return false;
135  else
136  return true;
137 }
138 
139 void SalomeContainerMultiHelper::setContainer(const Task *askingNode, Engines::Container_var cont)
140 {
141  const ComponentInstance *inst(askingNode?askingNode->getComponent():0);
142  _trueContainers[inst]=cont;
143 #ifdef REFCNT
144  std::map<const ComponentInstance *, Engines::Container_var >::const_iterator it;
145  for(it = _trueContainers.begin(); it != _trueContainers.end(); ++it)
146  {
147  DEBTRACE(it->second->_PR_getobj()->pd_refCount );
148  }
149 #endif
150 }
151 
153 {
154  for(std::map<const ComponentInstance *, Engines::Container_var >::const_iterator it = _trueContainers.begin(); it != _trueContainers.end(); ++it)
155  {
156  try
157  {
158  DEBTRACE("shutdown SALOME container: " );
159  CORBA::String_var containerName=it->second->name();
160  DEBTRACE(containerName);
161  it->second->Shutdown();
162  std::cerr << "shutdown SALOME container: " << containerName << std::endl;
163  }
164  catch(CORBA::Exception&)
165  {
166  DEBTRACE("Unexpected CORBA failure detected." );
167  }
168  catch(...)
169  {
170  DEBTRACE("Unknown exception ignored." );
171  }
172  }
173  _trueContainers.clear();
174 }
175 
177 {
178 }