Version: 9.15.0
CORBANode.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 //#define REFCNT
21 //
22 #ifdef REFCNT
23 #define private public
24 #define protected public
25 #include <omniORB4/CORBA.h>
26 #include <omniORB4/internal/typecode.h>
27 #endif
28 
29 #include "RuntimeSALOME.hxx"
30 #include "CORBANode.hxx"
31 #include "CORBAComponent.hxx"
32 #include "SalomeComponent.hxx"
33 #include "CORBAPorts.hxx"
34 #include "OutputDataStreamPort.hxx"
35 #include "CalStreamPort.hxx"
36 #include "InPort.hxx"
37 #include "TypeCode.hxx"
38 #include "AutoLocker.hxx"
39 
40 #ifdef SALOME_KERNEL
42 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "SALOME_Exception.hh"
44 #endif
45 
46 #include <omniORB4/CORBA.h>
47 #include <omniORB4/minorCode.h>
48 #include <iostream>
49 #include <set>
50 #include <list>
51 
52 //#define _DEVDEBUG_
53 #include "YacsTrace.hxx"
54 
55 using namespace YACS::ENGINE;
56 using namespace std;
57 
58 const char CORBANode::IMPL_NAME[]="CORBA";
59 const char CORBANode::KIND[]="CORBA";
60 
61 std::string CORBANode::getKind() const
62 {
63  return KIND;
64 }
65 
67 CORBANode::CORBANode(const std::string& name): ServiceNode(name)
68 {
70 }
71 
72 CORBANode::CORBANode(const CORBANode& other,ComposedNode *father):ServiceNode(other,father)
73 {
75 }
76 
79 {
80  YACSTRACE(1, "+++++++++++++ CorbaNode::execute: " << getName() << " +++++++++++++++" );
81  {
82  //DII request building :
83  // a service gets all its in parameters first
84  // then all its out parameters
85  // no inout parameters
86  // the return value (if any) is the first out parameter
87  // not yet user exception (only CORBA exception)
88 
89  CORBA::Object_var objComponent=((CORBAComponent*)_component)->getCompoPtr();
90  CORBA::Request_var req = objComponent->_request(_method.c_str());
91  CORBA::NVList_ptr arguments = req->arguments() ;
92 
93  DEBTRACE( "+++++++++++++++++CorbaNode::inputs+++++++++++++++++" )
94  int in_param=0;
95  //in parameters
96  list<InputPort *>::iterator iter2;
97  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
98  {
99  InputCorbaPort *p=(InputCorbaPort *)*iter2;
100  DEBTRACE( "port name: " << p->getName() )
101  DEBTRACE( "port kind: " << p->edGetType()->kind() )
102  CORBA::Any* ob=p->getAny();
103 #ifdef _DEVDEBUG_
104  CORBA::TypeCode_var typcod= ob->type();
105  switch(p->edGetType()->kind())
106  {
107  case Double:
108  CORBA::Double d;
109  *ob >>= d;
110  DEBTRACE( d )
111  break;
112  case Int:
113  CORBA::Long l;
114  *ob >>= l;
115  DEBTRACE( l )
116  break;
117  case String:
118  const char *s;
119  *ob >>= s;
120  DEBTRACE( s )
121  break;
122  case Bool:
123  CORBA::Boolean b;
124  if(*ob >>= CORBA::Any::to_boolean(b))
125  DEBTRACE( b )
126  else
127  DEBTRACE( "not a boolean" )
128  break;
129  case Objref:
130  DEBTRACE( typcod->id() )
131  break;
132  default:
133  break;
134  }
135 #endif
136  //add_value makes a copy of any (*ob). This copy will be deleted with the request
137  arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_IN ) ;
138  in_param=in_param+1;
139  }
140 
141  //output parameters
142  DEBTRACE( "+++++++++++++++++CorbaNode::outputs+++++++++++++++++" )
143  list<OutputPort *>::iterator iter;
144  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
145  {
147  DEBTRACE( "port name: " << p->getName() )
148  DEBTRACE( "port kind: " << p->edGetType()->kind() )
149  CORBA::Any* ob=p->getAnyOut();
150 #ifdef REFCNT
151  DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
152 #endif
153  //add_value makes a copy of any. Copy will be deleted with request
154  arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_OUT );
155 #ifdef REFCNT
156  DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
157 #endif
158  delete ob;
159  }
160 
161  //return value
162  req->set_return_type(CORBA::_tc_void);
163 
164  DEBTRACE( "+++++++++++++++++CorbaNode::calculation+++++++++++++++++" << _method )
165  req->invoke();
166  CORBA::Exception *exc =req->env()->exception();
167  if( exc )
168  {
169  DEBTRACE( "An exception was thrown!" )
170  DEBTRACE( "The raised exception is of Type:" << exc->_name() )
171 
172  std::cerr << "The raised exception is of Type:" << exc->_name() << std::endl;
173  /*
174  if(strcmp(exc->_name(),"MARSHAL") == 0)
175  {
176  const char* ms = ((CORBA::MARSHAL*)exc)->NP_minorString();
177  if (ms)
178  std::cerr << "(CORBA::MARSHAL: minor = " << ms << ")" << std::endl;
179  else
180  std::cerr << "(CORBA::MARSHAL: minor = " << ((CORBA::MARSHAL*)exc)->minor() << ")" << std::endl;
181  }
182  */
183  _errorDetails="Execution problem: the raised exception is of Type:";
184  _errorDetails += exc->_name();
185  throw Exception("Execution problem");
186  }
187 
188  DEBTRACE( "++++++++++++CorbaNode::outputs++++++++++++" )
189  int out_param=in_param;
190  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
191  {
193  DEBTRACE( "port name: " << p->getName() )
194  DEBTRACE( "port kind: " << p->edGetType()->kind() )
195  DEBTRACE( "port number: " << out_param )
196  CORBA::Any *ob=arguments->item(out_param)->value();
197 #ifdef REFCNT
198  DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
199 #endif
200 #ifdef _DEVDEBUG_
201  CORBA::TypeCode_var tc=ob->type();
202  switch(p->edGetType()->kind())
203  {
204  case Double:
205  CORBA::Double d;
206  *ob >>= d;
207  DEBTRACE( d )
208  break;
209  case Int:
210  CORBA::Long l;
211  *ob >>= l;
212  DEBTRACE( l )
213  break;
214  case String:
215  const char *s;
216  *ob >>= s;
217  DEBTRACE( s )
218  break;
219  case Objref:
220  DEBTRACE( tc->id() )
221  break;
222  default:
223  break;
224  }
225 #endif
226  //OutputPort must copy the input Any(ob).
227  //This Any will be deleted with the request.
228  //Copy is made by the method put.
229  p->put(ob);
230  out_param=out_param+1;
231 #ifdef REFCNT
232  DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
233 #endif
234  }
235  DEBTRACE( "++++++++++++++++++++++++++++++++++++++++++" )
236  }
237  //Request has been deleted (_var )
238  //All anys given to the request are deleted : don't forget to copy them
239  //if you want to keep them
240 #ifdef REFCNT
241  list<OutputPort *>::const_iterator iter;
242  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
243  {
245  CORBA::Any *ob=p->getAny();
246  DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
247  }
248 #endif
249  DEBTRACE( "+++++++++++++++++ End CorbaNode::execute: " << getName() << " +++++++++++++++++" )
250 }
251 
253 Node *CORBANode::simpleClone(ComposedNode *father, bool editionOnly) const
254 {
255  return new CORBANode(*this,father);
256 }
257 
259 
263 ServiceNode* CORBANode::createNode(const std::string& name)
264 {
265 
266  CORBANode* node= new CORBANode(name);
267  node->setComponent(_component);
268  return node;
269 }
270 
271 // SalomeNode Class
272 
273 const char SalomeNode::KIND[]="Salome";
274 
275 std::string SalomeNode::getKind() const
276 {
277  return KIND;
278 }
279 
281 SalomeNode::SalomeNode(const std::string& name):ServiceNode(name)
282 {
284 }
285 
286 SalomeNode::SalomeNode(const SalomeNode& other,ComposedNode *father):ServiceNode(other,father)
287 {
289 }
290 
292 {
293 }
294 
295 #ifdef DSC_PORTS
298 {
299  DEBTRACE( "SalomeNode::initService: "<<getName())
300  if(_setOfInputDataStreamPort.size() == 0 && _setOfOutputDataStreamPort.size() == 0)return;
301 
302  CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
303  Engines::Superv_Component_var compo=Engines::Superv_Component::_narrow(objComponent);
304  if( CORBA::is_nil(compo) )
305  {
306  std::string msg="Can't get reference to DSC object (or it was nil).";
307  _errorDetails=msg;
308  throw Exception(msg);
309  }
310  try
311  {
312  if (!_multi_port_node)
313  {
314  CORBA::Boolean ret=compo->init_service(_method.c_str());
315  if(!ret)
316  {
317  _errorDetails="Problem with component '"+_ref+"' in init_service of service '"+ _method + "'";
318  throw Exception(_errorDetails);
319  }
320  //Should check that component port types are the same as those declared in the xml file
321  }
322  else
323  {
324  CORBA::Boolean ret=compo->init_service_with_multiple(_method.c_str(), _param);
325  if(!ret)
326  {
327  _errorDetails="Problem with component '"+_ref+"' in init_service_with_multiple of service '"+ _method + "'";
328  throw Exception(_errorDetails);
329  }
330  }
331  }
332  catch(...)
333  {
334  _errorDetails="Problem with component '"+_ref+"' in init_service of service '"+ _method + "'";
335  throw;
336  }
337 }
338 
339 void
340 SalomeNode::addDatastreamPortToInitMultiService(const std::string & port_name, int number)
341 {
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;
346 }
347 
350 {
351  DEBTRACE( "SalomeNode::connectService: "<<getName());
352  if(_setOfOutputDataStreamPort.size() == 0)return;
353 
354  CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
356  Engines::Superv_Component_var me=Engines::Superv_Component::_narrow(objComponent);
357  if( CORBA::is_nil(me) )
358  {
359  std::string msg="Can't get reference to Engines::Superv_Component: "+getName();
360  _errorDetails=msg;
361  throw Exception(msg);
362  }
363  std::list<OutputDataStreamPort *>::iterator iter;
364  Engines::ConnectionManager::connectionId id;
365  for(iter = _setOfOutputDataStreamPort.begin(); iter != _setOfOutputDataStreamPort.end(); iter++)
366  {
368  std::set<InPort *> ports=port->edSetInPort();
369  std::set<InPort *>::iterator iterout;
370  for(iterout=ports.begin();iterout != ports.end(); iterout++)
371  {
372  //It's only possible to connect 2 SalomeNode : try to get a SalomeNode
373  SalomeNode* snode= dynamic_cast<SalomeNode*>((*iterout)->getNode());
374  if(snode == 0) //don't connect, it's not a SalomeNode
375  {
376  std::string msg="Can't connect : not a SalomeNode";
377  _errorDetails=msg;
378  throw Exception(msg);
379  }
380 
381  CORBA::Object_var comp=((SalomeComponent*)snode->getComponent())->getCompoPtr();
382  if( CORBA::is_nil(comp))
383  {
384  std::string msg="Problem in connectService: " + snode->getName();
385  msg=msg+" Component is probably not launched. Modify your YACS file";
386  _errorDetails=msg;
387  throw Exception(msg);
388  }
389 
390  Engines::Superv_Component_var other=Engines::Superv_Component::_narrow(comp);
391  if( CORBA::is_nil(other))
392  {
393  std::string msg="Can't connect to nil Engines::Superv_Component: " + snode->getName();
394  _errorDetails=msg;
395  throw Exception(msg);
396  }
397  try
398  {
399  id=manager.connect(me,port->getName().c_str(),other,(*iterout)->getName().c_str());
400  }
401  catch(Engines::DSC::PortNotDefined& ex)
402  {
403  std::string msg="Problem in connectService. Unknown port: "+port->getName()+" or "+(*iterout)->getName();
404  _errorDetails=msg;
405  throw Exception(msg);
406  }
407  catch(Engines::DSC::BadPortType& ex)
408  {
409  std::string msg="Problem in connectService. Type of provides port is bad. Expected: ";
410  msg=msg + ex.expected.in();
411  msg=msg + "Received: "+ex.received.in();
412  _errorDetails=msg;
413  throw Exception(msg);
414  }
415  catch(Engines::DSC::NilPort& ex)
416  {
417  std::string msg="Problem in connectService. Port is nil: "+port->getName()+" or "+(*iterout)->getName();
418  _errorDetails=msg;
419  throw Exception(msg);
420  }
421  catch( const SALOME::SALOME_Exception& ex )
422  {
423  std::string msg="Problem in connectService. ";
424  msg += ex.details.text.in();
425  msg=msg+getName()+" " + port->getName() + " " + snode->getName() + " " + (*iterout)->getName();
426  _errorDetails=msg;
427  throw Exception(msg);
428  }
429  catch(CORBA::SystemException& ex)
430  {
431  DEBTRACE( "minor code: " << ex.minor() );
432  DEBTRACE( "completion code: " << ex.completed() );
433  std::string msg="Problem in connectService. CORBA System exception ";
434  std::string excname=ex._name();
435  msg=msg+excname + " " +getName()+" " + port->getName() + " " + snode->getName() + " " + (*iterout)->getName();
436  _errorDetails=msg;
437  throw Exception(msg);
438  }
439  catch(...)
440  {
441  std::string msg="Problem in connectService. Unknown exception";
442  msg=msg+getName()+" " + port->getName() + " " + snode->getName() + " " + (*iterout)->getName();
443  _errorDetails=msg;
444  throw Exception(msg);
445  }
446  DEBTRACE("Connected: " <<id<<" "<<getName()<<" "<<port->getName()<<" "<<snode->getName()<<" "<<(*iterout)->getName());
447  ids.push_back(id);
448  }
449  }
450 
451  //Init component port properties
452  for(iter = _setOfOutputDataStreamPort.begin(); iter != _setOfOutputDataStreamPort.end(); iter++)
453  {
454  (*iter)->initPortProperties();
455  }
456  std::list<InputDataStreamPort *>::iterator iterin;
457  for(iterin = _setOfInputDataStreamPort.begin(); iterin != _setOfInputDataStreamPort.end(); iterin++)
458  {
459  (*iterin)->initPortProperties();
460  }
461 }
462 
465 {
466  DEBTRACE( "SalomeNode::disconnectService: "<<getName());
467  // in some rare cases, disconnectService can be called from 2 different threads
469 
470  if(ids.size() == 0)
471  return;
472 
474  std::list<Engines::ConnectionManager::connectionId>::iterator iter;
475  for(iter = ids.begin(); iter != ids.end(); iter++)
476  {
477  DEBTRACE("Trying to disconnect: " << *iter );
478  try
479  {
480  manager.disconnect(*iter,Engines::DSC::RemovingConnection);
481  }
482  catch(Engines::ConnectionManager::BadId& ex)
483  {
484  DEBTRACE( "Problem in disconnect: " << *iter );
485  }
486  catch(Engines::DSC::PortNotDefined& ex)
487  {
488  DEBTRACE( "Problem in disconnect: " << *iter );
489  }
490  catch(Engines::DSC::PortNotConnected& ex)
491  {
492  DEBTRACE( "Problem in disconnect: " << *iter );
493  }
494  catch(Engines::DSC::BadPortReference& ex)
495  {
496  DEBTRACE( "Problem in disconnect (Engines::DSC::BadPortReference): " << *iter );
497  }
498  catch(CORBA::SystemException& ex)
499  {
500  DEBTRACE( "Problem in disconnect (CORBA::SystemException): " << *iter );
501  }
502  catch(...)
503  {
504  DEBTRACE( "Problem in disconnect: " << *iter );
505  }
506  }
507  ids.clear();
508 }
509 
511 {
513 }
514 
515 #endif
516 
519 {
520  YACSTRACE(1,"+++++++++++++++++ SalomeNode::execute: " << getName() << " " << _method << " +++++++++++++++++" );
521  {
522  CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
523  Engines::EngineComponent_var compo=Engines::EngineComponent::_narrow(objComponent);
524 
525  // Set component properties
526  std::map<std::string,std::string> amap=getProperties();
527  if(amap.size() > 0)
528  {
529  Engines::FieldsDict_var dico = new Engines::FieldsDict;
530  dico->length(amap.size());
531  std::map<std::string,std::string>::const_iterator it;
532  int i=0;
533  for(it = amap.begin(); it != amap.end(); ++it)
534  {
535  dico[i].key=CORBA::string_dup(it->first.c_str());
536  dico[i].value <<=it->second.c_str();
537  i++;
538  }
539  compo->setProperties(dico);
540  }
541 
542  //DII request building :
543  // a service gets all its in parameters first
544  // then all its out parameters
545  // no inout parameters
546  // the return value (if any) is the first out parameter
547  //
548  CORBA::Request_var req ;
549  try
550  {
551  req = objComponent->_request(_method.c_str());
552  }
553  catch(CORBA::SystemException& ex)
554  {
555  std::string msg="component '" +_ref+ "' has no service '" + _method+ "'";
556  _errorDetails=msg;
557  throw Exception(msg);
558  }
559  CORBA::NVList_ptr arguments = req->arguments() ;
560 
561  DEBTRACE( "+++++++++++++++++SalomeNode::inputs+++++++++++++++++" );
562  int in_param=0;
563  //in parameters
564  list<InputPort *>::iterator iter2;
565  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
566  {
567  InputCorbaPort *p=(InputCorbaPort *)*iter2;
568  if(p->edGetType()->isA(Runtime::_tc_file))
569  continue;
570  DEBTRACE( "port name: " << p->getName() );
571  DEBTRACE( "port kind: " << p->edGetType()->kind() );
572  CORBA::Any* ob=p->getAny();
573 #ifdef _DEVDEBUG_
574  CORBA::TypeCode_var tc=ob->type();
575  switch(p->edGetType()->kind())
576  {
577  case Double:
578  CORBA::Double d;
579  *ob >>= d;
580  DEBTRACE( d )
581  break;
582  case Int:
583  CORBA::Long l;
584  *ob >>= l;
585  DEBTRACE( l )
586  break;
587  case String:
588  const char *s;
589  *ob >>= s;
590  DEBTRACE( s )
591  break;
592  case Objref:
593  DEBTRACE( tc->id() )
594  break;
595  default:
596  break;
597  }
598 #endif
599  //add_value makes a copy of any. Copy will be deleted with request
600  arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_IN ) ;
601  in_param=in_param+1;
602  }
603  //in files
604  int nfiles=0;
605  DEBTRACE("checkInputFilesToService: " << _method);
606  try
607  {
608  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
609  {
610  InputCorbaPort *p=(InputCorbaPort *)*iter2;
611  if(!p->edGetType()->isA(Runtime::_tc_file))
612  continue;
613  std::string filename=p->getName();
614  // replace ':' by '.'. Needed because port name can not contain '.'
615  string::size_type debut =filename.find_first_of(':',0);
616  while(debut != std::string::npos)
617  {
618  filename[debut]='.';
619  debut=filename.find_first_of(':',debut);
620  }
621  DEBTRACE( "inport with file: " << filename );
622  Engines::Salome_file_var isf=compo->setInputFileToService(_method.c_str(),p->getName().c_str());
623  isf->setDistributedFile(filename.c_str());
624  Engines::Salome_file_ptr osf;
625  CORBA::Any* any=p->getAny();
626  *any >>= osf;
627  isf->connect(osf);
628  nfiles++;
629  }
630  if(nfiles)
631  compo->checkInputFilesToService(_method.c_str());
632  }
633  catch( const SALOME::SALOME_Exception& ex )
634  {
635  std::string text="Execution problem in checkInputFilesToService: ";
636  text += (const char*)ex.details.text;
637  _errorDetails=text;
638  throw Exception(text);
639  }
640  catch(CORBA::SystemException& ex)
641  {
642  std::string msg="Execution problem: component probably does not support files ??";
643  _errorDetails=msg;
644  throw Exception(msg);
645  }
646 
647  //out parameters
648  DEBTRACE( "+++++++++++++++++SalomeNode::outputs+++++++++++++++++" )
649  list<OutputPort *>::iterator iter;
650  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
651  {
653  DEBTRACE( "port name: " << p->getName() )
654  DEBTRACE( "port kind: " << p->edGetType()->kind() )
655  if(p->edGetType()->isA(Runtime::_tc_file))
656  continue;
657  CORBA::Any* ob=p->getAnyOut();
658  //add_value makes a copy of any. Copy will be deleted with request
659  arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_OUT );
660  delete ob;
661  }
662 
663  //return value
664  //if return type is set to void (not mandatory, it's set by default)
665  //the return value will not be marshalled as a return value but
666  //as the first out argument (don't forget to add it as the first output argument)
667  req->set_return_type(CORBA::_tc_void);
668  //user exceptions
669  req->exceptions()->add(SALOME::_tc_SALOME_Exception);
670 
671  DEBTRACE( "+++++++++++++++++SalomeNode::calculation+++++++++++++++++" << _method )
672  req->invoke();
673  CORBA::Exception *exc =req->env()->exception();
674  if( exc )
675  {
676  DEBTRACE( "An exception was thrown!" )
677  DEBTRACE( "The raised exception is of Type:" << exc->_name() )
678 
679  CORBA::SystemException* sysexc;
680  sysexc=CORBA::SystemException::_downcast(exc);
681  if(sysexc != NULL)
682  {
683  // It's a SystemException
684  DEBTRACE( "minor code: " << sysexc->minor() );
685  DEBTRACE( "completion code: " << sysexc->completed() );
686  std::string text="Execution problem: ";
687  std::string excname=sysexc->_name();
688  if(excname == "BAD_OPERATION")
689  {
690  text=text+"component '" +_ref+ "' has no service '" + _method+ "'";
691  }
692  else if(excname == "BAD_PARAM")
693  {
694  text=text+"A parameter (input or output) passed to the call is out of range or otherwise considered illegal.\n";
695  text=text+"Minor code: "+sysexc->NP_minorString();
696  }
697  else if(excname == "MARSHAL" && sysexc->minor() == omni::MARSHAL_PassEndOfMessage)
698  {
699  text=text+"probably an error in arguments of service '" + _method + "' from component '" +_ref+ "'";
700  }
701  else if(excname == "COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalResults)
702  {
703  text=text+"probably an error in output arguments of service '" + _method + "' from component '" +_ref+ "'";
704  }
705  else if(excname == "COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalArguments)
706  {
707  text=text+"probably an error in input arguments of service '" + _method + "' from component '" +_ref+ "'";
708  }
709  else if(excname == "COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_WaitingForReply)
710  {
711  text=text+"probably an error in input arguments of service '" + _method + "' from component '" +_ref+ "'";
712  }
713  else
714  {
715  DEBTRACE(sysexc->NP_minorString() );
716  text=text+"System Exception "+ excname;
717  }
718  _errorDetails=text;
719  throw Exception(text);
720  }
721 
722  // Not a System Exception
723  CORBA::UnknownUserException* userexc;
724  userexc=CORBA::UnknownUserException::_downcast(exc);
725  if(userexc != NULL)
726  {
727  CORBA::Any anyExcept = userexc->exception();
728 
729  const SALOME::SALOME_Exception* salexc;
730  if(anyExcept >>= salexc)
731  {
732  DEBTRACE("SALOME_Exception: "<< salexc->details.sourceFile);
733  DEBTRACE("SALOME_Exception: "<<salexc->details.lineNumber);
734  _errorDetails=salexc->details.text;
735  throw Exception("Execution problem: Salome Exception occurred" + getErrorDetails() );
736  }
737  std::string msg="Execution problem: User Exception occurred";
738  _errorDetails=msg;
739  throw Exception(msg);
740  }
741  std::string msg="Execution problem";
742  _errorDetails=msg;
743  throw Exception(msg);
744  }
745 
746  DEBTRACE( "++++++++++++SalomeNode::outputs++++++++++++" )
747  int out_param=in_param;
748  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
749  {
751  DEBTRACE( "port name: " << p->getName() );
752  DEBTRACE( "port kind: " << p->edGetType()->kind() );
753  DEBTRACE( "port number: " << out_param );
754  if(p->edGetType()->isA(Runtime::_tc_file))
755  continue;
756  CORBA::Any *ob=arguments->item(out_param)->value();
757 #ifdef _DEVDEBUG_
758  switch(p->edGetType()->kind())
759  {
760  case Double:
761  CORBA::Double d;
762  *ob >>= d;
763  DEBTRACE( d )
764  break;
765  case Int:
766  CORBA::Long l;
767  *ob >>= l;
768  DEBTRACE( l )
769  break;
770  case String:
771  const char *s;
772  *ob >>= s;
773  DEBTRACE( s )
774  break;
775  default:
776  break;
777  }
778 #endif
779  //OutputPort must copy the input Any(ob).
780  //This Any will be deleted with the request.
781  //Copy is made by the method put.
782  p->put(ob);
783  out_param=out_param+1;
784  }
785 
786  //Out files
787  nfiles=0;
788  DEBTRACE("checkOutputFilesToService: " << _method);
789  try
790  {
791  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
792  {
794  if(!p->edGetType()->isA(Runtime::_tc_file))
795  continue;
796  // The output port has a file object : special treatment
797  std::string filename=p->getName();
798  // replace ':' by '.'. Needed because port name can not contain '.'
799  string::size_type debut =filename.find_first_of(':',0);
800  while(debut != std::string::npos)
801  {
802  filename[debut]='.';
803  debut=filename.find_first_of(':',debut);
804  }
805  DEBTRACE( "outport with file: " << filename );
806  Engines::Salome_file_var osf=compo->setOutputFileToService(_method.c_str(),p->getName().c_str());
807  osf->setLocalFile(filename.c_str());
808  CORBA::Any any;
809  any <<= osf;
810  p->put(&any);
811  }
812  if(nfiles)
813  compo->checkOutputFilesToService(_method.c_str());
814  }
815  catch( const SALOME::SALOME_Exception& ex )
816  {
817  std::string text=(const char*)ex.details.text;
818  _errorDetails=text;
819  throw Exception("Execution problem in checkOutputFilesToService: " + text);
820  }
821  catch(CORBA::SystemException& ex)
822  {
823  std::string msg="Execution problem: component probably does not support files ?";
824  _errorDetails=msg;
825  throw Exception(msg);
826  }
827  }
828  //Request has been deleted (_var )
829  //All anys given to the request are deleted : don't forget to copy them
830  //if you want to keep them
831  DEBTRACE( "+++++++++++++++++ End SalomeNode::execute: " << getName() << " +++++++++++++++++" )
832 }
833 
834 Node *SalomeNode::simpleClone(ComposedNode *father, bool editionOnly) const
835 {
836  return new SalomeNode(*this,father);
837 }
838 
840 
844 ServiceNode* SalomeNode::createNode(const std::string& name)
845 {
846  SalomeNode* node=new SalomeNode(name);
847  node->setComponent(_component);
848  return node;
849 }
850 
852 {
853  std::string msg="Component is not loaded";
854  try
855  {
856  CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
857  Engines::EngineComponent_var compo=Engines::EngineComponent::_narrow(objComponent);
858  if( !CORBA::is_nil(compo) )
859  {
860  Engines::Container_var cont= compo->GetContainerRef();
861  CORBA::String_var logname = cont->logfilename();
862  DEBTRACE(logname);
863  msg=logname;
864  std::string::size_type pos = msg.find(":");
865  msg=msg.substr(pos+1);
866  }
867  }
868  catch(CORBA::COMM_FAILURE& ex)
869  {
870  msg = ":Component no longer reachable: Caught system exception COMM_FAILURE";
871  msg += " -- unable to contact the object.";
872  }
873  catch(CORBA::SystemException& ex)
874  {
875  msg = ":Component no longer reachable: Caught a CORBA::SystemException.\n";
876  CORBA::Any tmp;
877  tmp <<= ex;
878  CORBA::TypeCode_var tc = tmp.type();
879  const char *p = tc->name();
880  if ( *p != '\0' )
881  msg += p;
882  else
883  msg += tc->id();
884  }
885  catch(CORBA::Exception& ex)
886  {
887  msg = ":Component no longer reachable: Caught CORBA::Exception.\n";
888  CORBA::Any tmp;
889  tmp <<= ex;
890  CORBA::TypeCode_var tc = tmp.type();
891  const char *p = tc->name();
892  if ( *p != '\0' )
893  msg += p;
894  else
895  msg += tc->id();
896  }
897  catch(omniORB::fatalException& fe)
898  {
899  msg = ":Component no longer reachable: Caught omniORB::fatalException.\n";
900  stringstream log;
901  log << " file: " << fe.file() << endl;
902  log << " line: " << fe.line() << endl;
903  log << " mesg: " << fe.errmsg() << endl;
904  msg += log.str();
905  }
906  catch(...)
907  {
908  msg = ":Component no longer reachable: Caught unknown exception.";
909  }
910  return msg;
911 }
912 
913 void SalomeNode::shutdown(int level)
914 {
915  DEBTRACE("SalomeNode::shutdown " << level);
916  if(_component)
917  _component->shutdown(level);
918 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
#define YACSTRACE(level, msg)
YACSTRACE macro for dynamic trace: print only if YACS_TRACELEVEL environment variable is set and leve...
Definition: YacsTrace.hxx:41
This class implements the interface Engines::ConnectionManager. It is used to make connections betwee...
ConnectionManager::connectionId connect(Engines::DSC_ptr uses_component, const char *uses_port_name, Engines::DSC_ptr provides_component, const char *provides_port_name)
void disconnect(ConnectionManager::connectionId id, Engines::DSC::Message message)
Class for CORBA component instance.
Class for CORBA Service Node.
Definition: CORBANode.hxx:45
static const char IMPL_NAME[]
Definition: CORBANode.hxx:57
virtual ServiceNode * createNode(const std::string &name)
Create a CORBANode with the same component object and no input or output port.
Definition: CORBANode.cxx:263
static const char KIND[]
Definition: CORBANode.hxx:54
Node * simpleClone(ComposedNode *father, bool editionOnly) const
Clone the node : must also clone the component instance ?
Definition: CORBANode.cxx:253
virtual void execute()
Execute the service on the component associated to the node.
Definition: CORBANode.cxx:78
virtual std::string getKind() const
Return the service node kind.
Definition: CORBANode.cxx:61
CORBANode(const CORBANode &other, ComposedNode *father)
Definition: CORBANode.cxx:72
virtual void shutdown(int level)
Base class for all composed nodes.
std::string getName() const
std::string getName() const
Definition: DataPort.hxx:55
std::list< InputPort * > _setOfInputPort
virtual std::string getErrorDetails()
Give a description of error when node status is ERROR.
std::list< OutputDataStreamPort * > _setOfOutputDataStreamPort
virtual void addDatastreamPortToInitMultiService(const std::string &port_name, int number)
std::list< InputDataStreamPort * > _setOfInputDataStreamPort
std::list< OutputPort * > _setOfOutputPort
Class for CORBA Input Ports.
Definition: CORBAPorts.hxx:45
Base class for all nodes.
Definition: Node.hxx:70
virtual void cleanNodes()
Clean the node in case of not clean exit.
Definition: Node.cxx:846
std::map< std::string, std::string > getProperties()
Definition: Node.cxx:509
std::string _implementation
Definition: Node.hxx:97
const std::string & getName() const
Definition: Node.hxx:125
std::string _errorDetails
Definition: Node.hxx:93
std::set< InPort * > edSetInPort() const
ConnectionManager & getConnectionManager()
static YACS::ENGINE::TypeCode * _tc_file
Definition: Runtime.hxx:140
Class for Salome component instance.
Class for Salome component Service Node.
Definition: CORBANode.hxx:68
virtual ServiceNode * createNode(const std::string &name)
Create a SalomeNode with the same component object and no input or output port.
Definition: CORBANode.cxx:844
virtual std::string getContainerLog()
returns a string that contains the name of the container log file if it exists
Definition: CORBANode.cxx:851
SalomeNode(const SalomeNode &other, ComposedNode *father)
Definition: CORBANode.cxx:286
virtual void execute()
Execute the service on the component associated to the node.
Definition: CORBANode.cxx:518
static const char KIND[]
Definition: CORBANode.hxx:78
YACS::BASES::Mutex _mutex
Definition: CORBANode.hxx:93
Node * simpleClone(ComposedNode *father, bool editionOnly) const
Definition: CORBANode.cxx:834
virtual void shutdown(int level)
Stop all pending activities of the node.
Definition: CORBANode.cxx:913
virtual std::string getKind() const
Return the service node kind.
Definition: CORBANode.cxx:275
Class for calculation node associated with a component service.
Definition: ServiceNode.hxx:35
ComponentInstance * _component
Definition: ServiceNode.hxx:60
virtual void setComponent(ComponentInstance *compo)
Associate an existing component instance to this service node AND check the consistency regarding the...
virtual ComponentInstance * getComponent()
Return the associated component instance.
Proc * p
Definition: driver.cxx:216
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()
string log
Definition: logview.py:23