[asterisk-scf-commits] asterisk-scf/examples.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Jun 5 17:02:06 CDT 2012
branch "master" has been updated
via dc9bcf1b3177673ebdaaefb6f6b5a4ba72279d6f (commit)
from 2577f640cc0f5c645d1f989b9923300989e6369d (commit)
Summary of changes:
Bridge_SessionListener.py | 59 +++++++++++++++++++---------------
ExamplePartyIdHooks.py | 78 +++++++++++++++++++++++++--------------------
ExampleSipAuthHook.py | 17 +++++++---
3 files changed, 88 insertions(+), 66 deletions(-)
mode change 100644 => 100755 ExamplePartyIdHooks.py
- Log -----------------------------------------------------------------
commit dc9bcf1b3177673ebdaaefb6f6b5a4ba72279d6f
Author: David M. Lee <dlee at digium.com>
Date: Tue Jun 5 16:11:25 2012 -0500
Fixed example hooks.
Added retry logic, and brought up to date with current code.
diff --git a/Bridge_SessionListener.py b/Bridge_SessionListener.py
index b537047..1bbef1e 100755
--- a/Bridge_SessionListener.py
+++ b/Bridge_SessionListener.py
@@ -3,7 +3,7 @@
#
# Asterisk SCF -- An open-source communications framework.
#
-# Copyright (C) 2011, Digium, Inc.
+# Copyright (C) 2011-2012, Digium, Inc.
#
# See http://www.asterisk.org for more information about
# the Asterisk SCF project. Please do not directly contact
@@ -16,18 +16,25 @@
# at the top of the source tree.
#
-import Ice, os, sys, getopt
+import Ice, os, sys, getopt, uuid
Ice.loadSlice("-I" + Ice.getSliceDir() + " -I" + os.environ["ASTSCF_HOME"] + " --all " + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/SessionCommunications/SessionCommunicationsIf.ice")
import AsteriskSCF.SessionCommunications.V1
+from AsteriskSCF.System.V1 import *
SessionListenerID = "SessionListener"
+def createContext():
+ newContext = OperationContext()
+ newContext.id = str(uuid.uuid4()) # Random UUID
+ newContext.transactionId = newContext.id
+ return newContext
+
class SessionListener(AsteriskSCF.SessionCommunications.V1.SessionListener):
def __init__(self, adapter):
self.adapter = adapter
- def indicated(self, source, event, cookies, current = None):
+ def indicated(self, context, source, event, cookies, current = None):
if isinstance(event, AsteriskSCF.SessionCommunications.V1.ConnectedIndication):
print "Session %s received Connected indication" % (source.ice_getIdentity().name)
if isinstance(event, AsteriskSCF.SessionCommunications.V1.FlashedIndication):
@@ -58,30 +65,30 @@ class SessionListener(AsteriskSCF.SessionCommunications.V1.SessionListener):
class BridgeListener(AsteriskSCF.SessionCommunications.V1.BridgeListener):
def __init__(self, adapter):
self.adapter = adapter
- def sessionsAdded(self, sessionBridge, sessions, current = None):
+ def sessionsAdded(self, context, sessionBridge, sessions, cookies, current = None):
print "Sessions added to bridge %s" % (sessionBridge.ice_getIdentity().name)
for s in sessions:
try:
- s.addListener(AsteriskSCF.SessionCommunications.V1.SessionListenerPrx.uncheckedCast(self.adapter.createDirectProxy(self.adapter.getCommunicator().stringToIdentity(SessionListenerID))))
+ s.addListener(createContext(), AsteriskSCF.SessionCommunications.V1.SessionListenerPrx.uncheckedCast(self.adapter.createDirectProxy(self.adapter.getCommunicator().stringToIdentity(SessionListenerID))))
print "Added ourself as a listener to session %s with endpoint %s" % (s.ice_getIdentity().name, s.getEndpoint().getId())
except Ice.Exception as ex:
print "Exception caught while attempting to add ourself as a SessionListener: " + ex.what()
- def sessionsRemoved(self, sessionBridge, sessions, current = None):
+ def sessionsRemoved(self, context, sessionBridge, sessions, cookies, current = None):
for s in sessions:
print "Session %s removed from bridge %s" % (s.ice_getIdentity().name, sessionBridge.ice_getIdentity().name)
- def stopped(self, sessionBridge, current = None):
+ def stopped(self, context, sessionBridge, cookies, current = None):
print "Bridge %s stopped" % (sessionBridge.ice_getIdentity().name)
- def stopping(self, sessionBridge, current = None):
+ def stopping(self, context, sessionBridge, cookies, current = None):
print "Bridge %s stopping" % (sessionBridge.ice_getIdentity().name)
class BridgeManagerListener(AsteriskSCF.SessionCommunications.V1.BridgeManagerListener):
def __init__(self, adapter):
self.adapter = adapter
- def bridgeCreated(self, manager, newBridge, current = None):
+ def bridgeCreated(self, context, manager, newBridge, current = None):
print "Detected creation of new bridge %s" % (newBridge.ice_getIdentity().name)
- def stopped(self, manager, current = None):
+ def stopped(self, context, manager, current = None):
print "Bridge Manager has stopped"
- def stopping(self, manager, current = None):
+ def stopping(self, context, manager, current = None):
print "Bridge Manager is stopping"
self.adapter.remove(self.communicator().stringToIdentity(BridgeManagerListenerId))
@@ -94,9 +101,9 @@ class ListenerApp(Ice.Application):
print "-h, --help Display help information"
print "-l, --locator=PROXY Use specified proxy for Service locator"
print " Default: 'LocatorService:tcp -p 4411"
-
+
def run(self, args):
-
+
try:
opts, arguments = getopt.getopt(args[1:], "hl:", ["help", "locator="])
except getopt.GetoptError, err:
@@ -143,7 +150,7 @@ class ListenerApp(Ice.Application):
# Now we need to find the bridge manager. We use the service locator for this.
# First, we get a proxy to the service locator.
serviceLocator = AsteriskSCF.Core.Discovery.V1.ServiceLocatorPrx.checkedCast(self.communicator().stringToProxy(serviceLocatorString))
-
+
if not serviceLocator:
print "Couldn't get the service locator"
return -1
@@ -151,16 +158,16 @@ class ListenerApp(Ice.Application):
# Next, we need to populate the parameters for the service locator to be able
# to find the bridge manager.
serviceLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
- serviceLocatorParams.category = AsteriskSCF.SessionCommunications.V1.BridgeServiceDiscoveryCategory
+ serviceLocatorParams.category = AsteriskSCF.SessionCommunications.V1.BridgeManagerDiscoveryCategory
# Now we locate the bridge manager
try:
service = serviceLocator.locate(serviceLocatorParams)
+ self.bridgeManager = AsteriskSCF.SessionCommunications.V1.BridgeManagerPrx.checkedCast(service)
except Ice.Exception as ex:
- print "Exception while attempting to locate BridgeManager: " + ex.what()
- self.bridgeManager = AsteriskSCF.SessionCommunications.V1.BridgeManagerPrx.checkedCast(service)
+ print "Exception while attempting to locate BridgeManager: ", ex
- if not self.bridgeManager:
+ if not hasattr(self, 'bridgeManager') or not self.bridgeManager:
print "Couldn't get the bridge manager"
return -1
@@ -169,9 +176,9 @@ class ListenerApp(Ice.Application):
# We add ourself as a listener to the bridge manager.
self.bridgeManagerListenerPrx = AsteriskSCF.SessionCommunications.V1.BridgeManagerListenerPrx.uncheckedCast(bridgeManagerListenerObjPrx)
try:
- self.bridgeManager.addListener(self.bridgeManagerListenerPrx)
+ self.bridgeManager.addListener(createContext(), self.bridgeManagerListenerPrx)
except Ice.Exception as ex:
- print "Exception while attempting to add ourself as a BridgeManagerListener: " + ex.what()
+ print "Exception while attempting to add ourself as a BridgeManagerListener: ", ex
print "Added ourself as a BridgeManagerListener"
@@ -179,9 +186,9 @@ class ListenerApp(Ice.Application):
# have ourself added as a listener to any bridge that gets created.
self.bridgeListenerPrx = AsteriskSCF.SessionCommunications.V1.BridgeListenerPrx.uncheckedCast(bridgeListenerObjPrx)
try:
- self.bridgeManager.addDefaultBridgeListener(self.bridgeListenerPrx)
+ self.bridgeManager.addDefaultBridgeListener(createContext(), self.bridgeListenerPrx)
except Ice.Exception as ex:
- print "Exception while attempting to add ourself as a DefaultBridgeListener: " + ex.what()
+ print "Exception while attempting to add ourself as a DefaultBridgeListener: ", ex
print "Added ourself as a default BridgeListener"
@@ -203,15 +210,15 @@ class ListenerApp(Ice.Application):
# as a default bridge listener and a bridge manager listener.
print "Removing ourself as a default bridge listener"
try:
- self.bridgeManager.removeDefaultBridgeListener(self.bridgeListenerPrx)
+ self.bridgeManager.removeDefaultBridgeListener(createContext(), self.bridgeListenerPrx)
except Ice.Exception as ex:
- print "Error trying to remove ourself as a default bridge listener: " + ex.what()
+ print "Error trying to remove ourself as a default bridge listener: ", ex
print "Removing ourself as a bridge manager listener"
try:
- self.bridgeManager.removeListener(self.bridgeManagerListenerPrx)
+ self.bridgeManager.removeListener(createContext(), self.bridgeManagerListenerPrx)
except Ice.Exception as ex:
- print "Error trying to remove ourself as a bridge manager listener: " + ex.what()
+ print "Error trying to remove ourself as a bridge manager listener: ", ex
Ice.Application._destroyOnInterruptCallback(sig)
diff --git a/ExamplePartyIdHooks.py b/ExamplePartyIdHooks.py
old mode 100644
new mode 100755
index 6b84688..fa1d5f3
--- a/ExamplePartyIdHooks.py
+++ b/ExamplePartyIdHooks.py
@@ -3,7 +3,7 @@
#
# Asterisk SCF -- An open-source communications framework.
#
-# Copyright (C) 2011, Digium, Inc.
+# Copyright (C) 2011-2012, Digium, Inc.
#
# See http://www.asterisk.org for more information about
# the Asterisk SCF project. Please do not directly contact
@@ -18,77 +18,85 @@
# Party Id sample hooks
-import sys, threading, Ice, os, getopt
+import sys, threading, Ice, os, getopt, uuid
Ice.loadSlice("--underscore -I\"" + os.environ["ASTSCF_HOME"] + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice\"")
Ice.loadSlice("--underscore -I\"" + os.environ["ASTSCF_HOME"] + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/SessionCommunications/SessionCommunicationsExtensionPointsIf.ice\"")
Ice.loadSlice("--underscore -I\"" + os.environ["ASTSCF_HOME"] + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/SessionCommunications/PartyIdentificationIf.ice\"")
-
from AsteriskSCF.Core.Discovery.V1 import *
from AsteriskSCF.SessionCommunications.ExtensionPoints.V1 import *
from AsteriskSCF.SessionCommunications.PartyIdentification.V1 import *
from AsteriskSCF.System.Hook.V1 import *
+from AsteriskSCF.System.V1 import *
+
+import AsteriskSCF.SessionCommunications.PartyIdentification.V1
-#
-# This hook is applied whenever a SessionController sends a ConnectedLine that is received by
-# the bridge's corresponding SessionController. The bridge caches the
+def createContext():
+ newContext = OperationContext()
+ newContext.id = str(uuid.uuid4()) # Random UUID
+ newContext.transactionId = newContext.id
+ return newContext
+
+#
+# This hook is applied whenever a SessionController sends a ConnectedLine that is received by
+# the bridge's corresponding SessionController. The bridge caches the
# ConnectedLine information for each session and this hook alters what gets cached
-# by the bridge for future use. So this is a handy place to do things like blocking
-# the ConnectedLine data altogether.
+# by the bridge for future use. So this is a handy place to do things like blocking
+# the ConnectedLine data altogether.
#
# The downside of this hook is that it is invoked when you don't know who the receiver
-# might eventually be.
+# might eventually be.
#
class ExampleReceivedConnectedLineHook(ReceivedConnectedLinePartyIdHook):
- def modifyReceivedConnectedLine(self, sendingSession, receivedConnectedLine, replacementConnectedLine):
+ def modifyReceivedConnectedLine(self, context, sendingSession, receivedConnectedLine, replacementConnectedLine):
result = HookResult()
result.status = HookStatus.Succeeded
- # Foo-ify the party names.
+ # Foo-ify the party names.
ids = receivedConnectedLine.ids[:] # Copy the ids
for id in ids:
id.partyName = 'foo.' + id.partyName
-
+
replacementConnectedLine = AsteriskSCF.SessionCommunications.PartyIdentification.V1.ConnectedLine()
replacementConnectedLine = ids
return (result, replacementConnectedLine)
#
-# This hook is applied when the bridge is about to send the ConnectedLine information to
-# members of the bridge other than the original sender. This hook can customize the
-# ConnectedLine information specifically to a given destination.
+# This hook is applied when the bridge is about to send the ConnectedLine information to
+# members of the bridge other than the original sender. This hook can customize the
+# ConnectedLine information specifically to a given destination.
#
class ExampleForwardingConnectedLineHook(ForwardingConnectedLinePartyIdHook):
- def modifyForwardingConnectedLine(self, sendingSession, destinationSession, receivedConnectedLine, replacementConnectedLine):
+ def modifyForwardingConnectedLine(self, context, sendingSession, destinationSession, receivedConnectedLine, replacementConnectedLine):
result = HookResult()
result.status = HookStatus.Succeeded
- # Bar-ify the party names. (We don't really make use of the destinationSession here,
- # but we could.)
+ # Bar-ify the party names. (We don't really make use of the destinationSession here,
+ # but we could.)
ids = receivedConnectedLine.ids[:] # Copy the ids
for id in ids:
id.partyName = id.partyName + '.bar'
-
+
replacementConnectedLine = AsteriskSCF.SessionCommunications.PartyIdentification.V1.ConnectedLine()
replacementConnectedLine = ids
return (result, replacementConnectedLine)
#
-# This hook is applied when the bridge is about to forward the Redirection information to
-# members of the bridge other than the original sender. This hook can customize the
-# Redirected information specifically to a given destination.
+# This hook is applied when the bridge is about to forward the Redirection information to
+# members of the bridge other than the original sender. This hook can customize the
+# Redirected information specifically to a given destination.
#
class ExampleForwardingRedirectionsHook(ForwardingRedirectionsPartyIdHook):
- def modifyForwardingRedirection(self, sendingSession, destinationSession, receivedRedirection, replacementRedirection):
+ def modifyForwardingRedirections(self, context, sendingSession, destinationSession, receivedRedirection, replacementRedirection):
result = HookResult()
result.status = HookStatus.Succeeded
- # Let's just provide a made-up redirect.
-
- replacementRedirection = AsteriskSCF.SessionCommunications.PartyIdentification.V1.Redirection()
+ # Let's just provide a made-up redirect.
+
+ replacementRedirections = AsteriskSCF.SessionCommunications.PartyIdentification.V1.Redirections()
redirection = AsteriskSCF.SessionCommunications.PartyIdentification.V1.Redirection()
fromName = AsteriskSCF.SessionCommunications.PartyIdentification.V1.Name('Linda')
@@ -99,10 +107,10 @@ class ExampleForwardingRedirectionsHook(ForwardingRedirectionsPartyIdHook):
toName = AsteriskSCF.SessionCommunications.PartyIdentification.V1.Name('Jenny')
toNumber = AsteriskSCF.SessionCommunications.PartyIdentification.V1.Number('867.5309')
toId = AsteriskSCF.SessionCommunications.PartyIdentification.V1.Id(toName, toNumber)
- redirection.toId = toId
+ redirection.toId = toId
# Adding a single redirection record here. But you could add more.
- replacementRedirections.redirects[0] = redirection
+ replacementRedirections.redirects = [redirection]
return (result, replacementRedirections)
@@ -168,18 +176,18 @@ class ExamplePartyIdHookApp(Ice.Application):
forwardRedirectionHookPrx = ForwardingRedirectionsPartyIdHookPrx.uncheckedCast(adapter.addWithUUID(forwardRedirectionHook))
print "Hooking into bridge service extension point..."
- extensionPoint.addReceivedConnectedLinePartyIdHook(receiveConnectedLineHookPrx)
- extensionPoint.addForwardingConnectedLinePartyIdHook(forwardConnectedLineHookPrx)
- extensionPoint.addForwardingRedirectionsPartyIdHook(forwardRedirectionHookPrx)
+ extensionPoint.addReceivedConnectedLinePartyIdHook(createContext(), receiveConnectedLineHookPrx)
+ extensionPoint.addForwardingConnectedLinePartyIdHook(createContext(), forwardConnectedLineHookPrx)
+ extensionPoint.addForwardingRedirectionsPartyIdHook(createContext(), forwardRedirectionHookPrx)
print "Hooks added."
- print "Processing until shutdown"
+ print "Processing until shutdown"
self.communicator().waitForShutdown()
print "Attempting to remove our hooks from the bridge service."
- extensionPoint.removeReceivedConnectedLinePartyIdHook(receiveConnectedLineHookPrx)
- extensionPoint.removeForwardingConnectedLinePartyIdHook(forwardConnectedLineHookPrx)
- extensionPoint.removeForwardingRedirectionsPartyIdHook(forwardRedirectionHookPrx)
+ extensionPoint.removeReceivedConnectedLinePartyIdHook(createContext(), receiveConnectedLineHookPrx)
+ extensionPoint.removeForwardingConnectedLinePartyIdHook(createContext(), forwardConnectedLineHookPrx)
+ extensionPoint.removeForwardingRedirectionsPartyIdHook(createContext(), forwardRedirectionHookPrx)
return 0
diff --git a/ExampleSipAuthHook.py b/ExampleSipAuthHook.py
index 2584ce9..1d210cd 100755
--- a/ExampleSipAuthHook.py
+++ b/ExampleSipAuthHook.py
@@ -16,9 +16,9 @@
# at the top of the source tree.
#
-# Sip Example Authentication Hook
+# SIP Example Authentication Hook
-import sys, threading, Ice, os, getopt
+import sys, threading, Ice, os, getopt, uuid
Ice.loadSlice("--underscore -I" + os.environ["ASTSCF_HOME"] + " -I" + Ice.getSliceDir() + " --all " + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice")
Ice.loadSlice("--underscore -I" + os.environ["ASTSCF_HOME"] + " -I" + Ice.getSliceDir() + " --all " + os.environ["ASTSCF_HOME"] + "/AsteriskSCF/SIP/SIPExtensionPointIf.ice")
@@ -26,6 +26,13 @@ Ice.loadSlice("--underscore -I" + os.environ["ASTSCF_HOME"] + " -I" + Ice.getSli
from AsteriskSCF.Core.Discovery.V1 import *
from AsteriskSCF.SIP.ExtensionPoint.V1 import *
from AsteriskSCF.System.Hook.V1 import *
+from AsteriskSCF.System.V1 import *
+
+def createContext():
+ newContext = OperationContext()
+ newContext.id = str(uuid.uuid4()) # Random UUID
+ newContext.transactionId = newContext.id
+ return newContext
class ExampleAuthHook(AuthHook):
def challengeRequest(self, info, challenges):
@@ -37,7 +44,7 @@ class ExampleAuthHook(AuthHook):
challenge.password = "alice"
challenge.realm = "example"
challenge.domain = [ "example.com" ]
-
+
challenges = [ challenge ]
return (result, challenges)
@@ -110,10 +117,10 @@ class ExampleAuthHookApp(Ice.Application):
proxy = AuthHookPrx.uncheckedCast(adapter.addWithUUID(hook))
- extensionPoint.addAuthHook(proxy, 1, [ RequestType.DialogEstablishing ])
+ extensionPoint.addAuthHook(createContext(), proxy, 1, [ RequestType.DialogEstablishing ])
self.communicator().waitForShutdown()
- extensionPoint.removeAuthHook(proxy)
+ extensionPoint.removeAuthHook(createContext(), proxy)
return 0
-----------------------------------------------------------------------
--
asterisk-scf/examples.git
More information about the asterisk-scf-commits
mailing list