23 #define private public
24 #define protected public
25 #include <omniORB4/CORBA.h>
26 #include <omniORB4/internal/typecode.h>
41 #include "SALOME_NamingService.hxx"
42 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "SALOME_Exception.hh"
46 #include <omniORB4/CORBA.h>
47 #include <omniORB4/minorCode.h>
55 using namespace YACS::ENGINE;
80 YACSTRACE(1,
"+++++++++++++ CorbaNode::execute: " <<
getName() <<
" +++++++++++++++" );
90 CORBA::Request_var req = objComponent->_request(
_method.c_str());
91 CORBA::NVList_ptr
arguments = req->arguments() ;
93 DEBTRACE(
"+++++++++++++++++CorbaNode::inputs+++++++++++++++++" )
96 list<InputPort *>::iterator iter2;
102 CORBA::Any* ob=p->
getAny();
104 CORBA::TypeCode_var typcod= ob->type();
124 if(*ob >>= CORBA::Any::to_boolean(b))
137 arguments->add_value( p->
getName().c_str() , *ob , CORBA::ARG_IN ) ;
142 DEBTRACE(
"+++++++++++++++++CorbaNode::outputs+++++++++++++++++" )
143 list<OutputPort *>::iterator iter;
151 DEBTRACE(
"refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
154 arguments->add_value( p->
getName().c_str() , *ob , CORBA::ARG_OUT );
156 DEBTRACE(
"refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
162 req->set_return_type(CORBA::_tc_void);
164 DEBTRACE(
"+++++++++++++++++CorbaNode::calculation+++++++++++++++++" <<
_method )
166 CORBA::Exception *exc =req->env()->exception();
169 DEBTRACE(
"An exception was thrown!" )
170 DEBTRACE(
"The raised exception is of Type:" << exc->_name() )
172 std::cerr <<
"The raised exception is of Type:" << exc->_name() << std::endl;
183 _errorDetails=
"Execution problem: the raised exception is of Type:";
188 DEBTRACE(
"++++++++++++CorbaNode::outputs++++++++++++" )
189 int out_param=in_param;
195 DEBTRACE(
"port number: " << out_param )
196 CORBA::Any *ob=arguments->item(out_param)->value();
198 DEBTRACE(
"refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
201 CORBA::TypeCode_var tc=ob->type();
230 out_param=out_param+1;
232 DEBTRACE(
"refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
235 DEBTRACE(
"++++++++++++++++++++++++++++++++++++++++++" )
241 list<OutputPort *>::const_iterator iter;
245 CORBA::Any *ob=p->
getAny();
246 DEBTRACE(
"refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
249 DEBTRACE(
"+++++++++++++++++ End CorbaNode::execute: " <<
getName() <<
" +++++++++++++++++" )
303 Engines::Superv_Component_var compo=Engines::Superv_Component::_narrow(objComponent);
304 if( CORBA::is_nil(compo) )
306 std::string msg=
"Can't get reference to DSC object (or it was nil).";
314 CORBA::Boolean
ret=compo->init_service(
_method.c_str());
324 CORBA::Boolean ret=compo->init_service_with_multiple(
_method.c_str(), _param);
342 int index = _param.length();
343 _param.length(index + 1);
344 _param[index].name = CORBA::string_dup(port_name.c_str());
345 _param[index].number = number;
356 SALOME_LifeCycleCORBA LCC(&NS) ;
357 CORBA::Object_var obj = NS.Resolve(
"/ConnectionManager");
358 Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj);
359 Engines::Superv_Component_var me=Engines::Superv_Component::_narrow(objComponent);
360 if( CORBA::is_nil(me) )
362 std::string msg=
"Can't get reference to Engines::Superv_Component: "+
getName();
366 std::list<OutputDataStreamPort *>::iterator iter;
367 Engines::ConnectionManager::connectionId id;
372 std::set<InPort *>::iterator iterout;
373 for(iterout=ports.begin();iterout != ports.end(); iterout++)
379 std::string msg=
"Can't connect : not a SalomeNode";
385 if( CORBA::is_nil(comp))
387 std::string msg=
"Problem in connectService: " + snode->
getName();
388 msg=msg+
" Component is probably not launched. Modify your YACS file";
393 Engines::Superv_Component_var other=Engines::Superv_Component::_narrow(comp);
394 if( CORBA::is_nil(other))
396 std::string msg=
"Can't connect to nil Engines::Superv_Component: " + snode->
getName();
402 id=manager->connect(me,port->
getName().c_str(),other,(*iterout)->getName().c_str());
404 catch(Engines::DSC::PortNotDefined& ex)
406 std::string msg=
"Problem in connectService. Unknown port: "+port->
getName()+
" or "+(*iterout)->getName();
410 catch(Engines::DSC::BadPortType& ex)
412 std::string msg=
"Problem in connectService. Type of provides port is bad. Expected: ";
413 msg=msg + ex.expected.in();
414 msg=msg +
"Received: "+ex.received.in();
418 catch(Engines::DSC::NilPort& ex)
420 std::string msg=
"Problem in connectService. Port is nil: "+port->
getName()+
" or "+(*iterout)->getName();
424 catch(
const SALOME::SALOME_Exception& ex )
426 std::string msg=
"Problem in connectService. ";
427 msg += ex.details.text.in();
432 catch(CORBA::SystemException& ex)
434 DEBTRACE(
"minor code: " << ex.minor() );
435 DEBTRACE(
"completion code: " << ex.completed() );
436 std::string msg=
"Problem in connectService. CORBA System exception ";
437 std::string excname=ex._name();
438 msg=msg+excname +
" " +
getName()+
" " + port->
getName() +
" " + snode->
getName() +
" " + (*iterout)->getName();
444 std::string msg=
"Problem in connectService. Unknown exception";
457 (*iter)->initPortProperties();
459 std::list<InputDataStreamPort *>::iterator iterin;
462 (*iterin)->initPortProperties();
477 SALOME_LifeCycleCORBA LCC(&NS) ;
478 CORBA::Object_var obj = NS.Resolve(
"/ConnectionManager");
479 Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj);
480 std::list<Engines::ConnectionManager::connectionId>::iterator iter;
481 for(iter = ids.begin(); iter != ids.end(); iter++)
483 DEBTRACE(
"Trying to disconnect: " << *iter );
486 manager->disconnect(*iter,Engines::DSC::RemovingConnection);
488 catch(Engines::ConnectionManager::BadId& ex)
490 DEBTRACE(
"Problem in disconnect: " << *iter );
492 catch(Engines::DSC::PortNotDefined& ex)
494 DEBTRACE(
"Problem in disconnect: " << *iter );
496 catch(Engines::DSC::PortNotConnected& ex)
498 DEBTRACE(
"Problem in disconnect: " << *iter );
500 catch(Engines::DSC::BadPortReference& ex)
502 DEBTRACE(
"Problem in disconnect (Engines::DSC::BadPortReference): " << *iter );
504 catch(CORBA::SystemException& ex)
506 DEBTRACE(
"Problem in disconnect (CORBA::SystemException): " << *iter );
510 DEBTRACE(
"Problem in disconnect: " << *iter );
526 YACSTRACE(1,
"+++++++++++++++++ SalomeNode::execute: " <<
getName() <<
" " <<
_method <<
" +++++++++++++++++" );
529 Engines::EngineComponent_var compo=Engines::EngineComponent::_narrow(objComponent);
535 Engines::FieldsDict_var
dico =
new Engines::FieldsDict;
536 dico->length(amap.size());
537 std::map<std::string,std::string>::const_iterator it;
539 for(it = amap.begin(); it != amap.end(); ++it)
541 dico[
i].key=CORBA::string_dup(it->first.c_str());
542 dico[
i].value <<=it->second.c_str();
545 compo->setProperties(dico);
554 CORBA::Request_var req ;
557 req = objComponent->_request(
_method.c_str());
559 catch(CORBA::SystemException& ex)
561 std::string msg=
"component '" +
_ref+
"' has no service '" +
_method+
"'";
565 CORBA::NVList_ptr
arguments = req->arguments() ;
567 DEBTRACE(
"+++++++++++++++++SalomeNode::inputs+++++++++++++++++" );
570 list<InputPort *>::iterator iter2;
578 CORBA::Any* ob=p->
getAny();
580 CORBA::TypeCode_var tc=ob->type();
606 arguments->add_value( p->
getName().c_str() , *ob , CORBA::ARG_IN ) ;
619 std::string filename=p->
getName();
621 string::size_type debut =filename.find_first_of(
':',0);
622 while(debut != std::string::npos)
625 debut=filename.find_first_of(
':',debut);
627 DEBTRACE(
"inport with file: " << filename );
628 Engines::Salome_file_var isf=compo->setInputFileToService(
_method.c_str(),p->
getName().c_str());
629 isf->setDistributedFile(filename.c_str());
630 Engines::Salome_file_ptr osf;
631 CORBA::Any* any=p->
getAny();
637 compo->checkInputFilesToService(
_method.c_str());
639 catch(
const SALOME::SALOME_Exception& ex )
641 std::string text=
"Execution problem in checkInputFilesToService: ";
642 text += (
const char*)ex.details.text;
646 catch(CORBA::SystemException& ex)
648 std::string msg=
"Execution problem: component probably does not support files ??";
654 DEBTRACE(
"+++++++++++++++++SalomeNode::outputs+++++++++++++++++" )
655 list<OutputPort *>::iterator iter;
665 arguments->add_value( p->
getName().c_str() , *ob , CORBA::ARG_OUT );
673 req->set_return_type(CORBA::_tc_void);
675 req->exceptions()->add(SALOME::_tc_SALOME_Exception);
677 DEBTRACE(
"+++++++++++++++++SalomeNode::calculation+++++++++++++++++" <<
_method )
679 CORBA::Exception *exc =req->env()->exception();
682 DEBTRACE(
"An exception was thrown!" )
683 DEBTRACE(
"The raised exception is of Type:" << exc->_name() )
685 CORBA::SystemException* sysexc;
686 sysexc=CORBA::SystemException::_downcast(exc);
690 DEBTRACE(
"minor code: " << sysexc->minor() );
691 DEBTRACE(
"completion code: " << sysexc->completed() );
692 std::string text=
"Execution problem: ";
693 std::string excname=sysexc->_name();
694 if(excname ==
"BAD_OPERATION")
696 text=text+
"component '" +
_ref+
"' has no service '" +
_method+
"'";
698 else if(excname ==
"BAD_PARAM")
700 text=text+
"A parameter (input or output) passed to the call is out of range or otherwise considered illegal.\n";
701 text=text+
"Minor code: "+sysexc->NP_minorString();
703 else if(excname ==
"MARSHAL" && sysexc->minor() == omni::MARSHAL_PassEndOfMessage)
705 text=text+
"probably an error in arguments of service '" +
_method +
"' from component '" +
_ref+
"'";
707 else if(excname ==
"COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalResults)
709 text=text+
"probably an error in output arguments of service '" +
_method +
"' from component '" +
_ref+
"'";
711 else if(excname ==
"COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalArguments)
713 text=text+
"probably an error in input arguments of service '" +
_method +
"' from component '" +
_ref+
"'";
715 else if(excname ==
"COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_WaitingForReply)
717 text=text+
"probably an error in input arguments of service '" +
_method +
"' from component '" +
_ref+
"'";
721 DEBTRACE(sysexc->NP_minorString() );
722 text=text+
"System Exception "+ excname;
729 CORBA::UnknownUserException* userexc;
730 userexc=CORBA::UnknownUserException::_downcast(exc);
733 CORBA::Any anyExcept = userexc->exception();
735 const SALOME::SALOME_Exception* salexc;
736 if(anyExcept >>= salexc)
738 DEBTRACE(
"SALOME_Exception: "<< salexc->details.sourceFile);
739 DEBTRACE(
"SALOME_Exception: "<<salexc->details.lineNumber);
743 std::string msg=
"Execution problem: User Exception occurred";
747 std::string msg=
"Execution problem";
752 DEBTRACE(
"++++++++++++SalomeNode::outputs++++++++++++" )
753 int out_param=in_param;
759 DEBTRACE(
"port number: " << out_param );
762 CORBA::Any *ob=arguments->item(out_param)->value();
789 out_param=out_param+1;
803 std::string filename=p->
getName();
805 string::size_type debut =filename.find_first_of(
':',0);
806 while(debut != std::string::npos)
809 debut=filename.find_first_of(
':',debut);
811 DEBTRACE(
"outport with file: " << filename );
812 Engines::Salome_file_var osf=compo->setOutputFileToService(
_method.c_str(),p->
getName().c_str());
813 osf->setLocalFile(filename.c_str());
819 compo->checkOutputFilesToService(
_method.c_str());
821 catch(
const SALOME::SALOME_Exception& ex )
823 std::string text=(
const char*)ex.details.text;
825 throw Exception(
"Execution problem in checkOutputFilesToService: " + text);
827 catch(CORBA::SystemException& ex)
829 std::string msg=
"Execution problem: component probably does not support files ?";
837 DEBTRACE(
"+++++++++++++++++ End SalomeNode::execute: " <<
getName() <<
" +++++++++++++++++" )
859 std::string msg=
"Component is not loaded";
863 Engines::EngineComponent_var compo=Engines::EngineComponent::_narrow(objComponent);
864 if( !CORBA::is_nil(compo) )
866 Engines::Container_var cont= compo->GetContainerRef();
867 CORBA::String_var logname = cont->logfilename();
870 std::string::size_type pos = msg.find(
":");
871 msg=msg.substr(pos+1);
874 catch(CORBA::COMM_FAILURE& ex)
876 msg =
":Component no longer reachable: Caught system exception COMM_FAILURE";
877 msg +=
" -- unable to contact the object.";
879 catch(CORBA::SystemException& ex)
881 msg =
":Component no longer reachable: Caught a CORBA::SystemException.\n";
884 CORBA::TypeCode_var tc = tmp.type();
885 const char *
p = tc->name();
891 catch(CORBA::Exception& ex)
893 msg =
":Component no longer reachable: Caught CORBA::Exception.\n";
896 CORBA::TypeCode_var tc = tmp.type();
897 const char *
p = tc->name();
903 catch(omniORB::fatalException& fe)
905 msg =
":Component no longer reachable: Caught omniORB::fatalException.\n";
907 log <<
" file: " << fe.file() << endl;
908 log <<
" line: " << fe.line() << endl;
909 log <<
" mesg: " << fe.errmsg() << endl;
914 msg =
":Component no longer reachable: Caught unknown exception.";
921 DEBTRACE(
"SalomeNode::shutdown " << level);