DIRECTORY Atom USING [ GetPName ], Commander USING [ CommandProc, Register ], CommandTool USING [ NextArgument ], Convert USING [ IntFromRope ], IO, Lark USING [ CommandEventSequence, LarkModel, SHHH ], LarkRpcControl USING [ ImportNewInterface, InterfaceRecord ], LarkSmarts, LarkSmartsMonitorImpl, LarkSmartsRpcControl USING [ExportInterface, InterfaceName, UnexportInterface], LupineRuntime, MBQueue USING [ Create ], NamesGV USING [ GVGetAttribute ], NamesRPC USING [ StartConversation ], Nice USING [ LarkConLogStream ], RefID USING [ ID, Reseal, Unseal ], Rope USING [Concat, Equal], RPC USING [ AuthenticateFailed, EncryptionKey, ExportFailed, GetCaller, ImportFailed ], ThNet USING [ pd ], ThPartyPrivate USING [ RegisterLocal ], ThParty USING [ Deregister, Enable, SmartsInterfaceRecord ], Thrush USING [ Credentials, epoch, Epoch, NB, NetAddress, nullID, PartyID, PartyType, ROPE, SmartsID, unencrypted ], ThSmartsPrivate USING [ CheckHookState, EnterLarkState, LarkFailed, LarkInfo, LarkInfoBody, LarkParseEvent, LarkProgress, NoteNewState, RegisterTrunk, SmartsInfo, SmartsInfoBody ], ThSmartsRpcControl, ThVersions, Triples USING [ Any, Erase, Make, Select ], TU, VoiceUtils USING [ CmdOrToken, CurrentPasskey, DNFProc, InstanceFromNetAddress, MakeAtom, Problem, ProblemFR, RegisterWhereToReport, ReportFR, RnameToRspec, Rspec, WhereProc ] ; LarkSmartsInitImpl: CEDAR MONITOR LOCKS root IMPORTS IO, Atom, Commander, CommandTool, Convert, LarkRpcControl, LarkSmartsRpcControl, NamesGV, NamesRPC, root: LarkSmartsMonitorImpl, LupineRuntime, MBQueue, Nice, RefID, Rope, RPC, ThNet, ThPartyPrivate, ThParty, Thrush, ThSmartsPrivate, ThSmartsRpcControl, ThVersions, Triples, TU, VoiceUtils EXPORTS LarkSmarts, ThSmartsPrivate SHARES LarkSmartsMonitorImpl = { OPEN IO; Reseal: PROC[r: REF] RETURNS[RefID.ID] = INLINE {RETURN[RefID.Reseal[r]]; }; nullID: RefID.ID = Thrush.nullID; PartyID: TYPE = Thrush.PartyID; ROPE: TYPE = Thrush.ROPE; SHHH: TYPE = Lark.SHHH; -- Encrypts conv. if first arg to RPC PROC SmartsID: TYPE = Thrush.SmartsID; SmartsInfo: TYPE = ThSmartsPrivate.SmartsInfo; SmartsInfoBody: TYPE = ThSmartsPrivate.SmartsInfoBody; larkRegistry: ROPE_".lark"; thSmartsExported: BOOL_FALSE; Register: PUBLIC PROC[ shh: SHHH, -- encrypts connection oldSmartsID: Thrush.SmartsID, oldEpoch: Thrush.Epoch, netAddress: Thrush.NetAddress, -- machine name for registering Lark -- model: Lark.LarkModel, authenticated: BOOL_FALSE, clientInstance: ROPE ] RETURNS [ smartsID: Thrush.SmartsID_nullID, epoch: Thrush.Epoch_Thrush.epoch ] = { larkSh: Lark.SHHH; localSmarts: ThParty.SmartsInterfaceRecord; info: SmartsInfo; larkInterface: LarkRpcControl.InterfaceRecord_NIL; smarts: REF; fullRname: ROPE = RPC.GetCaller[shh]; partyRname: ROPE _ fullRname; dbRname: ROPE; serviceName: ROPE; partyType: Thrush.PartyType _ $telephone; s: VoiceUtils.Rspec _ NIL; nb: Thrush.NB; credentials: Thrush.Credentials; IF (s_VoiceUtils.RnameToRspec[partyRname])#NIL AND VoiceUtils.RnameToRspec[s.simpleName] # NIL THEN partyRname_s.simpleName; dbRname _ partyRname.Concat[larkRegistry]; serviceName _ NamesGV.GVGetAttribute[dbRname, $service, NIL]; IF serviceName#NIL THEN partyType _ $service; DeregisterIfRegistered[netAddress, partyType]; larkSh _ IF NOT ThNet.pd.encryptionRequested THEN Thrush.unencrypted ELSE NamesRPC.StartConversation [ caller: myName.instance, callee: fullRname, key: serverPassword, level: --<>--CBCCheck ! RPC.AuthenticateFailed=> { VoiceUtils.ProblemFR["Can't authenticate %g to %g", $System, NIL, rope[myName.instance], rope[fullRname]]; GOTO NotSmart; }]; larkInterface _ LarkRpcControl.ImportNewInterface[ interfaceName: [type: "Lark.Lark", instance: clientInstance] ! RPC.ImportFailed=> { VoiceUtils.ProblemFR["Can't import Lark interface from %g", $System, NIL, rope[clientInstance]]; GOTO NotSmart; }]; localSmarts _ ThSmartsRpcControl.NewInterfaceRecord[]; localSmarts.clientStubProgress _ ThSmartsPrivate.LarkProgress; [nb, credentials] _ ThPartyPrivate.RegisterLocal[ rName: (SELECT partyType FROM $telephone => partyRname, ENDCASE=> serviceName), type: partyType, interfaceRecord: localSmarts, properties: [role: $voiceTerminal, machine: netAddress] ]; IF nb # $success OR (smartsID_credentials.smartsID) = nullID THEN { VoiceUtils.ProblemFR["Can't register Lark: %g, %g",$System,NIL, rope[fullRname], rope[clientInstance]]; GOTO NotSmart; }; smarts _ RefID.Unseal[smartsID]; IF smarts=NIL THEN ERROR; info _ NEW[SmartsInfoBody_ [ smartsID: smartsID, ParseEvent: ThSmartsPrivate.LarkParseEvent, NoteNewStateP: ThSmartsPrivate.NoteNewState, requests: MBQueue.Create[], larkInfo: NEW[ThSmartsPrivate.LarkInfoBody _ [ interface: larkInterface, shh: larkSh, netAddress: netAddress, model: model, textToSpeech: Rope.Equal[serviceName, "Text-to-Speech", FALSE] ]] ]]; info.larkInfo.larkSmartsInfo _ info; info.larkInfo.scratchEv _ NEW[Lark.CommandEventSequence[15]]; Triples.Make[$SmartsData, smarts, info]; IF partyType # $service THEN [--nb--, info.otherSmartsID]_ThSmartsPrivate.RegisterTrunk[ smartsID, info, partyRname ]; VoiceUtils.ReportFR[" (%g = %g)", $Smarts, info, rope[clientInstance], TU.RefAddr[smarts]]; EnableSmartsE[info]; -- Ready to go, as long as phone is on hook EXITS NotSmart => RETURN; }; EnableSmartsE: ENTRY PROC[info: SmartsInfo] = { []_EnableSmarts[info]; }; EnableSmarts: PUBLIC INTERNAL PROC[info: SmartsInfo] RETURNS[enabled: BOOL] = { ENABLE UNWIND, ThSmartsPrivate.LarkFailed =>GOTO Failed; SELECT info.larkInfo.larkState FROM $none, $failed, $recovering => NULL; ENDCASE=> RETURN[TRUE]; IF ThSmartsPrivate.CheckHookState[info.larkInfo].onHook=FALSE THEN RETURN[FALSE]; IF ThParty.Enable[ smartsID: info.smartsID] # $success THEN { VoiceUtils.Problem["Could not enable", $Smarts, info]; RETURN[FALSE]; }; IF ThParty.Enable[ smartsID: info.otherSmartsID] # $success THEN { VoiceUtils.Problem["Impossible", $Smarts, info]; ERROR; }; ThSmartsPrivate.EnterLarkState[ info.larkInfo, none ]; -- Clear any previous failure. ThSmartsPrivate.EnterLarkState[ info.larkInfo, idle ]; -- Reset the Lark RETURN[TRUE]; EXITS Failed => RETURN[FALSE]; }; DeregisterIfRegistered: ENTRY PROC[ netAddress: Thrush.NetAddress, partyType: Thrush.PartyType] = { hostAtom: ATOM = VoiceUtils.MakeAtom[VoiceUtils.InstanceFromNetAddress[netAddress, Atom.GetPName[partyType]]]; smarts: REF_Triples.Select[$SmartsForHost, hostAtom, -- smarts --]; IF smarts=NIL THEN RETURN; Deregister[Reseal[smarts]]; }; Deregister: PUBLIC INTERNAL PROC[smartsID: SmartsID] = { smarts: REF _ RefID.Unseal[smartsID]; info: SmartsInfo _ IF smarts=NIL THEN NIL ELSE NARROW[Triples.Select[$SmartsData, smarts, -- smartsInfo -- ]]; IF info#NIL THEN ThSmartsPrivate.EnterLarkState[ info.larkInfo, failed ]; -- prevent further action. VoiceUtils.ReportFR["Smarts %d (%g) is dead", $Smarts, info, card[Reseal[smarts]], TU.RefAddr[smarts]]; [--nb--]_ThParty.Deregister[smartsID: smartsID]; IF info=NIL THEN RETURN; info.larkInfo.larkSmartsInfo _ NIL; info.larkInfo.larkTrunkSmartsInfo _ NIL; info.larkInfo _ NIL; Triples.Erase[$SmartsData, smarts, Triples.Any -- smartsInfo --]; }; WhereIsSmartsLog: VoiceUtils.WhereProc -- [fixedWhereData: REF ANY, whereData: REF ANY] RETURNS [s: STREAM _ NIL] -- = CHECKED { info: SmartsInfo=NARROW[whereData]; IF info#NIL THEN s_Nice.LarkConLogStream[info.larkInfo.netAddress]; IF s#NIL AND s=Nice.LarkConLogStream[[[0],[0]]] THEN s_NIL; -- use default stream unless debug viewer stream open. }; WhereIsLarkLog: VoiceUtils.WhereProc -- [fixedWhereData: REF ANY, whereData: REF ANY] RETURNS [s: STREAM _ NIL] -- = CHECKED { info: ThSmartsPrivate.LarkInfo=NARROW[whereData]; IF info#NIL THEN s_Nice.LarkConLogStream[info.netAddress]; IF s#NIL AND s=Nice.LarkConLogStream[[[0],[0]]] THEN s_NIL; -- only want the debug viewer stream }; WhereIsLarkLogFerSherr: VoiceUtils.WhereProc _ WhereIsLarkLog; FerSherrDefault: VoiceUtils.DNFProc=TRUSTED{ RETURN[ThNet.pd.defaultLarkReports]; }; myName: LarkSmartsRpcControl.InterfaceName; serverPassword: RPC.EncryptionKey; KillLark: Commander.CommandProc = { netAddress: Thrush.NetAddress = [[173B],[Convert.IntFromRope[CommandTool.NextArgument[cmd], 8]]]; DeregisterIfRegistered[netAddress, $telephone]; DeregisterIfRegistered[netAddress, $service]; DeregisterIfRegistered[netAddress, $trunk]; }; LarkSmartsInit: Commander.CommandProc = { ENABLE { RPC.ExportFailed => { VoiceUtils.Problem["LarkSmarts export failed", $System]; GOTO Failed; }; }; myName _ [ type: "LarkSmarts.Lark", instance: VoiceUtils.CmdOrToken[cmd: cmd, key: "ThrushServerInstance", default: "Morley.Lark"], version: ThVersions.ThrushVR]; serverPassword _ VoiceUtils.CurrentPasskey[VoiceUtils.CmdOrToken[ cmd: cmd, key: "ThrushServerPassword", default: "MFLFLX"]]; IF thSmartsExported THEN RETURN; VoiceUtils.RegisterWhereToReport[proc: WhereIsLarkLog, where: $Lark]; VoiceUtils.RegisterWhereToReport[proc: WhereIsLarkLogFerSherr, where: $LarkDetailed, defaultIfNotFound: FerSherrDefault]; VoiceUtils.RegisterWhereToReport[proc: WhereIsSmartsLog, where: $Smarts]; LarkSmartsRpcControl.ExportInterface[ interfaceName: myName, user: myName.instance, password: serverPassword]; VoiceUtils.ReportFR["Export[LarkSmarts.Lark, %s]", $System, NIL, rope[myName.instance]]; thSmartsExported _ TRUE; EXITS Failed => LarkSmartsRpcControl.UnexportInterface[!LupineRuntime.BindingError=>CONTINUE]; }; Commander.Register["LarkSmarts", LarkSmartsInit, "LarkSmarts > -- Initialize and Export LarkSmarts"]; Commander.Register["KillLark", KillLark, "KillLark 110 -- deregisters lark 110"]; }. pLarkSmartsInitImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Last modified by D. Swinehart, December 6, 1985 2:53:30 pm PST Last Edited by: Pier, May 3, 1984 2:52:59 pm PDT Copies Registration/Deregistration/Initialization Develop partyRname: the actual RName to be used to represent this party; and dbRname: the name under which database items are stored in Grapevine. The rName obtained from the conversation handle may have either form initially, since Finches will supply the former and Larks will supply the latter. Also, obtain the name of the service represented by this Rname, if any, from the database. Above converts from, say, Swinehart.pa.lark to Swinehart.pa. Also, from Swinehart.pa to Swinehart.pa. Strips one registry if there are two or more. The LarkSmarts interface definition suggests that a Lark could present enough information during registration to be simply re-validated (kind of like a hand stamp at a dance) without any great effort. That turns out not to be worth it. If a Lark registers when already registered, we get rid of any old information about it first. Get encryption taken care of Make sure we can talk to the Lark No further bad things are expected to happen. If registered, undo everything at the smarts level and below, then deregister at the Party level Have to worry about trunk. Or do we? Other Utilities Initialization, export "LarkSmarts" Same as $Lark, except doesn't print at all if debugging viewer not found. Swinehart, May 22, 1985 5:03:50 pm PDT Cedar 6.0 New ways of defining service parties. autoAnswer (formerly hotLine), radio, and textToSpeech attributes obtained from data base. Text-To-Speech service contemplated. Deregistration works in the face of duplicate service names, etc. changes to: DIRECTORY, Register, DO changes to: DIRECTORY, Register, DO, DeregisterIfRegistered, ConsiderOne (local of DeregisterIfRegistered), Deregister Swinehart, October 28, 1985 9:55:38 am PST Names, Log => VoiceUtils, Handle => ID changes to: DIRECTORY, LarkSmartsInitImpl, ConversationID, Reseal, nullID, PartyID, SmartsID, Register, EnableSmarts, ConsiderOne (local of DeregisterIfRegistered), Deregister, SimpleDeregister, Login Swinehart, November 8, 1985 3:32:57 pm PST Accommodate new ThParty implementation changes to: DIRECTORY, Reseal, SHHH, Register, interfaceName, EnableSmarts, DeregisterIfRegistered, Deregister Κ ’˜šœ™Icodešœ Οmœ1™™>J™0J˜—šΟk œ˜ Jšœžœ˜Jšœ žœ˜*Jšœ žœ˜#Jšœžœ˜Jšžœ˜Jšœžœ$žœ˜5Jšœžœ)˜=J˜ J˜Jšœžœ5˜OJ˜Jšœžœ ˜Jšœžœ˜!Jšœ žœ˜%Jšœžœ˜ Jšœžœžœ˜#J˜JšžœžœN˜WJšœžœ˜Jšœžœ˜'Jšœ<˜šœ1˜1šœžœ ž˜Jšœ˜Jšžœ˜—J˜J˜Jšœ7˜7Jšœ˜—šžœžœ*žœ˜CJšœ;žœ˜?Jšœ(žœ ˜9—Jšœ-™-Jšœ ˜ Jšžœžœžœžœ˜šœžœ˜Jšœ˜J˜+J˜,J˜šœ žœ!˜.J˜J˜ J˜J˜ Jšœ8žœ˜>J˜——J˜$Jšœžœ ˜=J˜(šžœž˜Jšœ œR˜Y—Jšœ[˜[Jšœ +˜@šž˜Jšœ žœ˜—Jšœ˜—J˜JšŸ œžœžœ0˜Iš Ÿ œžœžœžœžœ žœ˜OJšžœžœžœ˜8šžœž˜#Jšœžœ˜$Jšžœžœžœ˜—Jš žœ6žœžœžœžœ˜Qšžœ5žœž˜=Jšœ7žœžœ˜H—šžœ:ž˜@Jšœ3žœ˜<—Jšœ7 ˜UJšœ7 ˜HJšžœžœ˜ Jšžœ žœžœ˜J˜J˜—šŸœžœžœ˜#Jšœ?˜?J™`šœ žœD˜RJšœ˜—Jšœžœ*  œ˜CJšžœžœžœžœ˜J˜J˜—J˜šŸ œžœžœžœ˜8Jšœžœ˜%šœžœžœžœž˜)Jšžœžœ% œ˜D—šžœžœž˜Jšœ9 ˜S—šœ<˜˜>šœ$žœžœ!˜TJ˜——šœ#™#J˜J˜+Jšœ"˜"J˜šŸœ˜#˜J˜A—J˜/J˜-J˜+J˜J˜—šŸœ˜)šžœ˜JšžœLžœ ˜^J˜—˜ J˜Jšœ_˜_J˜—šœA˜AJ˜;—Jšžœžœžœ˜ JšœE˜Ešœy˜yJ™I—JšœI˜I˜%J˜J˜J˜—Jšœ<žœ˜XJšœžœ˜šž˜˜ JšœDžœ˜N——J˜——˜J˜—šœ‘˜‘J˜J˜—šœQ˜QJ˜J˜—J˜™&K™ K™§K™AKšœ Οr™#Kšœ ’<œ"’ ™v—™*Kšœ$ž™&Kšœ ’uœ"’%™Θ—™*K™&Kšœ ’b™n—K™—…—%„9–