LocalRegistryClientStubs.mesa
Copyright Ó 1990, 1991, 1992 by Xerox Corporation. All rights reserved.
Spreitze, November 13, 1990 11:36 am PST
Michael Plass, April 19, 1991 11:40 pm PDT
DIRECTORY Atom, LocalRegistry, LocalRegistryClient, Rope, SunRPC;
LocalRegistryClientStubs: CEDAR PROGRAM
IMPORTS Atom, SunRPC
EXPORTS LocalRegistry, LocalRegistryClient
= BEGIN OPEN LocalRegistry, LocalRegistryClient;
fastTimeout: CARD ¬ 500;
mediumTimeout: CARD ¬ 1000;
defaultRetries: CARD ¬ 10;
noRetries: CARD ¬ 0;
Error: PUBLIC ERROR ~ CODE;
Null: PUBLIC PROC [h: Handle, c: Conversation] ~ {
SunRPC.StartCall[h, c, LocalRegistry.program, LocalRegistry.programVersion, LocalRegistry.null];
[] ¬ SunRPC.SendCallAndReceiveReply[h, fastTimeout, defaultRetries];
SunRPC.ReleaseReply[h];
};
Register: PUBLIC PROC [h: Handle, c: Conversation, reg: Registration, gen: Generation] RETURNS [rcode: ResultCode, sh: ServiceHandle--meaningful only if rcode=success--] ~ {
SunRPC.StartCall[h, c, LocalRegistry.program, LocalRegistry.programVersion, LocalRegistry.register];
SunRPC.PutRope[h, reg.name];
SunRPC.PutInt32[h, reg.msToLive];
PutPropList[h, reg.value];
SunRPC.PutCard32[h, gen];
[] ¬ SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
rcode ¬ GetRCode[h];
IF rcode=success THEN sh ¬ GetServiceHandle[h];
};
Refresh: PUBLIC PROC [h: Handle, c: Conversation, sh: ServiceHandle, msToLive: Milliseconds] RETURNS [rcode: ResultCode] ~ {
SunRPC.StartCall[h, c, LocalRegistry.program, LocalRegistry.programVersion, LocalRegistry.refresh];
PutServiceHandle[h, sh];
SunRPC.PutInt32[h, msToLive];
[] ¬ SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
rcode ¬ GetRCode[h];
RETURN};
GetNames: PUBLIC PROC [h: Handle, c: Conversation, NoteName: PROC [ROPE]] RETURNS [rcode: ResultCode] ~ {
SunRPC.StartCall[h, c, LocalRegistry.program, LocalRegistry.programVersion, LocalRegistry.getNames];
[] ¬ SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
rcode ¬ GetRCode[h];
IF rcode=success THEN {
nNames: CARD ~ SunRPC.GetCard32[h];
FOR i: CARD IN [0..nNames) DO
name: ROPE ~ SunRPC.GetRope[h];
NoteName[name];
ENDLOOP;
};
RETURN};
GetHandles: PUBLIC PROC [h: Handle, c: Conversation, name: ROPE, NoteHandle: PROC [ServiceHandle]] RETURNS [rcode: ResultCode, gen: Generation] ~ {
SunRPC.StartCall[h, c, LocalRegistry.program, LocalRegistry.programVersion, LocalRegistry.getHandles];
SunRPC.PutRope[h, name];
[] ¬ SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
rcode ¬ GetRCode[h];
IF rcode=success THEN {
n: CARD ~ SunRPC.GetCard32[h];
FOR i: CARD IN [0..n) DO
sh: ServiceHandle ~ GetServiceHandle[h];
NoteHandle[sh];
ENDLOOP;
gen ¬ SunRPC.GetCard32[h];
};
RETURN};
GetRegistration: PUBLIC PROC [h: Handle, c: Conversation, sh: ServiceHandle] RETURNS [rcode: ResultCode, reg: Registration] ~ {
SunRPC.StartCall[h, c, LocalRegistry.program, LocalRegistry.programVersion, LocalRegistry.getRegistration];
PutServiceHandle[h, sh];
[] ¬ SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
rcode ¬ GetRCode[h];
IF rcode=success THEN {
reg.name ¬ SunRPC.GetRope[h];
reg.msToLive ¬ SunRPC.GetInt32[h];
reg.value ¬ GetPropList[h];
};
RETURN};
PutPropList: PROC [h: Handle, pl: PropList] ~ {
DO
SunRPC.PutCard32[h, IF pl#NIL THEN 1 ELSE 0];
IF pl=NIL THEN EXIT;
WITH pl.first.key SELECT FROM
x: ATOM => SunRPC.PutRope[h, Atom.GetPName[x]];
ENDCASE => ERROR Error;
WITH pl.first.val SELECT FROM
x: ROPE => SunRPC.PutRope[h, x];
x: REF TEXT => SunRPC.PutRefText[h, x];
x: REF READONLY TEXT => SunRPC.PutRefText[h, x];
ENDCASE => ERROR Error;
pl ¬ pl.rest;
ENDLOOP;
RETURN};
GetPropList: PROC [h: Handle] RETURNS [pl: PropList] ~ {
tail: PropList ¬ pl ¬ LIST[NIL];
this: PropList ¬ NIL;
bit: CARD;
key, val: ROPE;
DO
bit ¬ SunRPC.GetCard32[h];
IF bit=0 THEN EXIT;
key ¬ SunRPC.GetRope[h];
val ¬ SunRPC.GetRope[h];
this ¬ Atom.PutPropOnList[propList: NIL, prop: Atom.MakeAtom[key], val: val];
tail.rest ¬ this;
tail ¬ this;
ENDLOOP;
RETURN [pl.rest]};
GetRCode: PROC [h: Handle] RETURNS [ResultCode] ~ {
ord: CARD ¬ SunRPC.GetCard32[h];
ord ¬ MIN[ord, ResultCode.LAST.ORD];
RETURN [VAL[ord]]};
PutServiceHandle: PROC [h: Handle, sh: ServiceHandle] ~ {
SunRPC.PutInt32[h, sh[0]];
SunRPC.PutInt32[h, sh[1]];
SunRPC.PutInt32[h, sh[2]];
RETURN};
GetServiceHandle: PROC [h: Handle] RETURNS [sh: ServiceHandle] ~ {
sh[0] ¬ SunRPC.GetInt32[h];
sh[1] ¬ SunRPC.GetInt32[h];
sh[2] ¬ SunRPC.GetInt32[h];
RETURN};
END.