diff options
Diffstat (limited to 'callagent/MGCPTrunk.st')
-rw-r--r-- | callagent/MGCPTrunk.st | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/callagent/MGCPTrunk.st b/callagent/MGCPTrunk.st index b58ddb3..52d8351 100644 --- a/callagent/MGCPTrunk.st +++ b/callagent/MGCPTrunk.st @@ -17,7 +17,7 @@ " Object subclass: MGCPTrunkBase [ - | ip ports sem | + | ip ports sem last | <comment: 'I represent a trunk for a Gateway'> <category: 'MGCP-Callagent'> @@ -54,13 +54,41 @@ Object subclass: MGCPTrunkBase [ ^ ports at: aNr ] + lastUsed [ + <category: 'private'> + ^ last ifNil: [0] + ] + endpointName: aNr [ + <category: 'accessing'> ^ self subclassResponsibility ] critical: aBlock [ + <category: 'accessing'> sem critical: aBlock. ] + + allocateEndpointIfFailure: aBlock [ + | alloc | + <category: 'allocation'> + "You need to hold the lock to do any changes here" + + alloc := [:each | + (self endpointAt: each) isUnused ifTrue: [ + last := each. + ^ (self endpointAt: each) + reserve; + yourself + ]]. + + "Go from last to end, and then from start to last." + self lastUsed + 1 to: ports size do: alloc. + 1 to: self lastUsed do: alloc. + + "And give up now" + ^ aBlock value. + ] ] MGCPTrunkBase subclass: MGCPVirtualTrunk [ |