Major modifications in Python module and pjsua.py wrapper:
 - replaced call/acc/buddy dictionaries with user data attachment
 - recommended to install callback when creating the object, to
   prevent missing some events
 - fixed circular references by using weakref
 - protect access to pjsua with mutex; found out that without this
   there will be deadlock in Python
 - fixed memory leaks in the _pjsua.c module (objects reference
   counter not properly maintained)



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2163 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip-apps/src/python/samples/call.py b/pjsip-apps/src/python/samples/call.py
index 2f44f62..ac053ad 100644
--- a/pjsip-apps/src/python/samples/call.py
+++ b/pjsip-apps/src/python/samples/call.py
@@ -1,4 +1,4 @@
-# $Id:$
+# $Id$
 #
 # SIP call sample.
 #
@@ -18,13 +18,12 @@
 # Callback to receive events from account
 class MyAccountCallback(pj.AccountCallback):
 
-    def __init__(self, account):
+    def __init__(self, account=None):
         pj.AccountCallback.__init__(self, account)
 
     # Notification on incoming call
     def on_incoming_call(self, call):
         global current_call 
-
         if current_call:
             call.answer(486, "Busy")
             return
@@ -43,13 +42,12 @@
 # Callback to receive events from Call
 class MyCallCallback(pj.CallCallback):
 
-    def __init__(self, call):
+    def __init__(self, call=None):
         pj.CallCallback.__init__(self, call)
 
     # Notification when call state has changed
     def on_state(self):
         global current_call
-
         print "Call with", self.call.info().remote_uri,
         print "is", self.call.info().state_text,
         print "last code =", self.call.info().last_code, 
@@ -57,6 +55,7 @@
         
         if self.call.info().state == pj.CallState.DISCONNECTED:
             current_call = None
+            print 'Current call is', current_call
 
     # Notification when call's media state has changed.
     def on_media_state(self):
@@ -73,12 +72,9 @@
 def make_call(uri):
     try:
         print "Making call to", uri
-        call = acc.make_call(uri)
-        call_cb = MyCallCallback(call)
-        call.set_callback(call_cb)
-        return call
+        return acc.make_call(uri, cb=MyCallCallback())
     except pj.Error, e:
-        print "Error: " + str(e)
+        print "Exception: " + str(e)
         return None
         
 
@@ -100,13 +96,14 @@
     lib.start()
 
     # Create local account
-    acc = lib.create_account_for_transport(transport)
-    acc_cb = MyAccountCallback(acc)
-    acc.set_callback(acc_cb)
+    acc = lib.create_account_for_transport(transport, cb=MyAccountCallback())
 
     # If argument is specified then make call to the URI
     if len(sys.argv) > 1:
+        lck = lib.auto_lock()
         current_call = make_call(sys.argv[1])
+        print 'Current call is', current_call
+        del lck
 
     my_sip_uri = "sip:" + transport.info().host + \
                  ":" + str(transport.info().port)
@@ -125,7 +122,9 @@
             input = sys.stdin.readline().rstrip("\r\n")
             if input == "":
                 continue
+            lck = lib.auto_lock()
             current_call = make_call(input)
+            del lck
 
         elif input == "h":
             if not current_call:
@@ -143,6 +142,9 @@
             break
 
     # Shutdown the library
+    transport = None
+    acc.delete()
+    acc = None
     lib.destroy()
     lib = None