Salome HOME
updated copyright message
[modules/yacs.git] / src / yacsloader / Test / echoclt.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2006-2023  CEA, EDF
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, or (at your option) any later version.
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
21 import sys
22
23 # Import the CORBA module
24 from omniORB import CORBA
25 import CosNaming
26
27 import eo
28
29 # Initialise the ORB
30 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
31
32 # Obtain a reference to the root naming context
33 obj         = orb.resolve_initial_references("NameService")
34 rootContext = obj._narrow(CosNaming.NamingContext)
35
36 if rootContext is None:
37     print("Failed to narrow the root naming context")
38     sys.exit(1)
39
40 # Resolve the name "test.my_context/Echo.Object"
41 name = [CosNaming.NameComponent("test", "my_context"),
42         CosNaming.NameComponent("Echo", "Object")]
43
44 try:
45     obj = rootContext.resolve(name)
46
47 except CosNaming.NamingContext.NotFound as ex:
48     print("Name not found")
49     sys.exit(1)
50
51 # Narrow the object to an eo::Echo
52 echo = obj._narrow(eo.Echo)
53
54 if echo is None:
55     print("Object reference is not an eo::Echo")
56     sys.exit(1)
57
58 # Invoke the echoString operation
59 message = "Hello from Python"
60 result  = echo.echoString(message)
61
62 print("I said '%s'. The object said '%s'." % (message,result))
63
64 """
65   struct S1
66   {
67     double x;
68     long y;
69     string s;
70     boolean b;
71     DoubleVec vd;
72   };
73   struct S2
74   {
75     S1 s;
76   };
77 """
78
79 s1=eo.S1(x=1,y=2,s="aa",b=True,vd=[1,2])
80 s2=eo.S2(s1)
81
82 r=echo.echoStruct(s2)
83 print(r)
84
85 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=None)
86 r=echo.echoStruct2(s3)
87 print(r)
88
89 ob=echo.createObj(3)
90 print(ob)
91 oc=echo.createC()
92 print(oc)
93
94 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=ob)
95 r=echo.echoStruct2(s3)
96 print(r)
97
98 s3=eo.S3(x=1,y=2,s="aa",b=True,ob=oc)
99 r=echo.echoStruct2(s3)
100 print(r)
101
102 r=echo.echoObjectVec([ob,ob])
103 print(r)
104
105 r=echo.echoObjectVec([oc,oc])
106 print(r)
107
108 r=echo.echoObjectVec([ob,oc])
109 print(r)
110
111 #echo.shutdown()