The following examples show a sample IDL file that uses context handles and a sample context rundown procedure file.
Example of an IDL File That Uses a Context Handle
/*
* Filename: context_handle.idl
*/
[uuid(f38f5080-2d27-11c9-a96d-08002b0ecef1),
pointer_default(ref), version (1.0)]
interface files
{
/* File context handle type */
typedef [context_handle] void * file_handle_t;
/* File specification type */
typedef [string] char * filespec_t;
/* File read buffer type */
typedef [string] char buf_t[*];
/*
* The file_open call requires that the client has located a
* file server interface files and that an RPC handle that is
* bound to that server be passed as the binding parameter h.
*
* Operation to OPEN a file; returns context handle for that file.
*/
file_handle_t file_open
(
/* RPC handle bound to file server */
[in] handle_t h,
/* File specification of file to open */
[in] filespec_t fs
);
/*
* The file_read call is able to use the context handle obtained
* from the file_open as the binding parameter, thus an RPC
* handle is not necessary.
*
* Operation to read from an opened file; returns true if not
* end-of-file
*/
boolean file_read
(
/* Context handle of opened file */
[in] file_handle_t fh,
/* Maximum number of characters to read */
[in] long buf_size,
/* Actual number of characters of data read */
[out] long *data_size,
/* Buffer for characters read */
[out, size_is(buf_size), length_is(*data_size)] buf_t buffer
);
/* Operation to close an opened file */
void file_close
(
/* Valid file context handle goes [in]. On successful close,
* null is returned.
*/
[in,out] file_handle_t *fh
);
}
Example of a Context Rundown Procedure
/*
* fh_rundown.c: A context rundown procedure.
*/
#include <stdio.h>
#include "context_handle.h" /* IDL-generated header file */
void file_handle_t_rundown
(
file_handle_t file_handle /* Active context handle
* (open file handle) */
)
{
/*
* This procedure is called by the RPC runtime on the SERVER
* side when communication is broken between the client and
* server. This gives the server the opportunity to reclaim
* resources identified by the passed context handle. In
* this case, the passed context handle identifies a file,
* and simply closing the file cleans up the state maintained
* by the context handle, that is "runs down" the context handle.
* Note that the file_close manager operation is not used here;
* perhaps it could be, but it is more efficient to use the
* underlying file system call to do the close.
*
* File handle is void*, it must be cast to FILE*
*/
fclose((FILE *)file_handle);
}