" (C) 2010 by Holger Hans Peter Freyther All Rights Reserved This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . " PackageLoader fileInPackage: 'OsmoNetwork'. Object subclass: IPAConnection [ | socket demuxer queue muxer dispatcher sccp ipa sem | IPAConnection class >> initWith: anAddr port: aPort token: aToken [ ^ (self new) socket: (Sockets.Socket remote: anAddr port: aPort); setup: aToken; yourself ] socket: aSocket [ socket := aSocket. ] setup: aToken [ sem := Semaphore forMutualExclusion. demuxer := Osmo.IPADemuxer initOn: socket. queue := SharedQueue new. muxer := Osmo.IPAMuxer initOn: queue. dispatcher := Osmo.IPADispatcher new. dispatcher initialize. sccp := SCCPHandler new. sccp registerOn: dispatcher. sccp connection: self. ipa := Osmo.IPAProtoHandler new. ipa registerOn: dispatcher. ipa muxer: muxer. ipa token: aToken ] serve [ [true] whileTrue: [ [ | data | data := demuxer next. dispatcher dispatch: data first with: data second. self drainSendQueue. ] on: SystemExceptions.EndOfStream do: [:e | ^ false ] ] ] drainSendQueue [ sem critical: [ [queue isEmpty] whileFalse: [ | msg | msg := queue next. socket nextPutAllFlush: msg. ] ] ] send: aMsg with: aType [ muxer nextPut: aMsg with: aType. self drainSendQueue. ] sccpHandler [ ^ sccp ] ] Object subclass: IPAConfig [ | socket addr port token connection sem | addr: anAddr port: aPort [ addr := anAddr. port := aPort. ] token: aToken [ token := aToken. ] connect [ sem := Semaphore new. connection := IPAConnection initWith: addr port: port token: token. ] connection [ ^ connection ] serve [ [ [ connection serve. 'Connection disconnected' printNl. ] ensure: [ connection := nil. sem signal. ] ] fork. ] isConnected [ ^ connection isNil not ] semaphore [ ^ sem ] doLU: aPhone [ ^ LUProcedure initWith: (connection sccpHandler) phone: aPhone. ] sendLU: aPhone [ (self doLU: aPhone) execute. ] doCallNumber: aPhone nr: aNr [ ^ CallProcedure initWith: (connection sccpHandler) phone: aPhone nr: aNr. ] callNumber: aPhone nr: aNumber [ ^ (self doCallNumber: aPhone nr: aNumber) execute ] ] Object subclass: PhoneConfig [ | imsi auKey | PhoneConfig class >> initWith: aImsi auKey: anAuKey [ ^ self new imsi: aImsi; auKey: anAuKey; yourself ] imsi: aImsi [ imsi := aImsi. ] imsi [ ^ imsi ] auKey [ ^ auKey ] auKey: anAuKey [ auKey := anAuKey. ] auKeyByteArray [ ^ auKey isString ifTrue: [ | array | array := OrderedCollection new. 1 to: auKey size by: 2 do: [:each | array add: (Number readFrom: (auKey copyFrom: each to: each + 1) readStream radix: 16) ]. array asByteArray. ] ifFalse: [auKey]. ] ]