- Timestamp:
- Apr 24, 2013 5:38:35 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m
r4464 r4497 11 11 #import <pjsua.h> 12 12 #import <pj/log.h> 13 #include "../../pjsua_common.h" 13 14 #include "../../pjsua_app.h" 15 #include "../../pjsua_app_config.h" 14 16 15 17 #import "ipjsuaViewController.h" … … 17 19 @implementation ipjsuaAppDelegate 18 20 21 #define THIS_FILE "ipjsuaAppDelegate.m" 22 19 23 #define KEEP_ALIVE_INTERVAL 600 20 24 21 static int _argc = 4; 22 static char *_argv[] = {"", 23 "--use-cli", 24 "--no-cli-console", 25 "--cli-telnet-port=6378" 26 }; 27 28 ipjsuaAppDelegate *app; 29 extern pj_cli_telnet_on_started on_started_cb; 30 extern pj_cli_on_quit on_quit_cb; 31 extern pj_cli_on_destroy on_destroy_cb; 32 extern pj_cli_on_restart_pjsua on_restart_pjsua_cb; 33 static pj_thread_desc a_thread_desc; 34 static pj_thread_t *a_thread; 35 36 int main_func(int argc, char *argv[]); 37 38 static void cli_telnet_started(pj_cli_telnet_info *telnet_info) 39 { 40 PJ_LOG(3,("ipjsua", "Telnet to %.*s:%d", 41 telnet_info->ip_address.slen, telnet_info->ip_address.ptr, 42 telnet_info->port)); 43 NSString *str = [NSString stringWithFormat:@"Telnet to %.*s:%d", 44 (int)telnet_info->ip_address.slen, 45 telnet_info->ip_address.ptr, 46 telnet_info->port]; 25 ipjsuaAppDelegate *app; 26 static pjsua_app_cfg_t app_cfg; 27 static bool isShuttingDown; 28 static char **restartArgv; 29 static int restartArgc; 30 static pj_thread_desc a_thread_desc; 31 static pj_thread_t *a_thread; 32 33 static void displayMsg(const char *msg) 34 { 35 NSString *str = [NSString stringWithFormat:@"%s", msg]; 47 36 [app performSelectorOnMainThread:@selector(displayMsg:) withObject:str 48 waitUntilDone:NO]; 49 } 50 51 static void cli_on_quit (pj_bool_t is_restarted) 52 { 53 PJ_LOG(3,("ipjsua", "CLI quit, restart(%d)", is_restarted)); 54 if (!is_restarted) { 55 NSString *str = [NSString stringWithFormat:@"CLI quit, " 56 "telnet unavailable"]; 57 [app performSelectorOnMainThread:@selector(displayMsg:) withObject:str 58 waitUntilDone:NO]; 59 } 60 } 61 62 - (void)displayMsg:(NSString *)str { 37 waitUntilDone:NO]; 38 } 39 40 static void pjsuaOnStartedCb(pj_status_t status, const char* msg) 41 { 42 char errmsg[PJ_ERR_MSG_SIZE]; 43 44 if (status != PJ_SUCCESS && (!msg || !*msg)) { 45 pj_strerror(status, errmsg, sizeof(errmsg)); 46 PJ_LOG(3,(THIS_FILE, "Error: %s", errmsg)); 47 msg = errmsg; 48 } else { 49 PJ_LOG(3,(THIS_FILE, "Started: %s", msg)); 50 } 51 52 displayMsg(msg); 53 } 54 55 static void pjsuaOnStoppedCb(pj_bool_t restart, 56 int argc, char** argv) 57 { 58 PJ_LOG(3,("ipjsua", "CLI %s request", (restart? "restart" : "shutdown"))); 59 if (restart) { 60 displayMsg("Restarting.."); 61 pj_thread_sleep(100); 62 app_cfg.argc = argc; 63 app_cfg.argv = argv; 64 } else { 65 displayMsg("Shutting down.."); 66 pj_thread_sleep(100); 67 isShuttingDown = true; 68 } 69 } 70 71 static void pjsuaOnAppConfigCb(pjsua_app_config *cfg) 72 { 73 PJ_UNUSED_ARG(cfg); 74 } 75 76 - (void)displayMsg:(NSString *)str 77 { 63 78 app.viewController.textLabel.text = str; 64 79 } 65 80 66 - (void)start_app { 67 on_started_cb = &cli_telnet_started; 68 on_quit_cb = &cli_on_quit; 69 main_func(_argc, _argv); 81 - (void)pjsuaStart 82 { 83 // TODO: read from config? 84 const char **argv = pjsua_app_def_argv; 85 int argc = PJ_ARRAY_SIZE(pjsua_app_def_argv) -1; 86 pj_status_t status; 87 88 isShuttingDown = false; 89 displayMsg("Starting.."); 90 91 pj_bzero(&app_cfg, sizeof(app_cfg)); 92 if (restartArgc) { 93 app_cfg.argc = restartArgc; 94 app_cfg.argv = restartArgv; 95 } else { 96 app_cfg.argc = argc; 97 app_cfg.argv = (char**)argv; 98 } 99 app_cfg.on_started = &pjsuaOnStartedCb; 100 app_cfg.on_stopped = &pjsuaOnStoppedCb; 101 app_cfg.on_config_init = &pjsuaOnAppConfigCb; 102 103 while (!isShuttingDown) { 104 status = pjsua_app_init(&app_cfg); 105 if (status != PJ_SUCCESS) { 106 char errmsg[PJ_ERR_MSG_SIZE]; 107 pj_strerror(status, errmsg, sizeof(errmsg)); 108 displayMsg(errmsg); 109 pjsua_app_destroy(); 110 return; 111 } 112 113 status = pjsua_app_run(PJ_TRUE); 114 if (status != PJ_SUCCESS) { 115 char errmsg[PJ_ERR_MSG_SIZE]; 116 pj_strerror(status, errmsg, sizeof(errmsg)); 117 displayMsg(errmsg); 118 } 119 120 pjsua_app_destroy(); 121 } 122 123 restartArgv = NULL; 124 restartArgc = 0; 70 125 } 71 126 … … 85 140 86 141 /* Start pjsua app thread */ 87 [NSThread detachNewThreadSelector:@selector( start_app) toTarget:self withObject:nil];142 [NSThread detachNewThreadSelector:@selector(pjsuaStart) toTarget:self withObject:nil]; 88 143 89 144 return YES;
Note: See TracChangeset
for help on using the changeset viewer.