OSF DCE Application Development Guide--Introduction and Style Guide
RPC Parameters
input array and return it without incrementing the pointer. The returned pointer will now
reference a copy of the original client array with all its elements. It will not, however
reference the original array itself.
The second pointer example illustrates passing a linked list. The .idl declaration is as
follows:
typedef struct link {
unsigned32 value;
[ptr] struct link *next;
} link_t;
void ptr_test2(
[in] handle_t handle,
[in, out, ref] link_t *head,
[out] error_status_t *status
);
The server manager code is as follows:
void
ptr_test2(
handle_t handle,
link_t *head,
error_status_t *status
)
{
link_t *element;
if (head)
{
element = head;
while (element->next)
element = element->next;
/* Add another element to the list... */
element->next = (link_t*) rpc_sm_allocate(sizeof(link_t), status);
element->next->value = element->value * 2;
element->next->next = NULL;
}
*status = error_status_ok;
};
The manager operation adds a new element to the end of the linked list. Note that the
head parameter has [in, out] semantics here: we must pass in a pointer to a valid element.
(The next example shows how to implement an [out] parameter that is allocated by the
operation.)
In this and the following example, we use rpc_sm_allocate( ) to allocate data on the
server side. This gives the semantics you probably want for a dynamically allocated
referent for a pointer parameter: on return, the data is automatically deallocated on the
server, and further manager operations that access this data do so via a pointer parameter
passed by the client. Memory leaks on the server are thus avoided.
124246 Tandem Computers Incorporated 6− 15










