SlateJoinAppImpl.mesa
Copyright Ó 1992, 1993 by Xerox Corporation. All rights reserved.
Created by Theimer, December 17, 1992 7:58:24 am PST
Theimer, May 5, 1993 2:53 pm PDT
Christian Jacobi, August 20, 1993 12:07 pm PDT
DIRECTORY
ForkOps,
IO,
JoinApp,
LB,
List,
NameService,
RefTab,
Rope,
RuntimeError,
SlateJoinApp,
Slate,
SunRPC,
SunRPCAuth,
SymTab,
UT;
SlateJoinAppImpl: CEDAR MONITOR
IMPORTS ForkOps, IO, JoinApp, LB, List, NameService, RefTab, Rope, RuntimeError, Slate, SunRPCAuth, SymTab
EXPORTS SlateJoinApp ~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
nextSessionIndex: CARD ← 0;
sessionRec: TYPE = RECORD [
slateBI: ROPENIL,
uid: ROPE,
rpc: SunRPC.Server,
session: Slate.Session,
sessionId: ROPE,
locations: LIST OF ROPE ← NIL
];
sessionInfo: TYPE = REF sessionRec;
sessionIdTable: SymTab.Ref ← SymTab.Create[];
sessionTable: RefTab.Ref ← RefTab.Create[];
Tables of sessionInfo records.
sessionIdRope: ROPE ← "SessionId";
LBClosure: TYPE = RECORD [
object: REF UT.Objct,
loc: REF LB.LocationObject.LocationVLocRoom
];
lb: LB.LB1;
RPC handle for the LocationBroker.
NewSessionEvent: Slate.EventProc = {
AdvertiseNewSession[session, NIL];
};
AdvertiseNewSession: PUBLIC PROC [session: Slate.Session, log: IO.STREAM] =
BEGIN
ENABLE RuntimeError.UNCAUGHT => GO TO Oops;
Catch error caused if there is no NMS running.
tRope: ROPE ← "t";
rpc: SunRPC.Server ¬ JoinApp.MakeJoinApp1Server[NIL, ServerNoOpProc, JoinApplicationProc];
sr: sessionInfo ← NEW [sessionRec];
IF log=NIL THEN log ¬ session.debugLog;
IO.PutRope[log, "AdvertiseNewSession\n"];
sr.rpc ← rpc;
sr.session ← session;
sr.sessionId ← IO.PutFR1["%g", IO.card[nextSessionIndex]];
[sr.slateBI, sr.uid] ← NameService.ExportRPCSun[name: "JoinApp", sp: rpc, prog: JoinApp.JoinAppPrognum, vers: JoinApp.version1, instance: "Slate:",
appl: CONS[
List.DotCons[sessionIdRope, sr.sessionId],
NIL]
];
[] ← SymTab.Store[sessionIdTable, sr.sessionId, sr];
[] ← RefTab.Store[sessionTable, session, sr];
nextSessionIndex ← nextSessionIndex + 1;
EXITS Oops => {};
END;
ServerNoOpProc: JoinApp.servernoopProc = {
};
JoinApplicationProc: JoinApp.joinapplicationProc = {
retVal: UT.ObjectDescription ← NEW[UT.SeqType1Object[0]];
xServer: ROPE ← "cleonie:0.1";
location: ROPE;
sessionId: ROPE;
found: BOOLEAN;
val: REF;
sr: sessionInfo;
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, "SessionId", FALSE] THEN sessionId ← in[i].value;
ENDLOOP;
ls ← Rope.Concat[ls, " called.\n"];
[found, val] ← SymTab.Fetch[sessionIdTable, sessionId];
sr ← NARROW[val];
sr.locations ← CONS[location, sr.locations];
IO.PutF1[sr.session.debugLog, "%g", IO.rope[ls]];
[] ← Slate.NewInstanceTool[sr.session, xServer];
IO.PutRope[sr.session.debugLog, "... "];
IO.PutRope[sr.session.debugLog, "About to call LB.AtLoc.\n"];
RegisterWithLocationBroker[location, sr.session, sessionId];
IO.PutRope[sr.session.debugLog, "Done with JoinApp.JoinApplication.\n"];
IO.PutRope[sr.session.debugLog, "Return from LB.AtLoc.\n"];
RETURN [NEW [JoinApp.JoinApplicationreturnObject.iluSuccess ← [iluSuccess[retVal]]]];
};
RegisterWithLocationBroker: PROC [location: ROPE, session: Slate.Session, sessionId: ROPE] ~ {
object: REF UT.Objct;
loc: REF LB.LocationObject.LocationVLocRoom ← NEW [LB.LocationObject.LocationVLocRoom];
found: BOOLEAN;
val: REF;
sr: sessionInfo;
cl: REF LBClosure ← NEW [LBClosure];
IO.PutRope[session.debugLog, "RegisterWithLocationBroker\n"];
[found, val] ← SymTab.Fetch[sessionIdTable, sessionId];
sr ← NARROW[val];
object ← NEW [UT.Objct];
object.binding ← sr.slateBI;
object.rock ← Rope.ToRefText[Rope.Cat["Slate", sessionId, ":", location]];
object.description ← NEW [UT.SeqType1Object[3]];
object.description[0].key ← "type";
object.description[0].value ← "Groupware";
object.description[1].key ← "Name";
object.description[1].value ← Rope.Concat["Slate:", Slate.SessionName[session]];
object.description[2].key ← "SessionId";
object.description[2].value ← sessionId;
loc.vLocRoom ← location;
cl.object ← object;
cl.loc ← loc;
ForkOps.Fork[LBRegisterPcs, cl];
};
LBRegisterPcs: PROC [data: REF] ~ {
ENABLE UNCAUGHT => GOTO Oops; --ChJ. August 20, 1993 I have no real idea what goes wrong but I want no wedging
cl: REF LBClosure ← NARROW[data];
[] ← lb.atloc[lb, cl.object^, cl.loc];
EXITS Oops => {};
};
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"];
lb ← LB.MakeLB1Client[h, SunRPCAuth.Initiate[]];
EXITS Oops => {};
END;
SessionRenamed: Slate.EventProc = {
found: BOOLEAN;
val: REF;
sr: sessionInfo;
location: ROPE;
l: LIST OF ROPE;
[found, val] ← RefTab.Fetch[sessionTable, session];
sr ← NARROW[val];
IO.PutRope[sr.session.debugLog, "SessionRenamed called\n"];
[] ← NameService.ReexportRPCSun[uid: sr.uid, name: "JoinApp", sp: sr.rpc, prog: JoinApp.JoinAppPrognum, vers: JoinApp.version1, instance: Rope.Concat["Slate:", Slate.SessionName[session]],
appl: CONS[
List.DotCons[sessionIdRope, sr.sessionId],
NIL]
];
l ← sr.locations;
WHILE l # NIL DO
location ← l.first;
l ← l.rest;
RegisterWithLocationBroker[location, sr.session, sr.sessionId];
ENDLOOP;
};
ConnectToLocationBroker[];
Slate.RegisterGlobalEventProc[$NewSession, NewSessionEvent];
Slate.RegisterGlobalEventProc[$SessionRenamed0, SessionRenamed];
END.