]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader/Test/echoclt.py
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / yacsloader / Test / echoclt.py
1 #!/usr/bin/env python
2 #  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 import sys
21
22 # Import the CORBA module
23 from omniORB import CORBA
24 import CosNaming
25
26 import eo
27
28 # Initialise the ORB
29 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
30
31 # Obtain a reference to the root naming context
32 obj         = orb.resolve_initial_references("NameService")
33 rootContext = obj._narrow(CosNaming.NamingContext)
34
35 if rootContext is None:
36     print "Failed to narrow the root naming context"
37     sys.exit(1)
38
39 # Resolve the name "test.my_context/Echo.Object"
40 name = [CosNaming.NameComponent("test", "my_context"),
41         CosNaming.NameComponent("Echo", "Object")]
42
43 try:
44     obj = rootContext.resolve(name)
45
46 except CosNaming.NamingContext.NotFound, ex:
47     print "Name not found"
48     sys.exit(1)
49
50 # Narrow the object to an eo::Echo
51 echo = obj._narrow(eo.Echo)
52
53 if echo is None:
54     print "Object reference is not an eo::Echo"
55     sys.exit(1)
56
57 # Invoke the echoString operation
58 message = "Hello from Python"
59 result  = echo.echoString(message)
60
61 print "I said '%s'. The object said '%s'." % (message,result)
62
63 """
64   struct S1
65   {
66     double x;
67     long y;
68     string s;
69     boolean b;
70     DoubleVec vd;
71   };
72   struct S2
73   {
74     S1 s;
75   };
76 """
77
78 s1=eo.S1(x=1,y=2,s="aa",b=True,vd=[1,2])
79 s2=eo.S2(s1)
80
81 r=echo.echoStruct(s2)
82 print r
83
84 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=None)
85 r=echo.echoStruct2(s3)
86 print r
87
88 ob=echo.createObj(3)
89 print ob
90 oc=echo.createC()
91 print oc
92
93 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=ob)
94 r=echo.echoStruct2(s3)
95 print r
96
97 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=oc)
98 r=echo.echoStruct2(s3)
99 print r
100
101 r=echo.echoObjectVec([ob,ob])
102 print r
103
104 r=echo.echoObjectVec([oc,oc])
105 print r
106
107 r=echo.echoObjectVec([ob,oc])
108 print r
109
110 #echo.shutdown()