blob: 2b36b709c8bf21468e29b4ed4f46507aa3b3c295 [file] [log] [blame]
Benny Prijonoba5926a2007-05-02 11:29:37 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijonoba5926a2007-05-02 11:29:37 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
Benny Prijonoba5926a2007-05-02 11:29:37 +000020#include <pjsua-lib/pjsua.h>
Benny Prijono72a81aa2007-05-02 23:06:11 +000021#include <pjsua-lib/pjsua_internal.h>
Nanang Izzuddina940b362009-02-23 13:53:30 +000022//#include <pjmedia/symbian_sound_aps.h>
Benny Prijonoba5926a2007-05-02 11:29:37 +000023#include "ua.h"
24
25#define THIS_FILE "symbian_ua.cpp"
Nanang Izzuddinda37ea32009-03-06 16:24:43 +000026#define CON_LOG_LEVEL 3 // console log level
27#define FILE_LOG_LEVEL 4 // logfile log level
Benny Prijonoba5926a2007-05-02 11:29:37 +000028
Benny Prijono72a81aa2007-05-02 23:06:11 +000029//
Benny Prijonoc71ad432007-05-04 07:25:19 +000030// Basic config.
31//
32#define SIP_PORT 5060
33
34
35//
Benny Prijonob2c96822007-05-03 13:31:21 +000036// Destination URI (to make call, or to subscribe presence)
37//
Benny Prijono0e2c6462008-02-14 13:39:24 +000038#define SIP_DST_URI "sip:100@pjsip.lab"
Benny Prijonob2c96822007-05-03 13:31:21 +000039
40//
Benny Prijono72a81aa2007-05-02 23:06:11 +000041// Account
42//
Nanang Izzuddin82f7a412008-12-17 11:36:22 +000043#define HAS_SIP_ACCOUNT 0 // 1 to enable registration
Benny Prijono0e2c6462008-02-14 13:39:24 +000044#define SIP_DOMAIN "pjsip.lab"
45#define SIP_USER "400"
46#define SIP_PASSWD "400"
Benny Prijonoba5926a2007-05-02 11:29:37 +000047
Benny Prijono72a81aa2007-05-02 23:06:11 +000048//
49// Outbound proxy for all accounts
50//
51#define SIP_PROXY NULL
Benny Prijono4b55e0a2008-12-18 13:22:52 +000052//#define SIP_PROXY "<sip:192.168.0.8;lr>"
Benny Prijono897f9f82007-05-03 19:56:21 +000053
Nanang Izzuddin940d3f62009-06-22 14:06:40 +000054//
55// Set to 1 if TCP is desired (experimental)
56//
57#define ENABLE_SIP_TCP 0
Benny Prijono897f9f82007-05-03 19:56:21 +000058
59//
60// Configure nameserver if DNS SRV is to be used with both SIP
61// or STUN (for STUN see other settings below)
62//
Nanang Izzuddin82f7a412008-12-17 11:36:22 +000063#define NAMESERVER NULL
64//#define NAMESERVER "192.168.0.2"
Benny Prijono897f9f82007-05-03 19:56:21 +000065
66//
67// STUN server
Benny Prijono684c0ad2008-01-03 18:50:27 +000068#if 0
Benny Prijono897f9f82007-05-03 19:56:21 +000069 // Use this to have the STUN server resolved normally
70# define STUN_DOMAIN NULL
Benny Prijono4b55e0a2008-12-18 13:22:52 +000071# define STUN_SERVER "stun.pjsip.org"
Benny Prijono897f9f82007-05-03 19:56:21 +000072#elif 0
73 // Use this to have the STUN server resolved with DNS SRV
Benny Prijono4b55e0a2008-12-18 13:22:52 +000074# define STUN_DOMAIN "pjsip.org"
Benny Prijono897f9f82007-05-03 19:56:21 +000075# define STUN_SERVER NULL
76#else
77 // Use this to disable STUN
78# define STUN_DOMAIN NULL
79# define STUN_SERVER NULL
80#endif
81
82//
83// Use ICE?
84//
Benny Prijono70c5ba02007-12-31 11:27:35 +000085#define USE_ICE 1
Benny Prijono72a81aa2007-05-02 23:06:11 +000086
Nanang Izzuddin6a6392f2008-06-02 18:30:15 +000087//
88// Use SRTP?
89//
90#define USE_SRTP PJSUA_DEFAULT_USE_SRTP
Benny Prijono72a81aa2007-05-02 23:06:11 +000091
Benny Prijonob2c96822007-05-03 13:31:21 +000092//
93// Globals
94//
95static pjsua_acc_id g_acc_id = PJSUA_INVALID_ID;
96static pjsua_call_id g_call_id = PJSUA_INVALID_ID;
97static pjsua_buddy_id g_buddy_id = PJSUA_INVALID_ID;
Benny Prijono72a81aa2007-05-02 23:06:11 +000098
Benny Prijonoba5926a2007-05-02 11:29:37 +000099
100/* Callback called by the library upon receiving incoming call */
101static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
102 pjsip_rx_data *rdata)
103{
104 pjsua_call_info ci;
105
106 PJ_UNUSED_ARG(acc_id);
107 PJ_UNUSED_ARG(rdata);
108
Benny Prijonob2c96822007-05-03 13:31:21 +0000109 if (g_call_id != PJSUA_INVALID_ID) {
110 pjsua_call_answer(call_id, PJSIP_SC_BUSY_HERE, NULL, NULL);
111 return;
112 }
113
Benny Prijonoba5926a2007-05-02 11:29:37 +0000114 pjsua_call_get_info(call_id, &ci);
115
116 PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!",
117 (int)ci.remote_info.slen,
118 ci.remote_info.ptr));
119
Benny Prijonob2c96822007-05-03 13:31:21 +0000120 g_call_id = call_id;
121
Benny Prijono897f9f82007-05-03 19:56:21 +0000122 /* Automatically answer incoming calls with 180/Ringing */
123 pjsua_call_answer(call_id, 180, NULL, NULL);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000124}
125
126/* Callback called by the library when call's state has changed */
127static void on_call_state(pjsua_call_id call_id, pjsip_event *e)
128{
129 pjsua_call_info ci;
130
131 PJ_UNUSED_ARG(e);
132
133 pjsua_call_get_info(call_id, &ci);
Benny Prijonob2c96822007-05-03 13:31:21 +0000134
135 if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
136 if (call_id == g_call_id)
137 g_call_id = PJSUA_INVALID_ID;
Benny Prijono897f9f82007-05-03 19:56:21 +0000138 } else if (ci.state != PJSIP_INV_STATE_INCOMING) {
Benny Prijonob2c96822007-05-03 13:31:21 +0000139 if (g_call_id == PJSUA_INVALID_ID)
140 g_call_id = call_id;
141 }
142
Benny Prijonoba5926a2007-05-02 11:29:37 +0000143 PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id,
144 (int)ci.state_text.slen,
145 ci.state_text.ptr));
146}
147
148/* Callback called by the library when call's media state has changed */
149static void on_call_media_state(pjsua_call_id call_id)
150{
151 pjsua_call_info ci;
152
153 pjsua_call_get_info(call_id, &ci);
154
155 if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
156 // When media is active, connect call to sound device.
157 pjsua_conf_connect(ci.conf_slot, 0);
158 pjsua_conf_connect(0, ci.conf_slot);
159 }
160}
161
162
Benny Prijonob2c96822007-05-03 13:31:21 +0000163/* Handler on buddy state changed. */
164static void on_buddy_state(pjsua_buddy_id buddy_id)
165{
166 pjsua_buddy_info info;
167 pjsua_buddy_get_info(buddy_id, &info);
168
169 PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s",
170 (int)info.uri.slen,
171 info.uri.ptr,
172 (int)info.status_text.slen,
173 info.status_text.ptr));
174}
175
176
177/* Incoming IM message (i.e. MESSAGE request)! */
178static void on_pager(pjsua_call_id call_id, const pj_str_t *from,
179 const pj_str_t *to, const pj_str_t *contact,
180 const pj_str_t *mime_type, const pj_str_t *text)
181{
182 /* Note: call index may be -1 */
183 PJ_UNUSED_ARG(call_id);
184 PJ_UNUSED_ARG(to);
185 PJ_UNUSED_ARG(contact);
186 PJ_UNUSED_ARG(mime_type);
187
188 PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s",
189 (int)from->slen, from->ptr,
190 (int)text->slen, text->ptr));
191}
192
193
194/* Received typing indication */
195static void on_typing(pjsua_call_id call_id, const pj_str_t *from,
196 const pj_str_t *to, const pj_str_t *contact,
197 pj_bool_t is_typing)
198{
199 PJ_UNUSED_ARG(call_id);
200 PJ_UNUSED_ARG(to);
201 PJ_UNUSED_ARG(contact);
202
203 PJ_LOG(3,(THIS_FILE, "IM indication: %.*s %s",
204 (int)from->slen, from->ptr,
205 (is_typing?"is typing..":"has stopped typing")));
206}
207
208
209/* Call transfer request status. */
210static void on_call_transfer_status(pjsua_call_id call_id,
211 int status_code,
212 const pj_str_t *status_text,
213 pj_bool_t final,
214 pj_bool_t *p_cont)
215{
216 PJ_LOG(3,(THIS_FILE, "Call %d: transfer status=%d (%.*s) %s",
217 call_id, status_code,
218 (int)status_text->slen, status_text->ptr,
219 (final ? "[final]" : "")));
220
221 if (status_code/100 == 2) {
222 PJ_LOG(3,(THIS_FILE,
223 "Call %d: call transfered successfully, disconnecting call",
224 call_id));
225 pjsua_call_hangup(call_id, PJSIP_SC_GONE, NULL, NULL);
226 *p_cont = PJ_FALSE;
227 }
228}
229
230
Benny Prijonoaecabfc2007-10-26 05:35:42 +0000231/* NAT detection result */
232static void on_nat_detect(const pj_stun_nat_detect_result *res)
233{
234 if (res->status != PJ_SUCCESS) {
235 pjsua_perror(THIS_FILE, "NAT detection failed", res->status);
236 } else {
237 PJ_LOG(3, (THIS_FILE, "NAT detected as %s", res->nat_type_name));
238 }
239}
240
Benny Prijonob2c96822007-05-03 13:31:21 +0000241/* Notification that call is being replaced. */
242static void on_call_replaced(pjsua_call_id old_call_id,
243 pjsua_call_id new_call_id)
244{
245 pjsua_call_info old_ci, new_ci;
246
247 pjsua_call_get_info(old_call_id, &old_ci);
248 pjsua_call_get_info(new_call_id, &new_ci);
249
250 PJ_LOG(3,(THIS_FILE, "Call %d with %.*s is being replaced by "
251 "call %d with %.*s",
252 old_call_id,
253 (int)old_ci.remote_info.slen, old_ci.remote_info.ptr,
254 new_call_id,
255 (int)new_ci.remote_info.slen, new_ci.remote_info.ptr));
256}
257
258
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000259//#include<e32debug.h>
260
Benny Prijonoba5926a2007-05-02 11:29:37 +0000261/* Logging callback */
Benny Prijono797e3382007-12-01 09:10:07 +0000262static void log_writer(int level, const char *buf, int len)
Benny Prijonoba5926a2007-05-02 11:29:37 +0000263{
Benny Prijonoc71ad432007-05-04 07:25:19 +0000264 static wchar_t buf16[PJ_LOG_MAX_SIZE];
Benny Prijonoba5926a2007-05-02 11:29:37 +0000265
266 PJ_UNUSED_ARG(level);
267
268 pj_ansi_to_unicode(buf, len, buf16, PJ_ARRAY_SIZE(buf16));
269
270 TPtrC16 aBuf((const TUint16*)buf16, (TInt)len);
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000271 //RDebug::Print(aBuf);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000272 console->Write(aBuf);
Benny Prijono797e3382007-12-01 09:10:07 +0000273
Benny Prijonoba5926a2007-05-02 11:29:37 +0000274}
275
276/*
277 * app_startup()
278 *
279 * url may contain URL to call.
280 */
Benny Prijonob2c96822007-05-03 13:31:21 +0000281static pj_status_t app_startup()
Benny Prijonoba5926a2007-05-02 11:29:37 +0000282{
Benny Prijonoba5926a2007-05-02 11:29:37 +0000283 pj_status_t status;
284
285 /* Redirect log before pjsua_init() */
Benny Prijono70c5ba02007-12-31 11:27:35 +0000286 pj_log_set_log_func(&log_writer);
287
288 /* Set log level */
Nanang Izzuddinda37ea32009-03-06 16:24:43 +0000289 pj_log_set_level(CON_LOG_LEVEL);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000290
291 /* Create pjsua first! */
292 status = pjsua_create();
293 if (status != PJ_SUCCESS) {
294 pjsua_perror(THIS_FILE, "pjsua_create() error", status);
295 return status;
296 }
297
Benny Prijonoba5926a2007-05-02 11:29:37 +0000298 /* Init pjsua */
Benny Prijonoc71ad432007-05-04 07:25:19 +0000299 pjsua_config cfg;
300 pjsua_logging_config log_cfg;
301 pjsua_media_config med_cfg;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000302
Benny Prijonoc71ad432007-05-04 07:25:19 +0000303 pjsua_config_default(&cfg);
304 cfg.max_calls = 2;
305 cfg.thread_cnt = 0; // Disable threading on Symbian
Nanang Izzuddin6a6392f2008-06-02 18:30:15 +0000306 cfg.use_srtp = USE_SRTP;
307 cfg.srtp_secure_signaling = 0;
308
Benny Prijonoc71ad432007-05-04 07:25:19 +0000309 cfg.cb.on_incoming_call = &on_incoming_call;
310 cfg.cb.on_call_media_state = &on_call_media_state;
311 cfg.cb.on_call_state = &on_call_state;
312 cfg.cb.on_buddy_state = &on_buddy_state;
313 cfg.cb.on_pager = &on_pager;
314 cfg.cb.on_typing = &on_typing;
315 cfg.cb.on_call_transfer_status = &on_call_transfer_status;
316 cfg.cb.on_call_replaced = &on_call_replaced;
Benny Prijonoaecabfc2007-10-26 05:35:42 +0000317 cfg.cb.on_nat_detect = &on_nat_detect;
318
Benny Prijonoc71ad432007-05-04 07:25:19 +0000319 if (SIP_PROXY) {
320 cfg.outbound_proxy_cnt = 1;
321 cfg.outbound_proxy[0] = pj_str(SIP_PROXY);
322 }
323
324 if (NAMESERVER) {
325 cfg.nameserver_count = 1;
326 cfg.nameserver[0] = pj_str(NAMESERVER);
327 }
328
329 if (NAMESERVER && STUN_DOMAIN) {
330 cfg.stun_domain = pj_str(STUN_DOMAIN);
331 } else if (STUN_SERVER) {
332 cfg.stun_host = pj_str(STUN_SERVER);
333 }
334
335
336 pjsua_logging_config_default(&log_cfg);
Nanang Izzuddinda37ea32009-03-06 16:24:43 +0000337 log_cfg.level = FILE_LOG_LEVEL;
338 log_cfg.console_level = CON_LOG_LEVEL;
Benny Prijonoc71ad432007-05-04 07:25:19 +0000339 log_cfg.cb = &log_writer;
Nanang Izzuddin83457d52009-02-16 16:29:05 +0000340 log_cfg.log_filename = pj_str("C:\\data\\symbian_ua.log");
Benny Prijonoba5926a2007-05-02 11:29:37 +0000341
Benny Prijonoc71ad432007-05-04 07:25:19 +0000342 pjsua_media_config_default(&med_cfg);
343 med_cfg.thread_cnt = 0; // Disable threading on Symbian
344 med_cfg.has_ioqueue = PJ_FALSE;
345 med_cfg.clock_rate = 8000;
Benny Prijono5df8bb62007-12-28 18:55:02 +0000346 med_cfg.audio_frame_ptime = 40;
Benny Prijonoc71ad432007-05-04 07:25:19 +0000347 med_cfg.ec_tail_len = 0;
348 med_cfg.enable_ice = USE_ICE;
Nanang Izzuddin81db8c72009-02-05 10:59:14 +0000349 med_cfg.snd_auto_close_time = 0; // wait for 0 seconds idle before sound dev get auto-closed
Nanang Izzuddina3775972009-03-03 18:25:55 +0000350 //med_cfg.no_vad = PJ_TRUE;
Benny Prijonoc71ad432007-05-04 07:25:19 +0000351
352 status = pjsua_init(&cfg, &log_cfg, &med_cfg);
353 if (status != PJ_SUCCESS) {
354 pjsua_perror(THIS_FILE, "pjsua_init() error", status);
355 pjsua_destroy();
356 return status;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000357 }
Nanang Izzuddin829ac022008-05-27 00:24:26 +0000358
359 /* Adjust Speex priority and enable only the narrowband */
360 {
361 pj_str_t codec_id = pj_str("speex/8000");
362 pjmedia_codec_mgr_set_codec_priority(
363 pjmedia_endpt_get_codec_mgr(pjsua_var.med_endpt),
364 &codec_id, PJMEDIA_CODEC_PRIO_NORMAL+1);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000365
Nanang Izzuddin829ac022008-05-27 00:24:26 +0000366 codec_id = pj_str("speex/16000");
367 pjmedia_codec_mgr_set_codec_priority(
368 pjmedia_endpt_get_codec_mgr(pjsua_var.med_endpt),
369 &codec_id, PJMEDIA_CODEC_PRIO_DISABLED);
370
371 codec_id = pj_str("speex/32000");
372 pjmedia_codec_mgr_set_codec_priority(
373 pjmedia_endpt_get_codec_mgr(pjsua_var.med_endpt),
374 &codec_id, PJMEDIA_CODEC_PRIO_DISABLED);
375 }
376
Benny Prijonoba5926a2007-05-02 11:29:37 +0000377 /* Add UDP transport. */
Benny Prijonoc71ad432007-05-04 07:25:19 +0000378 pjsua_transport_config tcfg;
379 pjsua_transport_id tid;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000380
Benny Prijonoc71ad432007-05-04 07:25:19 +0000381 pjsua_transport_config_default(&tcfg);
382 tcfg.port = SIP_PORT;
383 status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &tcfg, &tid);
384 if (status != PJ_SUCCESS) {
Nanang Izzuddin940d3f62009-06-22 14:06:40 +0000385 pjsua_perror(THIS_FILE, "Error creating UDP transport", status);
Benny Prijonoc71ad432007-05-04 07:25:19 +0000386 pjsua_destroy();
387 return status;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000388 }
389
Nanang Izzuddin940d3f62009-06-22 14:06:40 +0000390 /* Add TCP transport */
391#if ENABLE_SIP_TCP
392 pjsua_transport_config_default(&tcfg);
393 tcfg.port = SIP_PORT;
394 status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &tcfg, &tid);
395 if (status != PJ_SUCCESS) {
396 pjsua_perror(THIS_FILE, "Error creating TCP transport", status);
397 pjsua_destroy();
398 return status;
399 }
400#endif
401
Benny Prijonoc71ad432007-05-04 07:25:19 +0000402 /* Add account for the transport */
403 pjsua_acc_add_local(tid, PJ_TRUE, &g_acc_id);
404
405
Benny Prijonoba5926a2007-05-02 11:29:37 +0000406 /* Initialization is done, now start pjsua */
407 status = pjsua_start();
408 if (status != PJ_SUCCESS) {
409 pjsua_perror(THIS_FILE, "Error starting pjsua", status);
410 pjsua_destroy();
411 return status;
412 }
413
414 /* Register to SIP server by creating SIP account. */
Benny Prijono72a81aa2007-05-02 23:06:11 +0000415 if (HAS_SIP_ACCOUNT) {
Benny Prijonoba5926a2007-05-02 11:29:37 +0000416 pjsua_acc_config cfg;
417
418 pjsua_acc_config_default(&cfg);
419 cfg.id = pj_str("sip:" SIP_USER "@" SIP_DOMAIN);
420 cfg.reg_uri = pj_str("sip:" SIP_DOMAIN);
421 cfg.cred_count = 1;
Benny Prijono0e2c6462008-02-14 13:39:24 +0000422 cfg.cred_info[0].realm = pj_str("*");
Benny Prijonoba5926a2007-05-02 11:29:37 +0000423 cfg.cred_info[0].scheme = pj_str("digest");
424 cfg.cred_info[0].username = pj_str(SIP_USER);
425 cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
426 cfg.cred_info[0].data = pj_str(SIP_PASSWD);
427
Benny Prijonob2c96822007-05-03 13:31:21 +0000428 status = pjsua_acc_add(&cfg, PJ_TRUE, &g_acc_id);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000429 if (status != PJ_SUCCESS) {
430 pjsua_perror(THIS_FILE, "Error adding account", status);
431 pjsua_destroy();
432 return status;
433 }
434 }
435
Benny Prijonob2c96822007-05-03 13:31:21 +0000436 if (SIP_DST_URI) {
437 pjsua_buddy_config bcfg;
438
439 pjsua_buddy_config_default(&bcfg);
440 bcfg.uri = pj_str(SIP_DST_URI);
441 bcfg.subscribe = PJ_FALSE;
442
443 pjsua_buddy_add(&bcfg, &g_buddy_id);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000444 }
Benny Prijonoba5926a2007-05-02 11:29:37 +0000445 return PJ_SUCCESS;
446}
447
448
449////////////////////////////////////////////////////////////////////////////
Benny Prijonoc71ad432007-05-04 07:25:19 +0000450/*
451 * The interractive console UI
452 */
Benny Prijonoba5926a2007-05-02 11:29:37 +0000453#include <e32base.h>
454
455class ConsoleUI : public CActive
456{
457public:
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000458 ConsoleUI(CConsoleBase *con);
Nanang Izzuddin90b83202009-03-02 15:48:45 +0000459 ~ConsoleUI();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000460
Benny Prijonoc71ad432007-05-04 07:25:19 +0000461 // Run console UI
462 void Run();
463
464 // Stop
465 void Stop();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000466
467protected:
Benny Prijonoc71ad432007-05-04 07:25:19 +0000468 // Cancel asynchronous read.
469 void DoCancel();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000470
Benny Prijonoc71ad432007-05-04 07:25:19 +0000471 // Implementation: called when read has completed.
472 void RunL();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000473
474private:
Benny Prijonoc71ad432007-05-04 07:25:19 +0000475 CConsoleBase *con_;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000476};
477
478
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000479ConsoleUI::ConsoleUI(CConsoleBase *con)
480: CActive(EPriorityStandard), con_(con)
Benny Prijonoba5926a2007-05-02 11:29:37 +0000481{
Benny Prijonoc71ad432007-05-04 07:25:19 +0000482 CActiveScheduler::Add(this);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000483}
484
Nanang Izzuddin90b83202009-03-02 15:48:45 +0000485ConsoleUI::~ConsoleUI()
486{
487 Stop();
488}
489
Benny Prijonoba5926a2007-05-02 11:29:37 +0000490// Run console UI
491void ConsoleUI::Run()
492{
Benny Prijonoc71ad432007-05-04 07:25:19 +0000493 con_->Read(iStatus);
494 SetActive();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000495}
496
497// Stop console UI
498void ConsoleUI::Stop()
499{
Nanang Izzuddin90b83202009-03-02 15:48:45 +0000500 Cancel();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000501}
502
503// Cancel asynchronous read.
504void ConsoleUI::DoCancel()
505{
Benny Prijonoc71ad432007-05-04 07:25:19 +0000506 con_->ReadCancel();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000507}
508
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000509static void PrintMainMenu()
Benny Prijono72a81aa2007-05-02 23:06:11 +0000510{
Nanang Izzuddinda37ea32009-03-06 16:24:43 +0000511 const char *menu =
512 "\n\n"
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000513 "Main Menu:\n"
514 " d Enable/disable codecs\n"
Benny Prijono70c5ba02007-12-31 11:27:35 +0000515 " m Call " SIP_DST_URI "\n"
516 " a Answer call\n"
517 " g Hangup all calls\n"
Nanang Izzuddin0cb3b022009-02-27 17:37:35 +0000518 " t Toggle audio route\n"
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000519#if !defined(PJMEDIA_CONF_USE_SWITCH_BOARD) || PJMEDIA_CONF_USE_SWITCH_BOARD==0
Nanang Izzuddin0cb3b022009-02-27 17:37:35 +0000520 " j Toggle loopback audio\n"
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000521#endif
Nanang Izzuddin08694ea2009-03-10 15:03:04 +0000522 "up/dn Increase/decrease output volume\n"
Benny Prijono1f61a8f2007-08-16 10:11:44 +0000523 " s Subscribe " SIP_DST_URI "\n"
Benny Prijonoc71ad432007-05-04 07:25:19 +0000524 " S Unsubscribe presence\n"
525 " o Set account online\n"
526 " O Set account offline\n"
Nanang Izzuddinda37ea32009-03-06 16:24:43 +0000527 " w Quit\n";
528
529 PJ_LOG(3, (THIS_FILE, menu));
Benny Prijono72a81aa2007-05-02 23:06:11 +0000530}
531
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000532static void PrintCodecMenu()
533{
Nanang Izzuddinda37ea32009-03-06 16:24:43 +0000534 const char *menu =
535 "\n\n"
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000536 "Codec Menu:\n"
537 " a Enable all codecs\n"
Nanang Izzuddina3775972009-03-03 18:25:55 +0000538#if PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000539 " d Enable only AMR\n"
Nanang Izzuddina3775972009-03-03 18:25:55 +0000540#endif
541#if PJMEDIA_HAS_PASSTHROUGH_CODEC_G729
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000542 " g Enable only G.729\n"
Nanang Izzuddina3775972009-03-03 18:25:55 +0000543#endif
544#if PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000545 " j Enable only iLBC\n"
546#endif
547 " m Enable only Speex\n"
548 " p Enable only GSM\n"
549 " t Enable only PCMU\n"
Nanang Izzuddinda37ea32009-03-06 16:24:43 +0000550 " w Enable only PCMA\n";
551
552 PJ_LOG(3, (THIS_FILE, menu));
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000553}
554
555static void HandleMainMenu(TKeyCode kc) {
556 switch (kc) {
557
Nanang Izzuddin08694ea2009-03-10 15:03:04 +0000558 case EKeyUpArrow:
559 case EKeyDownArrow:
560 {
561 unsigned vol;
562 pj_status_t status;
563
564 status = pjsua_snd_get_setting(
565 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING, &vol);
566 if (status == PJ_SUCCESS) {
567 if (kc == EKeyUpArrow)
568 vol = PJ_MIN(100, vol+10);
569 else
570 vol = (vol>=10 ? vol-10 : 0);
571 status = pjsua_snd_set_setting(
572 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
573 &vol, PJ_TRUE);
574 }
575
576 if (status == PJ_SUCCESS) {
577 PJ_LOG(3,(THIS_FILE, "Output volume set to %d", vol));
578 } else {
579 pjsua_perror(THIS_FILE, "Error setting volume", status);
580 }
581 }
582 break;
583
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000584 case 't':
Nanang Izzuddin0cb3b022009-02-27 17:37:35 +0000585 {
Nanang Izzuddinfcb92d02009-03-10 13:32:09 +0000586 pjmedia_aud_dev_route route;
587 pj_status_t status;
588
589 status = pjsua_snd_get_setting(PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE,
590 &route);
591
592 if (status == PJ_SUCCESS) {
593 if (route == PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER)
594 route = PJMEDIA_AUD_DEV_ROUTE_EARPIECE;
595 else
596 route = PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER;
Nanang Izzuddin452b66b2009-02-18 15:23:47 +0000597
Nanang Izzuddinfcb92d02009-03-10 13:32:09 +0000598 status = pjsua_snd_set_setting(
599 PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE,
600 &route, PJ_TRUE);
Nanang Izzuddin0cb3b022009-02-27 17:37:35 +0000601 }
Nanang Izzuddinfcb92d02009-03-10 13:32:09 +0000602
603 if (status != PJ_SUCCESS)
604 pjsua_perror(THIS_FILE, "Error switch audio route", status);
Nanang Izzuddin0cb3b022009-02-27 17:37:35 +0000605 }
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000606 break;
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000607
608 case 'j':
Nanang Izzuddin0cb3b022009-02-27 17:37:35 +0000609 {
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000610 static pj_bool_t loopback_active = PJ_FALSE;
611 if (!loopback_active)
612 pjsua_conf_connect(0, 0);
613 else
614 pjsua_conf_disconnect(0, 0);
615 loopback_active = !loopback_active;
Nanang Izzuddin0cb3b022009-02-27 17:37:35 +0000616 }
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000617 break;
618
619 case 'm':
620 if (g_call_id != PJSUA_INVALID_ID) {
621 PJ_LOG(3,(THIS_FILE, "Another call is active"));
622 break;
623 }
624
625 if (pjsua_verify_sip_url(SIP_DST_URI) == PJ_SUCCESS) {
626 pj_str_t dst = pj_str(SIP_DST_URI);
627 pjsua_call_make_call(g_acc_id, &dst, 0, NULL,
628 NULL, &g_call_id);
629 } else {
630 PJ_LOG(3,(THIS_FILE, "Invalid SIP URI"));
631 }
632 break;
633 case 'a':
634 if (g_call_id != PJSUA_INVALID_ID)
635 pjsua_call_answer(g_call_id, 200, NULL, NULL);
636 break;
637 case 'g':
638 pjsua_call_hangup_all();
639 break;
640 case 's':
641 case 'S':
642 if (g_buddy_id != PJSUA_INVALID_ID)
643 pjsua_buddy_subscribe_pres(g_buddy_id, kc=='s');
644 break;
645 case 'o':
646 case 'O':
647 pjsua_acc_set_online_status(g_acc_id, kc=='o');
648 break;
649
650 default:
651 PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", kc, kc));
652 break;
653 }
654
655 PrintMainMenu();
656}
657
658static void HandleCodecMenu(TKeyCode kc) {
659 const pj_str_t ID_ALL = {"*", 1};
660 pj_str_t codec = {NULL, 0};
661
662 if (kc == 'a') {
663 pjsua_codec_set_priority(&ID_ALL, PJMEDIA_CODEC_PRIO_NORMAL);
664 PJ_LOG(3,(THIS_FILE, "All codecs activated"));
665 } else {
666 switch (kc) {
667 case 'd':
668 codec = pj_str("AMR");
669 break;
670 case 'g':
671 codec = pj_str("G729");
672 break;
673 case 'j':
674 codec = pj_str("ILBC");
675 break;
676 case 'm':
677 codec = pj_str("SPEEX/8000");
678 break;
679 case 'p':
680 codec = pj_str("GSM");
681 break;
682 case 't':
683 codec = pj_str("PCMU");
684 break;
685 case 'w':
686 codec = pj_str("PCMA");
687 break;
688 default:
689 PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", kc, kc));
690 break;
691 }
692
693 if (codec.slen) {
694 pj_status_t status;
695
696 pjsua_codec_set_priority(&ID_ALL, PJMEDIA_CODEC_PRIO_DISABLED);
697
698 status = pjsua_codec_set_priority(&codec,
699 PJMEDIA_CODEC_PRIO_NORMAL);
700 if (status == PJ_SUCCESS)
701 PJ_LOG(3,(THIS_FILE, "%s activated", codec.ptr));
702 else
703 PJ_LOG(3,(THIS_FILE, "Failed activating %s, err=%d",
704 codec.ptr, status));
705 }
706 }
Benny Prijonoba5926a2007-05-02 11:29:37 +0000707}
708
709// Implementation: called when read has completed.
710void ConsoleUI::RunL()
711{
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000712 enum {
713 MENU_TYPE_MAIN = 0,
714 MENU_TYPE_CODEC = 1
715 };
716 static int menu_type = MENU_TYPE_MAIN;
Benny Prijonoc71ad432007-05-04 07:25:19 +0000717 TKeyCode kc = con_->KeyCode();
718 pj_bool_t reschedule = PJ_TRUE;
719
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000720 if (menu_type == MENU_TYPE_MAIN) {
721 if (kc == 'w') {
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000722 CActiveScheduler::Stop();
Benny Prijonoc71ad432007-05-04 07:25:19 +0000723 reschedule = PJ_FALSE;
Nanang Izzuddin798bf452009-02-12 12:35:27 +0000724 } else if (kc == 'd') {
725 menu_type = MENU_TYPE_CODEC;
726 PrintCodecMenu();
727 } else {
728 HandleMainMenu(kc);
729 }
730 } else {
731 HandleCodecMenu(kc);
732
733 menu_type = MENU_TYPE_MAIN;
734 PrintMainMenu();
Benny Prijonoc71ad432007-05-04 07:25:19 +0000735 }
Benny Prijonoc71ad432007-05-04 07:25:19 +0000736
737 if (reschedule)
738 Run();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000739}
740
Benny Prijono70c5ba02007-12-31 11:27:35 +0000741#if 0
742// IP networking related testing
743static pj_status_t test_addr(void)
744{
745 int af;
746 unsigned i, count;
747 pj_addrinfo ai[8];
748 pj_sockaddr ifs[8];
749 const pj_str_t *hostname;
750 pj_hostent he;
751 pj_status_t status;
752
753 pj_log_set_log_func(&log_writer);
754
755 status = pj_init();
756 if (status != PJ_SUCCESS) {
757 pjsua_perror(THIS_FILE, "pj_init() error", status);
758 return status;
759 }
760
761 af = pj_AF_INET();
762
Benny Prijono684c0ad2008-01-03 18:50:27 +0000763#if 0
764 pj_in_addr in_addr;
765 pj_str_t aa = pj_str("1.1.1.1");
766 in_addr = pj_inet_addr(&aa);
767 char *the_addr = pj_inet_ntoa(in_addr);
768 PJ_LOG(3,(THIS_FILE, "IP addr=%s", the_addr));
769
770 aa = pj_str("192.168.0.15");
771 in_addr = pj_inet_addr(&aa);
772 the_addr = pj_inet_ntoa(in_addr);
773 PJ_LOG(3,(THIS_FILE, "IP addr=%s", the_addr));
774
775 aa = pj_str("2.2.2.2");
776 in_addr = pj_inet_addr(&aa);
777 the_addr = pj_inet_ntoa(in_addr);
778 PJ_LOG(3,(THIS_FILE, "IP addr=%s", the_addr));
779
780 return -1;
781#endif
782
Benny Prijono70c5ba02007-12-31 11:27:35 +0000783 // Hostname
784 hostname = pj_gethostname();
785 if (hostname == NULL) {
786 status = PJ_ERESOLVE;
787 pjsua_perror(THIS_FILE, "pj_gethostname() error", status);
788 goto on_return;
789 }
790
791 PJ_LOG(3,(THIS_FILE, "Hostname: %.*s", hostname->slen, hostname->ptr));
792
793 // Gethostbyname
794 status = pj_gethostbyname(hostname, &he);
795 if (status != PJ_SUCCESS) {
796 pjsua_perror(THIS_FILE, "pj_gethostbyname() error", status);
797 } else {
798 PJ_LOG(3,(THIS_FILE, "gethostbyname: %s",
799 pj_inet_ntoa(*(pj_in_addr*)he.h_addr)));
800 }
801
802 // Getaddrinfo
803 count = PJ_ARRAY_SIZE(ai);
804 status = pj_getaddrinfo(af, hostname, &count, ai);
805 if (status != PJ_SUCCESS) {
806 pjsua_perror(THIS_FILE, "pj_getaddrinfo() error", status);
807 } else {
808 for (i=0; i<count; ++i) {
809 char ipaddr[PJ_INET6_ADDRSTRLEN+2];
810 PJ_LOG(3,(THIS_FILE, "Addrinfo: %s",
811 pj_sockaddr_print(&ai[i].ai_addr, ipaddr, sizeof(ipaddr), 2)));
812 }
813 }
814
815 // Enum interface
816 count = PJ_ARRAY_SIZE(ifs);
817 status = pj_enum_ip_interface(af, &count, ifs);
818 if (status != PJ_SUCCESS) {
819 pjsua_perror(THIS_FILE, "pj_enum_ip_interface() error", status);
820 } else {
821 for (i=0; i<count; ++i) {
822 char ipaddr[PJ_INET6_ADDRSTRLEN+2];
823 PJ_LOG(3,(THIS_FILE, "Interface: %s",
824 pj_sockaddr_print(&ifs[i], ipaddr, sizeof(ipaddr), 2)));
825 }
826 }
827
828 // Get default iinterface
829 status = pj_getdefaultipinterface(af, &ifs[0]);
830 if (status != PJ_SUCCESS) {
831 pjsua_perror(THIS_FILE, "pj_getdefaultipinterface() error", status);
832 } else {
833 char ipaddr[PJ_INET6_ADDRSTRLEN+2];
834 PJ_LOG(3,(THIS_FILE, "Default IP: %s",
835 pj_sockaddr_print(&ifs[0], ipaddr, sizeof(ipaddr), 2)));
836 }
837
838 // Get default IP address
839 status = pj_gethostip(af, &ifs[0]);
840 if (status != PJ_SUCCESS) {
841 pjsua_perror(THIS_FILE, "pj_gethostip() error", status);
842 } else {
843 char ipaddr[PJ_INET6_ADDRSTRLEN+2];
844 PJ_LOG(3,(THIS_FILE, "Host IP: %s",
845 pj_sockaddr_print(&ifs[0], ipaddr, sizeof(ipaddr), 2)));
846 }
847
848 status = -1;
849
850on_return:
851 pj_shutdown();
852 return status;
853}
854#endif
855
856
Benny Prijono6b3ccdf2008-01-14 11:54:21 +0000857#include <es_sock.h>
Benny Prijono897f9f82007-05-03 19:56:21 +0000858
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000859#if 0
860// Force network connection to use the first IAP,
861// this is useful for debugging on emulator without GUI.
862// Include commdb.lib & apengine.lib in symbian_ua.mmp file
863// if this is enabled.
864
865#include <apdatahandler.h>
866
867inline void ForceUseFirstIAP()
868{
869 TUint32 rank = 1;
870 TUint32 bearers;
871 TUint32 prompt;
872 TUint32 iap;
873
874 CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
875 CleanupStack::PushL(commDb);
876
877 CApDataHandler* apDataHandler = CApDataHandler::NewLC(*commDb);
878
879 TCommDbConnectionDirection direction = ECommDbConnectionDirectionOutgoing;
880 apDataHandler->GetPreferredIfDbIapTypeL(rank, direction, bearers, prompt, iap);
881 prompt = ECommDbDialogPrefDoNotPrompt;
882 apDataHandler->SetPreferredIfDbIapTypeL(rank, direction, bearers, (TCommDbDialogPref)prompt, iap, ETrue);
883 CleanupStack::PopAndDestroy(2); // apDataHandler, commDb
884}
885
886static void SelectIAP()
887{
888 ForceUseFirstIAP();
889}
890
891#else
892
893static void SelectIAP()
894{
895}
896
897#endif
898
899
Nanang Izzuddin90b83202009-03-02 15:48:45 +0000900// Class CConnMon to monitor network connection (RConnection). Whenever
901// the connection is down, it will notify PJLIB and restart PJSUA-LIB.
902class CConnMon : public CActive {
903public:
904 static CConnMon* NewL(RConnection &conn, RSocketServ &sserver) {
905 CConnMon *self = new (ELeave) CConnMon(conn, sserver);
906 CleanupStack::PushL(self);
907 self->ConstructL();
908 CleanupStack::Pop(self);
909 return self;
910 }
911
912 void Start() {
913 conn_.ProgressNotification(nif_progress_, iStatus);
914 SetActive();
915 }
916
917 void Stop() {
918 Cancel();
919 }
920
921 ~CConnMon() { Stop(); }
922
923private:
924 CConnMon(RConnection &conn, RSocketServ &sserver) :
925 CActive(EPriorityHigh),
926 conn_(conn),
927 sserver_(sserver)
928 {
929 CActiveScheduler::Add(this);
930 }
931
932 void ConstructL() {}
933
934 void DoCancel() {
935 conn_.CancelProgressNotification();
936 }
937
938 void RunL() {
939 int stage = nif_progress_().iStage;
940
941 if (stage == KLinkLayerClosed) {
942 pj_status_t status;
943 TInt err;
944
945 // Tell pjlib that connection is down.
946 pj_symbianos_set_connection_status(PJ_FALSE);
947
948 PJ_LOG(3, (THIS_FILE, "RConnection closed, restarting PJSUA.."));
949
950 // Destroy pjsua
951 pjsua_destroy();
952 PJ_LOG(3, (THIS_FILE, "PJSUA destroyed."));
953
954 // Reopen the connection
955 err = conn_.Open(sserver_);
956 if (err == KErrNone)
957 err = conn_.Start();
958 if (err != KErrNone) {
959 CActiveScheduler::Stop();
960 return;
961 }
962
963 // Reinit Symbian OS param before pj_init()
964 pj_symbianos_params sym_params;
965 pj_bzero(&sym_params, sizeof(sym_params));
966 sym_params.rsocketserv = &sserver_;
967 sym_params.rconnection = &conn_;
968 pj_symbianos_set_params(&sym_params);
969
970 // Reinit pjsua
971 status = app_startup();
972 if (status != PJ_SUCCESS) {
973 pjsua_perror(THIS_FILE, "app_startup() error", status);
974 CActiveScheduler::Stop();
975 return;
976 }
977
978 PJ_LOG(3, (THIS_FILE, "PJSUA restarted."));
Benny Prijono9920dc32009-03-12 18:11:37 +0000979 PrintMainMenu();
Nanang Izzuddin90b83202009-03-02 15:48:45 +0000980 }
981
982 Start();
983 }
984
985 RConnection& conn_;
986 RSocketServ& sserver_;
987 TNifProgressBuf nif_progress_;
988};
989
Benny Prijonoba5926a2007-05-02 11:29:37 +0000990////////////////////////////////////////////////////////////////////////////
991int ua_main()
992{
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000993 RSocketServ aSocketServer;
994 RConnection aConn;
995 TInt err;
996 pj_symbianos_params sym_params;
Benny Prijonoc71ad432007-05-04 07:25:19 +0000997 pj_status_t status;
Nanang Izzuddin82f7a412008-12-17 11:36:22 +0000998
999 SelectIAP();
Benny Prijonoc71ad432007-05-04 07:25:19 +00001000
Benny Prijono70c5ba02007-12-31 11:27:35 +00001001 // Initialize RSocketServ
1002 if ((err=aSocketServer.Connect()) != KErrNone)
1003 return PJ_STATUS_FROM_OS(err);
1004
1005 // Open up a connection
1006 if ((err=aConn.Open(aSocketServer)) != KErrNone) {
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001007 aSocketServer.Close();
1008 return PJ_STATUS_FROM_OS(err);
Benny Prijono70c5ba02007-12-31 11:27:35 +00001009 }
1010
1011 if ((err=aConn.Start()) != KErrNone) {
1012 aSocketServer.Close();
1013 return PJ_STATUS_FROM_OS(err);
1014 }
1015
1016 // Set Symbian OS parameters in pjlib.
1017 // This must be done before pj_init() is called.
1018 pj_bzero(&sym_params, sizeof(sym_params));
1019 sym_params.rsocketserv = &aSocketServer;
1020 sym_params.rconnection = &aConn;
1021 pj_symbianos_set_params(&sym_params);
1022
Benny Prijonoc71ad432007-05-04 07:25:19 +00001023 // Initialize pjsua
1024 status = app_startup();
Benny Prijono70c5ba02007-12-31 11:27:35 +00001025 //status = test_addr();
1026 if (status != PJ_SUCCESS) {
1027 aConn.Close();
1028 aSocketServer.Close();
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001029 return status;
Benny Prijono70c5ba02007-12-31 11:27:35 +00001030 }
Benny Prijono897f9f82007-05-03 19:56:21 +00001031
Nanang Izzuddin90b83202009-03-02 15:48:45 +00001032
Benny Prijonoc71ad432007-05-04 07:25:19 +00001033 // Run the UI
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001034 ConsoleUI *con = new ConsoleUI(console);
Benny Prijonoc71ad432007-05-04 07:25:19 +00001035
1036 con->Run();
Nanang Izzuddin798bf452009-02-12 12:35:27 +00001037 PrintMainMenu();
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001038
Nanang Izzuddin90b83202009-03-02 15:48:45 +00001039 // Init & start connection monitor
1040 CConnMon *connmon = CConnMon::NewL(aConn, aSocketServer);
1041 connmon->Start();
1042
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001043 CActiveScheduler::Start();
Benny Prijonoc71ad432007-05-04 07:25:19 +00001044
Nanang Izzuddin90b83202009-03-02 15:48:45 +00001045 delete connmon;
Benny Prijonoc71ad432007-05-04 07:25:19 +00001046 delete con;
Benny Prijono684c0ad2008-01-03 18:50:27 +00001047
1048 // Dump memory statistics
1049 PJ_LOG(3,(THIS_FILE, "Max heap usage: %u.%03uMB",
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001050 pjsua_var.cp.peak_used_size / 1000000,
1051 (pjsua_var.cp.peak_used_size % 1000000)/1000));
Benny Prijonoc71ad432007-05-04 07:25:19 +00001052
Benny Prijono684c0ad2008-01-03 18:50:27 +00001053 // check max stack usage
1054#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
1055 pj_thread_t* this_thread = pj_thread_this();
1056 if (!this_thread)
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001057 return status;
Benny Prijono684c0ad2008-01-03 18:50:27 +00001058
1059 const char* max_stack_file;
1060 int max_stack_line;
1061 status = pj_thread_get_stack_info(this_thread, &max_stack_file, &max_stack_line);
1062
1063 PJ_LOG(3,(THIS_FILE, "Max stack usage: %u at %s:%d",
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001064 pj_thread_get_stack_max_usage(this_thread),
1065 max_stack_file, max_stack_line));
Benny Prijono684c0ad2008-01-03 18:50:27 +00001066#endif
1067
Benny Prijonoc71ad432007-05-04 07:25:19 +00001068 // Shutdown pjsua
1069 pjsua_destroy();
1070
Benny Prijono70c5ba02007-12-31 11:27:35 +00001071 // Close connection and socket server
1072 aConn.Close();
Nanang Izzuddin82f7a412008-12-17 11:36:22 +00001073 aSocketServer.Close();
Nanang Izzuddina940b362009-02-23 13:53:30 +00001074
Benny Prijono797e3382007-12-01 09:10:07 +00001075 return status;
Benny Prijonoba5926a2007-05-02 11:29:37 +00001076}
1077