1 // Copyright (C) 2006-2021 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 "InputPort.hxx"
21 #include "OutPort.hxx"
22 #include "ComposedNode.hxx"
29 #include "YacsTrace.hxx"
31 using namespace YACS::ENGINE;
34 const char InputPort::NAME[]="InputPort";
36 InputPort::InputPort(const InputPort& other, Node *newHelder)
37 : DataFlowPort(other, newHelder),
38 InPort(other, newHelder),
39 DataPort(other, newHelder),
40 Port(other, newHelder),
42 _canBeNull(other._canBeNull)
45 _initValue=other._initValue->clone();
48 InputPort::InputPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull)
49 : DataFlowPort(name, node, type),
50 InPort(name, node, type),
51 DataPort(name, node, type),
58 string InputPort::getNameOfTypeOfCurrentInstance() const
63 void InputPort::exInit(bool start)
65 checkBasicConsistency();
70 bool InputPort::isEmpty()
75 //! Specifies if this port has been \b manually set by the call of InputPort::edInit
76 bool InputPort::edIsManuallyInitialized() const
82 * Perform a quick and not complete check. Use ComposedNode::CheckConsistency instead.
84 bool InputPort::edIsInitialized() const
86 return (edIsManuallyInitialized() || _backLinks.size()!=0 );
89 InputPort::~InputPort()
92 _initValue->decrRef();
95 void InputPort::edInit(Any *value)
97 InputPort *manuallySet=getRuntime()->adapt(this,
98 Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME,_type,true);
101 manuallySet->put((const void *) value);
102 if(manuallySet!=this)
105 catch(ConversionException&)
107 if(manuallySet!=this)
115 //! Initialize the port with an object (value) coming from a world with implementation impl
117 * You should be careful when using this method : the caller must set the context according to implementation
118 * For instance, if implementation is Python, the caller must hold the Global Interpreter Lock (also known as GIL).
120 void InputPort::edInit(const std::string& impl,const void* value)
122 InputPort *manuallySet=getRuntime()->adapt(this,impl,_type,true);
125 manuallySet->put(value);
126 if(manuallySet!=this)
129 catch(ConversionException&)
131 if(manuallySet!=this)
139 //! Removes eventually previous manual initialisation.
140 void InputPort::edRemoveManInit()
143 _initValue->decrRef();
147 //! Check basically that this port has one chance to be specified on time. It's a necessary condition \b not \b sufficient at all.
148 void InputPort::checkBasicConsistency() const
150 if(!_canBeNull && !edIsManuallyInitialized() && _backLinks.size()==0 )
152 ostringstream stream;
153 stream << "InputPort::checkBasicConsistency : Port " << _name << " of node with name " << _node->getName() << " neither initialized nor linked back";
154 throw Exception(stream.str());
158 std::string InputPort::dump()
160 string xmldump = "<value><error> NO_SERIALISATION_AVAILABLE </error></value>";
164 std::string InputPort::getHumanRepr()
169 void InputPort::setStringRef(std::string strRef)
174 bool InputPort::canBeNull() const
179 ProxyPort::ProxyPort(InputPort* p):InputPort("Convertor", p->getNode(), p->edGetType()),DataPort("Convertor", p->getNode(), p->edGetType()),
185 ProxyPort::~ProxyPort()
187 //For the moment, there is no case in YACS we have a proxy port in a proxy port
188 //So don't test that. _port may be already deleted. The test is not sure.
190 if(_port->isIntermediate())
195 void ProxyPort::edRemoveAllLinksLinkedWithMe()
197 _port->edRemoveAllLinksLinkedWithMe();
201 * \note : Should never been called because Node clone process does not duplicate data attributes relative to links.
202 * This part is done afterwards on relink process.
204 InputPort *ProxyPort::clone(Node *newHelder) const
206 throw Exception("ProxyPort::clone : internal error - should never happened");
209 void ProxyPort::edNotifyReferencedBy(OutPort *fromPort, bool isLoopProof)
211 _port->edNotifyReferencedBy(fromPort,isLoopProof);
214 void ProxyPort::edNotifyDereferencedBy(OutPort *fromPort)
216 _port->edNotifyDereferencedBy(fromPort);
219 std::set<OutPort *> ProxyPort::edSetOutPort() const
221 return _port->edSetOutPort();
224 int ProxyPort::edGetNumberOfLinks() const
226 return _port->edGetNumberOfLinks();
229 void ProxyPort::exRestoreInit()
231 _port->exRestoreInit();
234 void ProxyPort::exSaveInit()
240 InPort *ProxyPort::getPublicRepresentant()
242 InputPort *ProxyPort::getPublicRepresentant()
245 return _port->getPublicRepresentant();
248 void *ProxyPort::get() const
253 void ProxyPort::releaseData()
255 _port->releaseData();
258 void ProxyPort::put(const void *data)
263 void ProxyPort::getAllRepresentants(std::set<InPort *>& repr) const
265 DEBTRACE("ProxyPort::getAllRepresentants");
266 _port->getAllRepresentants(repr);