From 0b48d4f990a228fcbb9736f307923ed30b047f94 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Tue, 23 Apr 2013 05:33:59 +0000 Subject: Re #1655, #1657: modified pjsua BB10 due to change in pjsua app framework git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4485 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/pjsua/bb10/.project | 7 +- pjsip-apps/src/pjsua/bb10/PjsuaBB.pro | 3 +- pjsip-apps/src/pjsua/bb10/bar-descriptor.xml | 2 + pjsip-apps/src/pjsua/bb10/src/applicationui.cpp | 175 ++++++++++++++---------- pjsip-apps/src/pjsua/bb10/src/applicationui.h | 23 +++- pjsip-apps/src/pjsua/pjsua_app.c | 1 + pjsip-apps/src/pjsua/pjsua_app_config.h | 40 ++++++ 7 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 pjsip-apps/src/pjsua/pjsua_app_config.h (limited to 'pjsip-apps') diff --git a/pjsip-apps/src/pjsua/bb10/.project b/pjsip-apps/src/pjsua/bb10/.project index e35b1d19..190bc564 100644 --- a/pjsip-apps/src/pjsua/bb10/.project +++ b/pjsip-apps/src/pjsua/bb10/.project @@ -8,6 +8,7 @@ org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, ?name? @@ -19,7 +20,7 @@ org.eclipse.cdt.make.core.autoBuildTarget - Device-Release + Device-Debug org.eclipse.cdt.make.core.buildArguments @@ -39,7 +40,7 @@ org.eclipse.cdt.make.core.enableAutoBuild - true + false org.eclipse.cdt.make.core.enableCleanBuild @@ -51,7 +52,7 @@ org.eclipse.cdt.make.core.fullBuildTarget - Device-Release + Device-Debug org.eclipse.cdt.make.core.stopOnError diff --git a/pjsip-apps/src/pjsua/bb10/PjsuaBB.pro b/pjsip-apps/src/pjsua/bb10/PjsuaBB.pro index 78928ad9..c0889668 100644 --- a/pjsip-apps/src/pjsua/bb10/PjsuaBB.pro +++ b/pjsip-apps/src/pjsua/bb10/PjsuaBB.pro @@ -5,7 +5,6 @@ CONFIG += qt warn_on cascades10 include(config.pri) SOURCES += ../../pjsua_app.c \ - ../../pjsua_cli_cmd.c \ ../../pjsua_cli.c \ ../../pjsua_common.c \ ../../pjsua_config.c \ @@ -20,6 +19,8 @@ device { CONFIG(release, debug|release) { # Device-Release custom configuration + include(../../../../pjsip.pri) + LIBS += -lbb } } diff --git a/pjsip-apps/src/pjsua/bb10/bar-descriptor.xml b/pjsip-apps/src/pjsua/bb10/bar-descriptor.xml index 90e71e3d..c3b1d8f1 100644 --- a/pjsip-apps/src/pjsua/bb10/bar-descriptor.xml +++ b/pjsip-apps/src/pjsua/bb10/bar-descriptor.xml @@ -68,6 +68,8 @@ armle-v7 PjsuaBB + lib/libopencore-amrnb.so.0 + lib/libopencore-amrwb.so.0 Qnx/Cascades diff --git a/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp b/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp index 9d304b82..a4de872a 100644 --- a/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp +++ b/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp @@ -10,111 +10,136 @@ 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(); -}; - -static void bb10_show_msg(const char *msg) +#include "../../pjsua_app_config.h" + +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) -{ - char msg[64]; - - pj_ansi_snprintf(msg, sizeof(msg), - "Telnet to %.*s:%d", - (int)telnet_info->ip_address.slen, - telnet_info->ip_address.ptr, - telnet_info->port); - PJ_LOG(3,(THIS_FILE, "Started: %s", msg)); +void ApplicationUI::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)); + } - 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 ApplicationUI::pjsuaOnAppConfigCb(pjsua_app_config *cfg) +{ + PJ_UNUSED_ARG(cfg); } -void CliThread::run() +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; - - pj_thread_register("CliThread", thread_desc, &thread); - // Wait UI to be created - pj_thread_sleep(100); - - on_started_cb = &bb10_telnet_started; - on_quit_cb = &bb10_on_quit; - main_func(argc, (char**)argv); + 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; + + 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; + + 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(); - // set created root object as a scene app->setScene(root); app->setAutoExit(true); connect(app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); - pj_init(); - - // Run CLI - cliThread = new CliThread; - cliThread->start(); + pjsuaStart(); } ApplicationUI::~ApplicationUI() { - pj_shutdown(); instance_ = NULL; } @@ -125,16 +150,10 @@ ApplicationUI* ApplicationUI::instance() 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(); } } @@ -147,4 +166,8 @@ void ApplicationUI::displayMsg(const QString &msg) } } -#include "applicationui.moc" +void ApplicationUI::restartPjsua() +{ + pjsuaDestroy(); + pjsuaStart(); +} diff --git a/pjsip-apps/src/pjsua/bb10/src/applicationui.h b/pjsip-apps/src/pjsua/bb10/src/applicationui.h index 785e017f..8dbb17c2 100644 --- a/pjsip-apps/src/pjsua/bb10/src/applicationui.h +++ b/pjsip-apps/src/pjsua/bb10/src/applicationui.h @@ -4,9 +4,9 @@ #include -namespace bb { namespace cascades { class Application; }} +#include "../../pjsua_app.h" -class CliThread; +namespace bb { namespace cascades { class Application; }} /*! * @brief Application pane object @@ -23,14 +23,31 @@ public: bool isShuttingDown; 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); }; diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index f3945d92..bd9f7980 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -1911,6 +1911,7 @@ on_return: stdout_refresh_quit = PJ_TRUE; pj_thread_join(stdout_refresh_thread); pj_thread_destroy(stdout_refresh_thread); + stdout_refresh_quit = PJ_FALSE; } return status; } diff --git a/pjsip-apps/src/pjsua/pjsua_app_config.h b/pjsip-apps/src/pjsua/pjsua_app_config.h new file mode 100644 index 00000000..417bc430 --- /dev/null +++ b/pjsip-apps/src/pjsua/pjsua_app_config.h @@ -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__ */ + -- cgit v1.2.3