[asterisk-scf-commits] asterisk-scf/examples.git branch "decorator" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Jul 13 16:13:52 CDT 2011
branch "decorator" has been updated
via a4f5f0557254d2959f1f2ff02d52e7c041f72152 (commit)
from b7a0dc30886982a44d492b6450bb9b95c0331f74 (commit)
Summary of changes:
Session_Decorator.py | 46 ++++++++++++++++++++++------------------------
1 files changed, 22 insertions(+), 24 deletions(-)
- Log -----------------------------------------------------------------
commit a4f5f0557254d2959f1f2ff02d52e7c041f72152
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Jul 13 16:14:09 2011 -0500
Decorate the session listener as well.
diff --git a/Session_Decorator.py b/Session_Decorator.py
index 992dcec..070bd03 100755
--- a/Session_Decorator.py
+++ b/Session_Decorator.py
@@ -29,21 +29,22 @@ import AsteriskSCF.SessionCommunications.V1
# we'd like. In this example, all we do is print messages to indicate
# things have happened, but it would be just as possible to do some
# interesting manipulations.
-class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
- def __init__(self, session, adapter):
+class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session, AsteriskSCF.SessionCommunications.V1.SessionListener):
+ def __init__(self, session, listeners, adapter):
self.session = session
+ self.listeners = listeners
self.adapter = adapter
self.sessionPrxID = None
self.file = None
- def setProxy(self, sessionPrxID):
+ def setProxyAndFile(self, sessionPrxID, file):
self.sessionPrxID = sessionPrxID
- self.file = open(sessionPrxID.name + ".txt", "w")
+ self.file = file
def addListener_async(self, cb, listener, current = None):
self.file.write("addListener\n")
- sys.stdout.flush()
- cb.ice_response(self.session.addListener(listener))
+ self.listeners.append(listener)
+ cb.ice_response(self.session.getInfo())
def setCookies(self, cookies, current = None):
self.file.write("setCookies\n")
@@ -107,7 +108,8 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
def removeListener_async(self, cb, listener, current = None):
self.file.write("removeListener\n")
- self.session.removeListener(listener)
+ self.listeners.remove(listener)
+ cb.ice_response()
def start(self, current = None):
self.file.write("start\n")
@@ -143,30 +145,26 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
cb.ice_response()
-class SessionListenerDecorator(AsteriskSCF.SessionCommunications.V1.SessionListener):
- def __init__(self, listeners, adapter):
- self.listeners = listeners
- self.adapter = adapter
-
- def setProxy(self, sessionListenerPrxID):
- self.sessionPrxID = sessionListenerPrxID
- self.file = open(sessionListenerPrxID.name + ".txt", "w")
+ def indicated(self, session, event, cookies, current=None):
+ for l in self.listeners:
+ l.indicated(session, event, cookies)
- def indicated(self, session, event, cookies):
- pass
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.Stopped):
+ self.adapter.remove(self.sessionPrxID)
+ self.file.close()
class SessionDecoratorHook(AsteriskSCF.SessionCommunications.ExtensionPoints.V1.SessionDecoratorHook):
def __init__(self, adapter):
self.adapter = adapter
def decorateSession(self, realSession, realListeners, current = None):
- decorator = SessionDecorator(realSession, self.adapter)
- decoratorPrx = AsteriskSCF.SessionCommunications.V1.SessionPrx.uncheckedCast(self.adapter.addWithUUID(decorator))
- decorator.setProxy(decoratorPrx.ice_getIdentity())
- decoratorListener = SessionListenerDecorator(realListeners, self.adapter)
- decoartorListenerPrx = AsteriskSCF.SessionCommunications.V1.SessionListenerPrx.uncheckedCast(self.adapter.addWithUUID(decoratorListener))
- decoratorListener.setProxy(decoratorListenerPrx.ice_getIdentity())
+ decorator = SessionDecorator(realSession, realListeners, self.adapter)
+ objPrx = self.adapter.addWithUUID(decorator)
+ decoratorPrx = AsteriskSCF.SessionCommunications.V1.SessionPrx.uncheckedCast(objPrx)
+ decoratorListenerPrx = AsteriskSCF.SessionCommunications.V1.SessionListenerPrx.uncheckedCast(objPrx)
+ file = open(decoratorPrx.ice_getIdentity().name + ".txt", "w")
+ decorator.setProxyAndFile(decoratorPrx.ice_getIdentity(), file)
result = AsteriskSCF.System.Hook.V1.HookResult(AsteriskSCF.System.Hook.V1.HookStatus.Succeeded, "cool")
- return (result, AsteriskSCF.SessionCommunications.V1.SessionPrx.uncheckedCast(decoratorPrx))
+ return (result, decoratorPrx, decoratorListenerPrx)
class DecoratorApp(Ice.Application):
def usage(self):
-----------------------------------------------------------------------
--
asterisk-scf/examples.git
More information about the asterisk-scf-commits
mailing list