This page describes the C++ mapping for the
ice_invoke proxy function and the
On this page:
ice_invoke in C++
The mapping for
ice_invoke is shown below:
Another overloading of
ice_invoke (not shown) adds a trailing argument of type
As an example, the code below demonstrates how to invoke the operation
op, which takes no
As a convenience, the Ice run time accepts an empty byte sequence when there are no input parameters and internally translates it into an empty encapsulation. In all other cases, the value for
inParams must be an encapsulation of the encoded parameters.
Using Streams with
ice_invoke in C++
The streaming interfaces provide the tools an application needs to dynamically invoke operations with arguments of any Slice type. Consider the following Slice definition:
Now let's write a client that dynamically invokes the
You can see here that the input and output parameters are enclosed in encapsulations.
We neglected to handle the case of a user exception in this example, so let's implement that now. We assume that we have compiled our program with the Slice-generated code, therefore we can call
throwException on the input stream and catch
This is obviously a contrived example: if the Slice-generated code is available, why bother using dynamic dispatch? In the absence of Slice-generated code, the caller would need to manually unmarshal the user exception, which is outside the scope of this manual.
As a defensive measure, the code traps
Ice::UserException. This could be raised if the Slice definition of
add is modified to include another user exception but this segment of code did not get updated accordingly.
Blobject in C++
Implementing the dynamic dispatch model requires writing a subclass of
Ice::Blobject. We continue using the
Compute interface to demonstrate a
An instance of
ComputeI is an Ice object because
Blobject derives from
Object, therefore an instance can be added to an object adapter like any other servant.
For the purposes of this discussion, the implementation of
ice_invoke handles only the
add operation and raises
OperationNotExistException for all other operations. In a real implementation, the servant must also be prepared to receive invocations of the following
Returns the Slice type ID of the servant's most-derived type.
Returns a sequence of strings representing all of the Slice interfaces supported by the servant, including
bool ice_isA(string id)
trueif the servant supports the interface denoted by the given Slice type ID, or
falseotherwise. This operation is invoked by the proxy function
Verifies that the object denoted by the identity and facet contained in
With that in mind, here is our simplified version of
If an overflow is detected, the code "raises" the
Calc::Overflow user exception by calling
writeException on the output stream and returning
false, otherwise the return value is encoded and the function returns
Using the Array Mapping for
Blobject in C++
Ice for C++ supports an alternative mapping for
sequence input parameters that avoids the overhead of extra copying. Since the
ice_invoke functions treat the encoded input parameters as a value of type
sequence<byte>, the dynamic invocation and dispatch facility includes interfaces that use the array mapping for the input parameter blob.
Ice provides two overloaded versions of the proxy function
ice_invoke that use the array mapping. The version that omits the trailing
Ice::Context argument is shown below:
Blobject servant uses the array mapping by deriving its implementation class from
Ice::BlobjectArray and overriding its