Steps in Developing a DCE RPC ApplicationThis section provides a step-by-step description of the development of the greet application. 1. Generate an IDL template. The first step is to run the uuidgen program, which creates a Unique Universal Identifier for uniquely labeling the application's interface. It also creates a template for an IDL file. The following command: uuidgen -i > greet.idl creates the file greet.idl. It contains the following:
[ 2. Name the interface. Replace the string INTERFACENAME in the IDL file with the name of the application interface, in this case, greetif.
[ 3. Define the interface operations. Within the braces, write definitions of the operations comprising the interface. In this example, there is only one operation, called greet.
/* The first line of the operation definition gives the name of the operation, greet, and indicates by the void declaration that it has no meaningful return value. The next three lines specify the arguments to the operation, namely h, client_greeting, and server_reply. The first argument is a handle containing binding information for the server. The second is a string that is passed from the client to the server (the client's greeting). The third argument is a string returned from the server back to the client (the server's reply). 4. Run the IDL compiler. The following command runs the IDL compiler: idl greet.idl (Some of the commands in this section are somewhat simplified. See the Makefile in Makefile for the greet Application for the complete command.) Three new files are created automatically as a result of this command: · greet.h · greet_cstub.o · greet_sstub.o 5. Write the client application code greet_client.c. In general, the DCE RPC application programmer writes three application code files: · The client code · The server initialization code · The server operation code The following is the client code for the greet application, a file called greet_client.c.
/* In this routine, the client makes two calls to the RPC runtime to acquire binding information needed to communicate with the server. The client then calls the greet remote procedure, supplying a greeting to be sent to the server. The client prints the reply received by the server. 6. Write the server initialization code greet_server.c The second file that the DCE RPC application programmer must write is the server initialization code. This is boilerplate code; that is, it is largely the same for any RPC application. The greet_server.c file contains the server initialization code for the greet application.
/*
#include <stdio.h>
#include "greet.h"
int
if (argc < 2) {
/*
/*
/*
/*
/*
/*
rpc_server_listen(rpc_c_listen_max_calls_default, &status);
/* In this file, the server registers its interface with the RPC runtime. It then retrieves the binding information assigned to it by the runtime. It registers its binding information with the RPC endpoint mapper, and then with the Cell Directory Service. It then is ready to service requests. Before exiting, the server unregisters its information in the endpoint map. 7. Write the server operation code greet_manager.c. The third file that an RPC programmer writes is the code that implements the operations defined in the IDL file. In this case, there is only one operation, greet. The greet_manager.c file implements this operation.
/* The server prints the message it received from the client, then puts its own message in the reply parameter to be sent back to the client. 8. Write any utility code. In addition to the three standard RPC application code files, greet_client.c, greet_server.c, and greet_manager.c, the greet application contains a utility file for handling errors. This file is called util.c.
/*
The util.c file comes with a header file called util.h.
#define ERROR_CHECK(status, text) \e
void 9. Compile the client and server programs. The greet_client and greet_server programs can now be compiled. The client side of the application is compiled using the following command (again, somewhat simplified): cc -o greet_client greet_client.c greet_cstub.o util.o -ldce The server side of the application is compiled as follows: cc -o greet_server greet_server.c greet_manager.c greet_sstub.o util.o -ldce
|