DIRECTORY Commander USING [ CommandProc, Register ], IO, Lark -- USING [ -- CommandEvents, ConnectionSpec, Event, LarkModel, Passel, StatusEvents ]--, LarkSmartsMonitorImpl, MBQueue USING [ Create, QueueClientAction ], Nice, RefID USING [ ID, Reseal, Unseal ], ThParty USING [ Alert, ConversationInfo, CreateConversation, DescribeParty, GetConversationInfo, GetKeyTable, GetParty, SmartsInterfaceRecord ], ThPartyPrivate USING [ RegisterLocal ], Thrush USING [ ConversationID, ConvEvent, Credentials, PartyID, NB, nullConvID, nullID, ROPE, SHHH, SmartsID, StateInConv ], ThSmartsPrivate USING [ AssessDamage, ChangeState, ComputeConnection, ConvDesc, Deregister, EnterLarkState, ForgetConv, GetConv, GetConvDesc, GetSIC, GetSmartsInfo, LarkFailed, LarkInfo, LarkState, OpenConversations, SmartsInfo, SmartsInfoBody, TrunkBundle ], ThSmartsRpcControl, Triples USING [Make ], TU, VoiceUtils USING [ Problem, ProblemFR, Report ] ; LarkTrunkSmartsImpl: CEDAR MONITOR LOCKS root IMPORTS Commander, root: LarkSmartsMonitorImpl, IO, MBQueue, Nice, RefID, ThParty, ThPartyPrivate, ThSmartsPrivate, ThSmartsRpcControl, Triples, TU, VoiceUtils EXPORTS ThSmartsPrivate --, ThSmarts via Interface record -- SHARES LarkSmartsMonitorImpl = { OPEN IO; ConvDesc: TYPE = ThSmartsPrivate.ConvDesc; Reseal: PROC[r: REF] RETURNS[RefID.ID] = INLINE {RETURN[RefID.Reseal[r]]; }; ROPE: TYPE = Thrush.ROPE; SHHH: TYPE = Lark.SHHH; -- Encrypts conv. if first arg to RPC PROC PartyID: TYPE = Thrush.PartyID; nullID: RefID.ID = Thrush.nullID; nullConvID: Thrush.ConversationID = Thrush.nullConvID; SmartsInfo: TYPE = ThSmartsPrivate.SmartsInfo; StateInConv: TYPE = Thrush.StateInConv; PD: TYPE = RECORD [ timeoutNoAction: INT_30, doReports: BOOL_FALSE, doNice: BOOL_FALSE ]; pd: REF PD _ NEW[PD_[]]; Report: PROC[what: ROPE, info: SmartsInfo] = { IF NOT pd.doReports THEN RETURN; VoiceUtils.Report[what, $Lark, info.larkInfo]; }; RegisterTrunk: PUBLIC ENTRY PROC[ hostSmartsID: Thrush.SmartsID, hostInfo: SmartsInfo, partyRname: ROPE ] RETURNS [ nb: Thrush.NB_$success, smartsID: Thrush.SmartsID_nullID ] = { { ENABLE UNWIND => NULL; localSmarts: ThParty.SmartsInterfaceRecord; info: SmartsInfo; smarts: REF; credentials: Thrush.Credentials; localSmarts _ ThSmartsRpcControl.NewInterfaceRecord[]; localSmarts.clientStubProgress _ LarkTrunkProgress; [nb, credentials] _ ThPartyPrivate.RegisterLocal [ rName: partyRname, type: $trunk, interfaceRecord: localSmarts, properties: [role: $voiceTerminal, machine: hostInfo.larkInfo.netAddress] ]; IF nb # $success OR (smartsID_credentials.smartsID) = nullID THEN { VoiceUtils.ProblemFR["Can't register Lark trunk: %g",$System,NIL, rope[partyRname]]; RETURN; }; smarts _ RefID.Unseal[smartsID]; IF smarts = NIL THEN { VoiceUtils.Problem["No smarts already?"]; RETURN[$noSuchSmarts]; }; info _ NEW[ThSmartsPrivate.SmartsInfoBody _ [ smartsID: smartsID, otherSmartsID: hostSmartsID, ParseEvent: LarkTrunkParseEvent, NoteNewStateP: NoteNewTkState, requests: MBQueue.Create[], larkInfo: hostInfo.larkInfo ]]; info.larkInfo.larkTrunkSmartsInfo _ info; Triples.Make[$SmartsData, smarts, info]; }; }; EventSpec: TYPE = REF EventSpecBody; EventSpecBody: TYPE = RECORD [ smartsInfo: SmartsInfo, sEvent: Lark.StatusEvent ]; LarkTrunkParseEvent: PROC[ smartsInfo: SmartsInfo, sEvent: Lark.StatusEvent] = { smartsInfo.requests.QueueClientAction[ QdLarkTrunkParseEvent, NEW[EventSpecBody _ [smartsInfo, sEvent]]]; }; QdLarkTrunkParseEvent: ENTRY PROC[r: REF] = { -- r is the EventSpec eventSpec: EventSpec = NARROW[r]; smartsInfo: SmartsInfo = eventSpec.smartsInfo; { ENABLE { UNWIND=>NULL; ThSmartsPrivate.LarkFailed => { VoiceUtils.ProblemFR["%g: Lark Failed", $Smarts, smartsInfo, TU.RefAddr[smartsInfo]]; GOTO Failed; }; }; sEvent: Lark.StatusEvent _ eventSpec.sEvent; SELECT sEvent.device FROM ringDetect => SELECT sEvent.event FROM Lark.enabled => CmdRinging[smartsInfo]; Lark.disabled => CmdStopRinging[smartsInfo]; ENDCASE => ERROR; ENDCASE; EXITS Failed => ThSmartsPrivate.Deregister[smartsInfo.smartsID]; }; }; CmdRinging: INTERNAL PROC[info: SmartsInfo] = { partyID: PartyID; -- self calledPartyRname: ROPE; calledPartyID: PartyID; cDesc: ConvDesc; convEvent: Thrush.ConvEvent; nb: Thrush.NB; { SELECT ThSmartsPrivate.GetSIC[info] FROM $idle => NULL; ENDCASE => RETURN; -- not a valid time for this call. Ignore. Host system will handle. cDesc _ ThSmartsPrivate.GetConv[info, nullConvID, TRUE]; partyID _ cDesc.situation.self.partyID; -- self [nb, calledPartyRname] _ ThParty.DescribeParty[partyID: partyID, nameReq: $owner]; IF nb # $success OR calledPartyRname=NIL THEN GOTO Failed; -- Enter error state? Forget Conv? [nb, calledPartyID] _ ThParty.GetParty[partyID: partyID, rName: calledPartyRname]; SELECT nb FROM $success => NULL; $noSuchParty2 => GOTO Failed; -- Enter error state? Forget Conv? ENDCASE => GOTO Failed; -- Enter error state? Forget Conv? [nb, convEvent] _ ThParty.CreateConversation[ credentials: cDesc.situation.self, state: $initiating ]; IF nb # $success THEN { ThSmartsPrivate.AssessDamage[nb, cDesc, convEvent]; GOTO Failed; } ELSE NoteNewTkState[cDesc, convEvent]; nb_ThParty.Alert[credentials: cDesc.situation.self, calledPartyID: calledPartyID]; IF nb # $success THEN GOTO Failed; -- enter error state? EXITS Failed => ThSmartsPrivate.ForgetConv[cDesc]; }}; CmdStopRinging: INTERNAL PROC[info: SmartsInfo] = { nb: Thrush.NB; cDesc: ConvDesc=ThSmartsPrivate.GetConvDesc[info]; IF cDesc=NIL THEN RETURN; SELECT cDesc.situation.self.state FROM $initiating, $ringback => NULL; -- ringing stopped before called party answered. ENDCASE => RETURN; -- already active or something; ignore end of ringing nb _ ThSmartsPrivate.ChangeState[cDesc, $idle, $terminating]; }; LarkTrunkProgress: PUBLIC ENTRY PROC[ interface: ThSmartsRpcControl.InterfaceRecord, shh: Thrush.SHHH, convEvent: Thrush.ConvEvent ] = { ENABLE UNWIND => NULL; -- RestoreInvariant; info: SmartsInfo = ThSmartsPrivate.GetSmartsInfo[smartsID: convEvent.self.smartsID]; IF info=NIL THEN { Report["No info at Progress", NIL]; RETURN; }; info.requests.QueueClientAction[QdLarkTrunkProgress, convEvent]; }; QdLarkTrunkProgress: ENTRY PROC[r: REF] = { ENABLE UNWIND => NULL; -- RestoreInvariant; convEvent: Thrush.ConvEvent = NARROW[r]; info: SmartsInfo = ThSmartsPrivate.GetSmartsInfo[smartsID: convEvent.self.smartsID]; cDesc: ConvDesc; convID: Thrush.ConversationID = convEvent.self.convID; whatNeedsDoing: WhatNeedsDoing; IF info=NIL THEN { Report["Smarts Info Missing at Progress", NIL]; RETURN; }; cDesc _ ThSmartsPrivate.GetConv[ info, convID, TRUE ]; IF convEvent.self.partyID = convEvent.other.partyID THEN { -- own state changed NoteNewTkState[cDesc, convEvent]; SELECT info.currentConvID FROM convID, nullConvID => NULL; ENDCASE => DoRejectCall[cDesc, convEvent]; RETURN; }; IF convID#info.currentConvID THEN { Report["Strange progress report", cDesc.info]; ThSmartsPrivate.ForgetConv[cDesc]; RETURN; }; whatNeedsDoing _ whatNeedsDoingIf[cDesc.situation.self.state][convEvent.other.state]; SELECT whatNeedsDoing FROM $noop, $ntiy => NULL; -- No action is needed, or we don't know what one to take. $imp => ERROR; -- This is supposed to be impossible! $xrep => Report["Didn't expect state change report", info]; $frgt => ThSmartsPrivate.ForgetConv[cDesc]; $invl => { Report["Invalid state transition", info]; []_ThSmartsPrivate.ChangeState[cDesc: cDesc, state: $idle, reason: $error, comment: "System Error: Invalid state transition"]; }; $idle => { nb2: Thrush.NB; cInfo: ThParty.ConversationInfo; [nb2, cInfo] _ ThParty.GetConversationInfo[convID: convEvent.self.convID]; IF nb2 # $success OR (cInfo.numParties-cInfo.numIdle) <= 1 THEN []_ThSmartsPrivate.ChangeState[cDesc, $idle, IF nb2#$success THEN $error ELSE $terminating]; }; $actv => [] _ ThSmartsPrivate.ChangeState[cDesc, $active]; $reac, $deac => NULL; ENDCASE => ERROR; }; QdNotification: ENTRY PROC [r: REF] ~ { ENABLE UNWIND => NULL; -- RestoreInvariant; cDesc: ConvDesc = NARROW[r]; IF cDesc.situation.self.state = $notified THEN [] _ ThSmartsPrivate.ChangeState[cDesc, $active]; }; DoRejectCall: INTERNAL PROC[cDesc: ConvDesc, convEvent: Thrush.ConvEvent] = { []_ThSmartsPrivate.ChangeState[cDesc, $idle, $busy]; }; NoteNewTkState: INTERNAL PROC[cDesc: ConvDesc, convEvent: Thrush.ConvEvent] ~ { OPEN now: cDesc.situation.self; nb: Thrush.NB; larkStateData: REF_NIL; state: StateInConv _ convEvent.self.state; info: ThSmartsPrivate.SmartsInfo = cDesc.info; larkInfo: ThSmartsPrivate.LarkInfo = info.larkInfo; cInfo: ThParty.ConversationInfo; larkState: ThSmartsPrivate.LarkState _ $none; savedCurrentConvID: Thrush.ConversationID; cDesc.situation _ convEvent^; IF info.currentConvID=nullConvID THEN info.currentConvID _ cDesc.situation.self.convID; savedCurrentConvID _ info.currentConvID; SELECT state FROM $notified => info.requests.QueueClientAction[QdNotification, cDesc]; $idle => { IF larkInfo.larkState=trunkForwarding THEN larkState _ $idle; ThSmartsPrivate.ForgetConv[cDesc]; }; $neverWas => ThSmartsPrivate.ForgetConv[cDesc]; $active => { phoneNumber: ROPE; [nb, phoneNumber] _ ThParty.DescribeParty[partyID: now.partyID, nameReq: $address]; IF nb = $success THEN [nb, cInfo] _ ThParty.GetConversationInfo[convID: now.convID]; larkState _ IF nb # $success OR phoneNumber=NIL OR cInfo.originator=now.partyID THEN trunkTalking ELSE trunkSignalling; larkStateData _ NEW[ThSmartsPrivate.TrunkBundle_[ThSmartsPrivate.ComputeConnection[cDesc], phoneNumber]]; }; ENDCASE; IF state > $idle AND cDesc.keyTable=NIL THEN { [nb, cDesc.keyTable] _ ThParty.GetKeyTable[credentials: now]; IF nb # $success THEN cDesc.keyTable_NIL; }; IF state>$idle AND cDesc.keyTable#info.larkInfo.keyTable AND larkStateData=NIL THEN { larkStateData _ cDesc.keyTable; larkState _ larkInfo.larkState; }; IF now.convID = savedCurrentConvID AND larkState # $none THEN ThSmartsPrivate.EnterLarkState[larkInfo, larkState, larkStateData]; }; WhatNeedsDoing: TYPE = ATOM; -- { whatNeedsDoingIf: ARRAY StateInConv OF ARRAY StateInConv OF WhatNeedsDoing _ [ [ $imp, $frgt, $frgt, $frgt, $frgt, $frgt, $frgt, $frgt, $frgt, $frgt, $frgt, $frgt], --neverWas [ $imp, $noop, $frgt, $noop, $noop, $noop, $noop, $noop, $noop, $noop, $noop, $ntiy ], -- idle [ $imp, $imp, $frgt, $imp, $imp, $imp, $imp, $imp, $imp, $imp, $imp, $imp ], -- failed [ $imp, $imp, $frgt, $imp, $imp, $imp, $imp, $imp, $imp, $imp, $imp, $imp ], -- reserved [ $imp, $imp, $frgt, $imp, $imp, $imp, $imp, $imp, $imp, $imp, $imp, $imp ], -- parsing [ $imp, $idle,$frgt, $invl, $invl, $invl, $xrep, $xrep, $xrep ,$actv, $actv, $actv ], -- initiating [ $imp, $idle,$frgt, $invl, $invl, $invl, $xrep, $noop, $noop, $ntiy, $noop, $ntiy ], -- notified [ $imp, $idle,$frgt, $invl, $invl, $invl, $invl, $invl, $invl, $invl, $invl, $invl ], -- ringback [ $imp, $idle,$frgt, $invl, $invl, $invl, $invl, $invl, $invl, $invl, $invl, $invl ], -- ringing [ $imp, $idle,$frgt, $invl, $invl, $invl, $xrep, $xrep, $noop, $ntiy, $noop, $ntiy ], -- canActivate [ $imp, $idle,$frgt, $invl, $invl, $invl, $xrep, $xrep, $noop, $ntiy, $reac, $deac ], -- active [ $imp, $idle,$frgt, $invl, $invl, $invl, $xrep, $xrep, $noop, $ntiy, $ntiy, $ntiy ] -- inactive (current ^) ]; ViewCmd: Commander.CommandProc = TRUSTED { Nice.View[pd, "Lark Trunk PD"]; }; Commander.Register["VuLarkTrunkSmarts", ViewCmd, "Program Management variables for Lark Trunk Smarts"]; }. fLarkTrunkSmartsImpl.mesa Smarts for the Lark "Back Door" Last modified by D. Swinehart, January 13, 1986 11:53:05 am PST Note: Incoming calls are those from the Etherphone to the outside party, whom this system represents. Outgoing calls are those from the outside world to an Etherphone. Remember; trunk party is a representative of people in the public telephone system. See LarkSmartsImpl and LarkSmartsSupImpl for various comments guiding the structure of this module; it's simpler, but similar. Types and Constants Initialization There's no provision here at all for reregistration. Yet. Events RecordTrunkEvent handles events from the EtherPhone Trunk connection. The only interesting events at present are "ring" (place trunk->station call) and "tones F" (station->trunk call being "answered") The upstream code produces a single "enabled" event when the line starts ringing, and a single "disabled" event when it appears that ringing has stopped. This "disabled" event must be anticipated and ignored if the station answers (calling trunk can't hang up on completed call!) No idea what to do! This is pretty catastrophic, since no one else know about conv Complain about nb # $success here? Some party has changed state in a conversation we know about. (new conversation and we're idle) or (this is the one we like) We have to reject this, since we're already dealing with another conv. We are (still) willing to seriously consider only one conversation at a time. Situation is that someone else reported a change of theirs concerning a conversation we've expressed no interest in. I don't believe this should happen. Someone else's state changed in a conv. we're interested in; see if it means anything to us! Just codes to dispatch on in Supervisor; explained there $noop, $idle, $actv, $frgt, $reac, $deac, -- cases explained in code $invl, -- considered an invalid request $xrep, -- we got a report we feel we shouldn't have got $ntiy, -- not implemented yet $imp -- this situation should not arise even in the face of invalid requests }; If we're in the state identified by the row, and someone else in the conversation reports a transition onto the state identified by the column, what should we do? never idle failed resrv pars init notif rback ring canAc activ inact -- _ (other) (Clip this table to view without these comments.) This situation arises when we've forgotten about the conversation that somebody else is still reporting on. The actions of other parties are not of interest to us yet, since they're not in this conv. Ditto. They can either enter ringing to indicate interest, or go active without ringing We don't expect to hear from others while we're deciding whether to play They have earlier expressed interest noopringing), and are now joining the fray The only thing that interests us here is everybody else quitting. Debugging nonsense << Comments left over from previous system. Think about it all sometime. was in section involving analysis of new pending state. >> <> nb _ ChangeState[info, busy, "Sorry, trunk in use"]; RETURN; }; Swinehart, October 28, 1985 10:01:46 am PST Log => VoiceUtils, Handle => ID changes to: DIRECTORY, LarkTrunkSmartsImpl, Reseal, PartyID, nullID, nullConvID, RegisterTrunk, LarkTrunkParseEvent, CmdCall, TrunkSupervise Κ ˜Jšœ™Jšœ™Jšœ?™?J™J™ύJ™J™€J˜šΟk œ˜ Jšœ œ˜*Jšœ˜šœΟc ˜JšžLœ˜M—J˜Jšœœ˜,J˜Jšœœœ˜#Jšœœƒ˜Jšœœ˜'šœœ˜Jšœ1œœœ˜m—šœœ˜Jšœλ˜λ—J˜Jšœœ ˜J˜Jšœ/˜/J˜J˜—šœ œœ˜-š˜Jšœ ˜ J˜Jšœ˜J˜J˜J˜J˜J˜J˜J˜J˜J˜J˜ —Jšœž$˜™>—šœ#˜*JšœF™FK™M——Kšœ˜K˜—šœœ˜#J™™J˜.Jšœ"˜"Jšœ˜Jšœ˜—J˜Jšœ\™\KšœU˜Ušœ˜Kšœœž:˜PKšœœž%˜4Kšœ;˜;K˜+šœ ˜ Kšœ)˜)šœ:˜:KšœC˜C—Kšœ˜—šœ ˜ Kšœ œ"˜0KšœJ˜Jšœœ'˜?šœ,˜,Kšœœœ˜/——K˜—Kšœ:˜:Kšœœ˜Kšœœ˜—J˜J˜—šŸœœœœ˜'Kšœœœž˜.Kšœœ˜šœ(˜/Kšœ1˜1—K˜J˜—šŸ œœœ2˜MK˜4Kšœ˜K˜—šŸœœœ2˜OKšœ˜Kšœ œ˜Kšœœœ˜K˜*K˜.K˜3K˜ K˜-K˜*K˜Kšœœ2˜WKšœ(˜(šœ˜KšœD˜D˜ Kšœ$œ˜=K˜"K˜—K˜/šœ ˜ K˜K˜SKšœœ?˜Tšœ ˜ Kš œœ œœœœ˜k—šœ˜KšœV˜Y—K˜—Kšœ˜—šœœœœ˜.Kšœ=˜=Kšœœœ˜)K˜—š œ œ'œœœ˜UKšœ˜K˜K˜—šœ!œ˜=KšœC˜C—K˜——J˜šœœœž˜!J™8Jšœ*ž™DJšœž ™'Jšœž0™7Jšœž™JšœžH™MJ™J˜—š œœ œœ œ˜NJ™’J™JšΟfΠfsX™Yš’ZΡcfs ˜dJšœ1™1Jšœk™k—Jš’[£˜bJš’Z£ ˜dš’Z£ ˜eJšœ[™[—š’Z£ ˜dJšœ™—š’Ρbfs’,€’€’€’€’€’£ ˜eJ™P—š’€’M£ ˜eJ™H—š’€’L£ ˜dJ™O—š’€’M£ ˜dJ™A—Jš’€’M£˜hJš’€’=€’€’£ ˜cJš’€’L£˜pJ˜—J˜J˜™šœ!œ˜*Jšœ˜Jšœ˜—Jšœg˜g—J˜J™J™J™…J™νJšœ5œ™?™+K™Kšœ Οr€™Œ—K™—…—,ΚG4