FinchSmartsImpl.mesa
Copyright © 1984, 1986 by Xerox Corporation. All rights reserved.
Last Edited by: Swinehart, August 14, 1986 11:32:31 pm PDT
Polle Zellweger (PTZ) October 24, 1985 4:55:57 pm PDT
DIRECTORY
Commander USING [ CommandProc, Register ],
FinchSmarts,
GList USING [ Member, Nconc ],
IO,
LarkFeepRpcControl USING [ Feep, ImportNewInterface ],
LupineRuntime USING [ BindingError ],
NamesGV USING [ GVGetAttribute, GVSetAttribute ],
NamesGVImpExp USING [ GVImport, UnGVImport ],
NamesRPC USING [ StartConversation ],
Nice,
PrincOpsUtils USING [ IsBound ],
Process USING [ SecondsToTicks, SetTimeout, Ticks ],
PupSocket USING [ GetUniqueID ],
RefID USING [ ID ],
RefQ USING [ Dequeue, Enqueue, Map, MapType, Queue ],
Rope,
RPC USING [ AuthenticateFailed, CallFailed, EncryptionKey, ImportFailed, VersionRange ],
ThParty USING [ Advance, Alert, ConversationInfo, CreateConversation, Deregister, Enable, GetConversationInfo, GetKeyTable, GetParty, GetPartyFromNumber, GetPartyInfo, LookupServiceInterface, Register, RegisterKey, Unvisit, Visit ],
ThPartyRpcControl,
Thrush USING[
ActionReport, ConversationID, ConvEvent, Credentials, EncryptionKey, InterfaceSpec, NB, none, notReallyInConv, nullConvID, nullID, nullKey, PartyID, Reason, ROPE, SHHH, SmartsID, StateInConv, unencrypted ],
ThSmarts,
ThSmartsRpcControl,
ThVersions USING [ GetThrushVR, FinchVersion, FinchVR ],
UserProfile USING [ Token],
VoiceTemp USING [ IntervalSpec, IntervalSpecBody, IntervalSpecs, nullTuneID, TuneID, VoiceTime ],
VoiceTempRpcControl USING [ DescribeInterval, ImportNewInterface, Play, Record, Stop ],
VoiceUtils USING [ CurrentPasskey, CurrentRName, InstanceFromNetAddress, MakeRName, NetAddress, NetAddressFromRope, OwnNetAddress, Problem, ProblemFR, Report ]
;
FinchSmartsImpl: CEDAR MONITOR
IMPORTS Commander, IO, FinchSmarts, GList, LarkFeepRpcControl, LupineRuntime, NamesGV, NamesGVImpExp, NamesRPC, Nice, PrincOpsUtils, Process, PupSocket, RefQ, Rope, RPC, ThParty, ThPartyRpcControl, ThSmartsRpcControl, ThVersions, UserProfile, VoiceTempRpcControl, VoiceUtils
EXPORTS FinchSmarts, ThSmarts = {
OPEN IO;
Declarations
ConvDesc: TYPE = FinchSmarts.ConvDesc;
ConversationID: TYPE = Thrush.ConversationID;
nullConvID: ConversationID = Thrush.nullConvID;
FinchInfo: TYPE = FinchSmarts.FinchInfo;
NB: TYPE = Thrush.NB;
none: SHHH = Thrush.none;
nullID: RefID.ID = Thrush.nullID;
PartyID: TYPE = Thrush.PartyID;
ROPE: TYPE = Thrush.ROPE;
SHHH: TYPE = Thrush.SHHH;
SmartsID: TYPE = Thrush.SmartsID;
StateInConv: TYPE = Thrush.StateInConv;
PD: TYPE = RECORD [
doReports: BOOLFALSE,
doNice: BOOLFALSE,
timeoutNoAction: INTEGER ← 30,
timeoutJayConnect: INTEGER ← 1,
noJayTicks: Process.Ticks ← Process.SecondsToTicks[1],
keyDistTicks: Process.Ticks ← Process.SecondsToTicks[10],
encryptionRequested: BOOLEANTRUE,
interfacesAreImported: BOOLEANFALSE,
smartsIsExported: BOOLEANFALSE,
waitsForConnect: NAT𡤆,
queueIt: BOOLFALSE,
finchOn: BOOLEANFALSE,
maxProseLength: INT
];
info: FinchInfo;
pd: REF PDNEW[PD←[]];
Report: PROC[what: ROPE] = {
IF NOT pd.doReports THEN RETURN;
VoiceUtils.Report[what, $Finch];
};
BeNice: PROC[r: REF, d: INT] = {
IF NOT pd.doNice THEN RETURN;
Nice.BeNice[r, d, $Finch, NIL];
};
NconcIntervals: PROC[l1, l2: VoiceTemp.IntervalSpecs] RETURNS [VoiceTemp.IntervalSpecs] = INLINE { RETURN[NARROW[GList.Nconc[l1, l2]]]; };
Supervision
Progress: PUBLIC ENTRY PROC[
shh: SHHH,
convEvent: Thrush.ConvEvent
] = {
ENABLE UNWIND => NULL; -- RestoreInvariant;
Some party has changed state in a conversation we know about (or should).
Two cases:
Our party has changed state in a conversation, whether or not we're going to deal with it (at present, LarkSmarts makes all such decisions)
Another party changed state in a conversation we know about (at present, we don't need to know that; again, LarkSmarts does all the work.) That case is filtered out in Progress, above.
It is our duty to obtain all relevant information about the call when the information becomes available, and to notify any Finch Clients.
IF convEvent.self.partyID = convEvent.other.partyID THEN [] ← NoteNewState[convEvent];
};
Substitution: PUBLIC ENTRY PROC[
shh: SHHH,
convEvent: Thrush.ConvEvent,
oldPartyID: Thrush.PartyID,
newPartyID: Thrush.PartyID
] = {
ENABLE UNWIND => NULL; -- RestoreInvariant;
One party has replaced another (they were or are now in a poacher/poachee relationship) in this conversation, so we need to update our information about the conversation. Same as Progress, except that we clear any indication that we know anything about the present state before noting the new state.
If this notice indicates that our own party is the oldPartyID, we should find a way to inform our ReportConversationState clients that we are no longer involved in this conversation. We should also pull the conv. from our active list. This happens when the same user logs in and runs Finch somewhere else.
cDesc: ConvDesc = GetConv[convEvent.self.convID, FALSE];
IF cDesc#NIL THEN cDesc.numParties ← 0; -- This will force the information update.
[] ← NoteNewState[ convEvent ];
};
ReportAction: PUBLIC ENTRY PROC[
shh: SHHH,
report: Thrush.ActionReport
] = {
ENABLE UNWIND => NULL;
request: REF;
cDesc: ConvDesc ← GetConv[report.self.convID, FALSE];
IF cDesc=NIL THEN { Problem["can't find conversation for report"]; RETURN; };
SELECT report.actionClass FROM
$keyDistribution => { BROADCAST cDesc.keysMightBeDistributed; cDesc.keysDistributed ← TRUE; RETURN; };
$recording, $playback => { -- We expect these, add Prose soon
FOR rqs: VoiceTemp.IntervalSpecs ← cDesc.pendingIntervals, rqs.rest WHILE rqs#NIL DO
IF report.actionID#rqs.first.intID THEN LOOP;
request ← rqs.first;
SELECT report.actionType FROM
Throw away pending intervals that are complete. This includes intervals preceding the one being reported on.
$finished, $flushed => cDesc.pendingIntervals ← rqs.rest; ENDCASE;
EXIT;
ENDLOOP;
};
ENDCASE=> shh ← shh; -- a place to stand during debugging
IF info.ReportRequestState=NIL THEN RETURN;
IF request = NIL THEN { Problem["missing reports"]; RETURN; };
info.ReportRequestState[report, request];
BROADCAST info.stateChange; -- Sometimes callers wait (Ugh!)}
};
Client Functions
CallInfo: TYPE = REF CallInfoBody; -- needed because MBQueue requires a REF
CallInfoBody: TYPE = RECORD [
convID: Thrush.ConversationID,
calledPartyID: Thrush.PartyID←nullID,
reason: Thrush.Reason←NIL,
comment: ROPENIL
];
DisconnectCall: PUBLIC ENTRY PROC[
convID: Thrush.ConversationID,
reason: Thrush.Reason ← $terminating,
comment: ROPENIL] = {
ENABLE UNWIND => NULL; -- RestoreInvariant;
cDesc: ConvDesc; state: StateInConv;
IF NOT(([,cDesc, state]𡤏inchOn[convID]).on) THEN RETURN;
SELECT state FROM
$idle, $neverWas => {
info.ReportConversationState[$convNotActive, NIL, "No conversation to disconnect"];
};
ENDCASE => []←Request[cDesc, $idle, reason, comment];
};
AnswerCall: PUBLIC ENTRY PROC[convID: Thrush.ConversationID] = {
ENABLE UNWIND => NULL; -- RestoreInvariant;
cDesc: ConvDesc; state: StateInConv;
[,cDesc, state]𡤏inchOn[convID];
SELECT state FROM $ringing, $notified => []←Request[cDesc, $active]; ENDCASE;
};
PlaceCall: PUBLIC ENTRY PROC [
convID: Thrush.ConversationID←nullConvID,
rName: ROPE, -- rName or description
number: ROPE, -- telephone number, if present
useNumber: BOOLFALSE
] = {
ENABLE {
UNWIND=>NULL; -- RestoreInvariant;
RPC.CallFailed => { UninitFinchSmarts["Communication Failure"]; CONTINUE; };
};
calledPartyID: PartyID;
nb: NB;
reason: Thrush.Reason ← $notFound;
comment: Rope.ROPENIL;
IF ~useNumber THEN {
[nb, calledPartyID] ←ThParty.GetParty[shh:info.shh, partyID:info.partyID, rName:rName];
SELECT nb FROM $noSuchParty2, $noIdentSupplied => useNumber ← TRUE; ENDCASE;
};
IF useNumber AND number.Length[]>0 THEN
[nb, calledPartyID] ← ThParty.GetPartyFromNumber[
shh: info.shh, partyID: info.partyID, phoneNumber: number, description: rName];
SELECT nb FROM
$success => reason ← NIL; -- reason: NIL, comment: NIL
$noSuchParty2 => NULL; -- reason: $notFound, comment: NIL
$narcissism => comment ← "Attempt to call self rejected on philosophical grounds";
ENDCASE => { info.ReportConversationState[nb, NIL, NIL]; RETURN; };
[--nb, cDesc--]𡤌onnect[calledPartyID, convID, reason, comment];
};
Feep: PUBLIC ENTRY PROC[convID: ConversationID, feepString: ROPE] = {
cDesc: ConvDesc;
nb: Thrush.NB←$success;
state: StateInConv;
IF NOT(([,cDesc, state]𡤏inchOn[convID]).on) OR state#$active THEN nb ← $convNotActive;
IF nb=$success AND cDesc.feepInterface=NIL THEN {
IF cDesc.numParties>1 THEN [nb, cDesc.feepInterfaceSpec] ← ThParty.LookupServiceInterface[
info.shh, cDesc.situation.self, cDesc.partyInfo[1].partyID, "LarkFeep"]
ELSE nb←$noFeepingParty;
IF nb=$success THEN
cDesc.feepInterface ← LarkFeepRpcControl.ImportNewInterface[
interfaceName: cDesc.feepInterfaceSpec.interfaceName,
hostHint: cDesc.feepInterfaceSpec.hostHint!RPC.ImportFailed => CONTINUE
];
};
IF nb=$success THEN nb ← LarkFeepRpcControl.Feep[
interface: cDesc.feepInterface, shhh: info.shh,
serviceID: cDesc.feepInterfaceSpec.serviceID,
convID: cDesc.situation.self.convID, requestingParty: cDesc.situation.self.partyID,
number: feepString, noisy: TRUE, on: 100, off: 80
];
IF nb # $success THEN VoiceUtils.Report["Sorry, was not able to `feep'.", $Finch];
};
PlaybackTune: PUBLIC ENTRY PROC [
convID: Thrush.ConversationID,
intervalSpec: VoiceTemp.IntervalSpec,
key: Thrush.EncryptionKey,
queueIt: BOOLTRUE,
failOK: BOOLFALSE -- playing is optional; leave connection open if tune doesn't exist.
] RETURNS [ started: BOOLFALSE, newConvID: Thrush.ConversationID←Thrush.nullConvID ] = { -- FALSE if failed
ENABLE UNWIND=>NULL;
cDesc: ConvDesc;
nb: NB;
keyIndex: [0..17B];
IF intervalSpec.tuneID<=VoiceTemp.nullTuneID THEN {
info.ReportConversationState[$convNotActive, NIL, "No such tune"]; RETURN; }; -- UGH!
[nb,cDesc]←VoiceConnect[convID];
IF nb#$success THEN RETURN; -- Complain?
newConvID ← cDesc.situation.self.convID;
[nb, keyIndex] ← ThParty.RegisterKey[
shh: info.shh, credentials: cDesc.situation.self, key: key, reportNewKeys: TRUE];
{SELECT nb FROM
$success => NULL;
$newKeys => {
A quandary. I hate these things that wait until something else has happened. Would rather queue up later tasks to do and return. But haven't come up with a general method yet. The problem here is that we don't want to schedule new voice until the encryption keys for it have been distributed. The Register key function will tell everybody about the keys and then tell us that it's told everybody. We wait one time around a timeout for a special condition variable (ugh) and then give up. 
cDesc.keysDistributed ← FALSE;
WAIT cDesc.keysMightBeDistributed;
IF ~cDesc.keysDistributed THEN GOTO Fail;
};
$stateMismatch => ???;
ENDCASE => GOTO Fail;
EXITS Fail => {
IF ~failOK THEN nb ← Request[cDesc, $failed, $error, "Could not encode encryption key"];
RETURN;
}; };
intervalSpec ← NEW[VoiceTemp.IntervalSpecBody ← intervalSpec^];
intervalSpec.keyIndex ← keyIndex;
intervalSpec.intID ← NewID[];
IF (nb←VoiceTempInterface[cDesc]) # $success THEN RETURN; -- sets interface & serviceID
nb ← info.voiceTemp.Play[info.shh, cDesc.situation.self, cDesc.voiceTempID, intervalSpec, queueIt];
started ← nb=$success;
IF ~started THEN RETURN;
cDesc.pendingIntervals ← NconcIntervals[cDesc.pendingIntervals, LIST[intervalSpec]];
};
RecordTune: PUBLIC ENTRY PROC [
convID: Thrush.ConversationID,
useIntervalSpec: VoiceTemp.IntervalSpec←NIL,
useKey: Thrush.EncryptionKey,
queueIt: BOOLFALSE
]
RETURNS[
nb: NB,
intervalSpec: VoiceTemp.IntervalSpec←NIL,
key: Thrush.EncryptionKey← Thrush.nullKey,
newConvID: Thrush.ConversationID←Thrush.nullConvID
] = {
cDesc: ConvDesc;
tuneID: VoiceTemp.TuneID;
[nb,cDesc]←VoiceConnect[convID];
IF nb#$success THEN RETURN; -- Complain?
newConvID ← cDesc.situation.self.convID;
intervalSpec ← NEW[VoiceTemp.IntervalSpecBody ← []];
IF useIntervalSpec#NIL THEN intervalSpec^ ← useIntervalSpec^;
intervalSpec.keyIndex ← 1;
intervalSpec.intID ← NewID[];
IF (nb←VoiceTempInterface[cDesc]) # $success THEN RETURN; -- sets interface & serviceID
[nb, tuneID] ← info.voiceTemp.Record[info.shh, cDesc.situation.self, cDesc.voiceTempID, intervalSpec, queueIt];
IF nb#$success THEN RETURN;
intervalSpec.tuneID ← tuneID;
cDesc.pendingIntervals ← NconcIntervals[cDesc.pendingIntervals, LIST[intervalSpec]];
WHILE cDesc.situation.self.state#idle AND
GList.Member[intervalSpec,cDesc.pendingIntervals] DO
WAIT info.stateChange;
ENDLOOP;
IF cDesc.keyTable=NIL THEN
[nb, cDesc.keyTable] ← ThParty.GetKeyTable[info.shh, cDesc.situation.self];
IF nb=$success THEN RETURN[nb, intervalSpec, cDesc.keyTable[1], newConvID];
};
StopTune: PUBLIC ENTRY PROC [convID: Thrush.ConversationID] = {
ENABLE UNWIND=>NULL;
cDesc: ConvDesc;
IF ([,cDesc]←VoiceConnect[convID]).nb#$success OR cDesc.situation.self.state#$active OR
VoiceTempInterface[cDesc] # $success THEN RETURN;
[] ← info.voiceTemp.Stop[info.shh, cDesc.situation.self, cDesc.voiceTempID];
};
DescribeInterval: PUBLIC ENTRY PROC [intervalSpec: VoiceTemp.IntervalSpec, minSilence: VoiceTemp.VoiceTime𡤁]
RETURNS[nb: NB, length: INT, intervals: VoiceTemp.IntervalSpecs] = {
ENABLE UNWIND=>NULL;
IF (nb←VoiceTempInterface[NIL]) # $success THEN RETURN;
[nb, length, intervals] ← info.voiceTemp.DescribeInterval[shhh: info.shh, targetInterval: intervalSpec, minSilence: minSilence, credentials: [], serviceID: nullID];
};
IdentifyVisitor: PUBLIC ENTRY PROC [visitor: Rope.ROPE] ~ {
nb: NB;
visitingPartyID: PartyID;
[nb, visitingPartyID] ←ThParty.GetParty[shh:info.shh, partyID:info.partyID, rName:visitor];
IF nb#$success THEN RETURN;
nb ← ThParty.Visit[shh: info.shh, visitedParty: info.partyID, visitingParty: visitingPartyID];
IF nb#$success THEN RETURN;
info.visitors ← CONS[visitor, info.visitors];
};
ReleaseVisitor: PUBLIC ENTRY PROC [visitor: Rope.ROPE] ~ {
Don't unvisit unless visitor is in your list. This isn't good enough.
nb: NB;
found: BOOLFALSE;
visitingPartyID: PartyID;
[nb, visitingPartyID] ←ThParty.GetParty[shh:info.shh, partyID:info.partyID, rName:visitor];
FOR v: LIST OF Rope.ROPE ← info.visitors, v.rest WHILE v#NIL DO
IF v.first.Equal[visitor, FALSE] THEN { found←TRUE; info.visitors ← v.rest; }
ELSE IF v.rest#NIL AND v.rest.first.Equal[visitor, FALSE] THEN {
v.rest ← v.rest.rest; found←TRUE; };
ENDLOOP;
IF nb=$success AND found THEN
[] ← ThParty.Unvisit[shh: info.shh, visitingParty: visitingPartyID];
};
Utilities
GetConv: PUBLIC PROC[convID: ConversationID, createOK: BOOLFALSE]
RETURNS [ cDesc: ConvDesc←NIL ] = --INLINE-- {
IsConv: RefQ.MapType = {
cDesc ← NARROW[subqueue.first];
IF cDesc.situation.self.convID = convID THEN RETURN[TRUE];
};
IF convID#nullConvID AND RefQ.Map[info.conversations, IsConv] THEN RETURN;
IF ~createOK THEN RETURN;
New conversation
cDesc ← NEW[FinchSmarts.ConvDescBody←[
situation: [ self: [ convID: convID, smartsID: info.smartsID, partyID: info.partyID ]]]];
TRUSTED { Process.SetTimeout[@cDesc.keysMightBeDistributed, pd.keyDistTicks]; };
info.conversations ← RefQ.Enqueue[info.conversations, cDesc];
};
FinchOn: INTERNAL PROC[convID: ConversationID←nullConvID] RETURNS [
on: BOOLFALSE, cDesc: ConvDesc←NIL, state: StateInConv←$idle] = {
IF ~pd.finchOn OR info=NIL THEN {
VoiceUtils.Report["Your Finch is not running", $Finch]; RETURN; };
on←TRUE;
IF convID=nullConvID THEN RETURN;
cDesc ← GetConv[convID, FALSE];
IF cDesc#NIL THEN state�sc.situation.self.state;
};
NoteNewState: INTERNAL PROC[convEvent: Thrush.ConvEvent] RETURNS[cDesc: ConvDesc]= {
cInfo: ThParty.ConversationInfo;
nb: NB;
cDesc ← GetConv[convEvent.self.convID, TRUE];
cDesc.situation ← convEvent^;
[nb, cInfo] ← ThParty.GetConversationInfo[shh: info.shh, convID: convEvent.self.convID];
Now gather up additional information that we might not know yet:
Who started this?
Who the other party(s) is (are)
SELECT TRUE FROM
nb # $success => Problem["Can't obtain conversation information"];
cDesc.numParties#cInfo.numParties, cDesc.numActive#cInfo.numActive,
cDesc.numIdle#cInfo.numIdle => {
State information guaranteed correct only as of last time one of these numbers changed.
cDesc.subject ← cInfo.subject;
cDesc.startTime ← cInfo.startTime;
cDesc.numParties ← cInfo.numParties;
cDesc.numActive ← cInfo.numActive;
cDesc.numIdle ← cInfo.numIdle;
[nb, cDesc.partyInfo] ←
ThParty.GetPartyInfo[shh: info.shh, credentials: cDesc.situation.self,
nameReq: $description, allParties: TRUE];
IF nb#$success THEN Problem["Can't obtain conversation information", nb]
ELSE IF cDesc.numParties>=1 THEN
cDesc.whoOriginated ←
IF cDesc.partyInfo[0].partyID=cInfo.originator THEN $us ELSE $them;
};
ENDCASE;
SELECT cDesc.situation.self.state FROM
$idle, $neverWas => info.conversations ← RefQ.Dequeue[info.conversations, cDesc];
$notified => SELECT filtering FROM -- Needs tests for calls already in progress. 
1 => []←Request[cDesc, $idle, $notImportantEnough, "This is a test"];
2 => []←Request[cDesc, $ringing];
3 => []←Request[cDesc, $active, $whatever, "Hot line!"];
ENDCASE;
ENDCASE => cDesc.ultimateState ← cDesc.situation.self.state;
If we've been called due to a Substitution that's kicking us out (cf Subst.), we should find a way to inform our ReportConversationState clients that we are no longer involved in this conversation. We should also do a Dequeue as above. 
info.ReportConversationState[$success, cDesc, NIL];
BROADCAST info.stateChange;
};
Request: INTERNAL PROC[
cDesc: ConvDesc,
state: StateInConv,
reason: Thrush.Reason←NIL,
comment: ROPENIL
]
RETURNS [nb: NB] = {
DO
convEvent: Thrush.ConvEvent;
reportToAll: BOOL = SELECT state FROM
$idle, $active, $inactive, $ringing => TRUE, ENDCASE=>FALSE;
[nb, convEvent] ←
ThParty.Advance[shhh: info.shh, credentials: cDesc.situation.self, state: state,
reportToAll: reportToAll, reason: reason, comment: comment];
SELECT nb FROM
$success => []←NoteNewState[convEvent];
$stateMismatch => {
cDesc←NoteNewState[convEvent];
IF state=$idle AND cDesc.situation.self.state # $idle THEN LOOP;
};
ENDCASE => -- Some cases are fatal, requiring re-registration! --
info.ReportConversationState[nb, cDesc, "Telephone server action failed"];
Real confused about Problem (typeout only) reporting vs. client reporting. The responsibilities are unconvincingly distributed among Smarts and client.
EXIT;
ENDLOOP;
};
Connect: INTERNAL PROC [calledPartyID: PartyID, convID: ConversationID←nullConvID, reason: Thrush.Reason ← NIL, comment: ROPENIL]
RETURNS [ nb: NB←$success, cDesc: ConvDesc←NIL ] = {
If there's a reason, the connect request's only purpose is to record an error condition, audibly as well as visually. This requires the creation of a conversation, then its immediate termination.
state: StateInConv;
newState: StateInConv =IF reason=NIL THEN $initiating ELSE $failed;
convEvent: Thrush.ConvEvent;
IF ~(([,cDesc, state]𡤏inchOn[convID]).on) THEN { nb ← $finchInactive; RETURN; }; --
SELECT state FROM
$idle => {
[nb, convEvent] ← ThParty.CreateConversation[
shhh: info.shh,
credentials: [partyID: info.partyID, smartsID: info.smartsID],
state: newState,
reason: reason,
comment: comment
];
IF nb = $success THEN cDesc ← NoteNewState[convEvent];
};
$reserved, $parsing => nb ← Request[cDesc, newState, reason, comment];
ENDCASE => {
info.ReportConversationState[$convStillActive, NIL, "Conversation already in progress"];
RETURN;
};
IF nb # $success OR newState=$failed THEN RETURN;
cDesc.originatorRecorded ← TRUE;
nb←ThParty.Alert[shhh: info.shh,
credentials: cDesc.situation.self, calledPartyID: calledPartyID];
SELECT nb FROM
$success => NULL;
$stateMismatch => {
nb←Request[cDesc, $failed, $error, "Conversation already in progress"];
Some smarts don't do this. They probably should.
RETURN;
};
ENDCASE => {
-- Do something interesting — see other smarts for more confusion -- ERROR; };
};
WaitForActive: INTERNAL PROC[cDesc: ConvDesc] RETURNS [nb: NB←$success] = {
For use in Recording, and so on, where client needs to wait for setup.
FOR i: NAT IN [0..pd.waitsForConnect) DO
TRUSTED { Process.SetTimeout[@info.stateChange, pd.noJayTicks]; };
WAIT info.stateChange; -- <<The supervisor condition vbl; will this work?>>
SELECT cDesc.situation.self.state FROM
$active => RETURN;
$idle, $neverWas, $failed => EXIT;
ENDCASE;
ENDLOOP;
nb←Request[cDesc, $failed, $error, "Finch failed to connect to voice service."];
IF nb=$success THEN nb←$timedOut;
};
VoiceConnect: INTERNAL PROC[convID: ConversationID←nullConvID] RETURNS [
nb: NB←$success,
cDesc: ConvDesc←NIL,
state: StateInConv←idle
] = {
calledPartyID: PartyID;
IF NOT (([,cDesc, state]𡤏inchOn[convID]).on) THEN {
Problem["Your Finch is not running"]; RETURN; };
IF cDesc=NIL THEN [convID, cDesc, state] ← GetActiveConversation[]; -- Hack
SELECT state FROM
idle, reserved => {
[nb, calledPartyID] ← ThParty.GetParty[shh: info.shh, partyID: info.partyID, rName: "recording", type: $service];
IF nb=$success THEN [nb, cDesc] ← Connect[calledPartyID, convID, NIL, NIL]
};
ENDCASE;
IF nb=$success THEN nb ← WaitForActive[cDesc];
};
GetActiveConversation: PROC
RETURNS[convID: ConversationID←Thrush.nullConvID, cDesc: ConvDesc←NIL, state: StateInConv←$idle] = {
Hack. Won't work when lots of conversations are the norm
FOR convs: LIST OF REF ← info.conversations, convs.rest WHILE convs#NIL DO
cDesc ← NARROW[convs.first];
IF cDesc.situation.self.state > Thrush.notReallyInConv THEN {
convID ← cDesc.situation.self.convID; state ← cDesc.situation.self.state; RETURN; }
ENDLOOP;
};
Problem: PROC[remark: ROPENIL, nb: NBNIL] = {
IF nb=NIL THEN VoiceUtils.Problem[remark, $Finch]
ELSE VoiceUtils.ProblemFR["%g, reason: %g", $Finch, NIL, rope[remark], atom[nb]];
};
VoiceTempInterface: PROC[cDesc: ConvDesc] RETURNS [nb: NB←$success] = {
partyID: Thrush.PartyID←Thrush.nullID;
interfaceSpec: Thrush.InterfaceSpec;
credentials: Thrush.Credentials;
IF cDesc#NIL THEN {
IF cDesc.voiceTempID#nullID THEN RETURN;
credentials ← cDesc.situation.self;
IF cDesc.numParties>1 THEN partyID ← cDesc.partyInfo[1].partyID;
}
ELSE {
IF info.voiceTemp#NIL THEN RETURN; -- want interface only
credentials ← [info.partyID, info.smartsID];
[nb, partyID] ←ThParty.GetParty[
shh: info.shh, partyID: info.partyID, rName: "recording", type: $service];
IF nb#$success THEN RETURN;
};
IF partyID = Thrush.nullID THEN RETURN[$noSuchParty2];
[nb, interfaceSpec] ← ThParty.LookupServiceInterface[
info.shh, credentials, partyID, "VoiceTemp"];
IF nb#$success THEN RETURN;
info.voiceTemp ← VoiceTempRpcControl.ImportNewInterface[
interfaceName: interfaceSpec.interfaceName,
hostHint: interfaceSpec.hostHint!RPC.ImportFailed => CONTINUE
];
IF info.voiceTemp=NIL THEN RETURN[$noVoiceTempInterface];
IF cDesc#NIL THEN cDesc.voiceTempID ← interfaceSpec.serviceID;
};
NewID: PROC RETURNS[LONG CARDINAL] ={RETURN[LOOPHOLE[PupSocket.GetUniqueID[]]]};
Registration
InitFinchSmarts: PUBLIC PROC [
thrushInstance: Thrush.ROPENIL,
ReportSystemState: PROC[ on: BOOL ],
ReportConversationState: PROC[ nb: NB, cDesc: ConvDesc, remark: Rope.ROPE ],
ReportRequestState: PROC[ actionReport: Thrush.ActionReport, actionRequest: REF ]
] = {
problem: ROPENIL; nb: NB; {
ENABLE RPC.CallFailed => { problem ← "Communication Failure"; GOTO InitFailed; };
credentials: Thrush.Credentials;
thVR: RPC.VersionRange = ThVersions.GetThrushVR;
problem: Thrush.ROPENIL;
namesGVInstance: Thrush.ROPENIL;
hostHint: VoiceUtils.NetAddress;
UninitFinchSmarts[NIL];
info ← NEW[FinchSmarts.FinchInfoBody]; -- Dump any old one!
info.requests ← MBQueue.Create[];
info.conversations ← NIL;
info.ReportSystemState←ReportSystemState;
info.ReportConversationState←ReportConversationState;
info.ReportRequestState←ReportRequestState;
thrushInstance ← VoiceUtils.MakeRName[style: rName, name:
IF thrushInstance#NIL THEN thrushInstance
ELSE UserProfile.Token[key: "ThrushClientServerInstance", default: "Strowger.Lark"]];
info.myName ← [
type: "ThSmarts.Lark",
instance: VoiceUtils.InstanceFromNetAddress[netAddress: VoiceUtils.OwnNetAddress[], suffix: "0"],
version: ThVersions.FinchVR];
info.myRName ← VoiceUtils.CurrentRName[];
info.myPassword ← VoiceUtils.CurrentPasskey[];
ThSmartsRpcControl.ExportInterface[
interfaceName: info.myName,
user: info.myRName,
password: info.myPassword];
pd.smartsIsExported←TRUE;
For the purpose of importing NamesGV, use prior binding of serverInstance if there is one and the server name is the same as before.
namesGVInstance ← UserProfile.Token[key: "NamesGVInstance", default: "Strowger.lark"];
IF ~(PrincOpsUtils.IsBound[LOOPHOLE[NamesGVImpExp.GVImport]] AND NamesGVImpExp.GVImport[namesGVInstance]) THEN {
problem ← "Couldn't import Grapevine Package"; GOTO InitFailed; };
info.shh ← IF NOT pd.encryptionRequested THEN Thrush.unencrypted
ELSE NamesRPC.StartConversation [
caller: info.myRName,
callee: thrushInstance,
key: info.myPassword,
level: --<<ECB>>--CBCCheck !
RPC.AuthenticateFailed=> { problem←"Could not authenticate"; GOTO InitFailed}];
hostHint ←
VoiceUtils.NetAddressFromRope[NamesGV.GVGetAttribute[thrushInstance, $connect, NIL]];
ThPartyRpcControl.ImportInterface[
interfaceName: [type: "ThParty.Lark", instance: thrushInstance, version: thVR],
hostHint: hostHint! RPC.ImportFailed=> {
IF why=wrongVersion THEN
problem ← IO.PutFR["Finch version %d too old; import failed",
card[ThVersions.FinchVersion]];
GOTO InitFailed;
}];
pd.interfacesAreImported←TRUE;
[nb, credentials]←ThParty.Register[
shh: info.shh,
rName: info.myRName,
type: $individual,
interface: info.myName,
properties: [$controller, VoiceUtils.OwnNetAddress[]]
];
IF nb=$success THEN nb ← ThParty.Enable[shh: info.shh, smartsID: credentials.smartsID];
IF nb#$success THEN {
problem←"Can't register with server"; GOTO InitFailed; };
info.smartsID ← credentials.smartsID;
info.partyID ← credentials.partyID;
ThParty.ConversationsForParty[shh: info.shh, partyID: partyID];
pd.finchOn←TRUE;
info.ReportSystemState[pd.finchOn];
EXITS
InitFailed => UninitFinchSmarts[problem, nb];
};};
UninitFinchSmarts: PUBLIC PROC[problem: ROPENIL, nb: NBNIL] = {
ENABLE RPC.CallFailed => GOTO Failed;
IF problem#NIL THEN Problem[problem, nb];
IF info#NIL THEN {
IF pd.finchOn AND info.partyID#nullID AND info.smartsID#nullID THEN
[-- nb --]←ThParty.Deregister[info.shh, info.smartsID!RPC.CallFailed=>CONTINUE];
info.shh←none;
info.ReportSystemState[FALSE];
{
ClearConvs: RefQ.MapType = {
cDesc: ConvDesc=NARROW[subqueue.first];
cDesc.clientData ← NIL;
};
[]←RefQ.Map[info.conversations, ClearConvs];
info.conversations ← NIL;
};
};
pd.finchOn←FALSE;
IF PrincOpsUtils.IsBound[LOOPHOLE[NamesGVImpExp.UnGVImport]] THEN
NamesGVImpExp.UnGVImport[];
pd.interfacesAreImported←FALSE;
IF pd.smartsIsExported THEN
ThSmartsRpcControl.UnexportInterface[!LupineRuntime.BindingError=>CONTINUE];
pd.smartsIsExported←FALSE;
EXITS
Failed => pd.interfacesAreImported ← pd.smartsIsExported ← FALSE;
};
FinchIsRunning: PUBLIC PROC RETURNS [finchIsRunning: BOOL] = { RETURN[pd.finchOn]; };
Debugging nonsense
ViewCmd: Commander.CommandProc = TRUSTED {
Nice.View[pd, "Finch PD"];
};
SetFiltering: PROC[which: INT, deferAnswer: ROPE← "true"] ← {
filtering ← which;
NamesGV.GVSetAttribute[
VoiceUtils.MakeRName[VoiceUtils.CurrentRName[]], $deferanswer, deferAnswer];
};
filtering: INT𡤀
FilterResetCmd: Commander.CommandProc = TRUSTED {
SetFiltering[0, "false"];
};
FilterZeroCmd: Commander.CommandProc = TRUSTED {
SetFiltering[0];
};
FilterOneCmd: Commander.CommandProc = TRUSTED {
SetFiltering[1];
};
FilterTwoCmd: Commander.CommandProc = TRUSTED {
SetFiltering[2];
};
FilterThreeCmd: Commander.CommandProc = TRUSTED {
SetFiltering[3];
};
Commander.Register["VuFinch", ViewCmd, "Program Management variables Finch"];
Commander.Register["FReset", FilterResetCmd, "Reset filtration method. This is a test."];
Commander.Register["F0", FilterZeroCmd, "Zeroth filtration method. This is a test."];
Commander.Register["F1", FilterOneCmd, "First filtration method. This is a test."];
Commander.Register["F2", FilterTwoCmd, "Second filtration method. This is a test."];
Commander.Register["F3", FilterThreeCmd, "Third filtration method. This is a test."];
Registration for use by arms-length systems
FinchSmarts.Register[NEW[FinchSmarts.ProcsRecord ← [
playbackTune: PlaybackTune,
recordTune: RecordTune,
stopTune: StopTune,
describeInterval: DescribeInterval,
textToSpeech: TextToSpeech,
registerTranslateProc: RegisterTranslateProc,
stopSpeech: StopSpeech,
finchIsRunning: FinchIsRunning
]]];
}.
Swinehart, May 22, 1985 1:08:51 pm PDT
Changes to GetParty.
changes to: JayConnection
Polle Zellweger (PTZ) July 13, 1985 5:20:26 pm PDT
adding Text-to-Speech server
changes to: DIRECTORY, ProseSpec, ProseSpecs, stopIntervalSpec (was stopSpec), stopProseSpec, Progress, Supervise, DisconnectCall, PlaceCall, StopSpeech, TextToSpeech, InitFinchSmarts, GetConv, ReportProses, EnqueueProses, Complain, Connect, ProseConnection
Swinehart, August 6, 1985 5:43:08 pm PDT
Merge PTZ prose changes
changes to: DIRECTORY, NB, PD, stopIntervalSpec, stopProseSpec, Report, Progress, Supervise, DisconnectCall, PlaceCall, StopTune, NoiseSpec, PlaybackTune, TextToSpeech, InitFinchSmarts, GetConv, ReportProses, CompareIntID, EnqueueProses, Complain, Connect, JayConnection, ProseConnection, RepRet, FinchSmarts
Polle Zellweger (PTZ) August 19, 1985 4:16:40 pm PDT
Meter text in TextToSpeech so as to avoid sending large ropes all at once. Allows speech to begin sooner and flush faster. Also flushing changes.
changes to: FinchInfo, PD, Supervise, TextToSpeech, StopSpeech, ReportProses (comments only)
Polle Zellweger (PTZ) September 3, 1985 6:28:29 pm PDT
Allow registration of defaultTranslateProc.
changes to: Supervise, defaultTranslateProc, RegisterTranslateProc, TextToSpeech, FinchSmarts
Swinehart, September 16, 1985 10:00:59 am PDT
If Finch has never been initialized, info is NIL -- don't let that bother you.
changes to: GetRname, PlayNoise, FinchOn
Polle Zellweger (PTZ) October 22, 1985 5:10:44 pm PDT
changes to: Progress (add prose debugging reports), TextToSpeech (report connection failure), ReportProses (fix debugging reports), JayConnection (report connection failure), ProseConnection (report connection failure)
Polle Zellweger (PTZ) October 24, 1985 4:53:21 pm PDT
Move bluejayConnection and proseConnection from FinchInfo to ConvDesc.
changes to: Supervise, DisconnectCall, InitFinchSmarts, Connect, JayConnection, ProseConnection
Swinehart, October 28, 1985 12:31:20 pm PST
Merge Above changes with other other minor changes (RefQ and the like)
changes to: DIRECTORY, FinchSmartsImpl, Progress, Supervise, DisconnectCall, TextToSpeech, InitFinchSmarts, UninitFinchSmarts, IsConv, GetConv, IsConv (local of GetConvDesc), GetConvDesc, ReportProses, FinchOn, Connect, JayConnection, ProseConnection, PlaybackTune, ClearConvs (local of UninitFinchSmarts)
Swinehart, December 13, 1985 2:52:25 pm PST
Massive change to new Thrush, leaving out proses and intervals for the moment.
changes to: ConversationHandle, FinchInfo, Progress, Supervise, DisconnectCall, AnswerCall, PlaceCall, Apprise, Complain, Connect, Problem, FinchSmarts, Progress, QdProgress
Swinehart, December 17, 1985 10:05:46 am PST
Major revision for new Thrush. Removed all Prose and Bluejay stuff temporarily
changes to: QdProgress, NoteNewState, PutFTime, Connect, Problem, Progress, Other, Supervise
Swinehart, May 19, 1986 12:22:17 pm PDT
Cedar 6.1
changes to: DIRECTORY, SHHH
Swinehart, June 1, 1986 7:48:10 pm PDT
Add ReportAction, eliminate the MBQueueing of ThParty-provoked actions. Others remain, but should go.
changes to: Progress, Substitution, ReportAction