- Timestamp:
- Apr 23, 2013 5:33:59 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/bb10/src/applicationui.cpp
r4482 r4485 11 11 using namespace bb::cascades; 12 12 13 #include "../../pjsua_common.h" 14 15 extern pj_cli_telnet_on_started on_started_cb; 16 extern pj_cli_on_quit on_quit_cb; 17 18 extern "C" int main_func(int argc, char *argv[]); 19 13 /* appUI singleton */ 20 14 ApplicationUI *ApplicationUI::instance_; 21 15 22 class CliThread : public QThread 23 { 24 Q_OBJECT 25 public: 26 virtual ~CliThread() {} 27 protected: 28 void run(); 29 }; 16 #include "../../pjsua_app_config.h" 30 17 31 static void bb10_show_msg(const char *msg)18 void ApplicationUI::extDisplayMsg(const char *msg) 32 19 { 33 20 /* Qt's way to invoke method from "foreign" thread */ 34 QMetaObject::invokeMethod((QObject*)ApplicationUI::instance(), "displayMsg",35 Qt::QueuedConnection,21 QMetaObject::invokeMethod((QObject*)ApplicationUI::instance(), 22 "displayMsg", Qt::AutoConnection, 36 23 Q_ARG(QString,msg)); 37 24 } 38 25 39 static void bb10_telnet_started(pj_cli_telnet_info *telnet_info) 26 27 void ApplicationUI::pjsuaOnStartedCb(pj_status_t status, const char* msg) 40 28 { 41 char msg[64];29 char errmsg[PJ_ERR_MSG_SIZE]; 42 30 43 pj_ansi_snprintf(msg, sizeof(msg), 44 "Telnet to %.*s:%d", 45 (int)telnet_info->ip_address.slen, 46 telnet_info->ip_address.ptr, 47 telnet_info->port); 31 if (status != PJ_SUCCESS && (!msg || !*msg)) { 32 pj_strerror(status, errmsg, sizeof(errmsg)); 33 PJ_LOG(3,(THIS_FILE, "Error: %s", errmsg)); 34 msg = errmsg; 35 } else { 36 PJ_LOG(3,(THIS_FILE, "Started: %s", msg)); 37 } 48 38 49 PJ_LOG(3,(THIS_FILE, "Started: %s", msg)); 50 51 bb10_show_msg(msg); 39 ApplicationUI::extDisplayMsg(msg); 52 40 } 53 41 54 static void bb10_on_quit (pj_bool_t is_restarted) 42 43 pj_bool_t ApplicationUI::pjsuaOnStoppedCb(pj_bool_t restart, 44 int argc, char** argv) 55 45 { 56 PJ_LOG(3,("ipjsua", "CLI quit, restart(%d)", is_restarted)); 57 if (!is_restarted) { 58 bb10_show_msg("Shutting down.."); 46 PJ_LOG(3,("ipjsua", "CLI %s request", (restart? "restart" : "shutdown"))); 47 if (restart) { 48 ApplicationUI::extDisplayMsg("Restarting.."); 49 pj_thread_sleep(100); 50 ApplicationUI::instance()->extRestartRequest(argc, argv); 51 } else { 52 ApplicationUI::extDisplayMsg("Shutting down.."); 53 pj_thread_sleep(100); 59 54 ApplicationUI::instance()->isShuttingDown = true; 55 60 56 bb::cascades::Application *app = bb::cascades::Application::instance(); 61 57 app->quit(); 62 58 } 59 60 return PJ_TRUE; 63 61 } 64 62 65 void CliThread::run() 63 64 void ApplicationUI::pjsuaOnAppConfigCb(pjsua_app_config *cfg) 65 { 66 PJ_UNUSED_ARG(cfg); 67 } 68 69 void ApplicationUI::extRestartRequest(int argc, char **argv) 70 { 71 restartArgc = argc; 72 restartArgv = argv; 73 QMetaObject::invokeMethod((QObject*)this, "restartPjsua", 74 Qt::QueuedConnection); 75 } 76 77 void ApplicationUI::pjsuaStart() 66 78 { 67 79 // TODO: read from config? 68 const char *argv[] = { "pjsuabb", 69 "--use-cli", 70 "--no-cli-console", 71 "--cli-telnet-port=2323", 72 "--no-vad", 73 "--add-buddy=sip:169.254.0.2", 74 "--quality=4", 75 //(char*)"--dis-codec=*", 76 //(char*)"--add-codec=g722", 77 NULL }; 78 int argc = PJ_ARRAY_SIZE(argv) -1; 79 pj_thread_desc thread_desc; 80 pj_thread_t *thread; 80 const char **argv = pjsua_app_def_argv; 81 int argc = PJ_ARRAY_SIZE(pjsua_app_def_argv) -1; 82 app_cfg_t app_cfg; 83 pj_status_t status; 81 84 82 pj_thread_register("CliThread", thread_desc, &thread); 83 // Wait UI to be created 84 pj_thread_sleep(100); 85 isShuttingDown = false; 86 displayMsg("Starting.."); 85 87 86 on_started_cb = &bb10_telnet_started; 87 on_quit_cb = &bb10_on_quit; 88 main_func(argc, (char**)argv); 88 pj_bzero(&app_cfg, sizeof(app_cfg)); 89 if (restartArgc) { 90 app_cfg.argc = restartArgc; 91 app_cfg.argv = restartArgv; 92 } else { 93 app_cfg.argc = argc; 94 app_cfg.argv = (char**)argv; 95 } 96 app_cfg.on_started = &pjsuaOnStartedCb; 97 app_cfg.on_stopped = &pjsuaOnStoppedCb; 98 app_cfg.on_config_init = &pjsuaOnAppConfigCb; 99 100 status = app_init(&app_cfg); 101 if (status != PJ_SUCCESS) { 102 char errmsg[PJ_ERR_MSG_SIZE]; 103 pj_strerror(status, errmsg, sizeof(errmsg)); 104 displayMsg(QString("Init error:") + errmsg); 105 app_destroy(); 106 return; 107 } 108 109 status = app_run(PJ_FALSE); 110 if (status != PJ_SUCCESS) { 111 char errmsg[PJ_ERR_MSG_SIZE]; 112 pj_strerror(status, errmsg, sizeof(errmsg)); 113 displayMsg(QString("Error:") + errmsg); 114 app_destroy(); 115 } 116 117 restartArgv = NULL; 118 restartArgc = 0; 119 } 120 121 void ApplicationUI::pjsuaDestroy() 122 { 123 app_destroy(); 89 124 } 90 125 91 126 ApplicationUI::ApplicationUI(bb::cascades::Application *app) 92 : QObject(app), isShuttingDown(false) 127 : QObject(app), isShuttingDown(false), restartArgv(NULL), restartArgc(0) 93 128 { 94 129 instance_ = this; 95 130 96 // create scene document from main.qml asset97 // set parent to created document to ensure it exists for the whole application lifetime98 131 QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); 99 100 // create root object for the UI101 132 AbstractPane *root = qml->createRootObject<AbstractPane>(); 102 // set created root object as a scene103 133 app->setScene(root); 104 134 … … 106 136 connect(app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); 107 137 108 pj_init(); 109 110 // Run CLI 111 cliThread = new CliThread; 112 cliThread->start(); 138 pjsuaStart(); 113 139 } 114 140 115 141 ApplicationUI::~ApplicationUI() 116 142 { 117 pj_shutdown();118 143 instance_ = NULL; 119 144 } … … 126 151 void ApplicationUI::aboutToQuit() 127 152 { 128 static pj_thread_desc thread_desc;129 pj_thread_t *thread;130 131 if (!pj_thread_is_registered())132 pj_thread_register("UIThread", thread_desc, &thread);133 134 153 if (!isShuttingDown) { 135 154 isShuttingDown = true; 136 155 PJ_LOG(3,(THIS_FILE, "Quit signal from GUI, shutting down pjsua..")); 137 pjsua _destroy();156 pjsuaDestroy(); 138 157 } 139 158 } … … 148 167 } 149 168 150 #include "applicationui.moc" 169 void ApplicationUI::restartPjsua() 170 { 171 pjsuaDestroy(); 172 pjsuaStart(); 173 }
Note: See TracChangeset
for help on using the changeset viewer.