testexecmgmt/ucc/BinInternal/rpcgen/rpc_clnt.c
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     1 /*********************************************************************
       
     2  * RPC for the Windows NT Operating System
       
     3  * 1993 by Martin F. Gergeleit
       
     4  * Users may use, copy or modify Sun RPC for the Windows NT Operating 
       
     5  * System according to the Sun copyright below.
       
     6  *
       
     7  * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO 
       
     8  * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE 
       
     9  * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
       
    10  *********************************************************************/
       
    11 
       
    12 /* @(#)rpc_clntout.c	2.1 88/08/01 4.0 RPCSRC */
       
    13 /*
       
    14  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
       
    15  * unrestricted use provided that this legend is included on all tape
       
    16  * media and as a part of the software program in whole or part.  Users
       
    17  * may copy or modify Sun RPC without charge, but are not authorized
       
    18  * to license or distribute it to anyone else except as part of a product or
       
    19  * program developed by the user.
       
    20  * 
       
    21  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
       
    22  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
       
    23  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
       
    24  * 
       
    25  * Sun RPC is provided with no support and without any obligation on the
       
    26  * part of Sun Microsystems, Inc. to assist in its use, correction,
       
    27  * modification or enhancement.
       
    28  * 
       
    29  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
       
    30  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
       
    31  * OR ANY PART THEREOF.
       
    32  * 
       
    33  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
       
    34  * or profits or other special, indirect and consequential damages, even if
       
    35  * Sun has been advised of the possibility of such damages.
       
    36  * 
       
    37  * Sun Microsystems, Inc.
       
    38  * 2550 Garcia Avenue
       
    39  * Mountain View, California  94043
       
    40  */
       
    41 //#ifndef lint
       
    42 //static char sccsid[] = "@(#)rpc_clntout.c 1.2 87/06/24 (C) 1987 SMI";
       
    43 //#endif
       
    44 
       
    45 /*
       
    46  * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
       
    47  * Copyright (C) 1987, Sun Microsytsems, Inc.
       
    48  */
       
    49 #include <stdio.h>
       
    50 #ifdef WIN32
       
    51 #include <stdlib.h>
       
    52 #include <string.h>
       
    53 #include "rpc_pars.h"
       
    54 #else
       
    55 #include <strings.h>
       
    56 #include "rpc_pars.h"
       
    57 #endif
       
    58 #include "rpc_util.h"
       
    59 #include "ae_component_rpc.h"
       
    60 
       
    61 #define DEFAULT_TIMEOUT 25	/* in seconds */
       
    62 
       
    63 /* prototypes */
       
    64 static void printbody( proc_list *proc );
       
    65 
       
    66 /* implementation */
       
    67 static void
       
    68 write_program(def)
       
    69 	definition *def;
       
    70 {
       
    71 	version_list *vp;
       
    72 	proc_list *proc;
       
    73 
       
    74 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
       
    75 		for (proc = vp->procs; proc != NULL; proc = proc->next) {
       
    76 			f_print(fout, "\n");
       
    77 			ptype(proc->res_prefix, proc->res_type, 1);
       
    78 			f_print(fout, "*\n");
       
    79 			pvname(proc->proc_name, vp->vers_num);
       
    80 			f_print(fout, "(argp, clnt)\n");
       
    81 			f_print(fout, "\t");
       
    82 			ptype(proc->arg_prefix, proc->arg_type, 1);
       
    83 			f_print(fout, "*argp;\n");
       
    84 			f_print(fout, "\tCLIENT *clnt;\n");
       
    85 			f_print(fout, "{\n");
       
    86 			printbody(proc);
       
    87 			f_print(fout, "}\n\n");
       
    88 		}
       
    89 	}
       
    90 }
       
    91 
       
    92 static char *
       
    93 ampr(type)
       
    94 	char *type;
       
    95 {
       
    96 	if (isvectordef(type, REL_ALIAS)) {
       
    97 		return ("");
       
    98 	} else {
       
    99 		return ("&");
       
   100 	}
       
   101 }
       
   102 
       
   103 static void
       
   104 printbody(proc)
       
   105 	proc_list *proc;
       
   106 {
       
   107 	f_print(fout, "\tstatic ");
       
   108 	if (streq(proc->res_type, "void")) {
       
   109 		f_print(fout, "char ");
       
   110 	} else {
       
   111 		ptype(proc->res_prefix, proc->res_type, 0);
       
   112 	}
       
   113 	f_print(fout, "res;\n");
       
   114 	f_print(fout, "\n");
       
   115  	f_print(fout, "\tbzero((char *)%sres, sizeof(res));\n",
       
   116  		ampr(proc->res_type));
       
   117 	f_print(fout,
       
   118 		"\tclnt_call(clnt, %s, xdr_%s, argp, xdr_%s, %sres, TIMEOUT);\n",
       
   119 		proc->proc_name, ae_extend_custom_types(stringfix(proc->arg_type)),
       
   120 		ae_extend_custom_types(stringfix(proc->res_type)), ampr(proc->res_type));
       
   121 //		"\tif (clnt_call(clnt, %s, xdr_%s, argp, xdr_%s, %sres, TIMEOUT) != RPC_SUCCESS) {\n",
       
   122 //		proc->proc_name, stringfix(proc->arg_type),
       
   123 //		stringfix(proc->res_type), ampr(proc->res_type));
       
   124 //	f_print(fout, "\t\treturn (NULL);\n");
       
   125 //	f_print(fout, "\t}\n");
       
   126 	if (streq(proc->res_type, "void")) {
       
   127 		f_print(fout, "\treturn ((void *)%sres);\n",
       
   128 			ampr(proc->res_type));
       
   129 	} else {
       
   130 		f_print(fout, "\treturn (%sres);\n", ampr(proc->res_type));
       
   131 	}
       
   132 }
       
   133 
       
   134 void
       
   135 write_stubs()
       
   136 {
       
   137 	list *l;
       
   138 	definition *def;
       
   139 
       
   140  	f_print(fout,
       
   141  		"\n/* Default timeout can be changed using clnt_control() */\n");
       
   142  	f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
       
   143 		DEFAULT_TIMEOUT);
       
   144 	for (l = defined; l != NULL; l = l->next) {
       
   145 		def = (definition *) l->val;
       
   146 		if (def->def_kind == DEF_PROGRAM) {
       
   147 			write_program(def);
       
   148 		}
       
   149 	}
       
   150 }