Debian Codegraph @

Xpjproject/pjsip-apps/src/python/samples/registration.py

raw symbols SCIP
1 #
2 # SIP account and registration sample. In this sample, the program
3 # will block to wait until registration is complete
4 #
5 # Copyright (C) 2003-2008 Benny Prijono <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #
21 import sys
22 import pjsua as pj
23 import threading
24
25
26 def log_cb(level, str, len):
27 print str,
28
29 class MyAccountCallback(pj.AccountCallback):
30 sem = None
31
32 def __init__(self, account):
33 pj.AccountCallback.__init__(self, account)
34
35 def wait(self):
36 self.sem = threading.Semaphore(0)
37 self.sem.acquire()
38
39 def on_reg_state(self):
40 if self.sem:
41 if self.account.info().reg_status >= 200:
42 self.sem.release()
43
44 lib = pj.Lib()
45
46 try:
47 lib.init(log_cfg = pj.LogConfig(level=4, callback=log_cb))
48 lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(5080))
49 lib.start()
50
51 acc = lib.create_account(pj.AccountConfig("pjsip.org", "bennylp", "***"))
52
53 acc_cb = MyAccountCallback(acc)
54 acc.set_callback(acc_cb)
55 acc_cb.wait()
56
57 print "\n"
58 print "Registration complete, status=", acc.info().reg_status, \
59 "(" + acc.info().reg_reason + ")"
60 print "\nPress ENTER to quit"
61 sys.stdin.readline()
62
63 lib.destroy()
64 lib = None
65
66 except pj.Error, e:
67 print "Exception: " + str(e)
68 lib.destroy()
69