WhiteboardDBImpl.mesa
Copyright (C) 1984 by Xerox Corporation. All rights reserved.
Last edited by
Jennifer Widom, August 24, 1984 8:38:52 pm PDT
Donahue, April 15, 1986 3:45:42 pm PST
(Corrected destruction of viewer properties when playing log; simplified CarefullyApply)
(Changed reset to close transaction before doing redisplay so that cached pages aren't used -- this gets the proper stuff redisplayed!)
(Added WBError and changed error handling behavior in the code -- now most of it is in CarefullyApply, where it should have been all along)
Last Edited by: Winkler, December 18, 1984 4:49:16 pm PST
DIRECTORY
Atom,
BasicTime,
Booting,
DB,
DBDefs USING[Entity],
DBIcons,
Nut,
Process,
Rope,
ViewerClasses USING [Viewer, ViewerRec],
ViewerLocks USING [CallUnderWriteLock],
ViewerOps,
ViewerTools,
UserCredentials,
WhiteboardDB,
WhiteboardDBPrivate,
WhiteboardDump,
WhiteboardLoad,
WhiteboardViewers;
WhiteboardDBImpl: CEDAR MONITOR
IMPORTS
BasicTime, Booting, DB, DBIcons, Nut, Process, Rope, ViewerLocks, ViewerOps, ViewerTools, WhiteboardDBPrivate, WhiteboardViewers, WhiteboardDump, WhiteboardLoad
EXPORTS WhiteboardDB =
BEGIN OPEN DB, WhiteboardDBPrivate;
Viewer: TYPE = ViewerClasses.Viewer;
ROPE: TYPE = Rope.ROPE;
WhiteboardLog: TYPE = LIST OF WhiteboardLogEntry;
WhiteboardLogEntry: TYPE = RECORD[action: ATOM, to: Viewer];
Currently action can be one of:
$NewIcon
$NewBox
$Delete
$EditText
$Grow
$Move
$Erase
whiteboard: PUBLIC ATOM ← WhiteboardDBPrivate.wbType;
destroyedList: LIST OF Viewer;
Monitoring database activity
ticksToWait: Process.Ticks ← Process.SecondsToTicks[5*60];
stopped: PUBLIC BOOLFALSE; -- true if the Rollback proc has been executed and the transaction is to remain closed
doingRestart: BOOLFALSE; -- true during the restart process, to keep iconic viewers from being opened
activity: BOOLEANTRUE; -- true if a database operation has been performed recently
WBError: PUBLIC ERROR[reason: ATOM] = CODE; -- the error that may be raised from this interface
WatchDBActivity: PROC[] = {
Don't keep a transaction open too long.
WHILE TRUE DO
Process.Pause[ticksToWait];
CheckConnection[]
ENDLOOP };
CheckConnection: ENTRY PROC[] = {
ENABLE UNWIND => NULL;
aborted: BOOLEANFALSE;
IF stopped THEN RETURN;
IF NOT activity THEN WhiteboardDBPrivate.CloseTransaction[ ];
activity ← FALSE };
Close: PUBLIC ENTRY PROC[] = {
ENABLE UNWIND => NULL;
WhiteboardDBPrivate.CloseTransaction[ ];
stopped ← TRUE };
Routines that read and/or write the database
Display: PUBLIC ENTRY PROC[eName: ROPE, v: Viewer ← NIL] RETURNS [viewer: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
DoDisplay: PROC[] = { viewer ← InternalDisplay[eName, v] };
CarefullyApply[DoDisplay]
END;
InternalDisplay: PROC[eName: ROPE, v: Viewer ← NIL] RETURNS [Viewer] =
BEGIN
locked: BOOLEANFALSE;
wb: Whiteboard = DeclareWhiteboard[eName];
children: ChildSet = Children[wb];
newViewer: BOOLFALSE;
nextChild: WBItem;
child: Viewer;
x, y: INT;
DisplayNoteEntity: PROC[] =
BEGIN
text: ViewerTools.TiogaContents = GetContents[nextChild];
w, h: INT;
[w, h] ← Size[nextChild];
child ← WhiteboardViewers.AddTextBox[v, x, y, w, h, text];
ViewerOps.PaintViewer[child, all]
END;
DisplayIconEntity: PROC[] =
BEGIN
label, icon: ROPE;
[label, icon] ← GetDisplayProps[nextChild];
child ← WhiteboardViewers.AddIcon[v, label, DBIcons.GetIcon[icon, tool], x, y];
END;
DoDisplay: PROC = {
versionNumber: INTEGER;
If v.newVersion then this is a reset and the name and menu are properly set
IF NOT v.newVersion THEN {
v.newVersion ← TRUE;
ViewerOps.PaintViewer[v, caption];
WhiteboardViewers.SetMenu[v];
WhiteboardViewers.SetWBName[v, eName];
};
Must make sure that the grid size is consistent with the current DB contents
BEGIN
gridSize: INT = GetGridSize[wb];
WhiteboardViewers.ResetGrid[v, gridSize]
END;
obtain version information
versionNumber ← GetVersion[wb];
ViewerOps.AddProp[v, $Version, NEW[INTEGER ← versionNumber]];
WHILE (nextChild ← NextChild[children]) # NIL DO
[x, y] ← Position[nextChild];
IF TypeOf[nextChild] = note THEN DisplayNoteEntity[] ELSE DisplayIconEntity[];
StoreEntity[child, DB.EntityInfo[nextChild].name];
ENDLOOP;
v.newVersion ← FALSE;
ViewerOps.PaintViewer[v, caption] };
BEGIN
ENABLE UNWIND => { IF newViewer THEN ViewerOps.DestroyViewer[v] };
IF v = NIL OR v.class.flavor # WhiteboardViewers.wb THEN {
v ← ViewerOps.CreateViewer[flavor: WhiteboardViewers.wb, info: [name: eName, iconic: TRUE]];
newViewer ← TRUE }
ELSE { v.child ← NIL; ViewerOps.PaintViewer[v, client] };
ViewerOps.AddProp[v, $Log, NIL]; -- establish log
[] ← Nut.SetFrozenProperty[v, FALSE];
Nut.SetNutInfo[v, $Whiteboard, "Whiteboard", eName];
ViewerOps.AddProp[v, $Lines, NIL];
ViewerLocks.CallUnderWriteLock[DoDisplay, v];
IF NOT doingRestart AND v.iconic AND NOT v.destroyed THEN ViewerOps.OpenIcon[v];
RETURN[v]
END
END;
Destroy: PUBLIC ENTRY PROC[eName: ROPE] =
BEGIN
ENABLE UNWIND => NULL;
DoDestroy: PROC[] = {
wb: Whiteboard = IF Exists[eName] THEN DeclareWhiteboard[eName] ELSE NIL;
IF WhiteboardDBPrivate.readOnly THEN WBError[$ReadOnly];
IF wb = NIL THEN RETURN ELSE DestroyWhiteboard[wb];
WhiteboardDBPrivate.MarkTransaction[]
};
v: Viewer;
CarefullyApply[DoDestroy];
Check if there's a viewer that needs to be destroyed
v ← ViewerOps.FindViewer[Rope.Cat["Whiteboard: ", eName]];
IF v # NIL THEN ViewerOps.DestroyViewer[v];
END;
New: PUBLIC ENTRY PROC[eName: ROPE] RETURNS[success: BOOL] =
BEGIN
ENABLE UNWIND => NULL;
wbEntity: DBDefs.Entity;
DoNew: PROC[] = {
IF WhiteboardDBPrivate.readOnly THEN WBError[$ReadOnly];
wbEntity ← DeclareWhiteboard[eName];
WhiteboardDBPrivate.MarkTransaction[] };
CarefullyApply[DoNew];
success ← wbEntity # NIL
END;
Reset: PUBLIC ENTRY PROC[wb: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
wb.newVersion ← TRUE;
ViewerOps.PaintViewer[wb, caption];
WhiteboardDBPrivate.CloseTransaction[];
Make sure the viewer gets repainted by setting its version number to nonsense
NARROW[ViewerOps.FetchProp[wb, $Version], REF INTEGER]^ ← -1;
InternalReset[wb];
END;
InternalReset: INTERNAL PROC[wb: Viewer] =
BEGIN
DoRedisplay: PROC[] = {
name: ROPE = GetWBName[wb];
IF WhiteboardDBPrivate.Exists[name] THEN {
wbEntity: Whiteboard = DeclareWhiteboard[name];
version: INTEGER = GetVersion[wbEntity];
IF version # NARROW[ViewerOps.FetchProp[wb, $Version], REF INTEGER]^
THEN [] ← InternalDisplay[name, wb] }
ELSE ViewerOps.DestroyViewer[wb] };
CarefullyApply[DoRedisplay];
END;
Save: PUBLIC ENTRY PROC[wb: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
eventLog: WhiteboardLog = NARROW[ViewerOps.FetchProp[wb, $Log], WhiteboardLog];
versionNumber: INTEGER = NARROW[ViewerOps.FetchProp[wb, $Version], REF INTEGER]^;
name: Rope.ROPE = GetWBName[wb];
DoSave: PROC[] = {
IF WhiteboardDBPrivate.readOnly THEN WBError[$ReadOnly];
BEGIN
wbEntity: Whiteboard ← DeclareWhiteboard[name];
IF GetVersion[wbEntity] # versionNumber THEN WBError[$WrongVersion];
FOR log: WhiteboardLog ← eventLog, log.rest UNTIL log = NIL DO
SELECT log.first.action FROM
$NewIcon => DoNewIcon[wbEntity, log.first.to];
$NewBox => DoNewBox[wbEntity, log.first.to];
$Delete => DoDelete[log.first.to];
$EditText => DoEditText[log.first.to];
$Grow => DoGrow[log.first.to];
$Move => DoMove[log.first.to];
$Erase => wbEntity ← DoErase[wbEntity];
Erase works by destroying the whiteboard and creating a new one
ENDCASE;
ENDLOOP;
SetGridSize[wbEntity, WhiteboardViewers.GetGrid[wb]];
SetVersion[wbEntity, versionNumber + 1];
SetCreateDate[wbEntity, BasicTime.Now[]];
WhiteboardDBPrivate.MarkTransaction[]
END };
[] ← wb.class.scroll[wb, thumb, 0];
CarefullyApply[DoSave];
Now it's safe to throw away any destroyed viewers (ones on the destroyedList); they either participated in a committed transaction (and thus can have their properties released) or they no longer exist on the whiteboard in any case
DestroyViewerList[];
[] ← InternalDisplay[name, wb]
END;
DestroyViewerList: PROC[] = {
FOR l: LIST OF Viewer ← destroyedList, l.rest UNTIL l = NIL DO
l.first.props ← NIL;
l.first.data ← NIL
ENDLOOP;
destroyedList ← NIL };
GetWBName: PUBLIC PROC[wb: Viewer] RETURNS [name: ROPE] =
BEGIN
domain: ROPE;
[domain ~ domain, entity ~ name] ← Nut.GetNutInfo[wb];
IF Rope.Equal[domain, "Whiteboard"] THEN RETURN;
RETURN[NIL]
END;
WBExists: PUBLIC ENTRY PROC[eName: ROPE] RETURNS [alreadyExists: BOOL] =
BEGIN
ENABLE UNWIND => NULL;
DoCheck: PROC[] = {alreadyExists ← Exists[eName]};
CarefullyApply[DoCheck];
END;
GetCreateDate: PUBLIC ENTRY PROC[eName: ROPE] RETURNS [date: BasicTime.GMT] =
BEGIN
ENABLE UNWIND => NULL;
DoGet: PROC[] = {
wb: Whiteboard = DeclareWhiteboard[eName];
date ← WhiteboardDBPrivate.GetCreateDate[wb]};
CarefullyApply[DoGet];
END;
CopyWB: PUBLIC ENTRY PROC[from, to: ROPE] =
BEGIN
ENABLE UNWIND => NULL;
DoCopy: INTERNAL PROC[] = {
IF WhiteboardDBPrivate.readOnly THEN WBError[$ReadOnly];
BEGIN
fromWB: Whiteboard = DeclareWhiteboard[from];
toWB: Whiteboard = DeclareWhiteboard[to];
children: ChildSet = Children[fromWB];
FOR child: WBItem ← NextChild[children], NextChild[children] UNTIL child = NIL DO
IF TypeOf[child] = note THEN CopyNote[toWB, child]
ELSE CopyIcon[toWB, child]
ENDLOOP;
Commit the transaction
WhiteboardDBPrivate.MarkTransaction[]
END };
CarefullyApply[DoCopy]
END;
CopyNote: INTERNAL PROC[to: Whiteboard, note: WBNote] =
BEGIN
text: ViewerTools.TiogaContents = GetContents[note];
x, y: INT;
w, h: INT;
[x, y] ← Position[note];
[w, h] ← Size[note];
[] ← NewNote[to, x, y, w, h, text]
END;
CopyIcon: INTERNAL PROC[to: Whiteboard, icon: WBIcon] =
BEGIN
x, y: INT;
name, label, iconName, argument: ROPE;
type: ATOM;
[x, y] ← Position[icon];
[label, iconName] ← GetDisplayProps[icon];
[name, type] ← WhiteboardDBPrivate.GetIconProps[icon];
argument ← WhiteboardDBPrivate.GetToolArgument[icon];
[] ← WhiteboardDBPrivate.NewIcon[to, x, y, name, label, iconName, argument, type]
END;
GetChildren: PUBLIC ENTRY PROC[eName: ROPENIL] RETURNS [wbList: LIST OF ROPE] =
BEGIN
ENABLE UNWIND => NULL;
EnumWBs: PROC[] = {
entityList: LIST OF WBItem;
children: ChildSet = Children[DeclareWhiteboard[eName], TRUE];
FOR child: WBItem ← NextChild[children], NextChild[children] UNTIL child = NIL DO
entityList ← CONS[child, entityList];
ENDLOOP;
FOR eL: LIST OF Whiteboard ← entityList, eL.rest UNTIL eL = NIL DO
wbList ← CONS[WhiteboardDBPrivate.GetIconProps[eL.first].name, wbList];
ENDLOOP };
CarefullyApply[EnumWBs]
END;
Enumerate: PUBLIC ENTRY PROC[pattern: ROPENIL] RETURNS [wbList: LIST OF ROPE] =
BEGIN
ENABLE UNWIND => NULL;
EnumWBs: PROC[] = {
entityList: LIST OF Whiteboard = WhiteboardDBPrivate.Enumerate[pattern];
FOR eL: LIST OF Whiteboard ← entityList, eL.rest UNTIL eL = NIL DO
wbList ← CONS[DB.EntityInfo[eL.first].name, wbList];
ENDLOOP };
CarefullyApply[EnumWBs]
END;
Dump: PUBLIC ENTRY PROC[to: ROPE] = {
ENABLE UNWIND => NULL;
DoDump: INTERNAL PROC[] = {WhiteboardDump.DumpToFile[to] };
CarefullyApply[DoDump] };
Load: PUBLIC ENTRY PROC[from: ROPE] = {
ENABLE UNWIND => NULL;
DoLoad: INTERNAL PROC[] = {
IF WhiteboardDBPrivate.readOnly THEN WBError[$ReadOnly];
WhiteboardLoad.LoadFromFile[from] };
CarefullyApply[DoLoad] };
Routines that log whiteboard events w/o accessing the database
NewIcon: PUBLIC ENTRY PROC[wb: Viewer, x, y: INT, name: ROPE, type: ATOM, icon: ROPE, label: ROPENIL, argument: ROPENIL] RETURNS [new: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
IF Rope.Equal[label, ""] THEN label ← argument;
new ← WhiteboardViewers.AddIcon[wb, IF Rope.Equal[label, ""] THEN name ELSE label, DBIcons.GetIcon[icon, tool], x, y];
ViewerOps.AddProp[new, $EntityName, name];
ViewerOps.AddProp[new, $IconLabel, label];
ViewerOps.AddProp[new, $IconType, type];
ViewerOps.AddProp[new, $IconIcon, icon];
ViewerOps.AddProp[new, $IconArgument, argument];
LogAction[wb, $NewIcon, new];
ViewerOps.PaintViewer[wb, caption];
END;
NewBox: PUBLIC ENTRY PROC[wb: Viewer, x, y, w, h: INT, contents: ViewerTools.TiogaContents ← NIL] RETURNS [new: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
new ← WhiteboardViewers.AddTextBox[wb, x, y, w, h, contents];
LogAction[wb, $NewBox, new];
ViewerOps.PaintViewer[new, all];
ViewerOps.PaintViewer[wb, caption];
END;
Delete: PUBLIC ENTRY PROC[child: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
logIt: BOOL = NOT WhiteboardViewers.DontLog[child];
props: Atom.PropList = child.props;
data: REF ANY = child.data;
Make sure the properties and clientdata don't go away just yet
IF logIt THEN LogAction[child.parent, $Delete, child];
ViewerOps.DestroyViewer[viewer: child, paint: FALSE];
IF logIt THEN {child.props ← props; child.data ← data}
END;
EditText: PUBLIC ENTRY PROC[box: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
LogAction[box.parent, $EditText, box];
END;
Grow: PUBLIC ENTRY PROC[box: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
LogAction[box.parent, $Grow, box];
END;
Move: PUBLIC ENTRY PROC[child: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
IF NOT WhiteboardViewers.DontLog[child] THEN
LogAction[child.parent, $Move, child];
END;
Erase: PUBLIC ENTRY PROC[wb: Viewer] =
BEGIN
ENABLE UNWIND => NULL;
LogAction[wb, $Erase, wb];
wb.child ← NIL; -- flushes viewer
ViewerOps.PaintViewer[wb, client];
END;
LogAction: PROC[wb: Viewer, action: ATOM, v: Viewer] =
BEGIN
log: WhiteboardLog ← NARROW[ViewerOps.FetchProp[wb, $Log], WhiteboardLog];
AddToEnd: PROC[log: WhiteboardLog, entry: WhiteboardLogEntry]
RETURNS[WhiteboardLog] = {
IF log = NIL THEN RETURN[LIST[entry]]
ELSE RETURN[CONS[log.first, AddToEnd[log.rest, entry]]] };
log ← AddToEnd[log, [action, v]];
ViewerOps.AddProp[wb, $Log, log];
END;
Playing the log
DoNewIcon: PROC[wb: Whiteboard, child: Viewer] =
Commit a $NewIcon action
BEGIN
name: ROPE = NARROW[ViewerOps.FetchProp[child, $EntityName], ROPE];
label: ROPE = NARROW[ViewerOps.FetchProp[child, $IconLabel], ROPE];
type: ATOM = NARROW[ViewerOps.FetchProp[child, $IconType], ATOM];
icon: ROPE = NARROW[ViewerOps.FetchProp[child, $IconIcon], ROPE];
argument: ROPE = NARROW[ViewerOps.FetchProp[child, $IconArgument], ROPE];
newIcon: WBItem = WhiteboardDBPrivate.NewIcon[wb, child.wx, child.wy, name, label, icon, argument, type];
StoreEntity[child, DB.EntityInfo[newIcon].name] -- in case subsequent operations in the log reference this viewer (eg., to move it)
END;
DoNewBox: PROC[wb: Whiteboard, box: Viewer] =
Commit a $NewBox action
BEGIN
text: ViewerTools.TiogaContents = ViewerTools.GetTiogaContents[box];
newNote: WBItem = WhiteboardDBPrivate.NewNote[wb, box.wx, box.wy, box.ww, box.wh, text];
StoreEntity[box, DB.EntityInfo[newNote].name] -- in case subsequent operations in the log reference this viewer (eg., to move it)
END;
DoDelete: PROC[child: Viewer] =
Commit a $Delete action
BEGIN
entity: WBItem = FetchEntity[child];
WhiteboardDBPrivate.Destroy[entity];
Save the child on the destroyedList so that you can release the props and data if the transaction succeeds
destroyedList ← CONS[child, destroyedList];
END;
DoEditText: PROC[box: Viewer] =
Commit an $EditText action
BEGIN
note: WBNote = FetchEntity[box];
text: ViewerTools.TiogaContents = ViewerTools.GetTiogaContents[box];
SetContents[note, text]
END;
DoGrow: PROC[box: Viewer] =
Commit a $Grow action
BEGIN
note: WBNote = FetchEntity[box];
WhiteboardDBPrivate.Grow[note, box.ww, box.wh]
END;
DoMove: PROC[child: Viewer] =
Commit a $Move action
BEGIN
entity: WBItem = FetchEntity[child];
WhiteboardDBPrivate.Move[entity, child.wx, child.wy]
END;
DoErase: PROC[wb: Whiteboard] RETURNS[newWB: Whiteboard] =
Commit an $Erase action
BEGIN
name: ROPE = NameOf[wb];
WhiteboardDBPrivate.DestroyWhiteboard[wb];
newWB ← DeclareWhiteboard[name]
END;
Support routines
FetchEntity: PUBLIC PROC[v: Viewer] RETURNS[e: WBItem] = {
name: ROPE = NARROW[ViewerOps.FetchProp[v, $Entity], ROPE];
IF name = NIL THEN RETURN[NIL];
SELECT v.class.flavor FROM
WhiteboardViewers.text => e ← FetchWBItem[name, note];
WhiteboardViewers.icon => e ← FetchWBItem[name, icon];
ENDCASE => e ← NIL };
StoreEntity: PUBLIC PROC[v: Viewer, name: ROPE] = {
ViewerOps.AddProp[v, $Entity, name ] };
Tool manipulation
GetIconProps: PUBLIC ENTRY PROC[wbIcon: Viewer] RETURNS[ name: ROPE, type: ATOM ] = {
ENABLE UNWIND => NULL;
DoGet: PROC[] = {
iconEntity: WBItem = FetchEntity[wbIcon];
[name, type] ← WhiteboardDBPrivate.GetIconProps[iconEntity] };
name ← NARROW[ViewerOps.FetchProp[wbIcon, $EntityName]];
IF name # NIL THEN
type ← NARROW[ViewerOps.FetchProp[wbIcon, $IconType]]
ELSE CarefullyApply[DoGet] };
GetToolArgument: PUBLIC ENTRY PROC[wbIcon: Viewer] RETURNS[ argument: ROPE] = {
ENABLE UNWIND => NULL;
DoGet: PROC[] = {
iconEntity: WBIcon = FetchEntity[wbIcon];
If the entity name is NIL, then don't bother looking in the database for an argument
IF iconEntity = NIL THEN {argument ← NIL; RETURN};
argument ← WhiteboardDBPrivate.GetToolArgument[iconEntity] };
argument ← NARROW[ViewerOps.FetchProp[wbIcon, $IconArgument]];
IF argument = NIL THEN CarefullyApply[DoGet];
ViewerOps.AddProp[wbIcon, $IconArgument, argument] };
Database initialization
EstablishWhiteboardDB: PUBLIC ENTRY PROC[DBFile: ROPENIL] = {
Sets newWhiteboardDB to DBFile (if a whiteboard DB was previously opened and the argument was NIL, then remember the previous DB file); also throws away old viewers on previous DB
ENABLE UNWIND => NULL;
IF DBFile = NIL THEN {
IF WhiteboardDBPrivate.WBSegment # NIL THEN {
Reopening a previously opened database
InternalResetViewers[destroy: FALSE];
stopped ← FALSE }
ELSE { stopped ← TRUE; WBError[$NoDatabaseOpen] };
RETURN };
Switching databases
IF NOT Rope.Equal[DBFile, WhiteboardDBPrivate.WBSegment, FALSE] THEN InternalResetViewers[TRUE];
IF WhiteboardDBPrivate.Initialize[DBFile].serverDown THEN ERROR WBError[$ServerDown];
stopped ← FALSE
};
InternalResetViewers: INTERNAL PROC[destroy: BOOL] = {
IF destroy THEN {
DestroyProc: ViewerOps.EnumProc = {
IF v.class.flavor = $Whiteboard THEN ViewerOps.DestroyViewer[v];
RETURN[TRUE] };
aborted: BOOLFALSE;
Close transaction if there's one open
WhiteboardDBPrivate.CloseTransaction[];
Destroy all Whiteboard viewers
ViewerOps.EnumerateViewers[enum: DestroyProc] }
ELSE {
ResetProc: INTERNAL ViewerOps.EnumProc = {
Leave edited or dead whiteboards alone!!
IF v.class.flavor = $Whiteboard AND NOT v.newVersion AND NOT v.destroyed
THEN InternalReset[v];
RETURN[TRUE] };
doingRestart ← TRUE;
ViewerOps.EnumerateViewers[enum: ResetProc];
The enumeration will fail and stop if the reset fails; this also sets the returned value of success
doingRestart ← FALSE } };
CarefullyApply: INTERNAL PROC [proc: PROC[]] ~ {
outcome: {aborted, failure, error, normal} ← normal;
BEGIN
ENABLE BEGIN
DB.Error => {outcome ← error; CONTINUE};
DB.Failure => {outcome ← failure; CONTINUE};
DB.Aborted => {outcome ← aborted; CONTINUE};
END;
IF stopped THEN RETURN; -- don't bother trying to do the operation
activity ← TRUE;
BEGIN
ENABLE DB.Aborted => { outcome ← aborted; CONTINUE };
WhiteboardDBPrivate.OpenTransaction[];
proc[]
END;
IF outcome = normal THEN RETURN; -- no aborted occurred
WhiteboardDBPrivate.AbortTransaction[];
WhiteboardDBPrivate.OpenTransaction[];
proc[]; -- don't bother trying to restart here --
END;
IF outcome = normal THEN RETURN;
WhiteboardDBPrivate.AbortTransaction[];
IF outcome = error THEN ERROR WBError[$InternalError];
IF outcome = failure THEN ERROR WBError[$ServerDown];
ERROR WBError[$TransactionAbort]
};
CloseWB: ENTRY Booting.CheckpointProc = {
ENABLE UNWIND => NULL;
WhiteboardDBPrivate.CloseTransaction[];
stopped ← TRUE };
OpenUp: Booting.RollbackProc = { DB.Initialize[nCachePages: 256] };
NewUserReset: ENTRY UserCredentials.CredentialsChangeProc = {
ENABLE UNWIND => NULL;
DestroyProc: ViewerOps.EnumProc = {
IF v.class.flavor = $Whiteboard THEN ViewerOps.DestroyViewer[v];
RETURN[TRUE] };
Close transaction if there's one open
WhiteboardDBPrivate.CloseTransaction[];
Destroy all whiteboard viewers
ViewerOps.EnumerateViewers[enum: DestroyProc] };
Initialization
TRUSTED {
Process.Detach[FORK WatchDBActivity[]];
Booting.RegisterProcs[c: CloseWB, r: OpenUp] }
END...