PlayNoiseImpl.mesa
Last Edited by: Swinehart, April 28, 1986 2:11:48 pm PDT
DIRECTORY
Atom USING [ GetProp, MakeAtom, PutProp ],
Booting USING [ CallBootingProcs, Deregister, RegisterProcs, CheckpointProc ],
Commander USING [ CommandProc, Register ],
FinchSmarts USING [ PlayNoise ],
Process USING [ Detach, MsecToTicks, Pause ],
UserProfile USING [ Token ]
;
PlayNoiseImpl: CEDAR PROGRAM
IMPORTS
Atom, Booting, Commander, FinchSmarts, Process, UserProfile
= {
reallyBoot: BOOLTRUE;
didOurBest: BOOL;
maxTime: CARDINAL ← 4000;
PlayTheRollbackButton: Booting.CheckpointProc = TRUSTED {
PlayAButton[$rollback];
IF ~reallyBoot THEN rejection ← "Just pretending";
};
PlayAButton: PROC[name: ATOM] = TRUSTED {
didOurBest ← FALSE;
Process.Detach[FORK ReallyPlayAButton[name]];
FOR i: NAT IN [0..100) DO
Process.Pause[Process.MsecToTicks[maxTime/100]];
IF didOurBest THEN EXIT;
ENDLOOP;
};
ReallyPlayAButton: PROC[name: ATOM] = {
[]𡤏inchSmarts.PlayNoise[noiseName: name, wait: TRUE];
didOurBest ← TRUE;
};
Register: PROC [newPlayTheRollbackButton: Booting.CheckpointProc] ~ {
vo: REF=Atom.GetProp[$Interfaces, $PlayTheRollback];
oldPlayTheRollbackButton: REF Booting.CheckpointProc ←
NARROW[vo, REF Booting.CheckpointProc];
IF oldPlayTheRollbackButton # NIL THEN
Booting.Deregister[c: oldPlayTheRollbackButton^, r: NIL, b: oldPlayTheRollbackButton^];
IF newPlayTheRollbackButton = NIL THEN RETURN;
Booting.RegisterProcs[c: PlayTheRollbackButton, r: NIL, b: PlayTheRollbackButton];
Atom.PutProp[$Interfaces, $PlayTheRollback, NEW[Booting.CheckpointProc←PlayTheRollbackButton]];
};
DoNoisyBoot: Commander.CommandProc = {
Register[PlayTheRollbackButton];
};
NoNoisyBoot: Commander.CommandProc = {
Register[NIL];
};
TestNoisyBoot: Commander.CommandProc = {
[]𡤋ooting.CallBootingProcs[];
};
IF Atom.MakeAtom[UserProfile.Token["Finch.NoisyBoot", "FALSE"]] = $TRUE
THEN Register[PlayTheRollbackButton];
Commander.Register["NoisyBoot", DoNoisyBoot, "Pleasant surprise on rollback or boot"];
Commander.Register["TestNoisyBoot", TestNoisyBoot];
Commander.Register["NoNoisyBoot", NoNoisyBoot, "No pleasant surprise on rollback or boot"];
}.