[ previous ] [ next ] [ threads ]
 To :  Carl Karsten <carl@p...>
 From :  Maciek Kaminski <maciejka@t...>
 Subject :  Re: [yate] yaypm puzzle
 Date :  Sat, 02 Sep 2006 10:01:49 +0200
Carl Karsten napisa?(a):

Hi Carl,
go_execute is a generator, to invoke generator as a flow one needs to 
wrap it with flow.go.

When you do just: self.go_execute(yatex), you just create an generator 
instance. To invoke it as a yaypm flow do: go(self.go_execute(yatex)), 
in return You will get a deferred.

See: http://yate.null.ro/pmwiki/index.php?n=Main.YAYPMGeneratorsInFlows

P.S.:
For consistency flow.go will also execute functions.

> 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)))
> 
> 
> 
>