Table of Contents Previous Next
Logo
Server-Side Slice-to-Python Mapping : 24.5 Parameter Passing
Copyright © 2003-2009 ZeroC, Inc.

24.5 Parameter Passing

For each in parameter of a Slice operation, the Python mapping generates a corresponding parameter for the corresponding method. In addition, every operation has an additional, trailing parameter of type Ice.Current. For example, the name operation of the Node interface has no parameters, but the name method in a Python servant has a current parameter. We explain the purpose of this parameter in Section 32.6 and will ignore it for now.
An operation returning multiple values1 returns them in a tuple consisting of a non-void return value, if any, followed by the out parameters in the order of declaration. An operation returning only one value simply returns the value itself.
To illustrate these rules, consider the following interface that passes string parameters in all possible directions:
interface Example {
    string op1(string sin);
    void op2(string sin, out string sout);
    string op3(string sin, out string sout);
};
The generated skeleton class for this interface looks as follows:
class Example(Ice.Object):
    def __init__(self):
        # ...

    #
    # Operation signatures.
    #
    # def op1(self, sin, current=None):
    # def op2(self, sin, current=None):
    # def op3(self, sin, current=None):
The signatures of the Python methods are identical because they all accept a single in parameter, but their implementations differ in the way they return values. For example, we could implement the operations as follows:
class ExampleI(Example):
    def op1(self, sin, current=None):
        print sin             # In params are initialized
        return "Done"         # Return value

    def op2(self, sin, current=None):
        print sin             # In params are initialized
        return "Hello World!" # Out parameter

    def op3(self, sin, current=None):
        print sin             # In params are initialized
        return ("Done", "Hello World!")
Notice that op1 and op2 return their string values directly, whereas op3 returns a tuple consisting of the return value followed by the out parameter.
This code is in no way different from what you would normally write if you were to pass strings to and from a function; the fact that remote procedure calls are involved does not impact on your code in any way. The same is true for parameters of other types, such as proxies, classes, or dictionaries: the parameter passing conventions follow normal Python rules and do not require special-purpose API calls.

1
An operation returns multiple values when it declares multiple out parameters, or when it declares a non-void return type and at least one out parameter.

Table of Contents Previous Next
Logo