Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / runtime / Test / echo_clt.cxx
1 #include <echo.hh>
2 #include <iostream>
3
4 int main(int argc, char** argv)
5 {
6   try {
7     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
8     CORBA::Object_var obj = orb->string_to_object("corbaname:rir:#test.my_context/Echo.Object");
9     eo::Echo_var echoref = eo::Echo::_narrow(obj);
10     if( CORBA::is_nil(echoref) ) {
11         std::cerr << "Can't narrow reference to type Echo (or it was nil)." << std::endl;
12       return 1;
13     }
14
15     CORBA::String_var src = (const char*) "Hello!";
16     CORBA::String_var dest = echoref->echoString(src);
17     std::cerr << "I said, \"" << (char*)src << "\"." << std::endl
18        << "The Echo object replied, \"" << (char*)dest <<"\"." << std::endl;
19
20     CORBA::Object_var ob = orb->string_to_object("corbaname:rir:#test.my_context/D.Object");
21     eo::D_var Dref = eo::D::_narrow(ob);
22     if( CORBA::is_nil(Dref) ) {
23         std::cerr << "Can't narrow reference to type D (or it was nil)." << std::endl;
24         return 1;
25     }
26     Dref->echoLong2(10);
27
28     eo::D_var dout;
29     echoref->echoD(Dref,dout);
30     std::cerr << dout->echoLong2(10) << std::endl;
31
32     eo::D_var ddout;
33     echoref->echoD(dout,ddout);
34     std::cerr << dout->echoLong2(10) << std::endl;
35
36     CORBA::Object_var oob = orb->string_to_object("corbaname:rir:#test.my_context/Obj.Object");
37     eo::Obj_var Objref = eo::Obj::_narrow(oob);
38     Objref->echoLong(10);
39     eo::Obj_var Objout;
40     echoref->echoObj2(Objref,Objout);
41     std::cerr << Objout->echoLong(10) << std::endl;
42
43     CORBA::Object_var cob = orb->string_to_object("corbaname:rir:#test.my_context/C.Object");
44     eo::C_var Cref = eo::C::_narrow(cob);
45     eo::C_var Cout;
46     echoref->echoC(Cref,Cout); 
47
48     echoref->echoObj2(Cref,Objout); 
49     //echoref->echoC(Cref,Objout); compilation impossible
50     //echoref->echoObj2(Cref,Cout);  compilation impossible
51     //echoref->echoC(Objref,Cout); compilation impossible
52
53     orb->destroy();
54   }
55   catch(CORBA::COMM_FAILURE& ex) {
56       std::cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
57          << "object." << std::endl;
58   }
59   catch(CORBA::SystemException&) {
60       std::cerr << "Caught a CORBA::SystemException." << std::endl;
61   }
62   catch(CORBA::Exception&) {
63       std::cerr << "Caught CORBA::Exception." << std::endl;
64   }
65   catch(omniORB::fatalException& fe) {
66       std::cerr << "Caught omniORB::fatalException:" << std::endl;
67       std::cerr << "  file: " << fe.file() << std::endl;
68       std::cerr << "  line: " << fe.line() << std::endl;
69       std::cerr << "  mesg: " << fe.errmsg() << std::endl;
70   }
71   catch(...) {
72       std::cerr << "Caught unknown exception." << std::endl;
73   }
74   return 0;
75 }