[Shtoom] big patch for dev to try and others to look at
zooko at zooko.com
zooko at zooko.com
Wed Sep 28 04:57:46 CEST 2005
> I have never used or
> completely understood doug, and I haven't tested it, therefore I'm sure that
> this patch breaks doug even though I tried to make what appeared to be the
> appropriate changes to doug as I went along.
Oh, but I omitted the changes to doug from that patch. Here are my changes to
doug:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 2975 bytes
Desc: doug.patch.gz
URL: <http://mail.python.org/pipermail/shtoom/attachments/20050927/b7d52149/attachment.obj>
-------------- next part --------------
Tue Sep 27 23:55:24 ADT 2005 zooko at zooko.com
* untested attempt to keep doug up to date with the big refactoring patch
diff -rN -u old-tailor1406/shtoom/shtoom/app/doug.py new-tailor1406/shtoom/shtoom/app/doug.py
--- old-tailor1406/shtoom/shtoom/app/doug.py 2005-09-27 23:56:17.160439200 -0300
+++ new-tailor1406/shtoom/shtoom/app/doug.py 2005-09-27 23:56:17.287419896 -0300
@@ -203,11 +203,6 @@
except IOError:
pass
- def outgoingRTP(self, cookie, sample):
- rtp = self._rtp.get(cookie)
- if rtp and sample:
- rtp.handle_media_sample(sample)
-
def placeCall(self, cookie, nleg, sipURL, fromURI=None):
ncookie = self.getCookie()
nleg.setCookie(ncookie)
diff -rN -u old-tailor1406/shtoom/shtoom/doug/leg.py new-tailor1406/shtoom/shtoom/doug/leg.py
--- old-tailor1406/shtoom/shtoom/doug/leg.py 2005-09-27 23:56:17.158439504 -0300
+++ new-tailor1406/shtoom/shtoom/doug/leg.py 2005-09-27 23:56:17.291419288 -0300
@@ -9,11 +9,9 @@
"""
from shtoom.doug.source import Source, SilenceSource, convertToSource
-from shtoom.audio.converters import DougConverter
from shtoom.doug.events import *
from shtoom.doug.exceptions import *
from twisted.python import log
-from twisted.internet.task import LoopingCall
class Leg(object):
@@ -22,13 +20,12 @@
_acceptDeferred = None
_voiceapp = None
- def __init__(self, cookie, dialog, voiceapp=None):
+ def __init__(self, cookie, dialog):
""" Create a new leg
"""
self._cookie = cookie
self._dialog = dialog
self._acceptDeferred = None
- self.__converter = DougConverter()
self.__playoutList = []
self.__recordDest = None
self.__silenceSource = SilenceSource()
@@ -37,26 +34,7 @@
self.__collectedDTMFKeys = ''
self.__dtmfSingleMode = True
self.__inbandDTMFdetector = None
- self._voiceapp = voiceapp
self._connectSource(self.__silenceSource)
- self._startAudio()
-
- def _startAudio(self):
- #print self, "starting audio"
- self.LC = LoopingCall(self._get_some_audio)
- self.LC.start(0.020)
-
- def _stopAudio(self):
- if self.LC is not None:
- #print self, "stopping audio", self.LC, self.LC.call
- self.LC.stop()
- self.LC = None
-
- def _get_some_audio(self):
- if self._voiceapp is not None:
- data = self.__connected.read()
- sample = self.__converter.convertOutbound(data)
- self._voiceapp.va_outgoingRTP(sample)
def getDialog(self):
return self._dialog
@@ -122,9 +100,7 @@
self._cookie), system='doug')
def hangupCall(self):
- self._stopAudio()
- if self._voiceapp:
- self._voiceapp.va_hangupCall(self._cookie)
+ self._voiceapp.va_hangupCall(self._cookie)
def sendDTMF(self, digits, duration=0.1, delay=0.05):
self._voiceapp.sendDTMF(digits, cookie=self._cookie,
@@ -196,9 +172,6 @@
dtmf, self.__collectedDTMFKeys = self.__collectedDTMFKeys, ''
self._voiceapp._triggerEvent(DTMFReceivedEvent(dtmf, self))
- def selectDefaultFormat(self, ptlist):
- return self.__converter.selectDefaultFormat(ptlist)
-
def leg_stopDTMFevent(self, dtmf):
# For now, I only care about dtmf start events
if dtmf == self.__currentDTMFKey:
@@ -230,9 +203,6 @@
self.__inbandDTMFdetector = None
# XXX handle timeout
- def __repr__(self):
- return '<Leg at %x connected to %r>'%(id(self), self._voiceapp)
-
class BridgeSource(Source):
"A BridgeSource connects a leg to another leg via a bridge"
diff -rN -u old-tailor1406/shtoom/shtoom/doug/statemachine.py new-tailor1406/shtoom/shtoom/doug/statemachine.py
--- old-tailor1406/shtoom/shtoom/doug/statemachine.py 2005-09-27 23:56:17.142441936 -0300
+++ new-tailor1406/shtoom/shtoom/doug/statemachine.py 2005-09-27 23:56:17.290419440 -0300
@@ -17,20 +17,16 @@
class StateMachine(object):
- _statemachine_debug = False
-
def __init__(self, defer, **kwargs):
self._doneDeferred = defer
self._deferredState = None
def returnResult(self, result):
- self._cleanup()
d, self._doneDeferred = self._doneDeferred, None
if d:
d.callback(result)
def returnError(self, exc):
- self._cleanup()
d, self._doneDeferred = self._doneDeferred, None
if d:
d.errback(exc)
@@ -57,8 +53,6 @@
else:
log.msg("No matching event for %s in state %s"%(
event.getEventName(), self.getCurrentState()))
- if self._statemachine_debug:
- log.msg("current transitions: %r"%(self.getCurrentEvents()))
self.returnError(EventNotSpecifiedError(
"No matching event for %s in state %s"
%(event.getEventName(), self.getCurrentState())))
@@ -75,14 +69,6 @@
def _doState(self, callable, evt=None):
self._curState = callable.__name__
- if self._statemachine_debug:
- if evt is not None:
- log.msg("%s switching to state %s (no event)"%(
- self.__class__.__name__, self._curState))
- else:
- log.msg("%s switching to state %s (%s)"%(
- self.__class__.__name__, self._curState,
- evt.__class__.__name__))
if evt:
em = callable(evt)
else:
@@ -114,7 +100,3 @@
def __start__(self):
raise NotImplementedError
-
- def _cleanup(self):
- # Override in subclass if needed
- pass
diff -rN -u old-tailor1406/shtoom/shtoom/doug/voiceapp.py new-tailor1406/shtoom/shtoom/doug/voiceapp.py
--- old-tailor1406/shtoom/shtoom/doug/voiceapp.py 2005-09-27 23:56:17.136442848 -0300
+++ new-tailor1406/shtoom/shtoom/doug/voiceapp.py 2005-09-27 23:56:17.289419592 -0300
@@ -42,15 +42,13 @@
super(VoiceApp, self).__init__(defer, **kwargs)
def getDefaultLeg(self):
- if self.__legs:
- return self.__legs.values()[0]
+ return self.__legs.values()[0]
def getLeg(self, cookie):
return self.__legs.get(cookie)
def setLeg(self, leg, cookie):
self.__legs[cookie] = leg
- #self.leg.hijackLeg(self)
def va_selectDefaultFormat(self, ptlist, callcookie):
return self.getLeg(callcookie).selectDefaultFormat(ptlist)
@@ -58,9 +56,6 @@
def va_incomingRTP(self, packet, callcookie):
return self.getLeg(callcookie).leg_incomingRTP(packet)
- def va_outgoingRTP(self, sample):
- self.__appl.outgoingRTP(self.__cookie, sample)
-
def va_start(self):
self._start(callstart=0)
@@ -87,18 +82,8 @@
system='doug')
self._triggerEvent(CallRejectedEvent(leg))
- def _clear_legs(self):
- from shtoom.util import stack
- #print self, "clearing running legs %r"%(self.__legs.items())#,stack(8)
- for name, leg in self.__legs.items():
- leg._stopAudio()
- del self.__legs[name]
-
- _cleanup = _clear_legs
-
def va_abort(self):
self.mediaStop()
- self._clear_legs()
self._triggerEvent(CallEndedEvent(None))
def mediaPlay(self, playlist, leg=None):
@@ -114,8 +99,7 @@
def mediaStop(self, leg=None):
if leg is None:
leg = self.getDefaultLeg()
- if leg is not None:
- leg.mediaStop()
+ leg.mediaStop()
def setTimer(self, delay):
return Timer(self, delay)
@@ -137,7 +121,7 @@
def placeCall(self, toURI, fromURI=None):
from shtoom.doug.leg import Leg
- nleg = Leg(cookie=None, dialog=None, voiceapp=self)
+ nleg = Leg(cookie=None, dialog=None)
self.__appl.placeCall(self.__cookie, nleg, toURI, fromURI)
def va_hangupCall(self, cookie):
diff -rN -u old-tailor1406/shtoom/shtoom/test/test_doug.py new-tailor1406/shtoom/shtoom/test/test_doug.py
--- old-tailor1406/shtoom/shtoom/test/test_doug.py 2005-09-27 23:56:17.125444520 -0300
+++ new-tailor1406/shtoom/shtoom/test/test_doug.py 2005-09-27 23:56:17.292419136 -0300
@@ -24,6 +24,10 @@
# ring ring
pass
+ def notifyEvent(self, event, arg):
+ # Okay.
+ pass
+
def acceptErrors(self, cookie, error):
#print "cookie %s got error %r"%(cookie, error)
if self._trial_def is not None:
@@ -43,17 +47,6 @@
#print "started!"
self.returnResult('hello world')
-class NullListenApp(VoiceApp):
- """ This application does nothing but return """
-
- def __start__(self):
- #print "started!"
- return ( ( CallStartedEvent, self.started), )
-
- def started(self, event):
- event.leg.rejectCall(CallRejected('you suck'))
- self.returnResult('hello world')
-
class SimpleListenApp(VoiceApp):
""" This application listens, connects a call, then either disconnects
it, or waits for the other end to disconnect it
@@ -87,7 +80,6 @@
""" This application places a call, then then either disconnects
it, or waits for the other end to disconnect it
"""
- _statemachine_debug = True
callURL = None
localDisconnect = False
@@ -165,9 +157,8 @@
self.assertEquals(s.val, 'hello world')
app.stopSIP()
- # This test is fundamentally broken.
- def not_test_callAndStartup(self):
- lapp = TestDougApplication(NullListenApp)
+ def test_callAndStartup(self):
+ lapp = TestDougApplication(NullApp)
lapp.boot(args=['--listenport', '0'])
# Now get the port number we actually listened on
port = lapp.sipListener.getHost().port
More information about the Shtoom
mailing list