From 8144889895f7a8772fe75d664bff91390685a2d3 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Wed, 24 Apr 2013 05:38:35 +0000 Subject: Re #1655: Modified pjsua iOS due to change in pjsua app framework git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4497 74dad513-b988-da41-8d7b-12977e46ad98 --- .../src/pjsua/ios/ipjsua.xcodeproj/project.pbxproj | 46 ++++--- .../src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m | 133 +++++++++++++++------ 2 files changed, 116 insertions(+), 63 deletions(-) (limited to 'pjsip-apps') diff --git a/pjsip-apps/src/pjsua/ios/ipjsua.xcodeproj/project.pbxproj b/pjsip-apps/src/pjsua/ios/ipjsua.xcodeproj/project.pbxproj index 3f2421bc..0f938686 100644 --- a/pjsip-apps/src/pjsua/ios/ipjsua.xcodeproj/project.pbxproj +++ b/pjsip-apps/src/pjsua/ios/ipjsua.xcodeproj/project.pbxproj @@ -7,15 +7,14 @@ objects = { /* Begin PBXBuildFile section */ - 3A00CD2E170EA6590093CE38 /* pjsua_cli.c in Sources */ = {isa = PBXBuildFile; fileRef = 3A00CD2A170EA6590093CE38 /* pjsua_cli.c */; }; - 3A00CD2F170EA6590093CE38 /* pjsua_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 3A00CD2B170EA6590093CE38 /* pjsua_common.c */; }; - 3A00CD30170EA6590093CE38 /* pjsua_config.c in Sources */ = {isa = PBXBuildFile; fileRef = 3A00CD2C170EA6590093CE38 /* pjsua_config.c */; }; - 3A00CD31170EA6590093CE38 /* pjsua_legacy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3A00CD2D170EA6590093CE38 /* pjsua_legacy.c */; }; - 3A92068416F1CE8000D49F96 /* pjsua_app.c in Sources */ = {isa = PBXBuildFile; fileRef = 3A92067F16F1CE8000D49F96 /* pjsua_app.c */; }; - 3A92068516F1CE8000D49F96 /* pjsua_cli_cmd.c in Sources */ = {isa = PBXBuildFile; fileRef = 3A92068016F1CE8000D49F96 /* pjsua_cli_cmd.c */; }; 3A92068F16F1DE7100D49F96 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A92068E16F1DE7100D49F96 /* AudioToolbox.framework */; }; 3A92069316F1DEA500D49F96 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A92069216F1DEA500D49F96 /* CFNetwork.framework */; }; 3ADCCD171715338D0007BE8E /* pjsua.png in Resources */ = {isa = PBXBuildFile; fileRef = 3ADCCD161715338D0007BE8E /* pjsua.png */; }; + 3ADCCD231726D1920007BE8E /* pjsua_app_cli.c in Sources */ = {isa = PBXBuildFile; fileRef = 3ADCCD1E1726D1920007BE8E /* pjsua_app_cli.c */; }; + 3ADCCD241726D1920007BE8E /* pjsua_app_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 3ADCCD1F1726D1920007BE8E /* pjsua_app_common.c */; }; + 3ADCCD251726D1920007BE8E /* pjsua_app_config.c in Sources */ = {isa = PBXBuildFile; fileRef = 3ADCCD201726D1920007BE8E /* pjsua_app_config.c */; }; + 3ADCCD261726D1920007BE8E /* pjsua_app_legacy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3ADCCD211726D1920007BE8E /* pjsua_app_legacy.c */; }; + 3ADCCD271726D1920007BE8E /* pjsua_app.c in Sources */ = {isa = PBXBuildFile; fileRef = 3ADCCD221726D1920007BE8E /* pjsua_app.c */; }; 3AF0580916F050770046B835 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF0580816F050770046B835 /* UIKit.framework */; }; 3AF0580B16F050770046B835 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF0580A16F050770046B835 /* Foundation.framework */; }; 3AF0580D16F050770046B835 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF0580C16F050770046B835 /* CoreGraphics.framework */; }; @@ -50,15 +49,14 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 3A00CD2A170EA6590093CE38 /* pjsua_cli.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_cli.c; path = ../../pjsua_cli.c; sourceTree = ""; }; - 3A00CD2B170EA6590093CE38 /* pjsua_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_common.c; path = ../../pjsua_common.c; sourceTree = ""; }; - 3A00CD2C170EA6590093CE38 /* pjsua_config.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_config.c; path = ../../pjsua_config.c; sourceTree = ""; }; - 3A00CD2D170EA6590093CE38 /* pjsua_legacy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_legacy.c; path = ../../pjsua_legacy.c; sourceTree = ""; }; - 3A92067F16F1CE8000D49F96 /* pjsua_app.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_app.c; path = ../../pjsua_app.c; sourceTree = ""; }; - 3A92068016F1CE8000D49F96 /* pjsua_cli_cmd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_cli_cmd.c; path = ../../pjsua_cli_cmd.c; sourceTree = ""; }; 3A92068E16F1DE7100D49F96 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 3A92069216F1DEA500D49F96 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; 3ADCCD161715338D0007BE8E /* pjsua.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pjsua.png; sourceTree = ""; }; + 3ADCCD1E1726D1920007BE8E /* pjsua_app_cli.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pjsua_app_cli.c; sourceTree = ""; }; + 3ADCCD1F1726D1920007BE8E /* pjsua_app_common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pjsua_app_common.c; sourceTree = ""; }; + 3ADCCD201726D1920007BE8E /* pjsua_app_config.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pjsua_app_config.c; sourceTree = ""; }; + 3ADCCD211726D1920007BE8E /* pjsua_app_legacy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pjsua_app_legacy.c; sourceTree = ""; }; + 3ADCCD221726D1920007BE8E /* pjsua_app.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pjsua_app.c; sourceTree = ""; }; 3AF0580416F050770046B835 /* ipjsua.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ipjsua.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3AF0580816F050770046B835 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 3AF0580A16F050770046B835 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -135,12 +133,11 @@ 3A92068D16F1D1A100D49F96 /* pjsua */ = { isa = PBXGroup; children = ( - 3A00CD2A170EA6590093CE38 /* pjsua_cli.c */, - 3A00CD2B170EA6590093CE38 /* pjsua_common.c */, - 3A00CD2C170EA6590093CE38 /* pjsua_config.c */, - 3A00CD2D170EA6590093CE38 /* pjsua_legacy.c */, - 3A92067F16F1CE8000D49F96 /* pjsua_app.c */, - 3A92068016F1CE8000D49F96 /* pjsua_cli_cmd.c */, + 3ADCCD1E1726D1920007BE8E /* pjsua_app_cli.c */, + 3ADCCD1F1726D1920007BE8E /* pjsua_app_common.c */, + 3ADCCD201726D1920007BE8E /* pjsua_app_config.c */, + 3ADCCD211726D1920007BE8E /* pjsua_app_legacy.c */, + 3ADCCD221726D1920007BE8E /* pjsua_app.c */, ); name = pjsua; sourceTree = ""; @@ -303,12 +300,11 @@ 3AF0581516F050780046B835 /* main.m in Sources */, 3AF0581916F050780046B835 /* ipjsuaAppDelegate.m in Sources */, 3AF0582216F050780046B835 /* ipjsuaViewController.m in Sources */, - 3A92068416F1CE8000D49F96 /* pjsua_app.c in Sources */, - 3A92068516F1CE8000D49F96 /* pjsua_cli_cmd.c in Sources */, - 3A00CD2E170EA6590093CE38 /* pjsua_cli.c in Sources */, - 3A00CD2F170EA6590093CE38 /* pjsua_common.c in Sources */, - 3A00CD30170EA6590093CE38 /* pjsua_config.c in Sources */, - 3A00CD31170EA6590093CE38 /* pjsua_legacy.c in Sources */, + 3ADCCD231726D1920007BE8E /* pjsua_app_cli.c in Sources */, + 3ADCCD241726D1920007BE8E /* pjsua_app_common.c in Sources */, + 3ADCCD251726D1920007BE8E /* pjsua_app_config.c in Sources */, + 3ADCCD261726D1920007BE8E /* pjsua_app_legacy.c in Sources */, + 3ADCCD271726D1920007BE8E /* pjsua_app.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -409,6 +405,7 @@ "../../../../pjlib-util/include", ../../../../pjnath/include, ../../../../pjmedia/include, + .., ); INFOPLIST_FILE = "ipjsua/ipjsua-Info.plist"; LIBRARY_SEARCH_PATHS = ( @@ -442,6 +439,7 @@ "../../../../pjlib-util/include", ../../../../pjnath/include, ../../../../pjmedia/include, + .., ); INFOPLIST_FILE = "ipjsua/ipjsua-Info.plist"; LIBRARY_SEARCH_PATHS = ( diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m index f1775bc2..739d88ad 100644 --- a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m @@ -10,63 +10,118 @@ #import #import #import -#include "../../pjsua_common.h" + +#include "../../pjsua_app.h" +#include "../../pjsua_app_config.h" #import "ipjsuaViewController.h" @implementation ipjsuaAppDelegate -#define KEEP_ALIVE_INTERVAL 600 - -static int _argc = 4; -static char *_argv[] = {"", - "--use-cli", - "--no-cli-console", - "--cli-telnet-port=6378" -}; +#define THIS_FILE "ipjsuaAppDelegate.m" -ipjsuaAppDelegate *app; -extern pj_cli_telnet_on_started on_started_cb; -extern pj_cli_on_quit on_quit_cb; -extern pj_cli_on_destroy on_destroy_cb; -extern pj_cli_on_restart_pjsua on_restart_pjsua_cb; -static pj_thread_desc a_thread_desc; -static pj_thread_t *a_thread; +#define KEEP_ALIVE_INTERVAL 600 -int main_func(int argc, char *argv[]); +ipjsuaAppDelegate *app; +static pjsua_app_cfg_t app_cfg; +static bool isShuttingDown; +static char **restartArgv; +static int restartArgc; +static pj_thread_desc a_thread_desc; +static pj_thread_t *a_thread; -static void cli_telnet_started(pj_cli_telnet_info *telnet_info) +static void displayMsg(const char *msg) { - PJ_LOG(3,("ipjsua", "Telnet to %.*s:%d", - telnet_info->ip_address.slen, telnet_info->ip_address.ptr, - telnet_info->port)); - NSString *str = [NSString stringWithFormat:@"Telnet to %.*s:%d", - (int)telnet_info->ip_address.slen, - telnet_info->ip_address.ptr, - telnet_info->port]; + NSString *str = [NSString stringWithFormat:@"%s", msg]; [app performSelectorOnMainThread:@selector(displayMsg:) withObject:str - waitUntilDone:NO]; + waitUntilDone:NO]; +} + +static void pjsuaOnStartedCb(pj_status_t status, const char* msg) +{ + char errmsg[PJ_ERR_MSG_SIZE]; + + if (status != PJ_SUCCESS && (!msg || !*msg)) { + pj_strerror(status, errmsg, sizeof(errmsg)); + PJ_LOG(3,(THIS_FILE, "Error: %s", errmsg)); + msg = errmsg; + } else { + PJ_LOG(3,(THIS_FILE, "Started: %s", msg)); + } + + displayMsg(msg); } -static void cli_on_quit (pj_bool_t is_restarted) +static void pjsuaOnStoppedCb(pj_bool_t restart, + int argc, char** argv) { - PJ_LOG(3,("ipjsua", "CLI quit, restart(%d)", is_restarted)); - if (!is_restarted) { - NSString *str = [NSString stringWithFormat:@"CLI quit, " - "telnet unavailable"]; - [app performSelectorOnMainThread:@selector(displayMsg:) withObject:str - waitUntilDone:NO]; + PJ_LOG(3,("ipjsua", "CLI %s request", (restart? "restart" : "shutdown"))); + if (restart) { + displayMsg("Restarting.."); + pj_thread_sleep(100); + app_cfg.argc = argc; + app_cfg.argv = argv; + } else { + displayMsg("Shutting down.."); + pj_thread_sleep(100); + isShuttingDown = true; } } -- (void)displayMsg:(NSString *)str { +static void pjsuaOnAppConfigCb(pjsua_app_config *cfg) +{ + PJ_UNUSED_ARG(cfg); +} + +- (void)displayMsg:(NSString *)str +{ app.viewController.textLabel.text = str; } -- (void)start_app { - on_started_cb = &cli_telnet_started; - on_quit_cb = &cli_on_quit; - main_func(_argc, _argv); +- (void)pjsuaStart +{ + // TODO: read from config? + const char **argv = pjsua_app_def_argv; + int argc = PJ_ARRAY_SIZE(pjsua_app_def_argv) -1; + pj_status_t status; + + isShuttingDown = false; + displayMsg("Starting.."); + + pj_bzero(&app_cfg, sizeof(app_cfg)); + if (restartArgc) { + app_cfg.argc = restartArgc; + app_cfg.argv = restartArgv; + } else { + app_cfg.argc = argc; + app_cfg.argv = (char**)argv; + } + app_cfg.on_started = &pjsuaOnStartedCb; + app_cfg.on_stopped = &pjsuaOnStoppedCb; + app_cfg.on_config_init = &pjsuaOnAppConfigCb; + + while (!isShuttingDown) { + status = pjsua_app_init(&app_cfg); + if (status != PJ_SUCCESS) { + char errmsg[PJ_ERR_MSG_SIZE]; + pj_strerror(status, errmsg, sizeof(errmsg)); + displayMsg(errmsg); + pjsua_app_destroy(); + return; + } + + status = pjsua_app_run(PJ_TRUE); + if (status != PJ_SUCCESS) { + char errmsg[PJ_ERR_MSG_SIZE]; + pj_strerror(status, errmsg, sizeof(errmsg)); + displayMsg(errmsg); + } + + pjsua_app_destroy(); + } + + restartArgv = NULL; + restartArgc = 0; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions @@ -84,7 +139,7 @@ static void cli_on_quit (pj_bool_t is_restarted) app = self; /* Start pjsua app thread */ - [NSThread detachNewThreadSelector:@selector(start_app) toTarget:self withObject:nil]; + [NSThread detachNewThreadSelector:@selector(pjsuaStart) toTarget:self withObject:nil]; return YES; } -- cgit v1.2.3