Index: /pjproject/trunk/pjsip-apps/src/pjsua/bb10/.project
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/bb10/.project	(revision 4484)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/bb10/.project	(revision 4485)
@@ -9,4 +9,5 @@
 		<buildCommand>
 			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<triggers>clean,full,incremental,</triggers>
 			<arguments>
 				<dictionary>
@@ -20,5 +21,5 @@
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
-					<value>Device-Release</value>
+					<value>Device-Debug</value>
 				</dictionary>
 				<dictionary>
@@ -40,5 +41,5 @@
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
-					<value>true</value>
+					<value>false</value>
 				</dictionary>
 				<dictionary>
@@ -52,5 +53,5 @@
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
-					<value>Device-Release</value>
+					<value>Device-Debug</value>
 				</dictionary>
 				<dictionary>
Index: /pjproject/trunk/pjsip-apps/src/pjsua/bb10/PjsuaBB.pro
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/bb10/PjsuaBB.pro	(revision 4484)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/bb10/PjsuaBB.pro	(revision 4485)
@@ -6,5 +6,4 @@
 
 SOURCES +=  ../../pjsua_app.c \
-            ../../pjsua_cli_cmd.c \
             ../../pjsua_cli.c \
             ../../pjsua_common.c \
@@ -21,4 +20,6 @@
     CONFIG(release, debug|release) {
         # Device-Release custom configuration
+        include(../../../../pjsip.pri)
+        LIBS += -lbb
     }
 }
Index: /pjproject/trunk/pjsip-apps/src/pjsua/bb10/bar-descriptor.xml
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/bb10/bar-descriptor.xml	(revision 4484)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/bb10/bar-descriptor.xml	(revision 4485)
@@ -69,4 +69,6 @@
        <platformArchitecture>armle-v7</platformArchitecture>
        <asset path="arm/o.le-v7-g/PjsuaBB" entry="true" type="Qnx/Elf">PjsuaBB</asset>
+       <asset path="/home/bennylp/Desktop/opt/bb10/lib/libopencore-amrnb.so.0" type="Qnx/Elf">lib/libopencore-amrnb.so.0</asset>
+       <asset path="/home/bennylp/Desktop/opt/bb10/lib/libopencore-amrwb.so.0" type="Qnx/Elf">lib/libopencore-amrwb.so.0</asset>
     </configuration>
     <configuration name="Device-Release">
Index: /pjproject/trunk/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp	(revision 4484)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp	(revision 4485)
@@ -11,94 +11,124 @@
 using namespace bb::cascades;
 
-#include "../../pjsua_common.h"
-
-extern pj_cli_telnet_on_started on_started_cb;
-extern pj_cli_on_quit           on_quit_cb;
-
-extern "C" int main_func(int argc, char *argv[]);
-
+/* appUI singleton */
 ApplicationUI *ApplicationUI::instance_;
 
-class CliThread : public QThread
-{
-    Q_OBJECT
-public:
-    virtual ~CliThread() {}
-protected:
-     void run();
-};
+#include "../../pjsua_app_config.h"
 
-static void bb10_show_msg(const char *msg)
+void ApplicationUI::extDisplayMsg(const char *msg)
 {
     /* Qt's way to invoke method from "foreign" thread */
-    QMetaObject::invokeMethod((QObject*)ApplicationUI::instance(), "displayMsg",
-			      Qt::QueuedConnection,
+    QMetaObject::invokeMethod((QObject*)ApplicationUI::instance(),
+			      "displayMsg", Qt::AutoConnection,
 			      Q_ARG(QString,msg));
 }
 
-static void bb10_telnet_started(pj_cli_telnet_info *telnet_info)
+
+void ApplicationUI::pjsuaOnStartedCb(pj_status_t status, const char* msg)
 {
-    char msg[64];
+    char errmsg[PJ_ERR_MSG_SIZE];
 
-    pj_ansi_snprintf(msg, sizeof(msg),
-		     "Telnet to %.*s:%d",
-	    	     (int)telnet_info->ip_address.slen,
-	    	     telnet_info->ip_address.ptr,
-	    	     telnet_info->port);
+    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));
+    }
 
-    PJ_LOG(3,(THIS_FILE, "Started: %s", msg));
-
-    bb10_show_msg(msg);
+    ApplicationUI::extDisplayMsg(msg);
 }
 
-static void bb10_on_quit (pj_bool_t is_restarted)
+
+pj_bool_t ApplicationUI::pjsuaOnStoppedCb(pj_bool_t restart,
+					  int argc, char** argv)
 {
-    PJ_LOG(3,("ipjsua", "CLI quit, restart(%d)", is_restarted));
-    if (!is_restarted) {
-	bb10_show_msg("Shutting down..");
+    PJ_LOG(3,("ipjsua", "CLI %s request", (restart? "restart" : "shutdown")));
+    if (restart) {
+	ApplicationUI::extDisplayMsg("Restarting..");
+	pj_thread_sleep(100);
+	ApplicationUI::instance()->extRestartRequest(argc, argv);
+    } else {
+	ApplicationUI::extDisplayMsg("Shutting down..");
+	pj_thread_sleep(100);
 	ApplicationUI::instance()->isShuttingDown = true;
+
 	bb::cascades::Application *app = bb::cascades::Application::instance();
 	app->quit();
     }
+
+    return PJ_TRUE;
 }
 
-void CliThread::run()
+
+void ApplicationUI::pjsuaOnAppConfigCb(pjsua_app_config *cfg)
+{
+    PJ_UNUSED_ARG(cfg);
+}
+
+void ApplicationUI::extRestartRequest(int argc, char **argv)
+{
+    restartArgc = argc;
+    restartArgv = argv;
+    QMetaObject::invokeMethod((QObject*)this, "restartPjsua",
+			      Qt::QueuedConnection);
+}
+
+void ApplicationUI::pjsuaStart()
 {
     // TODO: read from config?
-    const char *argv[] = { "pjsuabb",
-			   "--use-cli",
-			   "--no-cli-console",
-			   "--cli-telnet-port=2323",
-			   "--no-vad",
-			   "--add-buddy=sip:169.254.0.2",
-			   "--quality=4",
-			   //(char*)"--dis-codec=*",
-			   //(char*)"--add-codec=g722",
-			    NULL };
-    int argc = PJ_ARRAY_SIZE(argv) -1;
-    pj_thread_desc thread_desc;
-    pj_thread_t *thread;
+    const char **argv = pjsua_app_def_argv;
+    int argc = PJ_ARRAY_SIZE(pjsua_app_def_argv) -1;
+    app_cfg_t app_cfg;
+    pj_status_t status;
 
-    pj_thread_register("CliThread", thread_desc, &thread);
-    // Wait UI to be created
-    pj_thread_sleep(100);
+    isShuttingDown = false;
+    displayMsg("Starting..");
 
-    on_started_cb = &bb10_telnet_started;
-    on_quit_cb = &bb10_on_quit;
-    main_func(argc, (char**)argv);
+    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;
+
+    status = app_init(&app_cfg);
+    if (status != PJ_SUCCESS) {
+	char errmsg[PJ_ERR_MSG_SIZE];
+	pj_strerror(status, errmsg, sizeof(errmsg));
+	displayMsg(QString("Init error:") + errmsg);
+	app_destroy();
+	return;
+    }
+
+    status = app_run(PJ_FALSE);
+    if (status != PJ_SUCCESS) {
+	char errmsg[PJ_ERR_MSG_SIZE];
+	pj_strerror(status, errmsg, sizeof(errmsg));
+	displayMsg(QString("Error:") + errmsg);
+	app_destroy();
+    }
+
+    restartArgv = NULL;
+    restartArgc = 0;
+}
+
+void ApplicationUI::pjsuaDestroy()
+{
+    app_destroy();
 }
 
 ApplicationUI::ApplicationUI(bb::cascades::Application *app)
-: QObject(app), isShuttingDown(false)
+: QObject(app), isShuttingDown(false), restartArgv(NULL), restartArgc(0)
 {
     instance_ = this;
 
-    // create scene document from main.qml asset
-    // set parent to created document to ensure it exists for the whole application lifetime
     QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
-
-    // create root object for the UI
     AbstractPane *root = qml->createRootObject<AbstractPane>();
-    // set created root object as a scene
     app->setScene(root);
 
@@ -106,14 +136,9 @@
     connect(app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
 
-    pj_init();
-
-    // Run CLI
-    cliThread = new CliThread;
-    cliThread->start();
+    pjsuaStart();
 }
 
 ApplicationUI::~ApplicationUI()
 {
-    pj_shutdown();
     instance_ = NULL;
 }
@@ -126,14 +151,8 @@
 void ApplicationUI::aboutToQuit()
 {
-    static pj_thread_desc thread_desc;
-    pj_thread_t *thread;
-
-    if (!pj_thread_is_registered())
-	pj_thread_register("UIThread", thread_desc, &thread);
-
     if (!isShuttingDown) {
 	isShuttingDown = true;
 	PJ_LOG(3,(THIS_FILE, "Quit signal from GUI, shutting down pjsua.."));
-	pjsua_destroy();
+	pjsuaDestroy();
     }
 }
@@ -148,3 +167,7 @@
 }
 
-#include "applicationui.moc"
+void ApplicationUI::restartPjsua()
+{
+    pjsuaDestroy();
+    pjsuaStart();
+}
Index: /pjproject/trunk/pjsip-apps/src/pjsua/bb10/src/applicationui.h
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/bb10/src/applicationui.h	(revision 4484)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/bb10/src/applicationui.h	(revision 4485)
@@ -5,7 +5,7 @@
 #include <QObject>
 
+#include "../../pjsua_app.h"
+
 namespace bb { namespace cascades { class Application; }}
-
-class CliThread;
 
 /*!
@@ -24,12 +24,29 @@
     static ApplicationUI *instance();
 
+    /* Write msg to label (from different thread) */
+    static void extDisplayMsg(const char *msg);
+
+    /* Restart request (from different thread) */
+    void extRestartRequest(int argc, char **argv);
+
 public slots:
     void aboutToQuit();
 
+    Q_INVOKABLE void restartPjsua();
     Q_INVOKABLE void displayMsg(const QString &msg);
 
 private:
-    CliThread *cliThread;
     static ApplicationUI *instance_;
+    char **restartArgv;
+    int restartArgc;
+
+    /* pjsua main operations */
+    void pjsuaStart();
+    void pjsuaDestroy();
+
+    /* pjsua app callbacks */
+    static void 	pjsuaOnStartedCb(pj_status_t status, const char* msg);
+    static pj_bool_t 	pjsuaOnStoppedCb(pj_bool_t restart, int argc, char** argv);
+    static void 	pjsuaOnAppConfigCb(pjsua_app_config *cfg);
 };
 
Index: /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 4484)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 4485)
@@ -1912,4 +1912,5 @@
 	pj_thread_join(stdout_refresh_thread);
 	pj_thread_destroy(stdout_refresh_thread);
+	stdout_refresh_quit = PJ_FALSE;
     }
     return status;
Index: /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.h
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.h	(revision 4485)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.h	(revision 4485)
@@ -0,0 +1,40 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2013 Teluu Inc. (http://www.teluu.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef __PJSUA_APP_CONFIG_H__
+#define __PJSUA_APP_CONFIG_H__
+
+/* This file defines the default app config. It's used by pjsua
+ * *mobile* version only. If you're porting pjsua to new mobile
+ * platform, you should only include this file once in one of
+ * your source file.
+ */
+const char *pjsua_app_def_argv[] = { "pjsua",
+				     "--use-cli",
+				     "--no-cli-console",
+				     "--cli-telnet-port=2323",
+				     "--no-vad",
+				     "--quality=4",
+#if defined(PJ_CONFIG_BB10) && PJ_CONFIG_BB10
+			             "--add-buddy=sip:169.254.0.2",
+#endif
+			             NULL };
+
+
+#endif	/* __PJSUA_APP_CONFIG_H__ */
+
