1 // Copyright (C) 2006-2008 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
19 #include "InputPort.hxx"
20 #include "OutPort.hxx"
21 #include "ComposedNode.hxx"
28 #include "YacsTrace.hxx"
30 using namespace YACS::ENGINE;
33 const char InputPort::NAME[]="InputPort";
35 InputPort::InputPort(const InputPort& other, Node *newHelder):DataFlowPort(other,newHelder),InPort(other,newHelder),
36 DataPort(other,newHelder),Port(other,newHelder),
40 _initValue=other._initValue->clone();
43 InputPort::InputPort(const std::string& name, Node *node, TypeCode* type)
44 : DataFlowPort(name,node,type), InPort(name,node,type),DataPort(name,node,type),Port(node), _initValue(0)
48 string InputPort::getNameOfTypeOfCurrentInstance() const
53 void InputPort::exInit(bool start)
55 checkBasicConsistency();
60 bool InputPort::isEmpty()
65 //! Specifies if this port has been \b manually set by the call of InputPort::edInit
66 bool InputPort::edIsManuallyInitialized() const
72 * Perform a quick and not complete check. Use ComposedNode::CheckConsistency instead.
74 bool InputPort::edIsInitialized() const
76 return (edIsManuallyInitialized() or _backLinks.size()!=0 );
79 InputPort::~InputPort()
82 _initValue->decrRef();
85 void InputPort::edInit(Any *value)
87 InputPort *manuallySet=getRuntime()->adapt(this,
88 Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME,_type,true);
91 manuallySet->put((const void *) value);
95 catch(ConversionException&)
105 //! Initialize the port with an object (value) coming from a world with implementation impl
107 * You should be careful when using this method : the caller must set the context according to implementation
108 * For instance, if implementation is Python, the caller must hold the Global Interpreter Lock (also known as GIL).
110 void InputPort::edInit(const std::string& impl,const void* value)
112 InputPort *manuallySet=getRuntime()->adapt(this,impl,_type,true);
115 manuallySet->put(value);
116 if(manuallySet!=this)
119 catch(ConversionException&)
121 if(manuallySet!=this)
129 //! Removes eventually previous manual initialisation.
130 void InputPort::edRemoveManInit()
133 _initValue->decrRef();
137 //! Check basically that this port has one chance to be specified on time. It's a necessary condition \b not \b sufficient at all.
138 void InputPort::checkBasicConsistency() const throw(Exception)
140 if(!edIsManuallyInitialized() and _backLinks.size()==0 )
142 ostringstream stream;
143 stream << "InputPort::checkBasicConsistency : Port " << _name << " of node with name " << _node->getName() << " neither initialized nor linked back";
144 throw Exception(stream.str());
148 std::string InputPort::dump()
150 string xmldump = "<value><error> NO_SERIALISATION_AVAILABLE </error></value>";
154 void InputPort::setStringRef(std::string strRef)
159 ProxyPort::ProxyPort(InputPort* p):InputPort("Convertor", p->getNode(), p->edGetType()),DataPort("Convertor", p->getNode(), p->edGetType()),
165 ProxyPort::~ProxyPort()
167 //For the moment, there is no case in YACS we have a proxy port in a proxy port
168 //So don't test that. _port may be already deleted. The test is not sure.
170 if(_port->isIntermediate())
175 void ProxyPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
177 _port->edRemoveAllLinksLinkedWithMe();
181 * \note : Should never been called because Node clone process does not duplicate data attributes relative to links.
182 * This part is done afterwards on relink process.
184 InputPort *ProxyPort::clone(Node *newHelder) const
186 throw Exception("ProxyPort::clone : internal error - should never happened");
189 void ProxyPort::edNotifyReferencedBy(OutPort *fromPort)
191 _port->edNotifyReferencedBy(fromPort);
194 void ProxyPort::edNotifyDereferencedBy(OutPort *fromPort)
196 _port->edNotifyDereferencedBy(fromPort);
199 std::set<OutPort *> ProxyPort::edSetOutPort() const
201 return _port->edSetOutPort();
204 int ProxyPort::edGetNumberOfLinks() const
206 return _port->edGetNumberOfLinks();
209 void ProxyPort::exRestoreInit()
211 _port->exRestoreInit();
214 void ProxyPort::exSaveInit()
220 InPort *ProxyPort::getPublicRepresentant()
222 InputPort *ProxyPort::getPublicRepresentant()
225 return _port->getPublicRepresentant();
228 void *ProxyPort::get() const
233 void ProxyPort::put(const void *data) throw(ConversionException)
238 void ProxyPort::getAllRepresentants(std::set<InPort *>& repr) const
240 DEBTRACE("ProxyPort::getAllRepresentants");
241 _port->getAllRepresentants(repr);