File: GraphMonitor.mesa, Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Sweetsun Chen, November 26, 1985 6:52:15 pm PST
DIRECTORY
Graph USING [GraphHandle, GraphProc],
GraphOps,
GraphPrivate USING [GraphAtomProc, GraphPlaceProc],
GraphUtil USING [BlinkMsg, HandleNotNil],
Process USING [SecondsToTicks, SetTimeout];
GraphMonitor:
CEDAR
MONITOR
IMPORTS GraphUtil, Process
EXPORTS GraphOps, GraphPrivate = { OPEN Graph, GraphPrivate, GraphUtil;
timeOut: CONDITION;
Lock:
PUBLIC
ENTRY GraphProc = {
ENABLE UNWIND => NULL;
IF HandleNotNil[handle]
THEN {
WHILE handle.locked DO WAIT handle.unlocked; ENDLOOP;
handle.locked ← TRUE;
};
}; -- Lock
Unlock:
PUBLIC
ENTRY GraphProc = {
ENABLE UNWIND => NULL;
IF HandleNotNil[handle]
THEN {
handle.locked ← FALSE;
BROADCAST handle.unlocked;
};
}; -- Unlock
IsLocked:
PUBLIC
ENTRY
PROC [handle: GraphHandle ←
NIL]
RETURNS [
BOOL] = {
ENABLE UNWIND => NULL;
IF handle = NIL THEN RETURN[FALSE]
ELSE RETURN[handle.locked];
}; -- IsLocked
CallWithLock:
PUBLIC
PROC [handle: GraphHandle ←
NIL, proc: GraphProc] = {
IF HandleNotNil[handle]
AND proc #
NIL
THEN {
ENABLE UNWIND => Unlock[handle];
Lock[handle];
proc[handle];
Unlock[handle];
};
}; -- CallWithLock
LockedPlaceProc:
PUBLIC
PROC [handle: GraphHandle ←
NIL, sx, sy:
INTEGER ← 0, proc: GraphPlaceProc ←
NIL] = {
lockedProc: GraphProc = {proc[handle, sx, sy]};
CallWithLock[handle, lockedProc];
}; -- LockedPlaceProc
LockedAtomProc:
PUBLIC
PROC [handle: GraphHandle ←
NIL, atom:
ATOM, proc: GraphAtomProc ←
NIL] = {
lockedProc: GraphProc = {proc[handle, atom]};
CallWithLock[handle, lockedProc];
}; -- LockedAtomProc
Wait:
PUBLIC
ENTRY
PROC = {
-- wait a second.
ENABLE UNWIND => NULL;
WAIT timeOut;
};
UserEditAllowed:
PUBLIC
ENTRY
PROC [handle: GraphHandle ←
NIL]
RETURNS [
BOOL] = {
ENABLE UNWIND => NULL;
IF HandleNotNil[handle]
THEN {
OPEN handle;
IF userEditAllowed THEN RETURN [TRUE]
ELSE {
BlinkMsg["Graph is currently controlled by a program. Please wait till it finishes to do this."];
RETURN [FALSE];
};
}
ELSE RETURN [FALSE];
}; -- UserEditAllowed
Init:
PROC =
TRUSTED {
Process.SetTimeout[@timeOut, Process.SecondsToTicks[1]];
};
Init[];
}.
CHANGE
LOG.
SChen, create at October 9, 1985 6:46:56 pm PDT.