1
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
osmo-st-testphone/TestPhone.st

142 lines
3.0 KiB
Smalltalk
Raw Normal View History

2010-11-14 21:37:50 +00:00
PackageLoader fileInPackage: 'OsmoNetwork'.
Object subclass: IPAConnection [
| socket demuxer queue muxer dispatcher sccp ipa sem |
2010-11-14 21:37:50 +00:00
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.
2010-11-14 21:37:50 +00:00
demuxer := Osmo.IPADemuxer initOn: socket.
queue := SharedQueue new.
muxer := Osmo.IPAMuxer initOn: queue.
dispatcher := Osmo.IPADispatcher new.
dispatcher initialize.
sccp := SCCPHandler new.
2010-11-14 21:37:50 +00:00
sccp registerOn: dispatcher.
sccp connection: self.
2010-11-14 21:37:50 +00:00
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.
]
2010-11-14 21:37:50 +00:00
]
]
send: aMsg with: aType [
muxer nextPut: aMsg with: aType.
self drainSendQueue.
]
sccpHandler [
^ sccp
]
2010-11-14 21:37:50 +00:00
]
Object subclass: IPAConfig [
| socket addr port token connection sem |
2010-11-14 21:37:50 +00:00
addr: anAddr port: aPort [
addr := anAddr.
port := aPort.
]
token: aToken [
token := aToken.
]
connect [
sem := Semaphore new.
2010-11-14 21:37:50 +00:00
connection := IPAConnection initWith: addr port: port token: token.
]
connection [
^ connection
]
serve [
[
[
connection serve.
'Connection disconnected' printNl.
] ensure: [
connection := nil.
sem signal.
]
] fork.
]
2010-11-14 21:37:50 +00:00
isConnected [
^ connection isNil not
]
semaphore [ ^ sem ]
sendLU: aPhone [
| proc |
proc := LUProcedure initWith: (connection sccpHandler) phone: aPhone.
proc execute.
]
callNumber: aPhone [
| proc |
proc := CallProcedure initWith: (connection sccpHandler) phone: aPhone.
proc execute.
]
2010-11-14 21:37:50 +00:00
]
Object subclass: PhoneConfig [
| imsi auKey |
<comment: 'I am the config of a phone. I do have an IMSI and such.'>
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.
]
]