#ifndef lint static char sccsid[] = "@(#)rpc_svcout.c 1.1 90/10/29 (C) 1987 SMI"; #endif /* * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler * Copyright (C) 1987, Sun Microsytsems, Inc. */ #include #include #include "rpc_parse.h" #include "rpc_util.h" static char RQSTP[] = "rqstp"; static char TRANSP[] = "transp"; static char ARG[] = "argument"; static char RESULT[] = "result"; static char ROUTINE[] = "local"; char _errbuf[256]; /* For all messages */ /* * Write the objects and procedures for a particular version of a particular * program. */ void write_server_prog(svcName, progName, vers) char *svcName; char *progName; version_list *vers; { char pvName[256]; proc_list *proc; char *firstFlag = "|"; char *srcMethod; char *inParm, *outParm; definition *defStruct; decl_list *dl; int expandFlag; extern definition *FindStructDefn(); char *h, *c, *o, *out; char buf[128]; char *mName; char *sp; CurrentProgNameFlag++; sprintf(pvName, "%s%s", progName, vers->vers_num); if (PCedar) { if (PCedarUDP) { f_print(fout, "Export%s: PUBLIC PROC[p: %s.%s] = {\n", pvName, svcName, pvName); f_print(fout, " o: %s.%s _ NEW[%s.%sObject];\n", svcName, pvName, svcName, pvName); f_print(fout, " %sServer: %s.Server _ %s.CreateServer[\n", pvName, SunRPC, SunRPC); f_print(fout, "\t\t%s.%s, %s, %sHandler, \n", svcName, progName, vers->vers_num, pvName); f_print(fout, "\t\t%s.nullPort, 3, o];\n", SunRPC); f_print(fout, " [] _ SunPMapLocal.UnsetLocal[%s.%s, %s];\n", svcName, progName, vers->vers_num); f_print(fout, " [] _ SunPMapLocal.SetLocal[%s.%s, %s, SunPMap.ipProtocolUDP,\n", svcName, progName, vers->vers_num); f_print(fout, "\t\tBasics.Card16FromH[%s.GetServerPort[%sServer]]];\n", SunRPC, pvName); for (proc = vers->procs; proc != NULL; proc = proc->next) { f_print(fout, " o.%s _ p.%s;\n", locase(proc->proc_name), locase(proc->proc_name)); } f_print(fout, " };\n\n"); } else { /* PCedarTCP */ f_print(fout, "ExportStream%s: PUBLIC PROC[p: %s.%s] = {\n", pvName, svcName, pvName); f_print(fout, " o: %s.%s _ NEW[%s.%sObject];\n", svcName, pvName, svcName, pvName); f_print(fout, " %sServer: %s.Server _ %s.CreateServer[\n", pvName, SunRPC, SunRPC); f_print(fout, "\t\t%s.%s, %s, %sHandler, \n", svcName, progName, vers->vers_num, pvName); f_print(fout, "\t\t$ARPA, NIL, o];\n"); f_print(fout, " local: ROPE;\n"); f_print(fout, " port: CARD32;\n"); f_print(fout, " [] _ SunPMapLocal.UnsetLocal[%s.%s, %s];\n", svcName, progName, vers->vers_num); f_print(fout, " [,local] _ %s.GetServerInfo[%sServer];\n", SunRPC, pvName); f_print(fout, " port _ Convert.CardFromRope[Rope.Substr[local, Rope.FindBackward[local, \":\"]+1]];\n"); f_print(fout, " [] _ SunPMapLocal.SetLocal[%s.%s, %s, SunPMap.ipProtocolTCP, port];\n", svcName, progName, vers->vers_num); for (proc = vers->procs; proc != NULL; proc = proc->next) { f_print(fout, " o.%s _ p.%s;\n", locase(proc->proc_name), locase(proc->proc_name)); } f_print(fout, " };\n\n"); } } else { if (BadProgNameFlag[CurrentProgNameFlag]) { f_print(fout, "Make%s%sServer: PUBLIC PROC[\n", svcName, pvName); } else { f_print(fout, "Make%sServer: PUBLIC PROC[\n", pvName); } f_print(fout, " data: REF,\n"); for (proc = vers->procs; proc != NULL; proc = proc->next) { f_print(fout, " %s: %s.%sProc", locase(proc->proc_name), svcName, locase(proc->proc_name)); if (proc->next != NULL) f_print(fout, ",\n"); else f_print(fout, "\n"); } f_print(fout, " ] RETURNS [%s.Server] ~ {\n\n", SunRPC); if (BadProgNameFlag[CurrentProgNameFlag]) { f_print(fout, " pseudoClient: %s.%s%s ~\n", svcName, svcName, pvName); f_print(fout, "\tNEW[%s.%s%sObject _ [\n", svcName, svcName, pvName); } else { f_print(fout, " pseudoClient: %s.%s ~\n", svcName, pvName); f_print(fout, "\tNEW[%s.%sObject _ [\n", svcName, pvName); } f_print(fout, "\t\trpcHandle ~ NIL, rpcConversation ~ NIL, data ~ data,\n"); for (proc = vers->procs; proc != NULL; proc = proc->next) { f_print(fout, "\t\t%s ~ %s", locase(proc->proc_name), locase(proc->proc_name)); if (proc->next != NULL) f_print(fout, ",\n"); else f_print(fout, "\n"); } f_print(fout, "\t]];\n\n"); f_print(fout, "unbound: %s.Server ~ NEW[SunRPC.ServerObject _ [\n", SunRPC); if (BadProgNameFlag[CurrentProgNameFlag]) { f_print(fout, "\tpgm ~ %s.%sPrognum,\n", svcName, svcName); } else { f_print(fout, "\tpgm ~ %s.%s,\n", svcName, progName); } f_print(fout, "\tversion ~ %s.%s,\n", svcName, vers->vers_name); f_print(fout, "\tclientData ~ pseudoClient,\n"); if (BadProgNameFlag[CurrentProgNameFlag]) { f_print(fout, "\tserverProc ~ %s%sHandler\n", svcName, pvName); } else { f_print(fout, "\tserverProc ~ %sHandler\n", pvName); } f_print(fout, "\t]];\n\n"); f_print(fout, "RETURN [unbound];\n"); f_print(fout, " };\n\n"); } if (BadProgNameFlag[CurrentProgNameFlag]) { f_print(fout, "%s%sHandler: %s.ServerProc -- [h: Handle, c: Conversation, proc: CARD, clientData: REFANY\n", svcName, pvName, SunRPC); } else { f_print(fout, "%sHandler: %s.ServerProc -- [h: Handle, c: Conversation, proc: CARD, clientData: REFANY\n", pvName, SunRPC); } if (PCedarTCP) { f_print(fout, "\t\t-- RETURNS [doReply: BOOLEAN] -- = {\n"); } else { /* PCedarUDP or Cedar10 */ f_print(fout, "\t\t-- RETURNS [doReply: BOOLEAN, replyTimeToLive: CARDINAL] -- = {\n"); } if (BadProgNameFlag[CurrentProgNameFlag]) { f_print(fout, " o: %s.%s%s _ NARROW[clientData];\n", svcName, svcName, pvName); } else { f_print(fout, " o: %s.%s _ NARROW[clientData];\n", svcName, pvName); } f_print(fout, " doReply _ TRUE;\n"); if (!PCedarTCP) /* PCedarUDP or Cedar10 */ f_print(fout, " replyTimeToLive _ defaultReplyTTL;\n"); f_print(fout, " SELECT proc FROM\n"); for (proc = vers->procs; proc != NULL; proc = proc->next) { f_print(fout, " %s => %s%s[h, c, o];\n", proc->proc_num, locase(proc->proc_name), vers->vers_num); } f_print(fout, " ENDCASE => ERROR %s.Error[$wrongProc];\n", SunRPC); f_print(fout, " };\n\n"); for (proc = vers->procs; proc != NULL; proc = proc->next) { expandFlag = FALSE; h = "h"; c = "c"; o = "o"; out = "out"; if (ExpandProcArgs) { defStruct = FindStructDefn(proc->arg_type); if (defStruct != NULL) { h = FindUniqueName("h", defStruct->def.st.decls); c = FindUniqueName("c", defStruct->def.st.decls); o = FindUniqueName("o", defStruct->def.st.decls); out = FindUniqueName("out", defStruct->def.st.decls); } } if (BadProgNameFlag[CurrentProgNameFlag]) { f_print(fout, "%s%s: PROC[%s: Handle, %s: Conversation, %s: %s.%s%s] = {\n", locase(proc->proc_name), vers->vers_num, h, c, o, svcName, svcName, pvName); } else { f_print(fout, "%s%s: PROC[%s: Handle, %s: Conversation, %s: %s.%s] = {\n", locase(proc->proc_name), vers->vers_num, h, c, o, svcName, pvName); } if (ExpandProcArgs && defStruct != NULL && defStruct->def_kind == DEF_STRUCT) { expandFlag = TRUE; for (dl = defStruct->def.st.decls; dl != NULL; dl = dl->next) { pdeclaration(defStruct->def_name, &(dl->decl), 4, FALSE); f_print(fout, ";\n"); } } else if (!streq(proc->arg_type, "void")) { f_print(fout, " in: %s;\n", MapToCedarType(proc->arg_type, FALSE)); } if (!streq(proc->res_type, "void")) f_print(fout, " %s: %s;\n", out, MapToCedarType(proc->res_type, FALSE)); if (expandFlag) { for (dl = defStruct->def.st.decls; dl != NULL; dl = dl->next) { emit_get_stat(&(dl->decl), "", "", FALSE, h, defStruct->def_name); } } else { if (!streq(proc->arg_type, "void")) { srcMethod = rpcgenBaseType(proc->arg_type); if (srcMethod != NULL) f_print(fout, " in _ %s.Get%s[%s];\n", SunRPC, srcMethod, h); else { mName = ModuleName(proc->arg_type); f_print(fout, " in _ %sGetPut.Get%s[%s];\n", mName, StripPrefix(mName, proc->arg_type), h); } inParm = ", in"; } else inParm = ""; } if (streq(proc->res_type, "void")) outParm = ""; else { sprintf(buf, "%s _ ", out); outParm = buf; } if (expandFlag) { f_print(fout, " %so.%s[%s,\n", outParm, locase(proc->proc_name), o); for (dl = defStruct->def.st.decls; dl != NULL; dl = dl->next) { f_print(fout, "\t\t\t%s", dl->decl.name); if (dl->next != NULL) f_print(fout, ",\n"); else f_print(fout, "];\n"); } } else { f_print(fout, " %so.%s[%s%s];\n", outParm, locase(proc->proc_name), o, inParm); } f_print(fout, " %s.StartReply[%s];\n", SunRPC, h); if (!streq(proc->res_type, "void")) { srcMethod = rpcgenBaseType(proc->res_type); if (srcMethod != NULL) f_print(fout, " %s.Put%s[%s, %s];\n", SunRPC, srcMethod, h, out); else { mName = ModuleName(proc->res_type); if (streq(mName, svcName)) sp = proc->res_type; else sp = StripPrefix(mName, proc->res_type); f_print(fout, " %sGetPut.Put%s[%s, %s];\n", mName, sp, h, out); } } f_print(fout, "};\n\n"); } f_print(fout, "\n"); }