ListRegistryCommand:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ¬
NIL, msg:
ROPE ¬
NIL] ~ {
ENABLE {
Convert.Error => CommanderOps.Failed[IO.PutFR["Convert.Error[%g, %g]", [cardinal[ORD[reason]]], [integer[index]]]];
LocalRegistry.Error => CommanderOps.Failed["LocalRegistry.Error"];
NetworkName.Error => CommanderOps.Failed[Rope.Cat["NetworkName.Error[", msg, "]"]];
SunRPC.Error => CommanderOps.Failed[IO.PutFR1["SunRPC.Error[%g]", [atom[code]]]];
SunRPCAuth.Error => CommanderOps.Failed[IO.PutFR1["SunRPCAuth.Error[%g]", [atom[code]]] ];
};
debug: BOOL ¬ FALSE;
ParseArgs:
PROC
RETURNS [host:
ROPE ¬
NIL] ~ {
FOR arg:
ROPE ¬ CommanderOps.NextArgument[cmd], CommanderOps.NextArgument[cmd]
UNTIL arg =
NIL
DO
IF Rope.Match["-*", arg]
THEN {
FOR i:
INT
IN (0..Rope.Size[arg])
DO
SELECT Rope.Lower[Rope.Fetch[arg, i]]
FROM
'd => debug ¬ TRUE;
ENDCASE => GOTO Fail;
ENDLOOP;
}
ELSE {
IF host # NIL THEN GOTO Fail;
host ¬ arg;
};
ENDLOOP;
EXITS Fail => CommanderOps.Failed[cmd.procData.doc];
};
Report:
PROC[rope:
ROPE, int:
INT ¬ 0]
RETURNS [
BOOL ¬
FALSE] ~ {
IF debug THEN IO.PutF[cmd.err, "*** %g %g\n", [rope[rope]], [integer[int]]];
};
hostname: ROPE ~ ParseArgs[];
hostAddress: ROPE ~ NetworkName.AddressFromName[family: $ARPA, name: hostname, components: $host].addr;
host: Arpa.Address ~ Convert.ArpaAddressFromRope[hostAddress];
pmh: SunRPC.Handle ~ SunRPCOnUDP.Create[host, Basics.HFromCard16[SunPMap.udpPort]];
pmc: SunRPC.Conversation ~ SunRPCAuth.Initiate[SunRPCAuth.nullFlavor];
lrPortNum: CARD ¬ SunPMapClient.GetPort[pmh, pmc, LocalRegistry.program, LocalRegistry.programVersion, SunPMap.ipProtocolUDP];
d0: BOOL ~ Report["lrPortNum", lrPortNum];
lrh: SunRPC.Handle ~ SunRPCOnUDP.Create[host, Basics.HFromCard16[lrPortNum]];
lrc: SunRPC.Conversation ~ SunRPCAuth.Initiate[SunRPCAuth.nullFlavor];
ReportHandles:
PROC [serviceHandles:
LIST
OF LocalRegistry.ServiceHandle] ~ {
IF serviceHandles #
NIL
THEN {
rcode: LocalRegistry.ResultCode;
reg: LocalRegistry.Registration;
serviceHandle: LocalRegistry.ServiceHandle ~ serviceHandles.first;
ReportHandles[serviceHandles.rest];
[rcode, reg] ¬ LocalRegistryClient.GetRegistration[lrh, lrc, serviceHandle];
[] ¬ Report["rcode", ORD[rcode]];
IF rcode = success
THEN {
IO.PutF[cmd.out, "%g: (%g ms to live)\n", [rope[reg.name]], [integer[reg.msToLive]]];
FOR tail: Atom.PropList ¬ reg.value, tail.rest
UNTIL tail =
NIL
DO
IO.PutF[cmd.out, " %g: %g\n", [atom[NARROW[tail.first.key]]], [rope[NARROW[tail.first.val]]]];
ENDLOOP;
};
};
};
ReportNames:
PROC [names:
LIST
OF
ROPE] ~ {
handles: LIST OF LocalRegistry.ServiceHandle ¬ NIL;
NoteHandle:
PROC [serviceHandle: LocalRegistry.ServiceHandle] ~ {
d0: BOOL ~ Report["serviceHandle[0]", serviceHandle[0]];
d1: BOOL ~ Report["serviceHandle[1]", serviceHandle[1]];
d2: BOOL ~ Report["serviceHandle[2]", serviceHandle[2]];
handles ¬ CONS[serviceHandle, handles];
};
IF names #
NIL
THEN {
ReportNames[names.rest];
[] ¬ LocalRegistryClient.GetHandles[lrh, lrc, names.first, NoteHandle];
[] ¬ Report[names.first, 1];
ReportHandles[handles];
};
};
names: LIST OF ROPE ¬ NIL;
NoteName:
PROC [name:
ROPE] ~ {
d0: BOOL ~ Report[name];
names ¬ CONS[name, names];
};
rcode: LocalRegistry.ResultCode ~ LocalRegistryClient.GetNames[lrh, lrc, NoteName];
ReportNames[names];
IF rcode # success THEN CommanderOps.Failed[IO.PutFR1["LocalRegistryClient.GetNames failed (rc = %g)", [cardinal[ORD[rcode]]]]];
SunRPC.Destroy[lrh];
SunRPCAuth.Terminate[lrc];
SunRPC.Destroy[pmh];
SunRPCAuth.Terminate[pmc];
};