3 #include "InputPort.hxx"
4 #include "OutputPort.hxx"
5 #include "CppPorts.hxx"
6 #include "CppContainer.hxx"
7 #include "CppComponent.hxx"
14 #include "YacsTrace.hxx"
16 using namespace YACS::ENGINE;
19 const char CppNode::IMPL_NAME[]="Cpp";
20 const char CppNode::KIND[]="Cpp";
22 CppNode::CppNode(const CppNode& other,ComposedNode *father):ServiceNode(other,father),
24 _componentName(other._componentName)
26 DEBTRACE("CppNode::CppNode");
27 _implementation=IMPL_NAME;
30 CppNode::CppNode(const std::string & name) : ServiceNode(name), _run(NULL)
32 _implementation=IMPL_NAME;
35 void CppNode::setCode(const std::string & componentName, const std::string & method)
38 _componentName = componentName;
42 void CppNode::setFunc(MYRUN fonc) {
46 _component->decrRef();
60 setRef(_componentName);
65 void CppNode::execute()
67 std::list<InputPort *>::iterator iter1;
70 nIn = _setOfInputPort.size();
71 nOut = _setOfOutputPort.size();
73 Any ** In = new Any * [nIn], ** Out = new Any * [nOut];
78 for(iter1 = _setOfInputPort.begin(), it = 0; iter1 != _setOfInputPort.end();
81 InputCppPort *p = dynamic_cast<InputCppPort *> (*iter1);
82 In[it] = p->getCppObj();
87 CppComponent * _componentC = dynamic_cast<CppComponent *>(_component);
89 throw YACS::Exception("CppNode::execute : bad type of component");
90 _componentC->run(_method.c_str(), nIn, nOut, In, Out);
93 _run(nIn, nOut, In, Out);
96 std::list<OutputPort *>::iterator iter2;
97 for(iter2 = _setOfOutputPort.begin(), it=0; iter2 != _setOfOutputPort.end(); iter2++, it++)
99 OutputCppPort *p = dynamic_cast<OutputCppPort *> (*iter2);
101 //decref it, we don't need it more
103 DEBTRACE("ref count: " << Out[it]->getRefCnt());
106 catch (YACS::Exception & e) {
116 ServiceNode* CppNode::createNode(const std::string& name)
118 CppNode* node= new CppNode(name);
119 node->setComponent(_component);
123 //! Clone the node : must also clone the component instance ?
124 Node * CppNode::simpleClone(ComposedNode *father, bool editionOnly) const
126 return new CppNode(*this,father);
129 //! Create a new node of same type with a given name
130 CppNode* CppNode::cloneNode(const std::string& name)
132 DEBTRACE("CppNode::cloneNode");
133 CppNode* n=new CppNode(name);
139 n->setCode(_componentName, _method);
141 list<InputPort *>::iterator iter;
142 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
144 InputCppPort *p=(InputCppPort *)*iter;
145 DEBTRACE("port name: " << p->getName());
146 DEBTRACE("port kind: " << p->edGetType()->kind());
147 n->edAddInputPort(p->getName(),p->edGetType());
149 list<OutputPort *>::iterator iter2;
150 for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
152 OutputCppPort *p=(OutputCppPort *)*iter2;
153 DEBTRACE("port name: " << p->getName());
154 DEBTRACE("port kind: " << p->edGetType()->kind());
155 n->edAddOutputPort(p->getName(),p->edGetType());