OSF DCE Application Development Guide--Introduction and Style Guide

RPC Parameters
number_ptr nptr;
unsigned32 *nval;
nptr = (number_ptr) rpc_sm_allocate(sizeof(number), status);
nval = (unsigned32 *) rpc_sm_allocate(sizeof(unsigned32), status);
*nval = 256;
nptr->value = nval;
*client_ptr = nptr;
*status = error_status_ok;
};
The client test code looks like this:
number_ptr client_ptr = NULL;
ptr_test3(binding_h, &client_ptr, &status);
printf("Value = %i0, (unsigned32)* (client_ptr->value));
Note the use of [ref] pointers here. The top-level [ref] pointer (the one passed as a
parameter to the call) must point to valid storage when the call is made even though the
pointer is not marshalled when the call is made. This follows the rules for [ref] pointers:
they may not be NULL and may not change value during a call. The returned structure
also contains a [ref] pointer, and the client stub does automatically allocate space for its
referent when the call returns. This is an exception to the rule that an [out] [ref] pointer
must point to valid storage when the call is made. In this case, the pointer is embedded
in a structure which is created by the server. As long as the top-level pointer points to
valid storage (to hold the returned structure), the client stub will allocate space for the
referents of any newly-created [ref] pointers that it contains.
The final example illustrates node deletion. The .idl declaration is as follows:
[reflect_deletions] void ptr_test4(
[in] handle_t handle,
[in, out, ptr] unsigned32 *number,
[out] error_status_t *status);
The server code to implement this operation frees the memory pointed to by the input
pointer and returns the pointer:
void
ptr_test4(
handle_t h,
unsigned32 *number,
error_status_t *status
)
{
*number = 32;
rpc_sm_free(number, status);
*status = error_status_ok;
};
The client code is as follows:
124246 Tandem Computers Incorporated 6 17