Index: pjproject/trunk/build.symbian/bld.inf
===================================================================
--- pjproject/trunk/build.symbian/bld.inf	(revision 4491)
+++ pjproject/trunk/build.symbian/bld.inf	(revision 4492)
@@ -33,2 +33,3 @@
 //symsndtest.mmp
 pjlib_test.mmp
+../pjsip-apps/src/pjsua/symbian/group/pjsua.mmp
Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.h
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.h	(revision 4491)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.h	(revision 4492)
@@ -20,4 +20,6 @@
 #define __PJSUA_APP_CONFIG_H__
 
+#include <pjlib.h>
+
 /* This file defines the default app config. It's used by pjsua
  * *mobile* version only. If you're porting pjsua to new mobile
@@ -28,6 +30,10 @@
 				     "--use-cli",
 				     "--no-cli-console",
+#if defined(PJ_SYMBIAN) && PJ_SYMBIAN
+				     /* Can't reuse address on E52 */
+				     "--cli-telnet-port=0",
+#else
 				     "--cli-telnet-port=2323",
-				     "--no-vad",
+#endif
 				     "--quality=4",
 #if defined(PJ_CONFIG_BB10) && PJ_CONFIG_BB10
@@ -36,4 +42,6 @@
 			             NULL };
 
+#define pjsua_app_def_argc (PJ_ARRAY_SIZE(pjsua_app_def_argv)-1)
+
 
 #endif	/* __PJSUA_APP_CONFIG_H__ */
Index: pjproject/trunk/pjsip-apps/src/pjsua/symbian/group/pjsua.mmp
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/symbian/group/pjsua.mmp	(revision 4491)
+++ pjproject/trunk/pjsip-apps/src/pjsua/symbian/group/pjsua.mmp	(revision 4492)
@@ -102,4 +102,4 @@
 SOURCEPATH		..\..
 
-SOURCE 			pjsua_cli.c pjsua_legacy.c
-SOURCE 			pjsua_app.c pjsua_common.c pjsua_config.c
+SOURCE 			pjsua_app_cli.c pjsua_app_legacy.c
+SOURCE 			pjsua_app.c pjsua_app_common.c pjsua_app_config.c
Index: pjproject/trunk/pjsip-apps/src/pjsua/symbian/src/pjsuaAppUi.cpp
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/symbian/src/pjsuaAppUi.cpp	(revision 4491)
+++ pjproject/trunk/pjsip-apps/src/pjsua/symbian/src/pjsuaAppUi.cpp	(revision 4492)
@@ -24,20 +24,23 @@
 
 #include "../../pjsua_app.h"
+#include "../../pjsua_app_config.h"
 
 /* Global vars */
 static CpjsuaAppUi *appui = NULL;
 static pj_ioqueue_t *app_ioqueue = NULL;
-static int restart_argc = 0;
-static char **restart_argv = NULL;
+static int start_argc = 0;
+static char **start_argv = NULL;
+
+static pj_status_t InitSymbSocket();
+static void DestroySymbSocket();
 
 /* Helper funtions to init/restart/destroy the pjsua */
-static void LibInitL();
-static void LibDestroyL();
-static void LibRestartL();
+static void PjsuaInitL();
+static void PjsuaDestroyL();
 
 /* pjsua app callbacks */
-static void lib_on_started(pj_status_t status, const char* title);
-static pj_bool_t lib_on_stopped(pj_bool_t restart, int argc, char** argv);
-static void lib_on_config_init(pjsua_app_config *cfg);
+static void PjsuaOnStarted(pj_status_t status, const char* title);
+static void PjsuaOnStopped(pj_bool_t restart, int argc, char** argv);
+static void PjsuaOnConfig(pjsua_app_config *cfg);
 
 /* Helper class to schedule function execution */
@@ -209,6 +212,14 @@
 	Cba()->MakeVisible(EFalse);
 
-	// Schedule Lib Init
-	MyTimer::NewL(100, &LibInitL);
+	if (InitSymbSocket() != PJ_SUCCESS) {
+	    PutMsg("Failed to initialize Symbian network param.");
+	} else {	
+	    start_argc = pjsua_app_def_argc;
+	    start_argv = (char**)pjsua_app_def_argv;
+
+	    // Schedule Lib Init
+	    MyTimer::NewL(100, &PjsuaInitL);
+	}
+	
 	}
 
@@ -216,5 +227,7 @@
 void CpjsuaAppUi::PrepareToExit()
 {
-    TRAPD(result, LibDestroyL());
+    TRAPD(result, PjsuaDestroyL());
+    DestroySymbSocket();
+    CloseSTDLIB();
     CAknViewAppUi::PrepareToExit();
 }
@@ -232,24 +245,32 @@
 
 /* Called when pjsua is started */
-void lib_on_started(pj_status_t status, const char* title)
-{
+void PjsuaOnStarted(pj_status_t status, const char* title)
+{
+    char err_msg[128];
+
+    if (status != PJ_SUCCESS || title == NULL) {
+	char err_str[PJ_ERR_MSG_SIZE];
+	pj_strerror(status, err_str, sizeof(err_str));
+	pj_ansi_snprintf(err_msg, sizeof(err_msg), "%s: %s",
+			 (title?title:"App start error"), err_str);
+	title = err_msg;
+    }
+
     appui->PutMsg(title);
 }
 
 /* Called when pjsua is stopped */
-pj_bool_t lib_on_stopped(pj_bool_t restart, int argc, char** argv)
+void PjsuaOnStopped(pj_bool_t restart, int argc, char** argv)
 {
     if (restart) {
-	restart_argc = argc;
-	restart_argv = argv;
+	start_argc = argc;
+	start_argv = argv;
 
 	// Schedule Lib Init
-	MyTimer::NewL(100, &LibRestartL);
+	MyTimer::NewL(100, &PjsuaInitL);
     } else {
 	/* Destroy & quit GUI, e.g: clean up window, resources  */
 	appui->Exit();
     }
-
-    return PJ_FALSE;
 }
 
@@ -257,5 +278,5 @@
  * We need to override some settings here.
  */
-void lib_on_config_init(pjsua_app_config *cfg)
+void PjsuaOnConfig(pjsua_app_config *cfg)
 {
     /* Disable threading */
@@ -272,21 +293,14 @@
 }
 
-void LibInitL()
+// Set Symbian OS parameters in pjlib.
+// This must be done before pj_init() is called.
+pj_status_t InitSymbSocket()
 {
     pj_symbianos_params sym_params;
-    char* argv[] = {
-	"",
-	"--use-cli",
-	"--cli-telnet-port=0",
-	"--no-cli-console"
-    };
-    app_cfg_t app_cfg;
-    pj_status_t status;
     TInt err;
-
+    
     // Initialize RSocketServ
     if ((err=aSocketServer.Connect(32)) != KErrNone) {
-    	status = PJ_STATUS_FROM_OS(err);
-    	goto on_return;
+	return PJ_STATUS_FROM_OS(err);
     }
     
@@ -294,35 +308,49 @@
     if ((err=aConn.Open(aSocketServer)) != KErrNone) {
 	aSocketServer.Close();
-	status = PJ_STATUS_FROM_OS(err);
-    	goto on_return;
+	return PJ_STATUS_FROM_OS(err);
     }
     if ((err=aConn.Start()) != KErrNone) {
 	aConn.Close();
-    	aSocketServer.Close();
-    	status = PJ_STATUS_FROM_OS(err);
-    	goto on_return;
-    }
-    
-    // Set Symbian OS parameters in pjlib.
-    // This must be done before pj_init() is called.
+	aSocketServer.Close();
+	return PJ_STATUS_FROM_OS(err);
+    }
+    
     pj_bzero(&sym_params, sizeof(sym_params));
     sym_params.rsocketserv = &aSocketServer;
     sym_params.rconnection = &aConn;
     pj_symbianos_set_params(&sym_params);
-
+    
+    return PJ_SUCCESS;
+}
+
+
+void DestroySymbSocket()
+{
+    aConn.Close();
+    aSocketServer.Close();
+}
+
+
+void PjsuaInitL()
+{
+    pjsua_app_cfg_t app_cfg;
+    pj_status_t status;
+    
+    PjsuaDestroyL();
+    
     pj_bzero(&app_cfg, sizeof(app_cfg));
-    app_cfg.argc = PJ_ARRAY_SIZE(argv);
-    app_cfg.argv = argv;
-    app_cfg.on_started = &lib_on_started;
-    app_cfg.on_stopped = &lib_on_stopped;
-    app_cfg.on_config_init = &lib_on_config_init;
+    app_cfg.argc = start_argc;
+    app_cfg.argv = start_argv;
+    app_cfg.on_started = &PjsuaOnStarted;
+    app_cfg.on_stopped = &PjsuaOnStopped;
+    app_cfg.on_config_init = &PjsuaOnConfig;
 
     appui->PutMsg("Initializing..");
-    status = app_init(&app_cfg);
+    status = pjsua_app_init(&app_cfg);
     if (status != PJ_SUCCESS)
 	goto on_return;
     
     appui->PutMsg("Starting..");
-    status = app_run(PJ_FALSE);
+    status = pjsua_app_run(PJ_FALSE);
     if (status != PJ_SUCCESS)
 	goto on_return;
@@ -333,5 +361,5 @@
 }
 
-void LibDestroyL()
+void PjsuaDestroyL()
 {
     if (app_ioqueue) {
@@ -339,42 +367,4 @@
 	app_ioqueue = NULL;
     }
-    app_destroy();
-    CloseSTDLIB();
-}
-
-void LibRestartL()
-{
-    app_cfg_t app_cfg;
-    pj_status_t status;
-    
-    /* Destroy pjsua app first */
-
-    if (app_ioqueue) {
-	pj_ioqueue_destroy(app_ioqueue);
-	app_ioqueue = NULL;
-    }
-    app_destroy();
-
-    /* Reinit pjsua app */
-    
-    pj_bzero(&app_cfg, sizeof(app_cfg));
-    app_cfg.argc = restart_argc;
-    app_cfg.argv = restart_argv;
-    app_cfg.on_started = &lib_on_started;
-    app_cfg.on_stopped = &lib_on_stopped;
-    app_cfg.on_config_init = &lib_on_config_init;
-
-    status = app_init(&app_cfg);
-    if (status != PJ_SUCCESS) {
-	appui->PutMsg("app_init() failed");
-	return;
-    }
-	
-    /* Run pjsua app */
-
-    status = app_run(PJ_FALSE);
-    if (status != PJ_SUCCESS) {
-	appui->PutMsg("app_run() failed");
-	return;
-    }
-}
+    pjsua_app_destroy();
+}
Index: pjproject/trunk/pjsip-apps/src/pjsua/wm/main_wm.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/wm/main_wm.c	(revision 4491)
+++ pjproject/trunk/pjsip-apps/src/pjsua/wm/main_wm.c	(revision 4492)
@@ -17,11 +17,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  */
-#include <windows.h>
-
-#include <pjlib.h>
-#include <windows.h>
 #include <winuserm.h>
 #include <aygshell.h>
 #include "..\pjsua_app.h"
+#include "..\pjsua_app_config.h"
 
 #define MAINWINDOWCLASS TEXT("PjsuaDlg")
@@ -40,16 +37,15 @@
 static HBITMAP		 g_hBmp;
 
-static int restart_argc = 0;
-static char **restart_argv = NULL;
-
-/* Helper funtions to init/restart/destroy the pjsua */
-static void LibInit();
-static void LibDestroy();
-static void LibRestart();
+static int		 start_argc;
+static char	       **start_argv;
+
+/* Helper funtions to init/destroy the pjsua */
+static void PjsuaInit();
+static void PjsuaDestroy();
 
 /* pjsua app callbacks */
-static void lib_on_started(pj_status_t status, const char* title);
-static pj_bool_t lib_on_stopped(pj_bool_t restart, int argc, char** argv);
-static void lib_on_config_init(pjsua_app_config *cfg);
+static void PjsuaOnStarted(pj_status_t status, const char* title);
+static void PjsuaOnStopped(pj_bool_t restart, int argc, char** argv);
+static void PjsuaOnConfig(pjsua_app_config *cfg);
 
 LRESULT CALLBACK DialogProc(const HWND hWnd,
@@ -86,14 +82,10 @@
 
     case WM_APP_INIT:
-	LibInit();
+    case WM_APP_RESTART:
+	PjsuaInit();
 	break;
 
     case WM_APP_DESTROY:
-	LibDestroy();
 	PostQuitMessage(0);
-	break;
-
-    case WM_APP_RESTART:
-	LibRestart();
 	break;
 
@@ -108,5 +100,5 @@
 /* === GUI === */
 
-pj_status_t gui_init()
+pj_status_t GuiInit()
 {
     WNDCLASS wc;
@@ -193,5 +185,5 @@
 
     /* Create logo */
-    g_hBmp = SHLoadDIBitmap(LOGO_PATH); // for jpeg, uses SHLoadImageFile()
+    g_hBmp = SHLoadDIBitmap(LOGO_PATH); /* for jpeg, uses SHLoadImageFile() */
     if (g_hBmp == NULL) {
 	DWORD err = GetLastError();
@@ -228,5 +220,5 @@
 
 
-pj_status_t gui_start()
+pj_status_t GuiStart()
 {
     MSG msg;
@@ -239,5 +231,5 @@
 }
 
-void gui_destroy(void)
+void GuiDestroy(void)
 {
     if (g_hWndMain) {
@@ -267,9 +259,16 @@
 
 /* Called when pjsua is started */
-void lib_on_started(pj_status_t status, const char* title)
+void PjsuaOnStarted(pj_status_t status, const char* title)
 {
     wchar_t wtitle[128];
-
-    PJ_UNUSED_ARG(status);
+    char err_msg[128];
+
+    if (status != PJ_SUCCESS || title == NULL) {
+	char err_str[PJ_ERR_MSG_SIZE];
+	pj_strerror(status, err_str, sizeof(err_str));
+	pj_ansi_snprintf(err_msg, sizeof(err_msg), "%s: %s",
+			 (title?title:"App start error"), err_str);
+	title = err_msg;
+    }
 
     pj_ansi_to_unicode(title, strlen(title), wtitle, PJ_ARRAY_SIZE(wtitle));
@@ -278,9 +277,9 @@
 
 /* Called when pjsua is stopped */
-pj_bool_t lib_on_stopped(pj_bool_t restart, int argc, char** argv)
+void PjsuaOnStopped(pj_bool_t restart, int argc, char** argv)
 {
     if (restart) {
-	restart_argc = argc;
-	restart_argv = argv;
+	start_argc = argc;
+	start_argv = argv;
 
 	// Schedule Lib Restart
@@ -290,39 +289,35 @@
 	PostMessage(g_hWndMain, WM_APP_DESTROY, 0, 0);
     }
-
-    return PJ_FALSE;
 }
 
 /* Called before pjsua initializing config. */
-void lib_on_config_init(pjsua_app_config *cfg)
+void PjsuaOnConfig(pjsua_app_config *cfg)
 {
     PJ_UNUSED_ARG(cfg);
 }
 
-void LibInit()
-{
-    char* argv[] = {
-	"",
-	"--use-cli",
-	"--cli-telnet-port=0",
-	"--no-cli-console"
-    };
-    app_cfg_t app_cfg;
+void PjsuaInit()
+{
+    pjsua_app_cfg_t app_cfg;
     pj_status_t status;
 
+    /* Destroy pjsua app first */
+    pjsua_app_destroy();
+
+    /* Init pjsua app */
     pj_bzero(&app_cfg, sizeof(app_cfg));
-    app_cfg.argc = PJ_ARRAY_SIZE(argv);
-    app_cfg.argv = argv;
-    app_cfg.on_started = &lib_on_started;
-    app_cfg.on_stopped = &lib_on_stopped;
-    app_cfg.on_config_init = &lib_on_config_init;
+    app_cfg.argc = start_argc;
+    app_cfg.argv = start_argv;
+    app_cfg.on_started = &PjsuaOnStarted;
+    app_cfg.on_stopped = &PjsuaOnStopped;
+    app_cfg.on_config_init = &PjsuaOnConfig;
 
     SetWindowText(g_hWndLbl, _T("Initializing.."));
-    status = app_init(&app_cfg);
+    status = pjsua_app_init(&app_cfg);
     if (status != PJ_SUCCESS)
 	goto on_return;
     
     SetWindowText(g_hWndLbl, _T("Starting.."));
-    status = app_run(PJ_FALSE);
+    status = pjsua_app_run(PJ_FALSE);
     if (status != PJ_SUCCESS)
 	goto on_return;
@@ -333,42 +328,8 @@
 }
 
-void LibDestroy()
-{
-    app_destroy();
-}
-
-void LibRestart()
-{
-    app_cfg_t app_cfg;
-    pj_status_t status;
-    
-    /* Destroy pjsua app first */
-
-    app_destroy();
-
-    /* Reinit pjsua app */
-    
-    pj_bzero(&app_cfg, sizeof(app_cfg));
-    app_cfg.argc = restart_argc;
-    app_cfg.argv = restart_argv;
-    app_cfg.on_started = &lib_on_started;
-    app_cfg.on_stopped = &lib_on_stopped;
-    app_cfg.on_config_init = &lib_on_config_init;
-
-    status = app_init(&app_cfg);
-    if (status != PJ_SUCCESS) {
-	SetWindowText(g_hWndLbl, _T("app_init() failed"));
-	return;
-    }
-	
-    /* Run pjsua app */
-
-    status = app_run(PJ_FALSE);
-    if (status != PJ_SUCCESS) {
-	SetWindowText(g_hWndLbl, _T("app_run() failed"));
-	return;
-    }
-}
-
+void PjsuaDestroy()
+{
+    pjsua_app_destroy();
+}
 
 /* === MAIN === */
@@ -390,16 +351,19 @@
     g_hInst = hInstance;
 
-    status = gui_init();
+    // Start GUI
+    status = GuiInit();
     if (status != 0)
 	goto on_return;
 
-    // Start the engine
+    // Setup args and start pjsua
+    start_argc = pjsua_app_def_argc;
+    start_argv = (char**)pjsua_app_def_argv;
     PostMessage(g_hWndMain, WM_APP_INIT, 0, 0);
 
-    status = gui_start();
+    status = GuiStart();
 	
 on_return:
-    LibDestroy();
-    gui_destroy();
+    PjsuaDestroy();
+    GuiDestroy();
 
     return status;
