One important thing to remember about IDL is that it is not an implementation language. That is, applications can't be written in IDL. The sole purpose of IDL is to define interfaces; providing implementations for these interfaces is performed using some other language.
This page contains an abridged reference manual for mapping of IDL definitions
to Python language. It will be useful for Python programmers who are not
familiar with IDL language. All examples are taken from SALOME source
files. The complete version of Python Language Mapping Specification can
be found here.
Because of these constraints, scoped names are translated into Python using the following rules:
• An IDL module mapped into a Python module. Modules containing modules are mapped to packages (i.e., directories with an __init__ module containing all definitions excluding the nested modules). An implementation can chose to map toplevel definitions (including the module CORBA) to modules in an implementationdefined package, to allow concurrent installations of different CORBA runtime libraries. In that case, the implementation must provide additional modules so that toplevel modules can be used without importing them from a package.
• For all other scopes, a Python class is introduced that contains all the definitions inside this scope.
• Other global definitions (except modules) appear in a module whose name is implementation dependent. Implementations are encouraged to use the name of the IDL file when defining the name of that module.
For instance,
module SALOMEDS { interface StudyManager { void Close(in Study aStudy); }; };
# module SALOMEDS.py class StudyManager: def _Close(self,aStudy): pass #interfaces are discussed later
• For the wide string X and the integer n, X[n] returns the nth character, which is a wide string of length 1.
• len(X) returns the number of characters of wide string X.
• CORBA.wstr(c) returns a wide character with the code point c in an implementation-defined encoding.
• X+Y returns the concatenation of wide strings X and Y.
• CORBA.word(CORBA.wstr(c)) == c
The sequence template is mapped to sequence objects (e.g., tuples or lists). Applications should not assume that values of a sequence type are mutable. Sequences and arrays of octets and characters are mapped to the string type for efficiency reasons.
For example, given the IDL definitions
module SALOMEDS { typedef sequence <string> StringSeq; interface AttributeTableOfInteger : GenericAttribute { void SetRowTitles(in StringSeq theTitles) raises(IncorrectArgumentLength); }; };
print My_AttributeTableOfInteger.SetRowTitles(["X","F"])
Another example with arrays. The following IDL definition
module SALOMEDS { typedef sequence<GenericAttribute> ListOfAttributes; interface SObject { ListOfAttributes GetAllAttributes(); }; };
import SALOMEDS attributes=[] attributes = My_SObject.GetAllAttributes() length = len(attributes) print "Attributes number = ", length print attributes
The nil object is represented by None.
If an operation expects parameters of the IDL Object type, any Python object representing an object reference might be passed as actual argument.
If an operation expects a parameter of an abstract interface, either an object implementing that interface, or a value supporting this interface may be passed as actual argument. The semantics of abstract values then define whether the argument is passed by value or by reference.
Operations of an interface map to methods available on the object references. Parameters with a parameter attribute of in or inout are passed from left to right tothe method, skipping out parameters. The return value of a method depends on the number of out parameters and the return type. If the operation returns a value, this value forms the first result value. All inout or out parameters form consecutive result values. The method result depends then on the number of result values:
• If there is no result value, the method returns None.
• If there is exactly one result value, it is returned as a single value.
• If there is more than one result value, all of them are packed into a tuple, and this tuple is returned.
Assuming the IDL definition
module SALOMEDS{ interface StudyBuilder{ boolean FindAttribute ( in SObject anObject, out GenericAttribute anAttribute, in string aTypeOfAttribute ); }; };
from SALOMEDS import StudyBuilder; my_StudyBuilder=... res,A=my_StudyBuilder.FindAttribute(Sobj, "AttributeSequenceOfReal")
If an interface defines an attribute name, for example, the attribute is mapped into an operation _get_name. If the attribute is not readonly, there is an additional operation _set_name.
The IDL definition
module SALOMEDS{ interface Study{ attribute string Name; }; };
from SALOMEDS import Study My_Study=... Name=My_Study._get_name(); Name=My_Study._set_name();
Since there is no efficient and reliable way of automatically creating the most specific type, explicit narrowing is necessary. To narrow an object reference A to an interface class AttributeSequenceOfReal, the client can use the following operation
A = A._narrow(SALOMEDS.AttributeSequenceOfReal)
module SALOMEDS{ interface StudyBuilder{ exception LockProtection {}; void CommitCommand() raises(LockProtection); }; };
from SALOMEDS import StudyBuilder; my_StudyBuilder=... try: my_StudyBuilder.CommitCommand(); except StudyBuilder.LockProtection,value: print "Error! Study is locked for modifications"
module VISU { interface PrsObject{ enum PrsObjType{ TCURVE, TTABLE, TMESH, TCONTAINER, TSCALARMAP, TISOSURFACE, TDEFORMEDSHAPE, TCUTPLANES, TVECTORS }; }; };
from VISU import PrsObject VISU.PrsObjType.TCURVE,VISU.PrsObjType.TTABLE,VISU.PrsObjType.TMESH,VISU.PrsObjType.TCONTAINER, VISU.PrsObjType.TSCALARMAP,VISU.PrsObjType.TISOSURFACE,VISU.PrsObjType.TDEFORMEDSHAPE,VISU.PrsObjType.TCUTPLANES, VISU.PrsObjType.TVECTORS
struct SDate { short Second; short Minute; short Hour; short Day; short Month; short Year; };
Date=SDate(30, 12, 15, 26, 1, 79) print Date.Second,Date.Minute,Date.Hour,Date.Day,Date.Month,Date.Year