[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
Thu Jun 30 16:50:57 CDT 2011
branch "decorator" has been updated
via df5b1e5ca8cd785a0b9daa9084ef6afdcead72ec (commit)
via 858a74e24593b5e789273adfb401769ae5d22b9e (commit)
from 2bf8c5517e9b8502c4d8a078909ee8b7a724ef5e (commit)
Summary of changes:
README.txt | 7 ++
Session_Decorator.py | 169 +++++++++++++++++++++++++++++--------------------
2 files changed, 107 insertions(+), 69 deletions(-)
- Log -----------------------------------------------------------------
commit df5b1e5ca8cd785a0b9daa9084ef6afdcead72ec
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Jun 30 16:38:04 2011 -0500
* Write to a file now
* Update README.txt
* Register with all extension points instead of just one
diff --git a/README.txt b/README.txt
index 17c5284..73345ac 100644
--- a/README.txt
+++ b/README.txt
@@ -24,3 +24,10 @@ At startup, it adds itself as a BridgeManagerListener and a default BridgeListen
When sessions are added to a bridge, it then adds itself as a SessionListener. All
events on bridges and sessions are caught by this script. The script simply prints
a message to stdout when an event is received.
+
+* Session_Decorator.py
+
+This script registers a session decorator hook with Asterisk SCF. The session decorator
+will log all session operations to a file whose name is based on the identity of the session
+it is decorating. All operations are then forwarded to the session that is being decorated.
+The script can be run with the -h option to see all possible options.
diff --git a/Session_Decorator.py b/Session_Decorator.py
index 47a992a..4a09f05 100755
--- a/Session_Decorator.py
+++ b/Session_Decorator.py
@@ -33,7 +33,8 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
def __init__(self, session, adapter):
self.session = session
self.adapter = adapter
- self.sessionPrxID = None;
+ self.sessionPrxID = None
+ self.file = None
def __del__(self):
if self.sessionPrxID:
@@ -43,29 +44,54 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
print "Caught exception trying to remove session decorator from object adapter"
def setProxy(self, sessionPrxID):
- print "setProxy"
self.sessionPrxID = sessionPrxID
-
+ self.file = open(sessionPrxID.name + ".txt", "w")
def addListener_async(self, cb, listener, current = None):
- print "addListener"
+ self.file.write("addListener\n")
sys.stdout.flush()
cb.ice_response(self.session.addListener(listener))
def setCookies(self, cookies, current = None):
- print "setCookies"
+ self.file.write("setCookies\n")
self.session.setCookies(cookies)
def removeCookies(self, cookies, current = None):
- print "removeCookies"
+ self.file.write("removeCookies\n")
self.session.removeCookies(cookies)
def getCookies(self, cookieTypes, current = None):
- print "getCookies"
+ self.file.write("getCookies\n")
return self.session.getCookies(cookieTypes)
def indicate_async(self, cb, event, current = None):
- print "indicate"
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.ConnectedIndication):
+ self.file.write("indicate (Connected)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.FlashedIndication):
+ self.file.write("indicate (Flashed)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.HeldIndication):
+ self.file.write("indicate (Held)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.ProgressingIndication):
+ self.file.write("indicate (Progressing)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.RingingIndication):
+ self.file.write("indicate (Ringing)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.StoppedIndication):
+ self.file.write("indicate (Stopped)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.UnheldIndication):
+ self.file.write("indicate (Unheld)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.ConnectIndication):
+ self.file.write("indicate (Connect)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.FlashIndication):
+ self.file.write("indicate (Flash)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.HoldIndication):
+ self.file.write("indicate (Hold)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.UnholdIndication):
+ self.file.write("indicate (Unhold)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.RingIndication):
+ self.file.write("indicate (Ring)\n")
+ if isinstance(event, AsteriskSCF.SessionCommunications.V1.ProgressIndication):
+ self.file.write("indicate (Progress)\n")
+
try:
self.session.indicate(event)
except AsteriskSCF.SessionCommunications.V1.IndicationException:
@@ -75,31 +101,33 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
cb.ice_response()
def getEndpoint_async(self, cb, current = None):
- print "getEndpoint"
+ self.file.write("getEndpoint\n")
cb.ice_response(self.session.getEndpoint())
def getInfo_async(self, cb, current = None):
- print "getInfo"
+ self.file.write("getInfo\n")
cb.ice_response(self.session.getInfo())
def getMediaSession_async(self, cb, current = None):
- print "getMediaSession"
+ self.file.write("getMediaSession\n")
cb.ice_response(self.session.getMediaSession())
def removeListener_async(self, cb, listener, current = None):
- print "removeListener"
+ self.file.write("removeListener\n")
self.session.removeListener(listener)
def start(self, current = None):
- print "start"
+ self.file.write("start\n")
self.session.start()
def stop(self, response, current = None):
- print "stop"
+ self.file.write("stop\n")
self.session.stop(response)
+ self.file.close()
+ self.adapter.remove(self.sessionPrxID)
def getBridge_async(self, cb, current = None):
- print "getBridge"
+ self.file.write("getBridge\n")
try:
bridge = self.session.getBridge()
except AsteriskSCF.SessionCommunications.V1.NotBridged:
@@ -109,11 +137,11 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
cb.ice_response(bridge)
def setBridge_async(self, cb, newBridge, listener, current=None):
- print "setBridge"
+ self.file.write("setBridge\n")
cb.ice_response(self.session.setBridge(newBridge, listener))
def removeBridge_async(self, cb, listener, current=None):
- print "removeBridge"
+ self.file.write("removeBridge\n")
try:
self.session.removeBridge(listener)
except AsteriskSCF.SessionCommunications.V1.NotBridged:
@@ -191,23 +219,25 @@ class DecoratorApp(Ice.Application):
print "Couldn't get the service locator"
return -1
+ self.extensionPoints = []
# XXX Once changes have been merged for Service discovery to use names without registering a custom
# comparator, we'll actually use the passed-in decoratorName here.
params = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams(AsteriskSCF.SessionCommunications.ExtensionPoints.V1.SessionDecoratorLocatorCategory)
try:
- extensionPointObj = locator.locate(params)
+ extensionPointObjs = locator.locateAll(params)
except AsteriskSCF.Core.Discovery.V1.ServiceNotFound:
print "No session decorator service found"
return -1
- self.extensionPoint = AsteriskSCF.SessionCommunications.ExtensionPoints.V1.SessionDecoratorExtensionPointPrx.checkedCast(extensionPointObj)
-
- if not self.extensionPoint:
- print "Couldn't get the session decorator extension point interface"
- return -1
-
- self.extensionPoint.addDecorator(self.hookPrx)
- print "Added ourself as a session decorator"
+ for e in extensionPointObjs:
+ extensionPoint = AsteriskSCF.SessionCommunications.ExtensionPoints.V1.SessionDecoratorExtensionPointPrx.checkedCast(e)
+ if not extensionPoint:
+ print "Couldn't get the session decorator extension point interface"
+ return -1
+ else:
+ extensionPoint.addDecorator(self.hookPrx)
+ self.extensionPoints.append(extensionPoint)
+ print "Added ourself as a session decorator"
# We want to remove ourself as listeners when we terminate, so we need to hook into the
# termination signal. Ice.Application provides a nice way to do this.
@@ -226,10 +256,11 @@ class DecoratorApp(Ice.Application):
# For the sake of clarity and efficiency, we simply remove ourselves
# as a default bridge listener and a bridge manager listener.
print "Removing ourself as a session decorator"
- try:
- self.extensionPoint.removeDecorator(self.hookPrx)
- except Ice.Exception as ex:
- print "Error trying to remove decorator"
+ for e in self.extensionPoints:
+ try:
+ e.removeDecorator(self.hookPrx)
+ except Ice.Exception as ex:
+ print "Error trying to remove decorator"
Ice.Application._destroyOnInterruptCallback(sig)
commit 858a74e24593b5e789273adfb401769ae5d22b9e
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Jun 30 14:57:06 2011 -0500
Use AMD methods, Adjust thread pool size, and other minor adjustments
diff --git a/Session_Decorator.py b/Session_Decorator.py
index c61b62f..47a992a 100755
--- a/Session_Decorator.py
+++ b/Session_Decorator.py
@@ -23,10 +23,6 @@ Ice.loadSlice("-I" + Ice.getSliceDir() + " -I" + os.environ["ASTSCF_HOME"] + " -
import AsteriskSCF.SessionCommunications.V1
-class SessionDecoratorCookie(AsteriskSCF.SessionCommunications.V1.SessionCookie):
- def __init__(self):
- pass
-
# This is a decorator for the Session class. The idea for it is that
# It contains within it a "real" session of some sort. We can add our
# own augmentations around the "real" session's methods to do things
@@ -38,7 +34,6 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
self.session = session
self.adapter = adapter
self.sessionPrxID = None;
- self.cookies = []
def __del__(self):
if self.sessionPrxID:
@@ -52,55 +47,46 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
self.sessionPrxID = sessionPrxID
- def addListener(self, listener, current = None):
+ def addListener_async(self, cb, listener, current = None):
print "addListener"
- return self.session.addListener(listener)
+ sys.stdout.flush()
+ cb.ice_response(self.session.addListener(listener))
def setCookies(self, cookies, current = None):
print "setCookies"
- for c in cookies:
- if isinstance(c, SessionDecoratorCookie):
- self.cookies.append(c)
-
self.session.setCookies(cookies)
def removeCookies(self, cookies, current = None):
print "removeCookies"
- for c in cookies:
- if isinstance(c, SessionDecoratorCookie):
- self.cookies.remove(c)
-
self.session.removeCookies(cookies)
def getCookies(self, cookieTypes, current = None):
print "getCookies"
- for c in cookieTypes:
- if isinstance(c, SessionDecoratorCookie):
- retCookies.extend(self.cookies)
+ return self.session.getCookies(cookieTypes)
- retCookies.extend(self.session.getCookies(cookieTypes))
- return retCookies
-
- def indicate(self, event, current = None):
+ def indicate_async(self, cb, event, current = None):
print "indicate"
try:
self.session.indicate(event)
except AsteriskSCF.SessionCommunications.V1.IndicationException:
- raise
+ cb.ice_exception(AsteriskSCF.SessionCommunications.V1.IndicationException())
+ return
+
+ cb.ice_response()
- def getEndpoint(self, current = None):
+ def getEndpoint_async(self, cb, current = None):
print "getEndpoint"
- return self.session.getEndpoint()
+ cb.ice_response(self.session.getEndpoint())
- def getInfo(self, current = None):
+ def getInfo_async(self, cb, current = None):
print "getInfo"
- return self.session.getInfo()
+ cb.ice_response(self.session.getInfo())
- def getMediaSession(self, current = None):
+ def getMediaSession_async(self, cb, current = None):
print "getMediaSession"
- return self.session.getMediaSession()
+ cb.ice_response(self.session.getMediaSession())
- def removeListener(self, listener, current = None):
+ def removeListener_async(self, cb, listener, current = None):
print "removeListener"
self.session.removeListener(listener)
@@ -110,32 +96,41 @@ class SessionDecorator(AsteriskSCF.SessionCommunications.V1.Session):
def stop(self, response, current = None):
print "stop"
- self.session.stop()
+ self.session.stop(response)
- def getBridge(self, current = None):
+ def getBridge_async(self, cb, current = None):
print "getBridge"
try:
- return self.session.getBridge()
+ bridge = self.session.getBridge()
except AsteriskSCF.SessionCommunications.V1.NotBridged:
- raise
+ cb.ice_exception(AsteriskSCF.SessionCommunications.V1.NotBridged())
+ return
- def setBridge(self, newBridge, listener, current=None):
+ cb.ice_response(bridge)
+
+ def setBridge_async(self, cb, newBridge, listener, current=None):
print "setBridge"
- return self.session.setBridge(newBridge, listener)
+ cb.ice_response(self.session.setBridge(newBridge, listener))
- def removeBridge(self, listener, current=None):
+ def removeBridge_async(self, cb, listener, current=None):
print "removeBridge"
- self.session.removeBridge(listener)
+ try:
+ self.session.removeBridge(listener)
+ except AsteriskSCF.SessionCommunications.V1.NotBridged:
+ cb.ice_exception(AsteriskSCF.SessionCommunications.V1.NotBridged())
+ return
+
+ cb.ice_response()
class SessionDecoratorHook(AsteriskSCF.SessionCommunications.ExtensionPoints.V1.SessionDecoratorHook):
def __init__(self, adapter):
self.adapter = adapter
def decorateSession(self, realSession, current = None):
# XXX When is it appropriate to remove the decorator from the adapter?
+ print "The proxy for the real session is " + realSession.ice_getIdentity().name
decorator = SessionDecorator(realSession, self.adapter)
decoratorObjPrx = self.adapter.addWithUUID(decorator)
decorator.setProxy(decoratorObjPrx.ice_getIdentity())
- print "I am the god of hellfire and I bring you fire"
result = AsteriskSCF.System.Hook.V1.HookResult(AsteriskSCF.System.Hook.V1.HookStatus.Succeeded, "cool")
print "The proxy we're going to send to AsteriskSCF is " + decoratorObjPrx.ice_getIdentity().name
return (result, AsteriskSCF.SessionCommunications.V1.SessionPrx.uncheckedCast(decoratorObjPrx))
@@ -212,6 +207,7 @@ class DecoratorApp(Ice.Application):
return -1
self.extensionPoint.addDecorator(self.hookPrx)
+ print "Added ourself as a session decorator"
# We want to remove ourself as listeners when we terminate, so we need to hook into the
# termination signal. Ice.Application provides a nice way to do this.
@@ -238,4 +234,8 @@ class DecoratorApp(Ice.Application):
Ice.Application._destroyOnInterruptCallback(sig)
app = DecoratorApp()
-sys.exit(app.main(sys.argv))
+initData = Ice.InitializationData()
+initData.properties = Ice.createProperties()
+initData.properties.setProperty("Ice.ThreadPool.Client.Size", "5")
+initData.properties.setProperty("Ice.ThreadPool.Server.Size", "5")
+sys.exit(app.main(sys.argv, None, initData))
-----------------------------------------------------------------------
--
asterisk-scf/examples.git
More information about the asterisk-scf-commits
mailing list