Changeset 4648
- Timestamp:
- Nov 6, 2013 8:14:17 AM (11 years ago)
- Location:
- pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui
- Property svn:ignore
-
old new 1 1 pygui.log 2 2 pygui.dat 3 pygui.js
-
- Property svn:ignore
-
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui/account.py
r4640 r4648 51 51 if self.isValid(): 52 52 ai = self.getInfo() 53 if ai.regIsActive: 53 if ai.regLastErr: 54 status = self.app.ep.utilStrError(ai.regLastErr) 55 elif ai.regIsActive: 54 56 if ai.onlineStatus: 55 57 if len(ai.onlineStatusText): -
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui/application.py
r4640 r4648 36 36 37 37 import os 38 import pickle39 38 import traceback 40 39 41 #---------------------------------------------------------- 42 # Unfortunately SWIG classes cannot be serialized directly 43 # hence need to write these config classes 44 # 45 class AccountConfig: 46 """ 47 "Proxy" for the pj.AccountConfig class, serializable 48 """ 49 def __init__(self, acc_cfg = None): 50 if not acc_cfg: 51 acc_cfg = pj.AccountConfig() 52 self.priority = acc_cfg.priority 53 self.idUri = acc_cfg.idUri 54 self.regUri = acc_cfg.regConfig.registrarUri 55 self.registerOnAdd = acc_cfg.regConfig.registerOnAdd 56 self.proxies = [proxy for proxy in acc_cfg.sipConfig.proxies] 57 self.userName = "" 58 self.password = "" 59 if len(acc_cfg.sipConfig.authCreds): 60 self.userName = acc_cfg.sipConfig.authCreds[0].username 61 self.password = acc_cfg.sipConfig.authCreds[0].data 62 63 def getAccConfig(self, acc_cfg = None): 64 """ 65 Convert this class to pj.AccountConfig class 66 """ 67 if not acc_cfg: 68 acc_cfg = pj.AccountConfig() 69 acc_cfg.priority = self.priority 70 acc_cfg.idUri = self.idUri 71 acc_cfg.regConfig.registrarUri = self.regUri 72 acc_cfg.regConfig.registerOnAdd = self.registerOnAdd 73 for proxy in self.proxies: 74 acc_cfg.sipConfig.proxies.append(proxy) 75 if self.userName: 76 cred = pj.AuthCredInfo() 77 cred.scheme = "digest" 78 cred.realm = "*" 79 cred.username = self.userName 80 cred.data = self.password 81 acc_cfg.sipConfig.authCreds.append(cred) 82 return acc_cfg 83 84 class ApplicationConfig: 85 """ 86 Application config is serializable and contains all settings that application need. 87 """ 88 def __init__(self, ep_cfg = None, acc_cfgs = []): 89 if not ep_cfg: 90 ep_cfg = pj.EpConfig() 91 92 self.logFile = ep_cfg.logConfig.filename 93 self.logFlags = ep_cfg.logConfig.fileFlags 94 self.logLevel = ep_cfg.logConfig.consoleLevel 95 96 self.accCfgs = [] 97 for acc_cfg in acc_cfgs: 98 self.accCfgs.append( AccountConfig(acc_cfg) ) 99 100 def getEpConfig(self, ep_cfg = None): 101 if not ep_cfg: 102 ep_cfg = pj.EpConfig() 103 ep_cfg.logConfig.filename = self.logFile 104 ep_cfg.logConfig.fileFlags = self.logFlags 105 ep_cfg.logConfig.consoleLevel = self.logLevel 106 return ep_cfg 107 108 109 #---------------------------------------------------------- 110 111 40 class SipTransportConfig: 41 def __init__(self): 42 #pj.PersistentObject.__init__(self) 43 self.type = pj.PJSIP_TRANSPORT_UNSPECIFIED; 44 self.cfg = pj.TransportConfig() 45 46 def readObject(self, node): 47 child_node = node.readContainer("SipTransportConfig") 48 self.type = child_node.readInt("type") 49 self.cfg.readObject(child_node) 50 51 def writeObject(self, node): 52 child_node = node.writeNewContainer("SipTransportConfig") 53 child_node.writeInt("type", self.type) 54 self.cfg.writeObject(child_node) 55 56 112 57 class Application(ttk.Frame): 113 58 """ … … 122 67 self.logger = log.Logger() 123 68 124 # Global config, fill with default 69 # Accounts 70 self.accList = [] 71 72 # GUI variables 73 self.showLogWindow = tk.IntVar() 74 self.showLogWindow.set(1) 75 self.quitting = False 76 77 # Construct GUI 78 self._createWidgets() 79 80 # Log window 81 self.logWindow = log.LogWindow(self) 82 self._onMenuShowHideLogWindow() 83 84 # Instantiate endpoint 85 self.ep = endpoint.Endpoint() 86 self.ep.libCreate() 87 88 # Default config 125 89 self.epCfg = pj.EpConfig() 126 90 self.epCfg.uaConfig.threadCnt = 0; … … 131 95 self.epCfg.logConfig.consoleLevel = 5 132 96 133 # Accounts 134 self.accList = [] 135 136 # GUI variables 137 self.showLogWindow = tk.IntVar() 138 self.showLogWindow.set(1) 139 self.quitting = False 140 141 # Construct GUI 142 self._createWidgets() 143 144 # Log window 145 self.logWindow = log.LogWindow(self) 146 self._onMenuShowHideLogWindow() 147 148 def saveConfig(self, filename='pygui.dat'): 149 acc_cfgs = [acc.cfg for acc in self.accList] 150 app_cfg = ApplicationConfig(self.epCfg, acc_cfgs) 151 f = open(filename, 'wb') 152 pickle.dump(app_cfg, f, 0) 153 f.close() 154 155 def start(self, cfg_file='pygui.dat'): 97 self.transportCfgs = [] 98 t = SipTransportConfig() 99 t.type = pj.PJSIP_TRANSPORT_UDP 100 t.cfg.port = 0 101 self.transportCfgs.append(t) 102 103 104 def saveConfig(self, filename='pygui.js'): 105 json = pj.JsonDocument() 106 107 # Write endpoint config 108 json.writeObject(self.epCfg) 109 110 # Write transport config 111 node = json.writeNewArray("transports") 112 for t in self.transportCfgs: 113 t.writeObject(node); 114 115 # Write account configs 116 node = json.writeNewArray("accounts") 117 for acc in self.accList: 118 node.writeObject(acc.cfg); 119 json.saveFile(filename) 120 121 def start(self, cfg_file='pygui.js'): 156 122 # Load config 157 123 acc_cfgs = [] 158 124 if cfg_file and os.path.exists(cfg_file): 159 f = open(cfg_file, 'rb') 160 app_cfg = pickle.load(f) 161 app_cfg.getEpConfig(self.epCfg) 162 for c in app_cfg.accCfgs: 163 cfg = c.getAccConfig() 125 json = pj.JsonDocument() 126 json.loadFile(cfg_file) 127 128 # Load endpoint config 129 json.readObject(self.epCfg) 130 131 # Load transport configs 132 node = json.readArray("transports") 133 if node.hasUnread(): 134 self.transportCfgs = [] 135 while node.hasUnread(): 136 t = SipTransportConfig() 137 t.readObject(node) 138 self.transportCfgs.append(t) 139 140 # Load account configs 141 node = json.readArray("accounts") 142 while node.hasUnread(): 143 cfg = pj.AccountConfig() 144 cfg.readObject(node) 164 145 acc_cfgs.append(cfg) 165 f.close() 166 167 # Instantiate endpoint 168 self.ep = endpoint.Endpoint() 146 147 # Initialize library 169 148 self.epCfg.uaConfig.userAgent = "pygui-" + self.ep.libVersion().full; 170 self.ep. startLib(self.epCfg)149 self.ep.libInit(self.epCfg) 171 150 self.master.title('pjsua2 Demo version ' + self.ep.libVersion().full) 172 151 152 # Create transports 153 for t in self.transportCfgs: 154 self.ep.transportCreate(t.type, t.cfg) 155 173 156 # Add accounts 174 157 for cfg in acc_cfgs: 175 158 self._createAcc(cfg) 159 160 # Start library 161 self.ep.libStart() 176 162 177 163 # Start polling … … 329 315 330 316 def _onClose(self): 317 self.saveConfig() 331 318 self.quitting = True 332 self.ep. stopLib()319 self.ep.libDestroy() 333 320 self.ep = None 334 321 self.update() … … 391 378 app.start() 392 379 app.mainloop() 393 app.saveConfig()394 380 395 381 if __name__ == '__main__': -
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui/endpoint.py
r4640 r4648 42 42 Endpoint.instance = self 43 43 44 def startLib(self, ep_cfg):45 # Create lib46 self.libCreate()47 48 # Init lib49 self.libInit(ep_cfg)50 51 # Add transport52 tcfg = pj.TransportConfig()53 tcfg.port = 50060;54 self.transportCreate(pj.PJSIP_TRANSPORT_UDP, tcfg)55 56 # Start!57 self.libStart()58 59 def stopLib(self):60 self.libDestroy()61 44 62 45 def validateUri(uri): -
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui/log.py
r4640 r4648 121 121 122 122 def write(self, entry): 123 #print entry.msg,123 print entry.msg, 124 124 writeLog(entry) 125 125
Note: See TracChangeset
for help on using the changeset viewer.