2 #include "TypeConversions.hxx"
3 #include "Exception.hxx"
4 #include "RuntimeSALOME.hxx"
17 * Fonctions qui retournent un TypeCode CORBA equivalent a un TypeCode Superviseur
20 CORBA::TypeCode_ptr getCorbaTCNull(TypeCode *t)
23 msg << "Conversion not implemented: kind= " << t->kind() << " : " << __FILE__ << ":" << __LINE__;
24 throw YACS::Exception(msg.str());
27 CORBA::TypeCode_ptr getCorbaTCDouble(TypeCode *t)
29 return CORBA::_tc_double;
32 CORBA::TypeCode_ptr getCorbaTCInt(TypeCode *t)
34 return CORBA::_tc_long;
37 CORBA::TypeCode_ptr getCorbaTCString(TypeCode *t)
39 return CORBA::_tc_string;
42 CORBA::TypeCode_ptr getCorbaTCObjref(TypeCode *t)
44 return CORBA::_tc_Object;
47 CORBA::TypeCode_ptr getCorbaTCSequence(TypeCode *t)
49 return getSALOMERuntime()->getOrb()->create_sequence_tc(0,getCorbaTC(t->content_type()));
52 getCorbaTCFn getCorbaTCFns[]=
64 CORBA::TypeCode_ptr getCorbaTC(TypeCode *t)
67 return getCorbaTCFns[tk](t);
71 * Fin des Fonctions qui retournent un TypeCode CORBA equivalent a un TypeCode Superviseur
75 * Fonctions de conversion d'un PyObject * quelconque en CORBA::Any *
76 * du type donné par le TypeCode passé en argument
79 //Le TypeCode passé en argument est celui du port qui recoit la donnée : InputCorbaPort
81 //CORBA::Any *convertCorbaPyObject(TypeCode* t,PyObject* ob);
83 CORBA::Any *convertCorbaPyObjectNull(TypeCode *t,PyObject *ob)
86 msg << "Conversion not implemented: kind= " << t->kind() << " : " << __FILE__ << ":" << __LINE__;
87 throw YACS::Exception(msg.str());
91 //Conversion d'un objet Python "equivalent double" en CORBA::Any double
93 CORBA::Any *convertCorbaPyObjectDouble(TypeCode *t,PyObject *ob)
95 PyObject_Print(ob,stdout,Py_PRINT_RAW);
98 if (PyFloat_Check(ob))
99 d = (CORBA::Double)PyFloat_AS_DOUBLE(ob);
100 else if (PyInt_Check(ob))
101 d = (CORBA::Double)PyInt_AS_LONG(ob);
103 d = (CORBA::Double)PyLong_AsDouble(ob);
104 CORBA::Any *any = new CORBA::Any();
111 CORBA::Any *convertCorbaPyObjectInt(TypeCode *t,PyObject *ob)
113 PyObject_Print(ob,stdout,Py_PRINT_RAW);
117 l = PyInt_AS_LONG(ob);
119 l = PyLong_AsLong(ob);
120 CORBA::Any *any = new CORBA::Any();
127 CORBA::Any *convertCorbaPyObjectString(TypeCode *t,PyObject *ob)
129 PyObject_Print(ob,stdout,Py_PRINT_RAW);
131 char * s=PyString_AsString(ob);
132 CORBA::Any *any = new CORBA::Any();
139 CORBA::Any *convertCorbaPyObjectObjref(TypeCode *t,PyObject *ob)
141 PyObject_Print(ob,stdout,Py_PRINT_RAW);
143 PyObject *pystring=PyObject_CallMethod(getSALOMERuntime()->getPyOrb(),
144 "object_to_string", "O", ob);
145 CORBA::Object_ptr obref =
146 getSALOMERuntime()->getOrb()->string_to_object(PyString_AsString(pystring));
148 CORBA::Any *any = new CORBA::Any();
150 cerr << "typecode: " << any->type()->id() << endl;
156 CORBA::Any *convertCorbaPyObjectSequence(TypeCode *t,PyObject *ob)
158 PyObject_Print(ob,stdout,Py_PRINT_RAW);
160 int length=PySequence_Size(ob);
161 cerr <<"length: " << length << endl;
162 CORBA::TypeCode_var tc_content;
163 DynamicAny::AnySeq as ;
165 for(int i=0;i<length;i++)
167 PyObject *o=PySequence_ITEM(ob,i);
168 cerr <<"item[" << i << "]=";
169 PyObject_Print(o,stdout,Py_PRINT_RAW);
171 cerr << "o refcnt: " << o->ob_refcnt << endl;
172 CORBA::Any *a= convertCorbaPyObject(t->content_type(),o);
173 //ici on fait une copie. Peut-on l'éviter ?
175 tc_content=a->type();
180 CORBA::TypeCode_var tc =
181 getSALOMERuntime()->getOrb()->create_sequence_tc(0,tc_content);
182 DynamicAny::DynAny_var dynany =
183 getSALOMERuntime()->getDynFactory()->create_dyn_any_from_type_code(tc);
184 DynamicAny::DynSequence_var ds =
185 DynamicAny::DynSequence::_narrow(dynany);
189 ds->set_elements(as);
191 catch(DynamicAny::DynAny::TypeMismatch& ex)
193 throw YACS::Exception("type mismatch");
195 catch(DynamicAny::DynAny::InvalidValue& ex)
197 throw YACS::Exception("invalid value");
199 CORBA::Any *any=ds->to_any();
203 convertCorbaPyObjectFn convertCorbaPyObjectFns[] =
205 convertCorbaPyObjectNull,
206 convertCorbaPyObjectDouble,
207 convertCorbaPyObjectInt,
208 convertCorbaPyObjectString,
209 convertCorbaPyObjectNull,
210 convertCorbaPyObjectObjref,
211 convertCorbaPyObjectSequence,
214 CORBA::Any *convertCorbaPyObject(TypeCode *t,PyObject *ob)
217 return convertCorbaPyObjectFns[tk](t,ob);
221 * Fin des fonctions de conversion PyObject * -> CORBA::Any *
225 * Fonctions de test d'adaptation pour conversion PyObject * (t1) -> CORBA::Any * (t2)
227 //t1 est le type du port output Python
228 //t2 est le type du port input Corba
230 int isAdaptableCorbaPyObjectNull(TypeCode *t1,TypeCode* t2)
235 int isAdaptableCorbaPyObjectDouble(TypeCode *t1,TypeCode* t2)
237 if (t1->kind() == Double) return 1;
238 if (t1->kind() == Int) return 1;
242 int isAdaptableCorbaPyObjectInt(TypeCode *t1,TypeCode* t2)
244 if (t1->kind() == Int) return 1;
248 int isAdaptableCorbaPyObjectString(TypeCode *t1,TypeCode* t2)
250 if (t1->kind() == String)return 1;
254 int isAdaptableCorbaPyObjectObjref(TypeCode *t1,TypeCode* t2)
256 if(t1->kind() == Objref)
258 //Il faut que le type du inport soit plus général que celui du outport
259 if ( t1->is_a(t2->id()) ) return 1;
264 int isAdaptableCorbaPyObjectSequence(TypeCode *t1,TypeCode* t2)
266 if(t1->kind() == Sequence)
268 if(isAdaptableCorbaPyObject(t1->content_type(),t2->content_type()))
276 isAdaptableCorbaPyObjectFn isAdaptableCorbaPyObjectFns[]=
278 isAdaptableCorbaPyObjectNull,
279 isAdaptableCorbaPyObjectDouble,
280 isAdaptableCorbaPyObjectInt,
281 isAdaptableCorbaPyObjectString,
282 isAdaptableCorbaPyObjectNull,
283 isAdaptableCorbaPyObjectObjref,
284 isAdaptableCorbaPyObjectSequence,
287 int isAdaptableCorbaPyObject(TypeCode *t1,TypeCode *t2)
290 return isAdaptableCorbaPyObjectFns[tk](t1,t2);
294 * Fin des fonctions d'adaptation pour conversion PyObject * -> CORBA::Any *
298 * Fonctions de test d'adaptation pour conversion CORBA::Any * (t1) -> Xml::char * (t2)
300 //t1 est le type du port output Corba
301 //t2 est le type du port input Xml
303 int isAdaptableXmlCorbaNull(TypeCode *t1,TypeCode* t2)
308 int isAdaptableXmlCorbaDouble(TypeCode *t1,TypeCode* t2)
310 if(t1->kind() == Double)return 1;
311 if(t1->kind() == Int)return 1;
315 int isAdaptableXmlCorbaInt(TypeCode *t1,TypeCode* t2)
317 if(t1->kind() == Int)return 1;
321 int isAdaptableXmlCorbaString(TypeCode *t1,TypeCode* t2)
323 if(t1->kind() == String)return 1;
327 int isAdaptableXmlCorbaObjref(TypeCode *t1,TypeCode* t2)
329 if(t1->kind() == Objref)
331 //Il faut que le type du inport soit plus général que celui du outport
332 if( t1->is_a(t2->id()) )return 1;
337 int isAdaptableXmlCorbaSequence(TypeCode *t1,TypeCode* t2)
339 if(t1->kind() == Sequence)
341 if(isAdaptableXmlCorba(t1->content_type(),t2->content_type()))
349 isAdaptableXmlCorbaFn isAdaptableXmlCorbaFns[]=
351 isAdaptableXmlCorbaNull,
352 isAdaptableXmlCorbaDouble,
353 isAdaptableXmlCorbaInt,
354 isAdaptableXmlCorbaString,
355 isAdaptableXmlCorbaNull,
356 isAdaptableXmlCorbaObjref,
357 isAdaptableXmlCorbaSequence,
360 int isAdaptableXmlCorba(TypeCode *t1,TypeCode *t2)
363 return isAdaptableXmlCorbaFns[tk](t1,t2);
367 * Fin des fonctions d'adaptation pour conversion CORBA::Any * (t1) -> Xml::char * (t2)
371 * Fonctions de test d'adaptation pour conversion CORBA::Any * (t1) -> CORBA::Any * (t2)
373 //t1 est le type du port output Corba
374 //t2 est le type du port input Corba
376 int isAdaptableCorbaCorbaNull(TypeCode *t1,TypeCode* t2)
381 int isAdaptableCorbaCorbaDouble(TypeCode *t1,TypeCode* t2)
383 if(t1->kind() == Double)return 1;
384 if(t1->kind() == Int)return 1;
388 int isAdaptableCorbaCorbaInt(TypeCode *t1,TypeCode* t2)
390 if(t1->kind() == Int)return 1;
394 int isAdaptableCorbaCorbaString(TypeCode *t1,TypeCode* t2)
396 if(t1->kind() == String)return 1;
400 int isAdaptableCorbaCorbaObjref(TypeCode *t1,TypeCode* t2)
402 if(t1->kind() == Objref){
403 //Il faut que le type du inport soit plus général que celui du outport
404 if( t1->is_a(t2->id()) )return 1;
409 int isAdaptableCorbaCorbaSequence(TypeCode *t1,TypeCode* t2)
411 if(t1->kind() == Sequence)
413 if(isAdaptableCorbaCorba(t1->content_type(),t2->content_type()))
421 isAdaptableCorbaCorbaFn isAdaptableCorbaCorbaFns[]=
423 isAdaptableCorbaCorbaNull,
424 isAdaptableCorbaCorbaDouble,
425 isAdaptableCorbaCorbaInt,
426 isAdaptableCorbaCorbaString,
427 isAdaptableCorbaCorbaNull,
428 isAdaptableCorbaCorbaObjref,
429 isAdaptableCorbaCorbaSequence,
432 int isAdaptableCorbaCorba(TypeCode *t1,TypeCode *t2)
435 return isAdaptableCorbaCorbaFns[tk](t1,t2);
439 * Fin des fonctions d'adaptation pour conversion CORBA::Any * -> CORBA::Any *
443 * Fonctions de test d'adaptation pour conversion PyObject * (t1) -> PyObject * (t2)
445 //t1 est le type du port output Python
446 //t2 est le type du port input Python
448 int isAdaptablePyObjectPyObjectNull(TypeCode *t1,TypeCode* t2)
453 int isAdaptablePyObjectPyObjectDouble(TypeCode *t1,TypeCode* t2)
455 if(t1->kind() == Double)return 1;
456 if(t1->kind() == Int)return 1;
460 int isAdaptablePyObjectPyObjectInt(TypeCode *t1,TypeCode* t2)
462 if(t1->kind() == Int)return 1;
466 int isAdaptablePyObjectPyObjectString(TypeCode *t1,TypeCode* t2)
468 if(t1->kind() == String)return 1;
472 int isAdaptablePyObjectPyObjectObjref(TypeCode *t1,TypeCode* t2)
474 if(t1->kind() == Objref)
476 //Il faut que le type du inport soit plus général que celui du outport
477 if( t1->is_a(t2->id()) )return 1;
482 int isAdaptablePyObjectPyObjectSequence(TypeCode *t1,TypeCode* t2)
484 if(t1->kind() == Sequence)
486 if(isAdaptablePyObjectPyObject(t1->content_type(),t2->content_type()))
494 isAdaptablePyObjectPyObjectFn isAdaptablePyObjectPyObjectFns[]=
496 isAdaptablePyObjectPyObjectNull,
497 isAdaptablePyObjectPyObjectDouble,
498 isAdaptablePyObjectPyObjectInt,
499 isAdaptablePyObjectPyObjectString,
500 isAdaptablePyObjectPyObjectNull,
501 isAdaptablePyObjectPyObjectObjref,
502 isAdaptablePyObjectPyObjectSequence,
505 int isAdaptablePyObjectPyObject(TypeCode *t1,TypeCode *t2)
508 return isAdaptablePyObjectPyObjectFns[tk](t1,t2);
512 * Fin des fonctions d'adaptation pour conversion PyObject * -> PyObject *
516 * Fonctions de test d'adaptation pour conversion CORBA::Any * (t1) -> PyObject * (t2)
518 //t1 est le type du port output Corba
519 //t2 est le type du port input Python
521 int isAdaptablePyObjectCorbaNull(TypeCode *t1,TypeCode* t2)
526 //on peut convertir un double ou un int en CORBA double
527 int isAdaptablePyObjectCorbaDouble(TypeCode *t1,TypeCode* t2)
529 if(t1->kind() == Double)return 1;
530 if(t1->kind() == Int)return 1;
534 int isAdaptablePyObjectCorbaInt(TypeCode *t1,TypeCode* t2)
536 if(t1->kind() == Int)return 1;
540 int isAdaptablePyObjectCorbaString(TypeCode *t1,TypeCode* t2)
542 if(t1->kind() == String)return 1;
546 int isAdaptablePyObjectCorbaObjref(TypeCode *t1,TypeCode* t2)
548 if(t1->kind() == Objref){
549 //Il faut que le type du inport soit plus général que celui du outport
550 if( t1->is_a(t2->id()) )return 1;
555 int isAdaptablePyObjectCorbaSequence(TypeCode *t1,TypeCode* t2)
557 if(t1->kind() == Sequence)
559 if(isAdaptablePyObjectCorba(t1->content_type(),t2->content_type()))
567 isAdaptablePyObjectCorbaFn isAdaptablePyObjectCorbaFns[]={
568 isAdaptablePyObjectCorbaNull,
569 isAdaptablePyObjectCorbaDouble,
570 isAdaptablePyObjectCorbaInt,
571 isAdaptablePyObjectCorbaString,
572 isAdaptablePyObjectCorbaNull,
573 isAdaptablePyObjectCorbaObjref,
574 isAdaptablePyObjectCorbaSequence,
577 int isAdaptablePyObjectCorba(TypeCode *t1,TypeCode *t2)
580 return isAdaptablePyObjectCorbaFns[tk](t1,t2);
584 * Fin des fonctions d'adaptation pour conversion CORBA::Any * -> PyObject *
588 * Fonctions de conversion CORBA::Any * -> PyObject *
590 //Le TypeCode t est celui vers lequel on convertit (celui de l'InputPort)
591 //On a le type Corba de l'objet sortant par ob->type()
593 PyObject *convertPyObjectCorbaNull(TypeCode *t,CORBA::Any *ob)
596 msg << "Conversion not implemented: kind= " << t->kind() ;
597 msg << " : " << __FILE__ << ":" << __LINE__;
598 throw YACS::Exception(msg.str());
602 //Convertit un CORBA::Any "equivalent double" en Python double
604 PyObject *convertPyObjectCorbaDouble(TypeCode *t,CORBA::Any *ob)
606 CORBA::TypeCode_var tc = ob->type();
607 if (tc->equivalent(CORBA::_tc_double))
611 PyObject *pyob=PyFloat_FromDouble(d);
612 cerr << "pyob refcnt: " << pyob->ob_refcnt << endl;
615 if (tc->equivalent(CORBA::_tc_long))
619 //Faudrait-il convertir en PyFloat ??
620 PyObject *pyob=PyInt_FromLong(d);
621 cerr << "pyob refcnt: " << pyob->ob_refcnt << endl;
625 msg << "Internal error " ;
626 msg << " : " << __FILE__ << ":" << __LINE__;
627 throw YACS::Exception(msg.str());
630 PyObject *convertPyObjectCorbaInt(TypeCode *t,CORBA::Any *ob)
634 return PyInt_FromLong(l);
637 PyObject *convertPyObjectCorbaString(TypeCode *t,CORBA::Any *ob)
641 PyObject *pyob=PyString_FromString(s);
642 cerr << "pyob refcnt: " << pyob->ob_refcnt << endl;
646 PyObject *convertPyObjectCorbaObjref(TypeCode *t,CORBA::Any *ob)
648 CORBA::Object_ptr ObjRef ;
649 *ob >>= (CORBA::Any::to_object ) ObjRef ;
650 //hold_lock is true: caller is supposed to hold the GIL.
651 //omniorb will not take the GIL
652 PyObject *pyob = getSALOMERuntime()->getApi()->cxxObjRefToPyObjRef(ObjRef, 1);
653 cerr << "pyob refcnt: " << pyob->ob_refcnt << endl;
657 PyObject *convertPyObjectCorbaSequence(TypeCode *t,CORBA::Any *ob)
659 cerr << "convertPyObjectCorbaSequence" << endl;
660 DynamicAny::DynAny_var dynany= getSALOMERuntime()->getDynFactory()->create_dyn_any(*ob);
661 DynamicAny::DynSequence_var ds=DynamicAny::DynSequence::_narrow(dynany);
662 DynamicAny::AnySeq_var as=ds->get_elements();
663 int len=as->length();
664 PyObject *pyob = PyList_New(len);
665 for(int i=0;i<len;i++)
667 PyObject *e=convertPyObjectCorba(t->content_type(),&as[i]);
668 cerr << "e refcnt: " << e->ob_refcnt << endl;
669 PyList_SetItem(pyob,i,e);
670 cerr << "e refcnt: " << e->ob_refcnt << endl;
672 cerr << "pyob refcnt: " << pyob->ob_refcnt << endl;
673 cerr << "Sequence= ";
674 PyObject_Print(pyob,stdout,Py_PRINT_RAW);
680 convertPyObjectCorbaFn convertPyObjectCorbaFns[]=
682 convertPyObjectCorbaNull,
683 convertPyObjectCorbaDouble,
684 convertPyObjectCorbaInt,
685 convertPyObjectCorbaString,
686 convertPyObjectCorbaNull,
687 convertPyObjectCorbaObjref,
688 convertPyObjectCorbaSequence,
691 PyObject *convertPyObjectCorba(TypeCode *t,CORBA::Any *ob)
694 return convertPyObjectCorbaFns[tk](t,ob);
698 * Fin des fonctions de conversion CORBA::Any * -> PyObject *
702 * Fonctions de conversion CORBA::Any * -> Xml char *
704 //Le TypeCode t est celui vers lequel on convertit (celui de l'InputPort)
705 //On a le type Corba de l'objet sortant par ob->type()
707 char *convertXmlCorbaNull(TypeCode *t,CORBA::Any *ob)
710 msg << "Conversion not implemented: kind= " << t->kind() ;
711 msg << " : " << __FILE__ << ":" << __LINE__;
712 throw YACS::Exception(msg.str());
716 //Convertit un CORBA::Any "equivalent double" en Python double
718 char *convertXmlCorbaDouble(TypeCode *t,CORBA::Any *ob)
720 CORBA::TypeCode_var tc = ob->type();
721 if (tc->equivalent(CORBA::_tc_double))
726 msg << "<value><double>" << d << "</double></value>\n";
727 return (char *)msg.str().c_str();
729 if (tc->equivalent(CORBA::_tc_long))
734 msg << "<value><double>" << d << "</double></value>\n";
735 return (char *)msg.str().c_str();
738 msg << "Internal error " ;
739 msg << " : " << __FILE__ << ":" << __LINE__;
740 throw YACS::Exception(msg.str());
743 char *convertXmlCorbaInt(TypeCode *t,CORBA::Any *ob)
748 msg << "<value><int>" << l << "</int></value>\n";
749 return (char *)msg.str().c_str();
752 char *convertXmlCorbaString(TypeCode *t,CORBA::Any *ob)
757 msg << "<value><string>" << s << "</string></value>\n";
758 return (char *)msg.str().c_str();
761 char *convertXmlCorbaObjref(TypeCode *t,CORBA::Any *ob)
763 CORBA::Object_ptr ObjRef ;
764 *ob >>= (CORBA::Any::to_object ) ObjRef ;
766 msg << "<value><objref>" << getSALOMERuntime()->getOrb()->object_to_string(ObjRef) << "</objref></value>\n";
767 return (char *)msg.str().c_str();
770 char *convertXmlCorbaSequence(TypeCode *t,CORBA::Any *ob)
772 cerr << "convertXmlCorbaSequence" << endl;
773 DynamicAny::DynAny_var dynany=getSALOMERuntime()->getDynFactory()->create_dyn_any(*ob);
774 DynamicAny::DynSequence_var ds=DynamicAny::DynSequence::_narrow(dynany);
775 DynamicAny::AnySeq_var as=ds->get_elements();
776 int len=as->length();
778 xmlob << "<value><array><data>\n";
779 for(int i=0;i<len;i++)
781 xmlob << convertXmlCorba(t->content_type(),&as[i]);
783 xmlob << "</data></array></value>\n";
784 cerr << "Sequence= ";
787 return (char *)xmlob.str().c_str();
790 convertXmlCorbaFn convertXmlCorbaFns[]=
793 convertXmlCorbaDouble,
795 convertXmlCorbaString,
797 convertXmlCorbaObjref,
798 convertXmlCorbaSequence,
801 char *convertXmlCorba(TypeCode *t,CORBA::Any *ob)
804 return convertXmlCorbaFns[tk](t,ob);
808 * Fin des fonctions de conversion CORBA::Any * -> Xml char *
812 * Fonctions de conversion CORBA::Any * -> CORBA::Any *
814 //Le TypeCode t est celui vers lequel on convertit (celui de l'InputPort)
815 //On a le type Corba de l'objet sortant par ob->type()
817 CORBA::Any *convertCorbaCorbaNull(TypeCode *t,CORBA::Any *ob)
820 msg << "Conversion not implemented: kind= " << t->kind() ;
821 msg << " : " << __FILE__ << ":" << __LINE__;
822 throw YACS::Exception(msg.str());
826 //Convertit un CORBA::Any "equivalent double" en Python double
828 CORBA::Any *convertCorbaCorbaDouble(TypeCode *t,CORBA::Any *ob)
830 CORBA::TypeCode_var tc = ob->type();
831 if (tc->equivalent(CORBA::_tc_double))
835 if (tc->equivalent(CORBA::_tc_long))
839 CORBA::Any *any = new CORBA::Any();
840 *any <<= (CORBA::Double)d;
844 msg << "Internal error " ;
845 msg << " : " << __FILE__ << ":" << __LINE__;
846 throw YACS::Exception(msg.str());
849 CORBA::Any *convertCorbaCorbaInt(TypeCode *t,CORBA::Any *ob)
854 CORBA::Any *convertCorbaCorbaString(TypeCode *t,CORBA::Any *ob)
859 CORBA::Any *convertCorbaCorbaObjref(TypeCode *t,CORBA::Any *ob)
864 CORBA::Any *convertCorbaCorbaSequence(TypeCode *t,CORBA::Any *ob)
866 cerr << "convertCorbaCorbaSequence" << endl;
867 DynamicAny::DynAny_var dynany= getSALOMERuntime()->getDynFactory()->create_dyn_any(*ob);
868 DynamicAny::DynSequence_var ds=DynamicAny::DynSequence::_narrow(dynany);
869 DynamicAny::AnySeq_var as=ds->get_elements();
870 int length=as->length();
871 CORBA::TypeCode_var tc_content;
872 DynamicAny::AnySeq asout ;
873 asout.length(length);
874 for(int i=0;i<length;i++)
876 CORBA::Any *a=convertCorbaCorba(t->content_type(),&as[i]);
877 //ici on fait une copie. Peut-on l'éviter ?
879 tc_content=a->type();
882 CORBA::TypeCode_var tc= getSALOMERuntime()->getOrb()->create_sequence_tc(0,tc_content);
883 DynamicAny::DynAny_var dynanyout=getSALOMERuntime()->getDynFactory()->create_dyn_any_from_type_code(tc);
884 DynamicAny::DynSequence_var dsout=DynamicAny::DynSequence::_narrow(dynanyout);
887 dsout->set_elements(asout);
889 catch(DynamicAny::DynAny::TypeMismatch& ex)
891 throw YACS::Exception("type mismatch");
893 catch(DynamicAny::DynAny::InvalidValue& ex)
895 throw YACS::Exception("invalid value");
897 CORBA::Any *any=dsout->to_any();
902 convertCorbaCorbaFn convertCorbaCorbaFns[]=
904 convertCorbaCorbaNull,
905 convertCorbaCorbaDouble,
906 convertCorbaCorbaInt,
907 convertCorbaCorbaString,
908 convertCorbaCorbaNull,
909 convertCorbaCorbaObjref,
910 convertCorbaCorbaSequence,
913 CORBA::Any *convertCorbaCorba(TypeCode *t,CORBA::Any *ob)
916 return convertCorbaCorbaFns[tk](t,ob);
920 * Fin des fonctions de conversion CORBA::Any * -> PyObject *
924 * Fonctions de conversion Xml char * -> CORBA::Any *
927 //Le TypeCode t est celui vers lequel on convertit (celui de l'InputPort)
929 CORBA::Any *convertCorbaXmlNull(TypeCode *t, xmlDocPtr doc, xmlNodePtr cur)
932 msg << "Conversion not implemented: kind= " << t->kind() ;
933 msg << " : " << __FILE__ << ":" << __LINE__;
934 throw YACS::Exception(msg.str());
937 CORBA::Any *convertCorbaXmlDouble(TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
939 cur = cur->xmlChildrenNode;
942 if ((!xmlStrcmp(cur->name, (const xmlChar *)"double")))
944 //on attend un double, on a bien un double
946 s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
947 CORBA::Any *any = new CORBA::Any();
948 cerr << "convertCorbaXmlDouble " << (const char *)s << endl;
949 *any <<= (CORBA::Double)atof((const char *)s);
953 else if ((!xmlStrcmp(cur->name, (const xmlChar *)"int")))
955 //on attend un double, on a un int
957 s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
958 CORBA::Any *any = new CORBA::Any();
959 cerr << "convertCorbaXmlDouble " << (const char *)s << endl;
960 *any <<= (CORBA::Double)atof((const char *)s);
967 msg << "Problem in conversion: kind= " << t->kind() ;
968 msg << " : " << __FILE__ << ":" << __LINE__;
969 throw YACS::Exception(msg.str());
972 CORBA::Any *convertCorbaXmlSequence(TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
974 CORBA::TypeCode_var tc_content;
975 DynamicAny::AnySeq as ;
977 cur = cur->xmlChildrenNode;
980 if ((!xmlStrcmp(cur->name, (const xmlChar *)"array")))
982 cerr << "parse sequence " << endl;
983 xmlNodePtr cur1=cur->xmlChildrenNode;
986 if ((!xmlStrcmp(cur1->name, (const xmlChar *)"data")))
988 cerr << "parse data " << endl;
989 xmlNodePtr cur2=cur1->xmlChildrenNode;
992 //on recupere toutes les values
993 if ((!xmlStrcmp(cur2->name, (const xmlChar *)"value")))
995 cerr << "parse value " << endl;
996 CORBA::Any *a=convertCorbaXml(t->content_type(),doc,cur2);
999 tc_content=a->type();
1002 } // end while value
1010 } // end while array
1012 CORBA::TypeCode_var tc=getSALOMERuntime()->getOrb()->create_sequence_tc(0,tc_content);
1013 DynamicAny::DynAny_var dynanyout=getSALOMERuntime()->getDynFactory()->create_dyn_any_from_type_code(tc);
1014 DynamicAny::DynSequence_var dsout=DynamicAny::DynSequence::_narrow(dynanyout);
1017 dsout->set_elements(as);
1019 catch(DynamicAny::DynAny::TypeMismatch& ex)
1021 throw YACS::Exception("type mismatch");
1023 catch(DynamicAny::DynAny::InvalidValue& ex)
1025 throw YACS::Exception("invalid value");
1027 CORBA::Any *any=dsout->to_any();
1031 convertCorbaXmlFn convertCorbaXmlFns[]=
1033 convertCorbaXmlNull,
1034 convertCorbaXmlDouble,
1035 convertCorbaXmlNull,
1036 convertCorbaXmlNull,
1037 convertCorbaXmlNull,
1038 convertCorbaXmlNull,
1039 convertCorbaXmlSequence,
1042 CORBA::Any *convertCorbaXml(TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1045 return convertCorbaXmlFns[tk](t,doc,cur);
1049 * Fin des fonctions de conversion Xml char * -> CORBA::Any *