+ DEBTRACE( "An exception was thrown!" )
+ DEBTRACE( "The raised exception is of Type:" << exc->_name() )
+
+ std::cerr << "The raised exception is of Type:" << exc->_name() << std::endl;
+ /*
+ if(strcmp(exc->_name(),"MARSHAL") == 0)
+ {
+ const char* ms = ((CORBA::MARSHAL*)exc)->NP_minorString();
+ if (ms)
+ std::cerr << "(CORBA::MARSHAL: minor = " << ms << ")" << std::endl;
+ else
+ std::cerr << "(CORBA::MARSHAL: minor = " << ((CORBA::MARSHAL*)exc)->minor() << ")" << std::endl;
+ }
+ */
+ _errorDetails="Execution problem: the raised exception is of Type:";
+ _errorDetails += exc->_name();
+ throw Exception("Execution problem");
+ }
+
+ DEBTRACE( "++++++++++++CorbaNode::outputs++++++++++++" )
+ int out_param=in_param;
+ for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
+ {
+ OutputCorbaPort *p=(OutputCorbaPort *)*iter;
+ DEBTRACE( "port name: " << p->getName() )
+ DEBTRACE( "port kind: " << p->edGetType()->kind() )
+ DEBTRACE( "port number: " << out_param )
+ CORBA::Any *ob=arguments->item(out_param)->value();
+#ifdef REFCNT
+ DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
+#endif
+#ifdef _DEVDEBUG_
+ CORBA::TypeCode_var tc=ob->type();
+ switch(p->edGetType()->kind())
+ {
+ case Double:
+ CORBA::Double d;
+ *ob >>= d;
+ DEBTRACE( d )
+ break;
+ case Int:
+ CORBA::Long l;
+ *ob >>= l;
+ DEBTRACE( l )
+ break;
+ case String:
+ const char *s;
+ *ob >>= s;
+ DEBTRACE( s )
+ break;
+ case Objref:
+ DEBTRACE( tc->id() )
+ break;
+ default:
+ break;
+ }
+#endif
+ //OutputPort must copy the input Any(ob).
+ //This Any will be deleted with the request.
+ //Copy is made by the method put.
+ p->put(ob);
+ out_param=out_param+1;
+#ifdef REFCNT
+ DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
+#endif
+ }
+ DEBTRACE( "++++++++++++++++++++++++++++++++++++++++++" )
+ }
+ //Request has been deleted (_var )
+ //All anys given to the request are deleted : don't forget to copy them
+ //if you want to keep them
+#ifdef REFCNT
+ list<OutputPort *>::const_iterator iter;
+ for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
+ {
+ OutputCorbaPort *p=(OutputCorbaPort *)*iter;
+ CORBA::Any *ob=p->getAny();
+ DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
+ }
+#endif
+ DEBTRACE( "+++++++++++++++++ End CorbaNode::execute: " << getName() << " +++++++++++++++++" )
+}
+
+//! Clone the node : must also clone the component instance ?
+Node *CORBANode::simpleClone(ComposedNode *father, bool editionOnly) const
+{
+ return new CORBANode(*this,father);
+}
+
+//! Create a CORBANode with the same component object and no input or output port
+/*!
+ * \param name : node name
+ * \return a new CORBANode node
+ */
+ServiceNode* CORBANode::createNode(const std::string& name)
+{
+
+ CORBANode* node= new CORBANode(name);
+ node->setComponent(_component);
+ return node;
+}
+
+// SalomeNode Class
+
+const char SalomeNode::KIND[]="Salome";
+
+std::string SalomeNode::getKind() const
+{
+ return KIND;
+}
+
+//! SalomeNode constructor
+SalomeNode::SalomeNode(const std::string& name):ServiceNode(name)
+{
+ _implementation=CORBANode::IMPL_NAME;
+}
+
+SalomeNode::SalomeNode(const SalomeNode& other,ComposedNode *father):ServiceNode(other,father)
+{
+ _implementation=CORBANode::IMPL_NAME;
+}
+
+SalomeNode::~SalomeNode()
+{
+}
+
+#ifdef DSC_PORTS
+//! Init the datastream ports of the component associated to the node
+void SalomeNode::initService()
+{
+ DEBTRACE( "SalomeNode::initService: "<<getName())
+ if(_setOfInputDataStreamPort.size() == 0 && _setOfOutputDataStreamPort.size() == 0)return;
+
+ CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
+ Engines::Superv_Component_var compo=Engines::Superv_Component::_narrow(objComponent);
+ if( CORBA::is_nil(compo) )
+ {
+ std::string msg="Can't get reference to DSC object (or it was nil).";
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ try
+ {
+ if (!_multi_port_node)
+ {
+ CORBA::Boolean ret=compo->init_service(_method.c_str());
+ if(!ret)
+ {
+ _errorDetails="Problem with component '"+_ref+"' in init_service of service '"+ _method + "'";
+ throw Exception(_errorDetails);
+ }
+ //Should check that component port types are the same as those declared in the xml file
+ }
+ else
+ {
+ CORBA::Boolean ret=compo->init_service_with_multiple(_method.c_str(), _param);
+ if(!ret)
+ {
+ _errorDetails="Problem with component '"+_ref+"' in init_service_with_multiple of service '"+ _method + "'";
+ throw Exception(_errorDetails);
+ }
+ }
+ }
+ catch(...)
+ {
+ _errorDetails="Problem with component '"+_ref+"' in init_service of service '"+ _method + "'";
+ throw;
+ }
+}
+
+void
+SalomeNode::addDatastreamPortToInitMultiService(const std::string & port_name, int number)
+{
+ int index = _param.length();
+ _param.length(index + 1);
+ _param[index].name = CORBA::string_dup(port_name.c_str());
+ _param[index].number = number;
+}
+
+//! Connect the datastream ports of the component associated to the node
+void SalomeNode::connectService()
+{
+ DEBTRACE( "SalomeNode::connectService: "<<getName());
+ if(_setOfOutputDataStreamPort.size() == 0)return;
+
+ CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
+ SALOME_NamingService NS(getSALOMERuntime()->getOrb()) ;
+ SALOME_LifeCycleCORBA LCC(&NS) ;
+ CORBA::Object_var obj = NS.Resolve("/ConnectionManager");
+ Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj);
+ Engines::Superv_Component_var me=Engines::Superv_Component::_narrow(objComponent);
+ if( CORBA::is_nil(me) )
+ {
+ std::string msg="Can't get reference to Engines::Superv_Component: "+getName();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ std::list<OutputDataStreamPort *>::iterator iter;
+ Engines::ConnectionManager::connectionId id;
+ for(iter = _setOfOutputDataStreamPort.begin(); iter != _setOfOutputDataStreamPort.end(); iter++)
+ {
+ OutputDataStreamPort *port=(OutputDataStreamPort *)*iter;
+ std::set<InPort *> ports=port->edSetInPort();
+ std::set<InPort *>::iterator iterout;
+ for(iterout=ports.begin();iterout != ports.end(); iterout++)
+ {
+ //It's only possible to connect 2 SalomeNode : try to get a SalomeNode
+ SalomeNode* snode= dynamic_cast<SalomeNode*>((*iterout)->getNode());
+ if(snode == 0) //don't connect, it's not a SalomeNode
+ {
+ std::string msg="Can't connect : not a SalomeNode";
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+
+ CORBA::Object_var comp=((SalomeComponent*)snode->getComponent())->getCompoPtr();
+ if( CORBA::is_nil(comp))
+ {
+ std::string msg="Problem in connectService: " + snode->getName();
+ msg=msg+" Component is probably not launched. Modify your YACS file";
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+
+ Engines::Superv_Component_var other=Engines::Superv_Component::_narrow(comp);
+ if( CORBA::is_nil(other))
+ {
+ std::string msg="Can't connect to nil Engines::Superv_Component: " + snode->getName();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ try
+ {
+ id=manager->connect(me,port->getName().c_str(),other,(*iterout)->getName().c_str());
+ }
+ catch(Engines::DSC::PortNotDefined& ex)
+ {
+ std::string msg="Problem in connectService. Unknown port: "+port->getName()+" or "+(*iterout)->getName();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ catch(Engines::DSC::BadPortType& ex)
+ {
+ std::string msg="Problem in connectService. Type of provides port is bad. Expected: ";
+ msg=msg + ex.expected.in();
+ msg=msg + "Received: "+ex.received.in();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ catch(Engines::DSC::NilPort& ex)
+ {
+ std::string msg="Problem in connectService. Port is nil: "+port->getName()+" or "+(*iterout)->getName();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ catch( const SALOME::SALOME_Exception& ex )
+ {
+ std::string msg="Problem in connectService. ";
+ msg += ex.details.text.in();
+ msg=msg+getName()+" " + port->getName() + " " + snode->getName() + " " + (*iterout)->getName();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ catch(CORBA::SystemException& ex)
+ {
+ DEBTRACE( "minor code: " << ex.minor() );
+ DEBTRACE( "completion code: " << ex.completed() );
+ std::string msg="Problem in connectService. CORBA System exception ";
+ std::string excname=ex._name();
+ msg=msg+excname + " " +getName()+" " + port->getName() + " " + snode->getName() + " " + (*iterout)->getName();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ catch(...)
+ {
+ std::string msg="Problem in connectService. Unknown exception";
+ msg=msg+getName()+" " + port->getName() + " " + snode->getName() + " " + (*iterout)->getName();
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ DEBTRACE("Connected: " <<id<<" "<<getName()<<" "<<port->getName()<<" "<<snode->getName()<<" "<<(*iterout)->getName());
+ ids.push_back(id);
+ }
+ }
+
+ //Init component port properties
+ for(iter = _setOfOutputDataStreamPort.begin(); iter != _setOfOutputDataStreamPort.end(); iter++)
+ {
+ (*iter)->initPortProperties();
+ }
+ std::list<InputDataStreamPort *>::iterator iterin;
+ for(iterin = _setOfInputDataStreamPort.begin(); iterin != _setOfInputDataStreamPort.end(); iterin++)
+ {
+ (*iterin)->initPortProperties();
+ }
+}
+
+//! Disconnect the datastream ports of the component associated to the node
+void SalomeNode::disconnectService()
+{
+ DEBTRACE( "SalomeNode::disconnectService: "<<getName());
+ // in some rare cases, disconnectService can be called from 2 different threads
+ YACS::BASES::AutoLocker<YACS::BASES::Mutex> lock(&_mutex);
+
+ if(ids.size() == 0)
+ return;
+
+ SALOME_NamingService NS(getSALOMERuntime()->getOrb()) ;
+ SALOME_LifeCycleCORBA LCC(&NS) ;
+ CORBA::Object_var obj = NS.Resolve("/ConnectionManager");
+ Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj);
+ std::list<Engines::ConnectionManager::connectionId>::iterator iter;
+ for(iter = ids.begin(); iter != ids.end(); iter++)
+ {
+ DEBTRACE("Trying to disconnect: " << *iter );
+ try
+ {
+ manager->disconnect(*iter,Engines::DSC::RemovingConnection);
+ }
+ catch(Engines::ConnectionManager::BadId& ex)
+ {
+ DEBTRACE( "Problem in disconnect: " << *iter );
+ }
+ catch(Engines::DSC::PortNotDefined& ex)
+ {
+ DEBTRACE( "Problem in disconnect: " << *iter );
+ }
+ catch(Engines::DSC::PortNotConnected& ex)
+ {
+ DEBTRACE( "Problem in disconnect: " << *iter );
+ }
+ catch(Engines::DSC::BadPortReference& ex)
+ {
+ DEBTRACE( "Problem in disconnect (Engines::DSC::BadPortReference): " << *iter );
+ }
+ catch(CORBA::SystemException& ex)
+ {
+ DEBTRACE( "Problem in disconnect (CORBA::SystemException): " << *iter );
+ }
+ catch(...)
+ {
+ DEBTRACE( "Problem in disconnect: " << *iter );
+ }
+ }
+ ids.clear();
+}
+
+void SalomeNode::cleanNodes()
+{
+ disconnectService();
+}
+
+#endif
+
+//! Execute the service on the component associated to the node
+void SalomeNode::execute()
+{
+ YACSTRACE(1,"+++++++++++++++++ SalomeNode::execute: " << getName() << " " << _method << " +++++++++++++++++" );
+ {
+ CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
+ Engines::EngineComponent_var compo=Engines::EngineComponent::_narrow(objComponent);
+
+ // Set component properties
+ std::map<std::string,std::string> amap=getProperties();
+ if(amap.size() > 0)
+ {
+ Engines::FieldsDict_var dico = new Engines::FieldsDict;
+ dico->length(amap.size());
+ std::map<std::string,std::string>::const_iterator it;
+ int i=0;
+ for(it = amap.begin(); it != amap.end(); ++it)
+ {
+ dico[i].key=CORBA::string_dup(it->first.c_str());
+ dico[i].value <<=it->second.c_str();
+ i++;
+ }
+ compo->setProperties(dico);
+ }
+
+ //DII request building :
+ // a service gets all its in parameters first
+ // then all its out parameters
+ // no inout parameters
+ // the return value (if any) is the first out parameter
+ //
+ CORBA::Request_var req ;
+ try
+ {
+ req = objComponent->_request(_method.c_str());
+ }
+ catch(CORBA::SystemException& ex)
+ {
+ std::string msg="component '" +_ref+ "' has no service '" + _method+ "'";
+ _errorDetails=msg;
+ throw Exception(msg);
+ }
+ CORBA::NVList_ptr arguments = req->arguments() ;
+
+ DEBTRACE( "+++++++++++++++++SalomeNode::inputs+++++++++++++++++" );
+ int in_param=0;
+ //in parameters
+ list<InputPort *>::iterator iter2;
+ for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
+ {
+ InputCorbaPort *p=(InputCorbaPort *)*iter2;
+ if(p->edGetType()->isA(Runtime::_tc_file))
+ continue;
+ DEBTRACE( "port name: " << p->getName() );
+ DEBTRACE( "port kind: " << p->edGetType()->kind() );
+ CORBA::Any* ob=p->getAny();
+#ifdef _DEVDEBUG_
+ CORBA::TypeCode_var tc=ob->type();
+ switch(p->edGetType()->kind())
+ {
+ case Double:
+ CORBA::Double d;
+ *ob >>= d;
+ DEBTRACE( d )
+ break;
+ case Int:
+ CORBA::Long l;
+ *ob >>= l;
+ DEBTRACE( l )
+ break;
+ case String:
+ const char *s;
+ *ob >>= s;
+ DEBTRACE( s )
+ break;
+ case Objref:
+ DEBTRACE( tc->id() )
+ break;
+ default:
+ break;
+ }
+#endif
+ //add_value makes a copy of any. Copy will be deleted with request
+ arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_IN ) ;
+ in_param=in_param+1;
+ }
+ //in files
+ int nfiles=0;
+ DEBTRACE("checkInputFilesToService: " << _method);
+ try
+ {
+ for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
+ {
+ InputCorbaPort *p=(InputCorbaPort *)*iter2;
+ if(!p->edGetType()->isA(Runtime::_tc_file))
+ continue;
+ std::string filename=p->getName();
+ // replace ':' by '.'. Needed because port name can not contain '.'
+ string::size_type debut =filename.find_first_of(':',0);
+ while(debut != std::string::npos)
+ {
+ filename[debut]='.';
+ debut=filename.find_first_of(':',debut);
+ }
+ DEBTRACE( "inport with file: " << filename );
+ Engines::Salome_file_var isf=compo->setInputFileToService(_method.c_str(),p->getName().c_str());
+ isf->setDistributedFile(filename.c_str());
+ Engines::Salome_file_ptr osf;
+ CORBA::Any* any=p->getAny();
+ *any >>= osf;
+ isf->connect(osf);
+ nfiles++;
+ }
+ if(nfiles)
+ compo->checkInputFilesToService(_method.c_str());
+ }
+ catch( const SALOME::SALOME_Exception& ex )
+ {
+ std::string text="Execution problem in checkInputFilesToService: ";
+ text += (const char*)ex.details.text;
+ _errorDetails=text;
+ throw Exception(text);
+ }
+ catch(CORBA::SystemException& ex)
+ {
+ std::string msg="Execution problem: component probably does not support files ??";
+ _errorDetails=msg;
+ throw Exception(msg);