10.11. Methods

Declaration of a method satisfies the following syntax:


(74)               <method> ::= "method"
                                [ "<" [ <methodattr_vals> ] ">" ]
                                <identifier>
                                "("
                                [ <arguments> ]
                                ")"
                                [ <return_spec> ]
                                ";"

Method declaration consists of an optional list of method attribute assignments, the method name, specification of method arguments and an optional specification of method return type.

It's illegal to declare methods with the same name in both base and derived class. The IDL does not support method overloading and hiding, and default argument values. Virtual methods should be declared only in the class where they are first defined in the C++, and RPC to virtual methods will work as expected.

Constructors, destructors and operators can't be declared in the IDL. All methods declared in the IDL must be public in the C++.

[Note]Note

You don't have to declare all methods defined in the C++ in the IDL. However, only the declared methods can be called using the RPC.

10.11.1. Method Attributes

Method attribute value assignments satisfy the following syntax:


(76)      <methodattr_vals> ::= <methodattr_val>
                                { "," <methodattr_val> }*
(77)       <methodattr_val> ::= <boolmethodattr_name>
                              | <methodattr_name> "=" <const_expr>
(78)  <boolmethodattr_name> ::= <scoped_name>
(79)      <methodattr_name> ::= <scoped_name>

The following table lists all method attributes defined in src/core/object/object.idl:

Table 10.5. Method attributes defined in the Core IDL
NameTypeDefaultDescription
virtualboolfalse If true, the method is virtual in the C++ sense. Setting this attribute correctly is not required as it's not (and will not be) used by the RPC at all. However, the value is exported to metaobjects, and therefore should be set correctly to prevent confusion.
constboolfalse Meaning of this attribute is described in Section 8.5.2, “Synchronous RPC Optimizations”. It should be always false if the method is not const in the C++ sense. Set it to true if you want to allow replica-optimized RPC to the method.

10.11.2. Method Arguments and Results

Method argument specification satisfies the following syntax:


(80)            <arguments> ::= <argument>
                                { "," <argument> }*
(81)             <argument> ::= <pass_semantics>
                                <type>
                                <identifier>
(82)       <pass_semantics> ::= "in"
                              | "out"
                              | "inout"

The <pass_semantics> specify how the argument is passed over the network:

  • in - the argument is passed from the caller to the callee. out - the argument is passed from the callee to the caller. inout - the argument is passed in both directions.

If the method returns a value, its type is specified using the following syntax:


(83)          <return_spec> ::= ":"
                                <type>

Argument and return type can be any type described in Section 10.13, “Property and Argument Types”, except for types that are, or contain, a strong pointer.