Changeset 1246 for pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp
- Timestamp:
- May 3, 2007 1:31:21 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp
r1245 r1246 45 45 46 46 // 47 // Destination URI (to make call, or to subscribe presence) 48 // 49 #define SIP_DST_URI "sip:192.168.0.70:5061" 50 51 // 47 52 // Account 48 53 // … … 59 64 60 65 66 // 67 // Globals 68 // 69 static pjsua_acc_id g_acc_id = PJSUA_INVALID_ID; 70 static pjsua_call_id g_call_id = PJSUA_INVALID_ID; 71 static pjsua_buddy_id g_buddy_id = PJSUA_INVALID_ID; 61 72 62 73 … … 70 81 PJ_UNUSED_ARG(rdata); 71 82 83 if (g_call_id != PJSUA_INVALID_ID) { 84 pjsua_call_answer(call_id, PJSIP_SC_BUSY_HERE, NULL, NULL); 85 return; 86 } 87 72 88 pjsua_call_get_info(call_id, &ci); 73 89 … … 76 92 ci.remote_info.ptr)); 77 93 94 g_call_id = call_id; 95 78 96 /* Automatically answer incoming calls with 200/OK */ 79 97 pjsua_call_answer(call_id, 200, NULL, NULL); … … 88 106 89 107 pjsua_call_get_info(call_id, &ci); 108 109 if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { 110 if (call_id == g_call_id) 111 g_call_id = PJSUA_INVALID_ID; 112 } else { 113 if (g_call_id == PJSUA_INVALID_ID) 114 g_call_id = call_id; 115 } 116 90 117 PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, 91 118 (int)ci.state_text.slen, … … 108 135 109 136 137 /* Handler on buddy state changed. */ 138 static void on_buddy_state(pjsua_buddy_id buddy_id) 139 { 140 pjsua_buddy_info info; 141 pjsua_buddy_get_info(buddy_id, &info); 142 143 PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s", 144 (int)info.uri.slen, 145 info.uri.ptr, 146 (int)info.status_text.slen, 147 info.status_text.ptr)); 148 } 149 150 151 /* Incoming IM message (i.e. MESSAGE request)! */ 152 static void on_pager(pjsua_call_id call_id, const pj_str_t *from, 153 const pj_str_t *to, const pj_str_t *contact, 154 const pj_str_t *mime_type, const pj_str_t *text) 155 { 156 /* Note: call index may be -1 */ 157 PJ_UNUSED_ARG(call_id); 158 PJ_UNUSED_ARG(to); 159 PJ_UNUSED_ARG(contact); 160 PJ_UNUSED_ARG(mime_type); 161 162 PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s", 163 (int)from->slen, from->ptr, 164 (int)text->slen, text->ptr)); 165 } 166 167 168 /* Received typing indication */ 169 static void on_typing(pjsua_call_id call_id, const pj_str_t *from, 170 const pj_str_t *to, const pj_str_t *contact, 171 pj_bool_t is_typing) 172 { 173 PJ_UNUSED_ARG(call_id); 174 PJ_UNUSED_ARG(to); 175 PJ_UNUSED_ARG(contact); 176 177 PJ_LOG(3,(THIS_FILE, "IM indication: %.*s %s", 178 (int)from->slen, from->ptr, 179 (is_typing?"is typing..":"has stopped typing"))); 180 } 181 182 183 /* Call transfer request status. */ 184 static void on_call_transfer_status(pjsua_call_id call_id, 185 int status_code, 186 const pj_str_t *status_text, 187 pj_bool_t final, 188 pj_bool_t *p_cont) 189 { 190 PJ_LOG(3,(THIS_FILE, "Call %d: transfer status=%d (%.*s) %s", 191 call_id, status_code, 192 (int)status_text->slen, status_text->ptr, 193 (final ? "[final]" : ""))); 194 195 if (status_code/100 == 2) { 196 PJ_LOG(3,(THIS_FILE, 197 "Call %d: call transfered successfully, disconnecting call", 198 call_id)); 199 pjsua_call_hangup(call_id, PJSIP_SC_GONE, NULL, NULL); 200 *p_cont = PJ_FALSE; 201 } 202 } 203 204 205 /* Notification that call is being replaced. */ 206 static void on_call_replaced(pjsua_call_id old_call_id, 207 pjsua_call_id new_call_id) 208 { 209 pjsua_call_info old_ci, new_ci; 210 211 pjsua_call_get_info(old_call_id, &old_ci); 212 pjsua_call_get_info(new_call_id, &new_ci); 213 214 PJ_LOG(3,(THIS_FILE, "Call %d with %.*s is being replaced by " 215 "call %d with %.*s", 216 old_call_id, 217 (int)old_ci.remote_info.slen, old_ci.remote_info.ptr, 218 new_call_id, 219 (int)new_ci.remote_info.slen, new_ci.remote_info.ptr)); 220 } 221 222 110 223 /* Logging callback */ 111 224 static void log_writer(int level, const char *buf, unsigned len) … … 126 239 * url may contain URL to call. 127 240 */ 128 static pj_status_t app_startup(char *url) 129 { 130 pjsua_acc_id acc_id = 0; 241 static pj_status_t app_startup() 242 { 131 243 pj_status_t status; 132 244 … … 139 251 pjsua_perror(THIS_FILE, "pjsua_create() error", status); 140 252 return status; 141 }142 143 /* If argument is specified, it's got to be a valid SIP URL */144 if (url) {145 status = pjsua_verify_sip_url(url);146 if (status != PJ_SUCCESS) {147 pjsua_perror(THIS_FILE, "Invalid URL", status);148 return status;149 }150 253 } 151 254 … … 162 265 cfg.cb.on_call_media_state = &on_call_media_state; 163 266 cfg.cb.on_call_state = &on_call_state; 267 cfg.cb.on_buddy_state = &on_buddy_state; 268 cfg.cb.on_pager = &on_pager; 269 cfg.cb.on_typing = &on_typing; 270 cfg.cb.on_call_transfer_status = &on_call_transfer_status; 271 cfg.cb.on_call_replaced = &on_call_replaced; 164 272 165 273 if (SIP_PROXY) { … … 200 308 } 201 309 202 pjsua_acc_add_local(tid, PJ_TRUE, & acc_id);310 pjsua_acc_add_local(tid, PJ_TRUE, &g_acc_id); 203 311 } 204 312 … … 225 333 cfg.cred_info[0].data = pj_str(SIP_PASSWD); 226 334 227 status = pjsua_acc_add(&cfg, PJ_TRUE, & acc_id);335 status = pjsua_acc_add(&cfg, PJ_TRUE, &g_acc_id); 228 336 if (status != PJ_SUCCESS) { 229 337 pjsua_perror(THIS_FILE, "Error adding account", status); … … 233 341 } 234 342 235 /* If URL is specified, make call to the URL. */ 236 if (url != NULL) { 237 pj_str_t uri = pj_str(url); 238 status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL); 239 if (status != PJ_SUCCESS) { 240 pjsua_perror(THIS_FILE, "Error making call", status); 241 pjsua_destroy(); 242 return status; 243 } 244 245 } 246 343 if (SIP_DST_URI) { 344 pjsua_buddy_config bcfg; 345 346 pjsua_buddy_config_default(&bcfg); 347 bcfg.uri = pj_str(SIP_DST_URI); 348 bcfg.subscribe = PJ_FALSE; 349 350 pjsua_buddy_add(&bcfg, &g_buddy_id); 351 } 247 352 return PJ_SUCCESS; 248 353 } … … 308 413 " D Dump all states (detail)\n" 309 414 " P Dump pool factory\n" 415 " m Make call\n" 416 " a Answer call\n" 310 417 " h Hangup all calls\n" 418 " s Subscribe to buddy presence\n" 419 " S Unsubscribe buddy presence\n" 420 " o Set account online\n" 421 " O Set account offline\n" 311 422 " q Quit\n")); 312 423 } … … 316 427 { 317 428 TKeyCode kc = con_->KeyCode(); 318 429 pj_bool_t reschedule = PJ_TRUE; 430 319 431 switch (kc) { 320 432 case 'q': 321 433 asw_->AsyncStop(); 434 reschedule = PJ_FALSE; 322 435 break; 323 436 case 'D': 324 437 case 'd': 325 438 pjsua_dump(kc == 'D'); 326 Run();327 439 break; 328 440 case 'P': 329 441 pj_pool_factory_dump(&pjsua_var.cp.factory, PJ_TRUE); 330 442 break; 443 case 'm': 444 if (g_call_id != PJSUA_INVALID_ID) { 445 PJ_LOG(3,(THIS_FILE, "Another call is active")); 446 break; 447 } 448 449 if (pjsua_verify_sip_url(SIP_DST_URI) == PJ_SUCCESS) { 450 pj_str_t dst = pj_str(SIP_DST_URI); 451 pjsua_call_make_call(g_acc_id, &dst, 0, NULL, 452 NULL, &g_call_id); 453 } else { 454 PJ_LOG(3,(THIS_FILE, "Invalid SIP URI")); 455 } 456 break; 457 case 'a': 458 if (g_call_id != PJSUA_INVALID_ID) 459 pjsua_call_answer(g_call_id, 200, NULL, NULL); 460 break; 331 461 case 'h': 332 462 pjsua_call_hangup_all(); 333 Run(); 463 break; 464 case 's': 465 case 'S': 466 if (g_buddy_id != PJSUA_INVALID_ID) 467 pjsua_buddy_subscribe_pres(g_buddy_id, kc=='s'); 468 break; 469 case 'o': 470 case 'O': 471 pjsua_acc_set_online_status(g_acc_id, kc=='o'); 334 472 break; 335 473 default: 336 474 PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", 337 475 kc, kc)); 476 break; 477 } 478 479 PrintMenu(); 480 481 if (reschedule) 338 482 Run(); 339 break;340 }341 342 PrintMenu();343 483 } 344 484 … … 349 489 350 490 // Initialize pjsua 351 status = app_startup( "sip:192.168.0.77");491 status = app_startup(); 352 492 if (status != PJ_SUCCESS) 353 493 return status;
Note: See TracChangeset
for help on using the changeset viewer.