File: Nuthatch.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Swinehart, October 17, 1985 12:19:08 pm PDT
Created by: Lia on August 31, 1983
Last Edited by: Lia, September 30, 1983 11:16 am
DIRECTORY
GVBasics USING [RName],
IO USING [STREAM],
Rope USING [ROPE],
BasicTime USING [GMT, nullGMT],
Thrush USING [EncryptionKey, nullKey, Tune, VoiceInterval];
Nuthatch: CEDAR DEFINITIONS =
BEGIN
updateProcess: PROCESS;
Tune: TYPE = Thrush.Tune;
VoiceFileID: TYPE = Rope.ROPE;
IDType: TYPE = Rope.ROPE;
ID: TYPE = Rope.ROPE;
EncryptionKey: TYPE = Thrush.EncryptionKey;
VoiceInterval: TYPE = Thrush.VoiceInterval;
NuthatchUserHandle: TYPE = REF NuthatchUserRec; -- a REF to the data for a particular instance of a nuthatch client; multiple instances can be created.
LogEntryType: {Create, MakeRefEntry, Incr, Decr, DeleteRefEntry};
NuthatchUserRec: TYPE = RECORD [  -- the data for a particular tool instance
logStream: IO.STREAMNIL,   -- handle for the enclosing container
userName: GVBasics.RName←NIL,  -- current status line
updateProcess: PROCESS,    -- the process that updates the DB from this user's log
refIDType: Rope.ROPENIL,  -- the user's type for each ID associated with a voice file
logFileName: Rope.ROPENIL, -- log file name --
inUse: BOOLFALSE,
doneUsing: CONDITION,
-- info for playback of recently-recorded tune
tune: Nuthatch.Tune𡤀,  -- playback Tune
defaultType: Rope.ROPENIL,
samples: INT𡤀,
startSample: INT𡤀,
key: EncryptionKey←Thrush.nullKey,
logReadPoint: INT𡤀 -- read point in log --
];
PD: TYPE = RECORD [
transactionOpen: BOOLFALSE,
reportLogOut: BOOLFALSE,
reportLogIn: BOOLFALSE,
buildMsgInfoIndices: BOOLTRUE,
buildInterestIndices: BOOLTRUE
];
pd: REF PD;
InitializeNuthatch: PROC[
userName: GVBasics.RName←NIL, 
logFileName: Rope.ROPENIL,
RefIDType: Rope.ROPENIL, close: BOOLTRUE] RETURNS [success: BOOLTRUE, nuthatchUserHandle: NuthatchUserHandle];
InitializeNuthatch verifies that the nuthatch database is around and usable, and then looks for the user's log file. In nuthatchUserHandle, InitializeNuthatch initializes the logstream as the current log stream, userName as the current user, RefIDType as the current ID type for voice messages, and updateProcess as the identifier of the process that updates the database from the user's log.
CatalogVoiceFile: PROC[
nuthatchUserHandle: NuthatchUserHandle,
creator: GVBasics.RName, get this from current user name --
voiceFileID: VoiceFileID,
tuneNumber: INT,
recordedTime: BasicTime.GMT,
referenceCount: INT← 0, 
samples: INT← 0,    
startingSample: INT← 0,  
encryptionKey: EncryptionKey← NULL,  
close: BOOLTRUE,
time: BasicTime.GMT,
type: Rope.ROPE
];
Sets up a new directory entry for a voice file if none exists, or updates the information about an old entry. --
MakeInterestEntry: PROC[
nuthatchUserHandle: NuthatchUserHandle,
voiceFileID: VoiceFileID← NIL,
refIDType: Rope.ROPE← NIL, find this out from the user handle --
refID: Rope.ROPENIL,
close: BOOLTRUE,
time: BasicTime.GMT�sicTime.nullGMT
] ;
Writes a log entry to create an entry in the InterestList relation for this voice file, associating the RefID with the voiceFileID.
AddInterest: PROC[
nuthatchUserHandle: NuthatchUserHandle,
voiceFileID: VoiceFileID ← NIL, --optional --
refIDType: Rope.ROPE← NIL, find this out from the user handle --
refID: Rope.ROPENIL,
close: BOOLTRUE,
time: BasicTime.GMT�sicTime.nullGMT
] ;  -- Writes a log entry to increment the reference count for this voice file. If the voice message does not have an entry in the database, ignore it (can't tell till DB update time if that's so.) Either voiceFileID or RefID must be non-NIL.
LoseInterest: PROC[
nuthatchUserHandle: NuthatchUserHandle,
voiceFileID: VoiceFileID ← NIL, --optional --
refIDType: Rope.ROPE← NIL, find this out from the user handle --
refID: Rope.ROPENIL,
close: BOOL←TRUE,
time: BasicTime.GMT�sicTime.nullGMT
] ;
Writes a log entry to decrement the reference count for this voice file. If the database has no record of this message containing voice, that's OK; it will be ignored. (Happens after doing an expunge in Walnut, for example.)
RemoveInterestEntry: PROC[
nuthatchUserHandle: NuthatchUserHandle,
voiceFileID: VoiceFileID ← NIL, --optional --
refIDType: Rope.ROPE← NIL, find this out from the user handle --
refID: Rope.ROPENIL,
close: BOOLTRUE,
time: BasicTime.GMT�sicTime.nullGMT
] ;
Writes a log entry to remove the entry in the InterestList relation for this voice file.
FinishUpdates: PROC[
nuthatchUserHandle: NuthatchUserHandle
] ;
If updates were called with close=FALSE, update log read points and close transaction.
GetFileID: PROC[
ID: Rope.ROPE, nuthatchUserHandle: Nuthatch.NuthatchUserHandle, close: BOOLTRUE] RETURNS [voiceFileID: VoiceFileID] ;
Given the user's ID for a voice message, return its voiceFileID. --
Close argument mirrors those in NuthatchDB: FALSE leaves transaction open.
GetTune: PROC[
voiceFileID: VoiceFileID] RETURNS [tune: Tune] ;
Given the voiceFileID for a voice message, return its tune number. --
GetDirectoryEntry: PROC [voiceFileID: VoiceFileID, close: BOOLTRUE] RETURNS [
tuneNumber: Nuthatch.Tune← -1,
recordTime: BasicTime.GMT�sicTime.nullGMT,
creator: GVBasics.RName← NIL,
samples: INT← -1,
startSample: INT← -1,
expirationDate: BasicTime.GMT�sicTime.nullGMT,
encryptionKey: Nuthatch.EncryptionKey←Thrush.nullKey,
type: Rope.ROPENIL ,
referenceCount: INT← 0,
found: BOOLFALSE];
NHTime: PROC[time: BasicTime.GMT] RETURNS [nhTime: BasicTime.GMT];
currentNUH: NuthatchUserHandle; -- right now, there's just one of them.
END.