NewLarkVFSImpl.mesa
Last edit: L. Stewart, January 3, 1984 11:09 am
DIRECTORY
IO,
Jukebox USING [CloseTune, CreateTune, Error, FindJukebox, Handle, OpenJukebox, Tune],
Lark,
NewLark,
PrincOpsUtils USING [IsBound],
PupDefs USING [MsToTocks, PupSocketDestroy, PupSocketMake],
Rope USING [ROPE],
VoiceStream USING [AddPiece, Close, Open, SetSocket, wholeTune];
NewLarkVFSImpl: CEDAR MONITOR
IMPORTS IO, Jukebox, PrincOpsUtils, PupDefs, VoiceStream
EXPORTS NewLark
= BEGIN
jukeOpen: BOOLFALSE;
jukebox: Jukebox.Handle ← NIL;
InitializeJukeBox: PROCEDURE = TRUSTED {
jukeboxName: Rope.ROPE = "Test.Jukebox";
Initialize anything that has to be set up on the VFS side.
haveJuke: BOOLTRUE;
IF NOT PrincOpsUtils.IsBound[Jukebox.FindJukebox] THEN RETURN;
IF (jukebox ←Jukebox.FindJukebox[jukeboxName]) = NIL THEN {
jukebox ← Jukebox.OpenJukebox[jukeboxName ! Jukebox.Error => { CONTINUE; }];
};
jukeOpen ← jukebox # NIL;
};
OpenVFS: PUBLIC NewLark.BProc = TRUSTED {
IF NOT jukeOpen THEN InitializeJukeBox[];
IF NOT jukeOpen THEN RETURN;
self.out.PutF["VFS Connect[[%b, %b]\n", IO.int[self.rx1.remoteSocket.net], IO.int[self.rx1.remoteSocket.host]];
self.socket ← PupDefs.PupSocketMake[
local: self.rx1.remoteSocket.socket,
remote: self.rx1.localSocket,
ticks: PupDefs.MsToTocks[100]];
self.tx3 ← NEW[Lark.ConnectionSpecRec];
self.tx3.protocol ← Lark.Protocol[interactive];
self.tx3.encoding ← Lark.Encoding[muLaw];
self.tx3.blankA ← 0;
self.tx3.blankB ← 0;
self.tx3.blankC ← 0;
self.tx3.buffer ← in1;
self.tx3.keyIndex ← 0;
self.tx3.localSocket ← self.rx1.localSocket;
self.tx3.remoteSocket ← self.socket.getLocalAddress[];
self.stream ← VoiceStream.Open[jukebox];
VoiceStream.SetSocket[socket: self.socket, handle: self.stream];
};
CloseVFS: PUBLIC NewLark.BProc = TRUSTED {
IF NOT jukeOpen THEN RETURN;
IF self.stream#NIL THEN VoiceStream.Close[self.stream];
self.stream ← NIL;
IF self.socket#NIL THEN PupDefs.PupSocketDestroy[self.socket];
self.socket ← NIL;
};
SetInterval: ENTRY PROC[ self: NewLark.LarkHandle, utterance: INT, record: BOOL, queueIt: BOOLEAN, nBytes: INT ← VoiceStream.wholeTune] RETURNS [actualUtterance: INT] = TRUSTED {
ENABLE UNWIND=>NULL;
tune: Jukebox.Tune;
IF NOT jukeOpen THEN RETURN;
IF utterance = -1 THEN
IF record THEN {
tune ← Jukebox.CreateTune[jukebox, -1];
utterance ← tune.tuneId;
Jukebox.CloseTune[jukebox, tune];
}
ELSE RETURN;
VoiceStream.AddPiece[
handle: self.stream,
tuneId: utterance,
firstByte: 0,
nBytes: nBytes,
create: record,
playback: NOT record,
keyIndex: 0,
flush: NOT queueIt ];
RETURN[utterance];
};
Playback: PUBLIC NewLark.PlaybackProc = {
[] ← SetInterval[ self: self, utterance: message, record: FALSE, queueIt: queue ];
};
Record: PUBLIC NewLark.RecordProc = {
message ← SetInterval[ self: self, utterance: -1, record: TRUE, queueIt: FALSE, nBytes: seconds * 8000 ];
};
END.