Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / yacsloader / Test / echoclt.py
1 #!/usr/bin/env python
2
3 import sys
4
5 # Import the CORBA module
6 from omniORB import CORBA
7 import CosNaming
8
9 import eo
10
11 # Initialise the ORB
12 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
13
14 # Obtain a reference to the root naming context
15 obj         = orb.resolve_initial_references("NameService")
16 rootContext = obj._narrow(CosNaming.NamingContext)
17
18 if rootContext is None:
19     print "Failed to narrow the root naming context"
20     sys.exit(1)
21
22 # Resolve the name "test.my_context/Echo.Object"
23 name = [CosNaming.NameComponent("test", "my_context"),
24         CosNaming.NameComponent("Echo", "Object")]
25
26 try:
27     obj = rootContext.resolve(name)
28
29 except CosNaming.NamingContext.NotFound, ex:
30     print "Name not found"
31     sys.exit(1)
32
33 # Narrow the object to an eo::Echo
34 echo = obj._narrow(eo.Echo)
35
36 if echo is None:
37     print "Object reference is not an eo::Echo"
38     sys.exit(1)
39
40 # Invoke the echoString operation
41 message = "Hello from Python"
42 result  = echo.echoString(message)
43
44 print "I said '%s'. The object said '%s'." % (message,result)
45
46 """
47   struct S1
48   {
49     double x;
50     long y;
51     string s;
52     boolean b;
53     DoubleVec vd;
54   };
55   struct S2
56   {
57     S1 s;
58   };
59 """
60
61 s1=eo.S1(x=1,y=2,s="aa",b=True,vd=[1,2])
62 s2=eo.S2(s1)
63
64 r=echo.echoStruct(s2)
65 print r
66
67 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=None)
68 r=echo.echoStruct2(s3)
69 print r
70
71 ob=echo.createObj(3)
72 print ob
73 oc=echo.createC()
74 print oc
75
76 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=ob)
77 r=echo.echoStruct2(s3)
78 print r
79
80 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=oc)
81 r=echo.echoStruct2(s3)
82 print r
83
84 r=echo.echoObjectVec([ob,ob])
85 print r
86
87 r=echo.echoObjectVec([oc,oc])
88 print r
89
90 r=echo.echoObjectVec([ob,oc])
91 print r
92
93 #echo.shutdown()