From 69810d6afa9619e75d615aea665460810c069467 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 27 May 2014 17:36:34 +0200 Subject: [PATCH] invite: Create a base class for the "call" I nee to differentiate between incoming and outgoing calls. At the same time a lot of logic can be shared. Specially at the time the call is established the hangup will work the same on both sides. --- callagent/session/SIPCall.st | 110 +------------------------ callagent/session/SIPCallBase.st | 136 +++++++++++++++++++++++++++++++ package.xml | 1 + 3 files changed, 139 insertions(+), 108 deletions(-) create mode 100644 callagent/session/SIPCallBase.st diff --git a/callagent/session/SIPCall.st b/callagent/session/SIPCall.st index 27c74f6..5e83f9a 100644 --- a/callagent/session/SIPCall.st +++ b/callagent/session/SIPCall.st @@ -16,22 +16,13 @@ along with this program. If not, see . " -SIPSessionBase subclass: SIPCall [ - | sdp_offer sdp_result invite state | +SIPCallBase subclass: SIPCall [ + | sdp_offer sdp_result invite | - SIPCall class >> stateInitial [ ^ #initial ] - SIPCall class >> stateInvite [ ^ #invite ] - SIPCall class >> stateSession [ ^ #session ] - SIPCall class >> stateTimeout [ ^ #timeout ] - SIPCall class >> stateCancel [ ^ #cancel ] - SIPCall class >> stateHangup [ ^ #hangup ] - SIPCall class >> stateRemoteHangup [ ^ #remoteHangup ] - SIPCall class >> stateFailed [ ^ #failed ] - SIPCall class >> stateRedirect [ ^ #redirect ] LegalStates := nil. @@ -61,29 +52,6 @@ will simply ignore everything but the first dialog.'> ^self fromIdenity: aUser identity: aUseragent mainIdentity host: aHost port: aPort to: aTo on: aUseragent ] - state [ - - ^ state ifNil: [self class stateInitial] - ] - - moveToState: aState [ - - - "E.g. we get two remote hang ups as our ack has not arrived." - self state = aState ifTrue: [^true]. - - "Check if there is a state transition" - (self class legalStates includes: (self state -> aState)) ifFalse: [ - self logError: ('SIPCall(<1s>) transition <2p>-><3p> is not legal.' - expandMacrosWithArguments: {self callId. self state. aState}) - area: #sip. - ^ false - ]. - - state := aState. - ^ true - ] - createCall: aSDPOffer [ @@ -120,21 +88,6 @@ will simply ignore everything but the first dialog.'> ^ false ] - hangup [ - - (self moveToState: self class stateHangup) ifTrue: [ - self logNotice: ('SIPCall(<1s>) going to hangup.' expandMacrosWith: self callId) - area: #sip. - - self unregisterDialog. - (SIPByeTransaction createWith: dialog on: ua cseq: self nextCSeq) - onTimeout: [self hangupTimedOut]; - onSuccess: [:resp :dlg | self hangupSuccess: resp dialog: dlg]; - onFailure: [:resp :dlg | self hangupFailure: resp dialog: dlg]; - start - ]. - ] - callTimedOut [ self logError: ('SIPCall(<1s>) timed-out.' expandMacrosWith: self callId) @@ -201,53 +154,11 @@ will simply ignore everything but the first dialog.'> self sessionNotification: aResponse. ] - hangupTimedOut [ - - self logNotice: ('SIPCall(<1s>) hang-up timedout.' - expandMacrosWith: self callId) area: #sip. - ] - - hangupSuccess: aResponse dialog: aDialog [ - - (self check: aDialog) ifFalse: [ - self logError: ('SIPCall(<1s>) can only have one session. Ignoring failure.' - expandMacrosWith: self callId) area: #sip. - ^ false - ]. - - self logNotice: ('SIPCall(<1s>) hang-up success.' - expandMacrosWith: self callId) area: #sip. - ] - - hangupFailure: aResponse dialog: aDialog [ - - (self check: aDialog) ifFalse: [ - self logError: ('SIPCall(<1s>) can only have one session. Ignoring failure.' - expandMacrosWith: self callId) area: #sip. - ^ false - ]. - - self logNotice: ('SIPCall(<1s>) hang-up failure.' - expandMacrosWith: self callId) area: #sip. - ] - remoteReInvite: aRequest dialog: aDialog [ "TODO: check if we are in a session..." ua respondWith: 200 phrase: 'OK' on: aRequest dialog: aDialog. ] - remoteHangup: aRequest dialog: aDialog [ - - - (self moveToState: self class stateRemoteHangup) ifTrue: [ - self logNotice: ('SIPCall(<1s>) session remotely terminated.' - expandMacrosWith: self callId) area: #sip. - ua respondWith: 200 phrase: 'OK' on: aRequest dialog: aDialog. - self unregisterDialog. - self sessionEnd. - ]. - ] - terminate [ "I try to finish up things." @@ -275,33 +186,16 @@ will simply ignore everything but the first dialog.'> ^true. ] - sessionNew [ - - ] - - sessionFailed [ - - ] - sessionRedirect: aContact [ "Legacy support to just fail" ^self sessionFailed ] - sessionEnd [ - - ] - sessionNotification: aNot [ ] - newRequest: aRequest dialog: aDialog [ - - aRequest sipCallDispatch: self dialog: aDialog. - ] - extractContact: aResponse [ | contact | contact := aResponse parameter: 'Contact'. diff --git a/callagent/session/SIPCallBase.st b/callagent/session/SIPCallBase.st new file mode 100644 index 0000000..5d5772e --- /dev/null +++ b/callagent/session/SIPCallBase.st @@ -0,0 +1,136 @@ +" + (C) 2011, 2014 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 . +" + +SIPSessionBase subclass: SIPCallBase [ + | state | + + + + + SIPCallBase class >> stateInitial [ ^ #initial ] + SIPCallBase class >> stateInvite [ ^ #invite ] + SIPCallBase class >> stateSession [ ^ #session ] + SIPCallBase class >> stateTimeout [ ^ #timeout ] + SIPCallBase class >> stateCancel [ ^ #cancel ] + SIPCallBase class >> stateHangup [ ^ #hangup ] + SIPCallBase class >> stateRemoteHangup [ ^ #remoteHangup ] + SIPCallBase class >> stateFailed [ ^ #failed ] + SIPCallBase class >> stateRedirect [ ^ #redirect ] + + state [ + + ^ state ifNil: [self class stateInitial] + ] + + moveToState: aState [ + + + "E.g. we get two remote hang ups as our ack has not arrived." + self state = aState ifTrue: [^true]. + + "Check if there is a state transition" + (self class legalStates includes: (self state -> aState)) ifFalse: [ + self logError: ('SIPCallBase(<1s>) transition <2p>-><3p> is not legal.' + expandMacrosWithArguments: {self callId. self state. aState}) + area: #sip. + ^ false + ]. + + state := aState. + ^ true + ] + + hangup [ + + (self moveToState: self class stateHangup) ifTrue: [ + self logNotice: ('SIPCallBase(<1s>) going to hangup.' expandMacrosWith: self callId) + area: #sip. + + self unregisterDialog. + (SIPByeTransaction createWith: dialog on: ua cseq: self nextCSeq) + onTimeout: [self hangupTimedOut]; + onSuccess: [:resp :dlg | self hangupSuccess: resp dialog: dlg]; + onFailure: [:resp :dlg | self hangupFailure: resp dialog: dlg]; + start + ]. + ] + + hangupTimedOut [ + + self logNotice: ('SIPCallBase(<1s>) hang-up timedout.' + expandMacrosWith: self callId) area: #sip. + ] + + hangupSuccess: aResponse dialog: aDialog [ + + (self check: aDialog) ifFalse: [ + self logError: ('SIPCallBase(<1s>) can only have one session. Ignoring failure.' + expandMacrosWith: self callId) area: #sip. + ^ false + ]. + + self logNotice: ('SIPCallBase(<1s>) hang-up success.' + expandMacrosWith: self callId) area: #sip. + ] + + hangupFailure: aResponse dialog: aDialog [ + + (self check: aDialog) ifFalse: [ + self logError: ('SIPCallBase(<1s>) can only have one session. Ignoring failure.' + expandMacrosWith: self callId) area: #sip. + ^ false + ]. + + self logNotice: ('SIPCallBase(<1s>) hang-up failure.' + expandMacrosWith: self callId) area: #sip. + ] + + remoteHangup: aRequest dialog: aDialog [ + + + (self moveToState: self class stateRemoteHangup) ifTrue: [ + self logNotice: ('SIPCallBase(<1s>) session remotely terminated.' + expandMacrosWith: self callId) area: #sip. + ua respondWith: 200 phrase: 'OK' on: aRequest dialog: aDialog. + self unregisterDialog. + self sessionEnd. + ]. + ] + + newRequest: aRequest dialog: aDialog [ + + aRequest sipCallDispatch: self dialog: aDialog. + ] + + sessionNew [ + + "Add custom handling" + ] + + sessionFailed [ + + "Add custom handling" + ] + + sessionEnd [ + + "Add custom handling" + ] + +] diff --git a/package.xml b/package.xml index cba2e62..01c45d8 100644 --- a/package.xml +++ b/package.xml @@ -51,6 +51,7 @@ callagent/session/Extensions.st callagent/session/SIPSessionBase.st + callagent/session/SIPCallBase.st callagent/session/SIPCall.st callagent/transport/SIPTransport.st