4 Component with remote access (through CORBA)
5 ================================================
8 The interfaces necessary to “see” an internal object like a remote component are based on the definition of a “contract” that
9 specifies the services proposed by a component and the mode of accessing these services (input and output parameters, exceptions returned).
11 These declarations are contained in an **IDL file** that is used as a reference to define the interface code at the component end
12 and at the clients end of the component. Examples are given later. The designer of the component starts from the IDL file and
13 develops a server end interface to set up communication between the network (through CORBA) and the internal object.
14 The designer of each client starts from the IDL file and develops an interface to set up communication between the
15 network (through CORBA) and the component user code.
20 .. image:: images/accesCorbaIDL.png
23 .. centered:: Access from CORBA
27 The first step is for the component developer to define a list of proposed services and the method of calling them, in
28 a file called the IDL file. This file contains data structures declarations and classes (“interface” in the CORBA terminology) in
29 a language defined by the CORBA (IDL) standard.
30 `OMG IDL Syntax and Semantics <http://doc.ece.uci.edu/CORBA/formal/01-12-07.pdf>`_ [IDL]_ is a reference document on the IDL language syntax.
33 This language is similar to a sub-set of the C++ and java languages. CORBA defined its own interface language to achieve
34 transparency relative to client and server implementation languages. A client written with a programming language can connect
35 through CORBA to a server implemented in another language. The only condition is that there are two CORBA ORBs (or systems)
36 interfaced with languages used in the server and the client. There are ORBs capable of managing many
37 languages (C, C++, java, python, etc.). A single ORB (omniORB) was chosen within SALOME, making it possible to use clients
38 and servers written in C++ or in python indifferently.
41 ^^^^^^^^^^^^^^^^^^^^^^^
42 An IDL file is written to access objects (C++) in the alglin class from CORBA (see the ``alglin.hxx`` file in Example 1 and
43 other examples). The corresponding IDL file may for example contain:
50 .. include:: ./exemples/exemple6/alglin.idl
55 #. The IDL file begins with the ``module Distant {`` line. Whenever possible, it is recommended that interface declarations
56 should be contained within a module.
57 #. The ``vecteur`` class of the C++ version does not have to be declared in IDL. The IDL language has a base type (``sequence <double>``)
58 that can manage a simple vector.
61 ^^^^^^^^^^^^^^^^^^^^^^^
62 An IDL file is constructed to access (python) objects in the FreeFem class from CORBA (see ``FreeFem.py``, Example 4 and
63 subsequent examples). The corresponding IDL file may for example contain:
70 .. include:: ./exemples/exemple7/FreeFem.idl
75 ----------------------
76 A server end interface has to be developed from the IDL file. The principle consists of defining an object communicating
77 firstly with the internal object and secondly with the CORBA communication layer. It will be written in a manner that will
78 depend on the implementation language of the internal object (C++ or python).
85 .. image:: images/objCorbaCpp.png
88 .. centered:: CORBA C++ interface generation
90 When the internal object is written in C++ (or it has a C++ higher layer), a C++ implementation class will have to be
91 defined at the server end that
93 - is derived from the ``POA_<module name>::<idl class name>`` class (class generated by the system starting from the IDL file)
94 - is derived from the ``PortableServer::ServantBase`` class (class provided by the system, that provides a reference
95 counter to the implementation class)
96 - defines methods corresponding to the methods and attributes of the IDL class
97 - has a pointer to the internal object as an attribute.
100 The final point above can be replaced by:
104 is derived from the class of the internal object
106 The first version is recommended in preference, because it is easier to implement.
108 **Important**: Most CORBA implementations can generate skeletons of implementation classes. It is strongly recommended
109 that this feature should be used to facilitate writing implementation classes.
111 In the case of omniORB::
113 omniidl -bcxx -Wbexample <nom>.idl
115 (note the –Wbexample option) generates a ``<name>_i.cc`` file that contains the implementation class and an example of
116 the main program at the server end. This file then has to be “cleaned” (keeping the method call prototypes) and completed.
117 Methods for implementation classes receive and return CORBA objects. Therefore, if necessary, each method must:
119 - convert CORBA objects in input into C++ objects (or into simple types)
120 - call the method(s) of the internal object
121 - convert the C++ objects resulting from the methods of the internal object into CORBA objects
125 Example 6 (continued)
126 ^^^^^^^^^^^^^^^^^^^^^^^
127 Consider an example consisting of a server end implementation class that calls objects in the ``alglin`` class from CORBA:
134 .. include:: ./exemples/exemple6/alglin_i.hxx
142 .. include:: ./exemples/exemple6/alglin_i.cxx
146 Note that the ``create_vector`` and ``destroy_vector`` functions are not exported in IDL, because a standard CORBA type
147 is used (``sequence<double>``).
149 Python server interface
150 ^^^^^^^^^^^^^^^^^^^^^^^^
151 This case is similar to the previous case. It can be simpler (it is not always necessary to include input and output
152 parameter conversion phases).
157 .. image:: images/objCorbapy.png
160 .. centered:: Generation of the python CORBA interface
163 This is due to the fact that python is not as strongly typed as C++: a python function can be executed if the input parameters
164 possess all methods and attributes called in the function. This is the case if the methods in the implementation class have
165 the same signatures as methods in the internal object class, as in example 7 below.
167 Example 7 (continued)
168 ^^^^^^^^^^^^^^^^^^^^^^^^^
169 We will consider an example consisting of the python implementation class at the server end used to call objects in
170 the ``FreeFem`` class from CORBA:
177 .. include:: ./exemples/exemple7/FreeFem_i.py
182 The client end interface code can be written in any language (provided that there is a CORBA implementation in this
183 language), independently of the language(s) used at the server end.
185 Essentially, it is necessary:
187 - during compilation, to have the CORBA interface generated at the client end (generally, CORBA generates the two
188 interfaces at the client and server ends simultaneously) and to integrate it into the client code,
189 - during execution, retrieve the CORBA reference of the server end component,
190 - call component methods on this CORBA reference.
194 In the context of SALOME, there is no need to write clients for user components. However, consider a C++ client example
195 and a python client example in the CORBA AlgLin class:
199 .. include:: ./exemples/exemple8/client.cxx
205 .. include:: ./exemples/exemple8/client.py