From f4f65632542b7fbc5e752060007c6d57ce016439 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 15 Jun 2011 18:39:05 +0200 Subject: [PATCH] sccp: Remove the blocking interface from the SCCP code. --- SCCPHandler.st | 101 ++++++++++++++----------------------------------- Tests.st | 28 ++++++++++++++ 2 files changed, 57 insertions(+), 72 deletions(-) diff --git a/SCCPHandler.st b/SCCPHandler.st index 4b0f924..bc8fe58 100644 --- a/SCCPHandler.st +++ b/SCCPHandler.st @@ -18,24 +18,23 @@ PackageLoader fileInPackage: 'OsmoNetwork'. -Object subclass: SCCPConnection [ - | src dst queue conManager confirmSem proc state | +Object subclass: SCCPConnectionBase [ + | src dst conManager confirmSem proc state | - SCCPConnection class >> stateInitial [ ^ 0 ] - SCCPConnection class >> stateConnected [ ^ 1 ] - SCCPConnection class >> stateReleased [ ^ 2 ] - SCCPConnection class >> stateReleaseComplete [ ^ 3 ] - SCCPConnection class >> stateTimeout [ ^ 3 ] + SCCPConnectionBase class >> stateInitial [ ^ 0 ] + SCCPConnectionBase class >> stateConnected [ ^ 1 ] + SCCPConnectionBase class >> stateReleased [ ^ 2 ] + SCCPConnectionBase class >> stateReleaseComplete [ ^ 3 ] + SCCPConnectionBase class >> stateTimeout [ ^ 3 ] - SCCPConnection class >> new [ + SCCPConnectionBase class >> new [ ^ super new initialize; yourself ] initialize [ - state := SCCPConnection stateInitial. + state := self class stateInitial. confirmSem := Semaphore new. - queue := SharedQueue new. ] conManager [ @@ -48,11 +47,6 @@ Object subclass: SCCPConnection [ conManager := aHandler. ] - readQueue [ - - ^ queue - ] - srcRef [ ^ src @@ -72,34 +66,6 @@ Object subclass: SCCPConnection [ ^ dst ] - next [ - "Read the next item. If the connection is terminated" - | msg | - - "If we are not connected we need to wait" - state = SCCPConnection stateInitial - ifTrue: [ - self waitForConfirmation. - ]. - - "If we are not connected here. Send a EndOfStream signal" - (state > SCCPConnection stateConnected and: [self readQueue isEmpty]) - ifTrue: [ - ^ SystemExceptions.EndOfStream signal - ]. - - msg := self readQueue next. - - "If this is a small integer our connection is gone" - (msg isKindOf: SmallInteger) - ifTrue: [ - ^ SystemExceptions.EndOfStream signal - ]. - - "We do have a real message" - ^ msg - ] - nextPutData: aMsg [ | dt1 | dt1 := Osmo.SCCPConnectionData initWith: self dstRef data: aMsg. @@ -110,47 +76,24 @@ Object subclass: SCCPConnection [ conManager sendMsg: aMsg. ] - waitForConfirmation [ - "Wait for the connection to be confirmed and then exit" - - ((Delay forSeconds: 10) timedWaitOn: confirmSem) - ifTrue: [ - state := SCCPConnection stateTimeout. - conManager connectionTimeout: self. - ^ false - ]. - - ^ true - ] - - - "SCCP Connection state handling" - terminate [ - self readQueue nextPut: 0. - ] - confirm: aCC [ self dstRef: aCC src. - state := SCCPConnection stateConnected. + state := self class stateConnected. confirmSem signal. ] - data: aDT [ - self readQueue nextPut: aDT data. - ] - release [ | rlsd | - state := SCCPConnection stateReleased. + state := self class stateReleased. rlsd := Osmo.SCCPConnectionReleased initWithDst: self dstRef src: self srcRef cause: 0. self nextPut: rlsd toMessage. ] releaseComplete: aMSG [ "TODO: verify that we are in the right state" - state := SCCPConnection stateReleaseComplete. + state := self class stateReleaseComplete. self terminate. ] @@ -158,7 +101,7 @@ Object subclass: SCCPConnection [ | rlc | "Give up local resources here. We are done." - state := SCCPConnection stateReleaseComplete. + state := self class stateReleaseComplete. rlc := Osmo.SCCPConnectionReleaseComplete initWithDst: aRLSD src src: aRLSD dst. self nextPut: rlc toMessage. @@ -168,6 +111,16 @@ Object subclass: SCCPConnection [ state [ ^ state ] ] +SCCPConnectionBase subclass: SCCPConnection [ + data: aDT [ + "nothing implemented" + ] + + terminate [ + "noting implemented" + ] +] + Object subclass: MSGParser [ @@ -330,9 +283,13 @@ Object subclass: SCCPHandler [ "Interesting for subclasses" ] + connectionSpecies [ + ^ SCCPConnection + ] + confirmConnection: aMsg [ | con res | - con := SCCPConnection new. + con := self connectionSpecies new. con conManager: self. self addConnection: con. @@ -381,7 +338,7 @@ Object subclass: SCCPHandler [ createConnection: aData [ | con res| - con := SCCPConnection new. + con := self connectionSpecies new. con conManager: self. self addConnection: con. diff --git a/Tests.st b/Tests.st index 84cf047..2b88b0c 100644 --- a/Tests.st +++ b/Tests.st @@ -465,8 +465,36 @@ Object subclass: DirectConnection [ ] ] +SCCPConnection subclass: SCCPMockConnection [ + | queue | + + readQueue [ ^ queue ifNil: [queue := SharedQueue new]] + + next [ + | res | + + res := queue next. + res = 0 ifTrue: [ + ^ SystemExceptions.EndOfStream signal + ]. + + ^ res + ] + + data: aDT [ + self readQueue nextPut: aDT data + ] + + terminate [ + self readQueue nextPut: 0 + ] +] SCCPHandler subclass: SCCPHandlerNonRec [ + connectionSpecies [ + ^ SCCPMockConnection + ] + dissectMSG: aMsg [ ^ Osmo.SCCPMessage decode: aMsg asByteArray. ]