JaMImagerContextsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last change by Bill Paxton, 2-Feb-82 12:50:27
Last changed by Rick Beach, July 1, 1982 11:29 am
Last changed by Ken Pier, March 22, 1983 4:36 pm
Last Edited by: Stone, January 30, 1984 1:26:03 pm PST
Tim Diebert: July 18, 1985 3:27:27 pm PDT
DIRECTORY
Imager USING [Context],
JaMIPrivate,
JaMImagerContexts;
JaMIContextsImpl: CEDAR MONITOR
IMPORTS
EXPORTS JaMIPrivate, JaMImagerContexts =
BEGIN OPEN JaMImagerContexts;
InfoList: TYPE = REF InfoListRec;
InfoListRec: TYPE = RECORD [info: Info, rest: InfoList];
list: InfoList← NIL;
State: TYPE = JaMIPrivate.State;
Info: TYPE = JaMIPrivate.Info;
NotFound: PUBLIC SIGNAL = CODE;
CreateInfo: PUBLIC ENTRY PROC [state: State] RETURNS [info: Info] = {
ENABLE UNWIND => NULL;
info ← NEW[JaMIPrivate.InfoRec];
info.state ← state;
FOR l:InfoList ← list, l.rest UNTIL l=NIL DO
IF l.info.state=state THEN ERROR;
ENDLOOP;
list ← NEW[InfoListRec ← [info,list]] };
ForgetInfo: PUBLIC ENTRY PROC [state: State] = {
ENABLE UNWIND => NULL;
pred: InfoList;
IF list=NIL THEN RETURN;
IF list.info.state=state THEN { list ← list.rest; RETURN };
pred ← list;
FOR l:InfoList ← list.rest, l.rest UNTIL l=NIL DO
IF l.info.state=state THEN { pred.rest ← l.rest; RETURN };
pred ← l; ENDLOOP };
GetInfo: PUBLIC ENTRY PROC [state: State] RETURNS [info: Info] = {
ENABLE UNWIND => NULL;
FOR l:InfoList ← list, l.rest UNTIL l=NIL DO
IF l.info.state=state THEN RETURN [l.info];
ENDLOOP;
RETURN [NIL] };
AddContext: PUBLIC ENTRY PROC [state: State, context: Context, callMe: CallMe, name: ATOM, enabled: BOOLEANTRUE] = {
ENABLE UNWIND => NULL;
end,new: JaMImagerContexts.DCList ← NIL;
found: BOOLEANFALSE;
FOR l:InfoList ← list, l.rest UNTIL l=NIL DO
IF l.info.state=state THEN {
FOR dl: JaMImagerContexts.DCList ← l.info.dcList, dl.next UNTIL dl=NIL DO
IF dl.name=name THEN {
dl.callMe �llMe; dl.dc ← context;
dl.enabled ← enabled;
found ← TRUE;
};
end ← dl;
ENDLOOP;
IF ~found THEN new ← NEW[JaMImagerContexts.DCRec ←
[next: NIL, callMe: callMe, dc: context, enabled: enabled, name: name]];
IF end=NIL THEN l.info.dcList ← new ELSE end.next ← new;
RETURN};
ENDLOOP;
};
RemoveContext: PUBLIC ENTRY PROC [state: State, name: ATOM] RETURNS [context: Imager.Context]= {
ENABLE UNWIND => NULL;
prev: JaMImagerContexts.DCList ← NIL;
FOR l:InfoList ← list, l.rest UNTIL l=NIL DO
IF l.info.state=state THEN
FOR dl: JaMImagerContexts.DCList ← l.info.dcList, dl.next UNTIL dl=NIL DO
IF dl.name=name THEN {
IF prev=NIL THEN l.info.dcList ← dl.next
ELSE prev.next ← dl.next;
RETURN[dl.dc];
};
prev ← dl;
ENDLOOP;
ENDLOOP;
SIGNAL NotFound;
RETURN[NIL];
};
EnableContext: PUBLIC PROC [state: State, name: ATOM] = {
ENABLE UNWIND => NULL;
FOR l:InfoList ← list, l.rest UNTIL l=NIL DO
IF l.info.state=state THEN
FOR dl: JaMImagerContexts.DCList ← l.info.dcList, dl.next UNTIL dl=NIL DO
IF dl.name=name THEN {dl.enabled ← TRUE; RETURN};
ENDLOOP;
ENDLOOP;
SIGNAL NotFound;
};
DisableContext: PUBLIC PROC [state: State, name: ATOM] = {
ENABLE UNWIND => NULL;
FOR l:InfoList ← list, l.rest UNTIL l=NIL DO
IF l.info.state=state THEN
FOR dl: JaMImagerContexts.DCList ← l.info.dcList, dl.next UNTIL dl=NIL DO
IF dl.name=name THEN {dl.enabled ← FALSE; RETURN};
ENDLOOP;
ENDLOOP;
SIGNAL NotFound;
};
ForAllDCs: PUBLIC PROC [list: JaMImagerContexts.DCList, proc: JaMImagerContexts.GProc] = {
FOR l: JaMImagerContexts.DCList ← list, l.next UNTIL l=NIL DO
IF l.enabled THEN proc[l.dc];
ENDLOOP;
};
END...