RPCServiceImpl.mesa
Copyright Ó 1993 by Xerox Corporation. All rights reserved.
Created by Theimer, December 17, 1992 7:58:24 am PST
Theimer, May 15, 1993 1:08 pm PDT
DIRECTORY
Commander,
CommanderOps,
IO,
JoinApp,
LB,
List,
NameService,
Rope,
RPCService,
RuntimeError,
SimpleFeedback,
SunRPC,
SunRPCAuth,
SymTab,
ThisMachine,
UT;
RPCServiceImpl: CEDAR MONITOR
IMPORTS Commander, CommanderOps, IO, JoinApp, LB, List, NameService, Rope, RuntimeError, SimpleFeedback, SunRPCAuth, SymTab, ThisMachine
EXPORTS RPCService ~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
RegistrationRec: TYPE = RECORD [
nmsInstance: ROPE,
cmd: ROPE,
doLBRegistrations: BOOLEAN,
uid: ROPE,
UID returned from NMS registration.
locations: LIST OF ROPE ← NIL
];
RegistrationInfo: TYPE = REF RegistrationRec;
RegistrationsTable: SymTab.Ref ← SymTab.Create[];
JoinAppRPC: SunRPC.Server;
RPC handle for our exported JoinApp interface.
JoinAppRPCBI: ROPE;
String binding handle for exported JoinApp interface.
CedarWorldUid: ROPE;
NMS uid for the registration of this Cedar world in the NMS.
CedarWorldName: ROPE;
Instance name used for this Cedar world in the NMS. Consists of CedarWorld:<hostname>:<worldId>
HostName: ROPE ← ThisMachine.Name[];
CirioPort: CARD ← 4815;
LBCl: LB.LB1;
RPC handle for the LocationBroker.
GetPortNum: PROC RETURNS[CARD]
= TRUSTED MACHINE CODE {"CirioNubLocalGetPort"};
Register: PUBLIC PROC [nmsInstance: ROPE, cmd: ROPE, doLBRegistrations: BOOLEANFALSE, oldNmsInstance: ROPENIL] =
BEGIN
ENABLE RuntimeError.UNCAUGHT => GO TO Oops;
Catch error caused if there is no NMS running.
reg: RegistrationInfo ← NEW [RegistrationRec];
SimpleFeedback.Append[$RPCService, oneLiner, $Debug, IO.PutFR["RegisterWithRPCService[%g, %g]\n", IO.rope[nmsInstance], IO.rope[cmd]]];
reg.nmsInstance ← nmsInstance;
reg.cmd ← cmd;
reg.doLBRegistrations ← doLBRegistrations;
[] ← SymTab.Store[RegistrationsTable, nmsInstance, reg];
[JoinAppRPCBI, reg.uid] ← NameService.ExportRPCSun[name: "JoinApp", sp: JoinAppRPC, prog: JoinApp.JoinAppPrognum, vers: JoinApp.version1, instance: nmsInstance,
appl: CONS[
List.DotCons["Command", cmd],
NIL]
];
EXITS Oops => {};
END;
ServerNoOpProc: JoinApp.servernoopProc = {
};
JoinApplicationProc: JoinApp.joinapplicationProc = {
retVal: UT.ObjectDescription;
result: ROPE"";
instance: ROPENIL;
xServer: ROPENIL;
location: ROPE ← NIL;
cmd: ROPENIL;
cmdArgs: ROPENIL;
fullCmd: ROPE;
found: BOOLEAN;
val: REF;
reg: RegistrationInfo;
ls: ROPE ← "JoinApp.JoinApplication called: ";
FOR i: CARD IN [0..in.size) DO
ls ← Rope.Concat[ls, IO.PutFR["(%g, %g) ", IO.rope[in[i].key], IO.rope[in[i].value]]];
IF Rope.Equal[in[i].key, "XServer", FALSE] THEN xServer ← in[i].value
ELSE IF Rope.Equal[in[i].key, "Location", FALSE] THEN location ← in[i].value
ELSE IF Rope.Equal[in[i].key, "Instance", FALSE] THEN instance ← in[i].value
ELSE IF Rope.Equal[in[i].key, "Command", FALSE] THEN cmd ← in[i].value
ELSE IF Rope.Equal[in[i].key, "CommandArgs", FALSE] THEN cmdArgs ← in[i].value;
ENDLOOP;
ls ← Rope.Concat[ls, " called.\n"];
SimpleFeedback.Append[$RPCService, oneLiner, $Debug, ls];
IF cmd # NIL THEN
{
fullCmd ← cmd;
IF cmdArgs # NIL THEN fullCmd ← Rope.Cat[fullCmd, " ", cmdArgs];
IF xServer # NIL THEN fullCmd ← Rope.Cat["X11 -server ", xServer, " -- ", fullCmd];
result ← DoCommand[fullCmd];
ls ← IO.PutFR["%g -> %g\n", IO.rope[fullCmd], IO.rope[result]];
SimpleFeedback.Append[$RPCService, oneLiner, $Test, ls];
};
IF instance # NIL THEN
{
[found, val] ← SymTab.Fetch[RegistrationsTable, instance];
reg ← NARROW[val];
IF location # NIL AND reg.doLBRegistrations THEN reg.locations ← CONS[location, reg.locations];
IF reg.doLBRegistrations THEN
{
SimpleFeedback.Append[$RPCService, oneLiner, $Debug, "About to call LB.AtLoc.\n"];
RegisterWithLocationBroker[reg, location];
SimpleFeedback.Append[$RPCService, oneLiner, $Debug, "Return from LB.AtLoc.\n"];
}
};
retVal ← NEW[UT.SeqType1Object[1]];
retVal[0].key ← "Result";
retVal[0].value ← result;
RETURN [NEW [JoinApp.JoinApplicationreturnObject.iluSuccess ← [iluSuccess[retVal]]]];
};
DoCommand: PROC [cmd: ROPE] RETURNS [result: ROPE] =
BEGIN
ENABLE RuntimeError.UNCAUGHT => GO TO Oops;
r: REF;
result ← "ERROR";
[result, r] ¬ CommanderOps.DoCommandRope[cmd, NIL, NIL];
EXITS Oops => {};
END;
RegisterWithLocationBroker: PROC [reg: RegistrationInfo, location: ROPE] ~ {
object: UT.Objct;
loc: REF LB.LocationObject.LocationVLocRoom ← NEW [LB.LocationObject.LocationVLocRoom];
res: LB.AtLocreturn;
SimpleFeedback.Append[$RPCService, oneLiner, $Debug, "RegisterWithLocationBroker\n"];
object.binding ← JoinAppRPCBI;
object.rock ← Rope.ToRefText[Rope.Cat[reg.nmsInstance, ":", location]];
object.description ← NEW [UT.SeqType1Object[3]];
object.description[0].key ← "type";
object.description[0].value ← "JoinApp";
object.description[1].key ← "Name";
object.description[1].value ← reg.nmsInstance;
object.description[2].key ← "Command";
object.description[2].value ← reg.cmd;
loc.vLocRoom ← location;
res ← LBCl.atloc[LBCl, object, loc];
IF res.returnCode # iluSuccess THEN ERROR;
};
ConnectToLocationBroker: PROC [] =
BEGIN
ENABLE RuntimeError.UNCAUGHT => GO TO Oops;
Catch error caused if there is no NMS running.
h: SunRPC.Handle;
r: NameService.Registration;
[h, r] ← NameService.ImportRPCSun["LocationBroker"];
LBCl ← LB.MakeLB1Client[h, SunRPCAuth.Initiate[]];
EXITS Oops => {};
END;
ExportJoinAppInterface: PROC [] =
BEGIN
ENABLE RuntimeError.UNCAUGHT => GO TO Oops;
Catch error caused if there is no NMS running.
com: ROPE ← "Command";
xcom: ROPE ← "XCommander";
SimpleFeedback.Append[$RPCService, oneLiner, $Debug, "ExportJoinAppInterface\n"];
JoinAppRPC ← JoinApp.MakeJoinApp1Server[NIL, ServerNoOpProc, JoinApplicationProc];
CirioPort ← GetPortNum[];
CedarWorldName ← IO.PutFR["CedarWorld:%g:%g", IO.rope[HostName], IO.card[CirioPort]];
[JoinAppRPCBI, CedarWorldUid] ← NameService.ExportRPCSun[name: "JoinApp", sp: JoinAppRPC, prog: JoinApp.JoinAppPrognum, vers: JoinApp.version1, instance: CedarWorldName,
appl: CONS[
List.DotCons[com, xcom],
NIL]
];
EXITS Oops => {};
END;
RPCServiceCommand: Commander.CommandProc =
BEGIN
SimpleFeedback.Append[$RPCService, oneLiner, $Launch, "RPCService launched.\n"];
END;
ExportJoinAppInterface[];
ConnectToLocationBroker[];
Commander.Register["RPCService", RPCServiceCommand, "Commander access service via SunRPC"];
END.