[ previous ] [ next ] [ threads ]
 To :  yate@v...
 From :  Carl Karsten <carl@p...>
 Subject :  yaypm puzzle
 Date :  Fri, 01 Sep 2006 20:18:53 -0500
I am trying to build a class that abstracts the concepts of processing a call. 
  I am designing it as I go along, as I use it I will flesh it out, and any 
suggestions are welcome.

problem is, something that seems like it should work doesn't.  If I comment out 
#1 and uncomment #2, why doesn't it work?

(The 2 lines that use yatex2 will be removed if I can get #2 working.)

Carl K


# CallHandler.py
# Classes to abstract the tasks of makeing and receiving calls.

from twisted.internet import reactor, defer
from yaypm import TCPDispatcherFactory, AbandonedException
from yaypm.flow import go, getResult
import logging, yaypm.utils

class OutboundCall:
	"A complete outbound call"

	# instance of the message logger
	logger = logging.getLogger('yaypm.examples')

	def __init__(self):
		self.yate=None # the server object
		self.target='101' # the number to dial
		self.state=0  # Phase the call is in

	def log( self, text ):
		self.logger.info( text )

	def go_pre(self):
		pass

	def go_execute(self,yatex2):
		# Setup handlers for the various events that may occure
		# tie the events to the methods of this class
		# (havn't even stubbed the events yet -
		#  just trying to get something to work)
		# I am guessing most of this should be moved into .init
		# It is here because I am trying to make a class
		# from a function maciejka posted in #yate

		self.yate=yatex2

		execute = self.yate.msg("call.execute",
			{"callto": "dumb/",
			"target": self.target})
		yield execute.dispatch()

		if not getResult():
			self.log("Outgoing call failed.")
			return

		end = self.yate.onwatch(
			"chan.hangup",
			lambda m : m["id"] == execute["id"])

		try:
			yield self.yate.onwatch(
				"call.answered",
				lambda m : m["targetid"] == execute["id"],
				until = end)
			answered = getResult()
			# do call processing here,
			# you can call handler function for example:
			go(handler(yate, execute["id"], execute["peerid"]))
		except AbandonedException, e:
			self.log("Outgoing call to %s abandoned" % execute["id"])
	def go_post(self):
                 pass

	def gox(self, yatex):
		self.yate=yatex
		self.go_pre()
		self.go_execute(yatex)
		self.go_post()

onecall = OutboundCall()

#1 works
# yaypm.utils.setup(lambda yate: go(onecall.go_execute(yate)))

#2 doesn;t work
yaypm.utils.setup(lambda yate: go(onecall.gox(yate)))