Changeset 236 for pjproject/trunk/pjsip/src/pjsua/main.c
- Timestamp:
- Feb 26, 2006 9:23:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua/main.c
r230 r236 24 24 25 25 /* Current dialog */ 26 static struct pjsua_inv_data *inv_session; 26 static int current_acc; 27 static int current_call = -1; 28 29 30 /* 31 * Find next call. 32 */ 33 static pj_bool_t find_next_call(void) 34 { 35 int i; 36 37 for (i=current_call+1; i<(int)pjsua.max_calls; ++i) { 38 if (pjsua.calls[i].inv != NULL) { 39 current_call = i; 40 return PJ_TRUE; 41 } 42 } 43 44 for (i=0; i<current_call; ++i) { 45 if (pjsua.calls[i].inv != NULL) { 46 current_call = i; 47 return PJ_TRUE; 48 } 49 } 50 51 current_call = -1; 52 return PJ_FALSE; 53 } 54 55 56 /* 57 * Find previous call. 58 */ 59 static pj_bool_t find_prev_call(void) 60 { 61 int i; 62 63 for (i=current_call-1; i>=0; --i) { 64 if (pjsua.calls[i].inv != NULL) { 65 current_call = i; 66 return PJ_TRUE; 67 } 68 } 69 70 for (i=pjsua.max_calls-1; i>current_call; --i) { 71 if (pjsua.calls[i].inv != NULL) { 72 current_call = i; 73 return PJ_TRUE; 74 } 75 } 76 77 current_call = -1; 78 return PJ_FALSE; 79 } 80 81 27 82 28 83 /* 29 84 * Notify UI when invite state has changed. 30 85 */ 31 void pjsua_ui_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e) 32 { 86 void pjsua_ui_inv_on_state_changed(int call_index, pjsip_event *e) 87 { 88 pjsua_call *call = &pjsua.calls[call_index]; 89 33 90 PJ_UNUSED_ARG(e); 34 91 35 PJ_LOG(3,(THIS_FILE, " INVITE sessionstate changed to %s",36 pjsua_inv_state_names[inv->state]));37 38 if (inv->state == PJSIP_INV_STATE_DISCONNECTED) { 39 if (inv == inv_session->inv) {40 inv_session = inv_session->next;41 if (inv_session == &pjsua.inv_list)42 inv_session = pjsua.inv_list.next;92 PJ_LOG(3,(THIS_FILE, "Call %d state changed to %s", 93 call_index, 94 pjsua_inv_state_names[call->inv->state])); 95 96 if (call->inv->state == PJSIP_INV_STATE_DISCONNECTED) { 97 call->inv = NULL; 98 if ((int)call->index == current_call) { 99 find_next_call(); 43 100 } 44 101 45 102 } else { 46 103 47 if ( inv_session == &pjsua.inv_list || inv_session == NULL)48 inv_session = inv->mod_data[pjsua.mod.id];104 if (call && current_call==-1) 105 current_call = call->index; 49 106 50 107 } … … 67 124 static void print_buddy_list(void) 68 125 { 69 unsignedi;126 int i; 70 127 71 128 puts("Buddy list:"); 72 //puts("-------------------------------------------------------------------------------"); 129 73 130 if (pjsua.buddy_cnt == 0) 74 131 puts(" -none-"); … … 94 151 } 95 152 153 96 154 /* 97 * Show a bit of help.98 */ 99 static void keystroke_help(void)155 * Print account status. 156 */ 157 static void print_acc_status(int acc_index) 100 158 { 101 159 char reg_status[128]; 102 160 103 if (pjsua. regc == NULL) {161 if (pjsua.acc[acc_index].regc == NULL) { 104 162 pj_ansi_strcpy(reg_status, " -not registered to server-"); 105 } else if (pjsua.regc_last_err != PJ_SUCCESS) { 106 pj_strerror(pjsua.regc_last_err, reg_status, sizeof(reg_status)); 107 } else if (pjsua.regc_last_code>=200 && pjsua.regc_last_code<=699) { 163 164 } else if (pjsua.acc[acc_index].reg_last_err != PJ_SUCCESS) { 165 pj_strerror(pjsua.acc[acc_index].reg_last_err, reg_status, sizeof(reg_status)); 166 167 } else if (pjsua.acc[acc_index].reg_last_code>=200 && 168 pjsua.acc[acc_index].reg_last_code<=699) { 108 169 109 170 pjsip_regc_info info; 110 171 111 pjsip_regc_get_info(pjsua. regc, &info);172 pjsip_regc_get_info(pjsua.acc[acc_index].regc, &info); 112 173 113 174 pj_snprintf(reg_status, sizeof(reg_status), 114 175 "%s (%.*s;expires=%d)", 115 pjsip_get_status_text(pjsua. regc_last_code)->ptr,176 pjsip_get_status_text(pjsua.acc[acc_index].reg_last_code)->ptr, 116 177 (int)info.client_uri.slen, 117 178 info.client_uri.ptr, … … 119 180 120 181 } else { 121 pj_sprintf(reg_status, "in progress (%d)", pjsua.regc_last_code); 122 } 123 124 printf(">>>>\nRegistration status: %s\n", reg_status); 125 printf("Online status: %s\n", 126 (pjsua.online_status ? "Online" : "Invisible")); 182 pj_sprintf(reg_status, "in progress (%d)", 183 pjsua.acc[acc_index].reg_last_code); 184 } 185 186 printf("[%2d] Registration status: %s\n", acc_index, reg_status); 187 printf(" Online status: %s\n", 188 (pjsua.acc[acc_index].online_status ? "Online" : "Invisible")); 189 } 190 191 /* 192 * Show a bit of help. 193 */ 194 static void keystroke_help(void) 195 { 196 int i; 197 198 printf(">>>>\n"); 199 200 for (i=0; i<pjsua.acc_cnt; ++i) 201 print_acc_status(i); 202 127 203 print_buddy_list(); 128 204 … … 135 211 puts("| h Hangup call | u Unsubscribe presence | ru Unregister |"); 136 212 puts("| ] Select next dialog | t ToGgle Online status | d Dump status |"); 137 puts("| [ Select previous dialog | | 213 puts("| [ Select previous dialog | | dc Dump config |"); 138 214 puts("| +--------------------------+-------------------+"); 139 215 puts("| H Hold call | Conference Command | |"); … … 263 339 { 264 340 unsigned i, count; 265 pjmedia_conf_port_info info[ 16];341 pjmedia_conf_port_info info[PJSUA_MAX_CALLS]; 266 342 267 343 printf("Conference ports:\n"); … … 270 346 pjmedia_conf_get_ports_info(pjsua.mconf, &count, info); 271 347 for (i=0; i<count; ++i) { 272 char txlist[ 80];273 unsignedj;348 char txlist[PJSUA_MAX_CALLS*4+10]; 349 int j; 274 350 pjmedia_conf_port_info *port_info = &info[i]; 275 351 276 352 txlist[0] = '\0'; 277 for (j=0; j<pjsua.max_ ports; ++j) {353 for (j=0; j<pjsua.max_calls+PJSUA_CONF_MORE_PORTS; ++j) { 278 354 char s[10]; 279 355 if (port_info->listener[j]) { … … 310 386 case 'm': 311 387 /* Make call! : */ 312 if (pj_list_size(&pjsua.inv_list)) 313 printf("(You have %d calls)\n", pj_list_size(&pjsua.inv_list)); 388 printf("(You currently have %d calls)\n", pjsua.call_cnt); 314 389 315 390 ui_input_url("Make call", buf, sizeof(buf), &result); … … 318 393 puts("You can't do that with make call!"); 319 394 else 320 pjsua_invite(pjsua.buddies[result.nb_result].uri.ptr, NULL); 395 pjsua_make_call( current_acc, 396 pjsua.buddies[result.nb_result].uri.ptr, 397 NULL); 321 398 } else if (result.uri_result) 322 pjsua_ invite(result.uri_result, NULL);399 pjsua_make_call( current_acc, result.uri_result, NULL); 323 400 324 401 break; … … 327 404 case 'a': 328 405 329 if ( inv_session == &pjsua.inv_list||330 inv_session->inv->role != PJSIP_ROLE_UAS ||331 inv_session->inv->state >= PJSIP_INV_STATE_CONNECTING)406 if (current_call == -1 || 407 pjsua.calls[current_call].inv->role != PJSIP_ROLE_UAS || 408 pjsua.calls[current_call].inv->state >= PJSIP_INV_STATE_CONNECTING) 332 409 { 333 410 puts("No pending incoming call"); … … 350 427 * keyboard input. 351 428 */ 352 if ( inv_session == &pjsua.inv_list) {429 if (current_call == -1) { 353 430 puts("Call has been disconnected"); 354 431 fflush(stdout); … … 356 433 } 357 434 358 status = pjsip_inv_answer(inv_session->inv, atoi(buf), 435 status = pjsip_inv_answer(pjsua.calls[current_call].inv, 436 atoi(buf), 359 437 NULL, NULL, &tdata); 360 438 if (status == PJ_SUCCESS) 361 status = pjsip_inv_send_msg(inv_session->inv, tdata, NULL); 439 status = pjsip_inv_send_msg(pjsua.calls[current_call].inv, 440 tdata, NULL); 362 441 363 442 if (status != PJ_SUCCESS) … … 371 450 case 'h': 372 451 373 if ( inv_session == &pjsua.inv_list) {452 if (current_call == -1) { 374 453 puts("No current call"); 375 454 fflush(stdout); … … 377 456 378 457 } else { 379 pjsua_ inv_hangup(inv_session, PJSIP_SC_DECLINE);458 pjsua_call_hangup(current_call, PJSIP_SC_DECLINE); 380 459 } 381 460 break; … … 387 466 */ 388 467 if (menuin[0] == ']') { 389 inv_session = inv_session->next; 390 if (inv_session == &pjsua.inv_list) 391 inv_session = pjsua.inv_list.next; 468 find_next_call(); 392 469 393 470 } else { 394 inv_session = inv_session->prev; 395 if (inv_session == &pjsua.inv_list) 396 inv_session = pjsua.inv_list.prev; 397 } 398 399 if (inv_session != &pjsua.inv_list) { 471 find_prev_call(); 472 } 473 474 if (current_call != -1) { 400 475 char url[PJSIP_MAX_URL_SIZE]; 401 476 int len; 402 403 len = pjsip_uri_print(0, inv_session->inv->dlg->remote.info->uri, 404 url, sizeof(url)-1); 477 const pjsip_uri *u; 478 479 u = pjsua.calls[current_call].inv->dlg->remote.info->uri; 480 len = pjsip_uri_print(0, u, url, sizeof(url)-1); 405 481 if (len < 1) { 406 482 pj_ansi_strcpy(url, "<uri is too long>"); … … 420 496 * Hold call. 421 497 */ 422 if ( inv_session != &pjsua.inv_list) {498 if (current_call != -1) { 423 499 424 pjsua_ inv_set_hold(inv_session);500 pjsua_call_set_hold(current_call); 425 501 426 502 } else { … … 433 509 * Send re-INVITE (to release hold, etc). 434 510 */ 435 if ( inv_session != &pjsua.inv_list) {511 if (current_call != -1) { 436 512 437 pjsua_ inv_reinvite(inv_session);513 pjsua_call_reinvite(current_call); 438 514 439 515 } else { … … 446 522 * Transfer call. 447 523 */ 448 if ( inv_session == &pjsua.inv_list) {524 if (current_call == -1) { 449 525 450 526 PJ_LOG(3,(THIS_FILE, "No current call")); 451 527 452 528 } else { 453 struct pjsua_inv_data *cur = inv_session;529 int call = current_call; 454 530 455 531 ui_input_url("Transfer to URL", buf, sizeof(buf), &result); … … 457 533 /* Check if call is still there. */ 458 534 459 if (c ur != inv_session) {535 if (call != current_call) { 460 536 puts("Call has been disconnected"); 461 537 continue; … … 466 542 puts("You can't do that with transfer call!"); 467 543 else 468 pjsua_ inv_xfer_call( inv_session,469 544 pjsua_call_xfer( current_call, 545 pjsua.buddies[result.nb_result].uri.ptr); 470 546 471 547 } else if (result.uri_result) { 472 pjsua_ inv_xfer_call( inv_session, result.uri_result);548 pjsua_call_xfer( current_call, result.uri_result); 473 549 } 474 550 } … … 479 555 * Send DTMF strings. 480 556 */ 481 if ( inv_session == &pjsua.inv_list) {557 if (current_call == -1) { 482 558 483 559 PJ_LOG(3,(THIS_FILE, "No current call")); 484 560 485 } else if ( inv_session->session == NULL) {561 } else if (pjsua.calls[current_call].session == NULL) { 486 562 487 563 PJ_LOG(3,(THIS_FILE, "Media is not established yet!")); … … 489 565 } else { 490 566 pj_str_t digits; 491 struct pjsua_inv_data *cur = inv_session;567 int call = current_call; 492 568 pj_status_t status; 493 569 … … 498 574 } 499 575 500 if (c ur != inv_session) {576 if (call != current_call) { 501 577 puts("Call has been disconnected"); 502 578 continue; … … 504 580 505 581 digits = pj_str(buf); 506 status = pjmedia_session_dial_dtmf( inv_session->session, 0,582 status = pjmedia_session_dial_dtmf(pjsua.calls[current_call].session, 0, 507 583 &digits); 508 584 if (status != PJ_SUCCESS) { … … 522 598 if (result.nb_result != NO_NB) { 523 599 if (result.nb_result == -1) { 524 unsignedi;600 int i; 525 601 for (i=0; i<pjsua.buddy_cnt; ++i) 526 602 pjsua.buddies[i].monitor = (menuin[0]=='s'); … … 529 605 } 530 606 531 pjsua_pres_refresh( );607 pjsua_pres_refresh(current_acc); 532 608 533 609 } else if (result.uri_result) { … … 544 620 * Re-Register. 545 621 */ 546 pjsua_regc_update( PJ_TRUE);622 pjsua_regc_update(current_acc, PJ_TRUE); 547 623 break; 548 624 case 'u': … … 550 626 * Unregister 551 627 */ 552 pjsua_regc_update( PJ_FALSE);628 pjsua_regc_update(current_acc, PJ_FALSE); 553 629 break; 554 630 } … … 556 632 557 633 case 't': 558 pjsua.online_status = !pjsua.online_status; 559 pjsua_pres_refresh(); 634 pjsua.acc[current_acc].online_status = 635 !pjsua.acc[current_acc].online_status; 636 pjsua_pres_refresh(current_acc); 560 637 break; 561 638 … … 607 684 608 685 case 'd': 609 pjsua_dump(); 686 if (menuin[1] == 'c') { 687 char settings[2000]; 688 int len; 689 690 len = pjsua_dump_settings(settings, sizeof(settings)); 691 if (len < 1) 692 PJ_LOG(3,(THIS_FILE, "Error: not enough buffer")); 693 else 694 PJ_LOG(3,(THIS_FILE, 695 "Dumping configuration (%d bytes):\n%s\n", 696 len, settings)); 697 } else { 698 pjsua_dump(); 699 } 610 700 break; 611 701 … … 766 856 767 857 /* Init default settings. */ 768 769 858 pjsua_default(); 770 859 … … 772 861 /* Initialize pjsua (to create pool etc). 773 862 */ 774 775 863 if (pjsua_init() != PJ_SUCCESS) 776 864 return 1; … … 778 866 779 867 /* Parse command line arguments: */ 780 781 868 if (pjsua_parse_args(argc, argv) != PJ_SUCCESS) 782 869 return 1; … … 784 871 785 872 /* Init logging: */ 786 787 873 app_logging_init(); 788 874 … … 791 877 * messages. 792 878 */ 793 794 879 pjsip_endpt_register_module(pjsua.endpt, &console_msg_logger); 795 880 796 881 797 882 /* Start pjsua! */ 798 799 883 if (pjsua_start() != PJ_SUCCESS) { 800 884 … … 805 889 806 890 /* Sleep for a while, let any messages get printed to console: */ 807 808 891 pj_thread_sleep(500); 809 892 810 893 811 /* No current call initially: */812 813 inv_session = &pjsua.inv_list;814 815 816 894 /* Start UI console main loop: */ 817 818 895 ui_console_main(); 819 896 820 897 821 898 /* Destroy pjsua: */ 822 823 899 pjsua_destroy(); 824 900 825 901 826 902 /* Close logging: */ 827 828 903 app_logging_shutdown(); 829 904
Note: See TracChangeset
for help on using the changeset viewer.