Ignore:
Timestamp:
Feb 8, 2006 10:44:25 PM (18 years ago)
Author:
bennylp
Message:

Finished invite session UAS implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua/main.c

    r147 r160  
    1919#include "pjsua.h" 
    2020#include "getopt.h" 
    21  
    22  
    23 /* For debugging, disable threading. */ 
    24 //#define NO_WORKER_THREAD 
    25  
    26 #ifdef NO_WORKER_THREAD 
    27 #include <conio.h> 
    28 #endif 
     21#include <stdlib.h> 
     22 
    2923 
    3024#define THIS_FILE       "main.c" 
     
    6963    puts("Console keys:"); 
    7064    puts("  m    Make a call"); 
     65    puts("  a    Answer incoming call"); 
    7166    puts("  h    Hangup current call"); 
    7267    puts("  q    Quit"); 
     
    7570} 
    7671 
     72static pj_bool_t input(const char *title, char *buf, pj_size_t len) 
     73{ 
     74    char *p; 
     75 
     76    printf("%s (empty to cancel): ", title); fflush(stdout); 
     77    fgets(buf, len, stdin); 
     78 
     79    /* Remove trailing newlines. */ 
     80    for (p=buf; ; ++p) { 
     81        if (*p=='\r' || *p=='\n') *p='\0'; 
     82        else if (!*p) break; 
     83    } 
     84 
     85    if (!*buf) 
     86        return PJ_FALSE; 
     87     
     88    return PJ_TRUE; 
     89} 
     90 
    7791static void ui_console_main(void) 
    7892{ 
    79     char keyin[10]; 
    8093    char buf[128]; 
    81     char *p; 
    8294    pjsip_inv_session *inv; 
    8395 
     
    8698    for (;;) { 
    8799 
    88 #ifdef NO_WORKER_THREAD 
    89         pj_time_val timeout = { 0, 10 }; 
    90         pjsip_endpt_handle_events (pjsua.endpt, &timeout); 
    91  
    92         if (kbhit()) 
    93             fgets(keyin, sizeof(keyin), stdin); 
    94 #else 
    95100        ui_help(); 
    96         fgets(keyin, sizeof(keyin), stdin); 
    97 #endif 
    98  
    99         switch (keyin[0]) { 
     101        fgets(buf, sizeof(buf), stdin); 
     102 
     103        switch (buf[0]) { 
    100104 
    101105        case 'm': 
     
    107111 
    108112#if 1 
    109             printf("Enter URL to call: "); fflush(stdout); 
    110             fgets(buf, sizeof(buf), stdin); 
    111  
    112             if (buf[0]=='\r' || buf[0]=='\n') { 
    113                 /* Cancelled. */ 
    114                 puts("<cancelled>"); 
     113            /* Make call! : */ 
     114            if (!input("Enter URL to call", buf, sizeof(buf))) 
     115                continue; 
     116            pjsua_invite(buf, &inv); 
     117 
     118#else 
     119 
     120            pjsua_invite("sip:localhost:5061", &inv); 
     121#endif 
     122            break; 
     123 
     124 
     125        case 'a': 
     126 
     127            if (inv_session == NULL || inv_session->role != PJSIP_ROLE_UAS || 
     128                inv_session->state >= PJSIP_INV_STATE_CONNECTING)  
     129            { 
     130                puts("No pending incoming call"); 
    115131                fflush(stdout); 
    116132                continue; 
    117             } 
    118  
    119             /* Remove trailing newlines. */ 
    120             for (p=buf; ; ++p) { 
    121                 if (*p=='\r' || *p=='\n') *p='\0'; 
    122                 else if (!*p) break; 
    123             } 
    124             /* Make call! : */ 
    125  
    126             pjsua_invite(buf, &inv); 
    127  
    128 #else 
    129  
    130             pjsua_invite("sip:localhost:5061", &inv); 
    131 #endif 
    132             break; 
    133  
     133 
     134            } else { 
     135                pj_status_t status; 
     136                pjsip_tx_data *tdata; 
     137 
     138                if (!input("Answer with code (100-699)", buf, sizeof(buf))) 
     139                    continue; 
     140                 
     141                status = pjsip_inv_answer(inv_session, atoi(buf), NULL, NULL,  
     142                                          &tdata); 
     143                if (status == PJ_SUCCESS) 
     144                    status = pjsip_inv_send_msg(inv_session, tdata, NULL); 
     145 
     146                if (status != PJ_SUCCESS) 
     147                    pjsua_perror("Unable to create/send response", status); 
     148            } 
     149 
     150            break; 
    134151 
    135152        case 'h': 
     
    673690 
    674691 
    675 #ifdef NO_WORKER_THREAD 
    676     pjsua.thread_cnt = 0; 
    677 #endif 
    678  
    679  
    680692    /* Initialize pjsua (to create pool etc). 
    681693     */ 
Note: See TracChangeset for help on using the changeset viewer.