1 // Copyright (C) 2006-2013 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.
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 throw(YACS::Exception)
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 void InputPort::setStringRef(std::string strRef)
169 bool InputPort::canBeNull() const
174 ProxyPort::ProxyPort(InputPort* p):InputPort("Convertor", p->getNode(), p->edGetType()),DataPort("Convertor", p->getNode(), p->edGetType()),
180 ProxyPort::~ProxyPort()
182 //For the moment, there is no case in YACS we have a proxy port in a proxy port
183 //So don't test that. _port may be already deleted. The test is not sure.
185 if(_port->isIntermediate())
190 void ProxyPort::edRemoveAllLinksLinkedWithMe() throw(YACS::Exception)
192 _port->edRemoveAllLinksLinkedWithMe();
196 * \note : Should never been called because Node clone process does not duplicate data attributes relative to links.
197 * This part is done afterwards on relink process.
199 InputPort *ProxyPort::clone(Node *newHelder) const
201 throw Exception("ProxyPort::clone : internal error - should never happened");
204 void ProxyPort::edNotifyReferencedBy(OutPort *fromPort)
206 _port->edNotifyReferencedBy(fromPort);
209 void ProxyPort::edNotifyDereferencedBy(OutPort *fromPort)
211 _port->edNotifyDereferencedBy(fromPort);
214 std::set<OutPort *> ProxyPort::edSetOutPort() const
216 return _port->edSetOutPort();
219 int ProxyPort::edGetNumberOfLinks() const
221 return _port->edGetNumberOfLinks();
224 void ProxyPort::exRestoreInit()
226 _port->exRestoreInit();
229 void ProxyPort::exSaveInit()
235 InPort *ProxyPort::getPublicRepresentant()
237 InputPort *ProxyPort::getPublicRepresentant()
240 return _port->getPublicRepresentant();
243 void *ProxyPort::get() const
248 void ProxyPort::put(const void *data) throw(ConversionException)
253 void ProxyPort::getAllRepresentants(std::set<InPort *>& repr) const
255 DEBTRACE("ProxyPort::getAllRepresentants");
256 _port->getAllRepresentants(repr);