diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-01-07 01:44:04 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-01-07 01:44:04 +0000 |
commit | af93dd72c42bce9dc5528d7de9fd09ec285d8cb7 (patch) | |
tree | 3d3775d415a01b56fe4f534234b6dc7a9d0425b5 /client/ivamPipeConnector.py | |
parent | 2076ab0ce49b934ce287ff9a863d4b8885946dec (diff) |
It works!
git-svn-id: file:///home/lennart/svn/public/ivam2/trunk@17 dbf6933d-3bce-0310-9bcc-ed052ba35b35
Diffstat (limited to 'client/ivamPipeConnector.py')
-rw-r--r-- | client/ivamPipeConnector.py | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/client/ivamPipeConnector.py b/client/ivamPipeConnector.py index ff0be5f..70fd93d 100644 --- a/client/ivamPipeConnector.py +++ b/client/ivamPipeConnector.py @@ -1,5 +1,5 @@ -import os, sys, time, select, signal +import os, sys, time, select, signal, gzip import ivamCore, ivamApi, ivamUtil @@ -12,7 +12,7 @@ class PipeConnector(ivamApi.Connector): BUFSIZE = 128 - sdtin = sys.stdin + stdin = sys.stdin stdout = sys.stdout playing = False @@ -42,15 +42,15 @@ class PipeConnector(ivamApi.Connector): self.dtmfFifo = None return - self.dtmfFifo = file.open(fn, "rb") + self.dtmfFifo = file(fn, "rb") def playClip(self, fname): + self.stopPlayback() + if ivamCore.DEBUG: ivamCore.log("playClip('%s')" % fname) - self.stopPlayback() - self.playFile = ivamUtil.magicFile(fname, "rb") self.playName = fname self.playing = True @@ -65,16 +65,19 @@ class PipeConnector(ivamApi.Connector): self.playFile.close() self.playing = False - processor.onClipFinish(self, self.playName) + def stopPlayback2(self): - def recordClip(self, fname, gzip = False): + self.stopPlayback() + self.processor.onClipFinish(self, self.playName) - if ivamCore.DEBUG: - ivamCore.log("recordClip('%s')" % fname) + def recordClip(self, fname, z = False): self.stopRecording() - if gzip: + if ivamCore.DEBUG: + ivamCore.log("recordClip('%s')" % fname) + + if z: self.recordFile = gzip.open(fname, "w+b") else: self.recordFile = open(fname, "w+b") @@ -91,9 +94,9 @@ class PipeConnector(ivamApi.Connector): self.recordFile.close() self.recording = False - processor.onRecordFinish(self, self.recordName) + self.processor.onRecordFinish(self, self.recordName) - def timeout(self, t): + def setTimeout(self, t): if ivamCore.DEBUG: ivamCore.log("timeout(%u)" % t) @@ -115,7 +118,9 @@ class PipeConnector(ivamApi.Connector): self.stopPlayback() self.stopRecording() self.processor.onHangup(self) - self.dtmfFifo.close() + + if not self.dtmfFifo is None: + self.dtmfFifo.close() if ivamCore.DEBUG: ivamCore.log("run() finished") @@ -131,9 +136,6 @@ class PipeConnector(ivamApi.Connector): while not self.quit: - if ivamCore.DEBUG: - ivamCore.log("iteration") - t = None now = time.time() @@ -153,14 +155,15 @@ class PipeConnector(ivamApi.Connector): o += [self.stdout] if t is None: - i, o = select.select(i, o, []) + i, o, x = select.select(i, o, []) else: - i, o = select.select(i, o, [], t) + i, o, x = select.select(i, o, [], t) now = time.time() - if self.timeout < now: - processor.onTimeout() + if self.timeout and self.timeout < now: + self.processor.onTimeout(self) + self.timeout = 0 if self.quit: break # Check DTMF fifo @@ -174,12 +177,13 @@ class PipeConnector(ivamApi.Connector): if self.quit: break # Check STDIN - if self.stdin in o: + if self.stdin in i: self.readStdin() if self.quit: break def readStdin(self): + buf = os.read(self.stdin.fileno(), self.BUFSIZE) if buf == "": @@ -199,7 +203,7 @@ class PipeConnector(ivamApi.Connector): # EOF? if len(self.playBuffer) == 0: - self.stopPlayback() + self.stopPlayback2() return c = os.write(self.stdout.fileno(), self.playBuffer) @@ -208,14 +212,14 @@ class PipeConnector(ivamApi.Connector): if len(self.playBuffer) == 0: self.playBuffer = None - def dtmfCheck(self): + def handleDtmf(self): if not self.dtmfFifo is None: - d = self.dtmfFifoFd.read(1) + d = self.dtmfFifo.read(1) if d == "": self.dtmfFifo.close() self.dtmfFifo = None else: - self.onDtmfEvent(self, d) + self.processor.onDtmfEvent(self, d) |