Changeset 1249


Ignore:
Timestamp:
May 4, 2007 7:25:19 AM (17 years ago)
Author:
bennylp
Message:

Added comments for Symbian sample

Location:
pjproject/trunk/pjsip-apps/src/symbian_ua
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/symbian_ua/main_symbian.cpp

    r1248 r1249  
    1 //Auto-generated file. Please do not modify. 
    2 //#include <e32cmn.h> 
    3  
    4 //#pragma data_seg(".SYMBIAN") 
    5 //__EMULATOR_IMAGE_HEADER2 (0x1000007a,0x00000000,0x00000000,EPriorityForeground,0x00000000u,0x00000000u,0x00000000,0x00000000,0x00000000,0) 
    6 //#pragma data_seg() 
    7  
     1/* $Id$ */ 
     2/*  
     3 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> 
     4 * 
     5 * This program is free software; you can redistribute it and/or modify 
     6 * it under the terms of the GNU General Public License as published by 
     7 * the Free Software Foundation; either version 2 of the License, or 
     8 * (at your option) any later version. 
     9 * 
     10 * This program is distributed in the hope that it will be useful, 
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13 * GNU General Public License for more details. 
     14 * 
     15 * You should have received a copy of the GNU General Public License 
     16 * along with this program; if not, write to the Free Software 
     17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 */ 
    819#include "ua.h" 
    9 #include <stdlib.h> 
    10 #include <pj/errno.h> 
    11 #include <pj/os.h> 
    12 #include <pj/log.h> 
    13 #include <pj/unicode.h> 
    14 #include <stdio.h> 
    1520 
    1621#include <e32std.h> 
    17  
    18 #include <pj/os.h> 
    19  
    2022#include <e32base.h> 
    2123#include <e32std.h> 
    22  
     24#include <stdlib.h> 
    2325 
    2426 
     
    2729 
    2830 
    29 ///////////////////////////////////// 
     31//////////////////////////////////////////////////////////////////////////// 
    3032class MyTask : public CActive 
    3133{ 
     
    8789void MyTask::DoCancel() 
    8890{ 
     91 
    8992} 
     93 
     94//////////////////////////////////////////////////////////////////////////// 
    9095 
    9196LOCAL_C void DoStartL() 
     
    116121//////////////////////////////////////////////////////////////////////////// 
    117122 
    118 //  Global Functions 
     123// E32Main() 
    119124GLDEF_C TInt E32Main() 
    120125{ 
     126    // Mark heap usage 
     127    __UHEAP_MARK; 
     128 
    121129    // Create cleanup stack 
    122     __UHEAP_MARK; 
    123130    CTrapCleanup* cleanup = CTrapCleanup::New(); 
    124131 
     
    131138 
    132139    console->Printf(_L("[press any key to close]\n")); 
    133     //console->Getch(); 
     140    console->Getch(); 
    134141     
    135142    delete console; 
    136143    delete cleanup; 
    137144 
    138     CloseSTDLIB();     
     145    CloseSTDLIB();  
     146 
     147    // Mark end of heap usage, detect memory leaks 
    139148    __UHEAP_MARKEND; 
    140149    return KErrNone; 
  • pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp

    r1248 r1249  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
    19  
    20 /** 
    21  * simple_pjsua.c 
    22  * 
    23  * This is a very simple but fully featured SIP user agent, with the  
    24  * following capabilities: 
    25  *  - SIP registration 
    26  *  - Making and receiving call 
    27  *  - Audio/media to sound device. 
    28  * 
    29  * Usage: 
    30  *  - To make outgoing call, start simple_pjsua with the URL of remote 
    31  *    destination to contact. 
    32  *    E.g.: 
    33  *       simpleua sip:user@remote 
    34  * 
    35  *  - Incoming calls will automatically be answered with 200. 
    36  * 
    37  * This program will quit once it has completed a single call. 
    38  */ 
    39  
    4019#include <pjsua-lib/pjsua.h> 
    4120#include <pjsua-lib/pjsua_internal.h> 
     
    4322 
    4423#define THIS_FILE       "symbian_ua.cpp" 
     24 
     25// 
     26// Basic config. 
     27// 
     28#define SIP_PORT        5060 
     29 
    4530 
    4631// 
     
    253238static void log_writer(int level, const char *buf, unsigned len) 
    254239{ 
    255     wchar_t buf16[PJ_LOG_MAX_SIZE]; 
     240    static wchar_t buf16[PJ_LOG_MAX_SIZE]; 
    256241 
    257242    PJ_UNUSED_ARG(level); 
     
    283268 
    284269    /* Init pjsua */ 
    285     { 
    286         pjsua_config cfg; 
    287         pjsua_logging_config log_cfg; 
    288         pjsua_media_config med_cfg; 
    289  
    290         pjsua_config_default(&cfg); 
    291         cfg.max_calls = 2; 
    292         cfg.thread_cnt = 0; // Disable threading on Symbian 
    293         cfg.cb.on_incoming_call = &on_incoming_call; 
    294         cfg.cb.on_call_media_state = &on_call_media_state; 
    295         cfg.cb.on_call_state = &on_call_state; 
    296         cfg.cb.on_buddy_state = &on_buddy_state; 
    297         cfg.cb.on_pager = &on_pager; 
    298         cfg.cb.on_typing = &on_typing; 
    299         cfg.cb.on_call_transfer_status = &on_call_transfer_status; 
    300         cfg.cb.on_call_replaced = &on_call_replaced; 
    301  
    302         if (SIP_PROXY) { 
    303                 cfg.outbound_proxy_cnt = 1; 
    304                 cfg.outbound_proxy[0] = pj_str(SIP_PROXY); 
    305         } 
    306          
    307         if (NAMESERVER) { 
    308                 cfg.nameserver_count = 1; 
    309                 cfg.nameserver[0] = pj_str(NAMESERVER); 
    310         } 
    311          
    312         if (NAMESERVER && STUN_DOMAIN) { 
    313                 cfg.stun_domain = pj_str(STUN_DOMAIN); 
    314         } else if (STUN_SERVER) { 
    315                 cfg.stun_host = pj_str(STUN_SERVER); 
    316         } 
    317          
    318          
    319         pjsua_logging_config_default(&log_cfg); 
    320         log_cfg.console_level = 4; 
    321         log_cfg.cb = &log_writer; 
    322  
    323         pjsua_media_config_default(&med_cfg); 
    324         med_cfg.thread_cnt = 0; // Disable threading on Symbian 
    325         med_cfg.has_ioqueue = PJ_FALSE; 
    326         med_cfg.clock_rate = 8000; 
    327         med_cfg.ec_tail_len = 0; 
    328         med_cfg.enable_ice = USE_ICE; 
    329          
    330         status = pjsua_init(&cfg, &log_cfg, &med_cfg); 
    331         if (status != PJ_SUCCESS) { 
    332                 pjsua_perror(THIS_FILE, "pjsua_init() error", status); 
    333                 pjsua_destroy(); 
    334                 return status; 
    335         } 
     270    pjsua_config cfg; 
     271    pjsua_logging_config log_cfg; 
     272    pjsua_media_config med_cfg; 
     273 
     274    pjsua_config_default(&cfg); 
     275    cfg.max_calls = 2; 
     276    cfg.thread_cnt = 0; // Disable threading on Symbian 
     277    cfg.cb.on_incoming_call = &on_incoming_call; 
     278    cfg.cb.on_call_media_state = &on_call_media_state; 
     279    cfg.cb.on_call_state = &on_call_state; 
     280    cfg.cb.on_buddy_state = &on_buddy_state; 
     281    cfg.cb.on_pager = &on_pager; 
     282    cfg.cb.on_typing = &on_typing; 
     283    cfg.cb.on_call_transfer_status = &on_call_transfer_status; 
     284    cfg.cb.on_call_replaced = &on_call_replaced; 
     285 
     286    if (SIP_PROXY) { 
     287            cfg.outbound_proxy_cnt = 1; 
     288            cfg.outbound_proxy[0] = pj_str(SIP_PROXY); 
     289    } 
     290     
     291    if (NAMESERVER) { 
     292            cfg.nameserver_count = 1; 
     293            cfg.nameserver[0] = pj_str(NAMESERVER); 
     294    } 
     295     
     296    if (NAMESERVER && STUN_DOMAIN) { 
     297            cfg.stun_domain = pj_str(STUN_DOMAIN); 
     298    } else if (STUN_SERVER) { 
     299            cfg.stun_host = pj_str(STUN_SERVER); 
     300    } 
     301     
     302     
     303    pjsua_logging_config_default(&log_cfg); 
     304    log_cfg.console_level = 4; 
     305    log_cfg.cb = &log_writer; 
     306 
     307    pjsua_media_config_default(&med_cfg); 
     308    med_cfg.thread_cnt = 0; // Disable threading on Symbian 
     309    med_cfg.has_ioqueue = PJ_FALSE; 
     310    med_cfg.clock_rate = 8000; 
     311    med_cfg.ec_tail_len = 0; 
     312    med_cfg.enable_ice = USE_ICE; 
     313     
     314    status = pjsua_init(&cfg, &log_cfg, &med_cfg); 
     315    if (status != PJ_SUCCESS) { 
     316            pjsua_perror(THIS_FILE, "pjsua_init() error", status); 
     317            pjsua_destroy(); 
     318            return status; 
    336319    } 
    337320 
    338321    /* Add UDP transport. */ 
    339     { 
    340         pjsua_transport_config cfg; 
    341         pjsua_transport_id tid; 
    342  
    343         pjsua_transport_config_default(&cfg); 
    344         cfg.port = 5060; 
    345         status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, &tid); 
    346         if (status != PJ_SUCCESS) { 
    347                 pjsua_perror(THIS_FILE, "Error creating transport", status); 
    348                 pjsua_destroy(); 
    349                 return status; 
    350         } 
    351          
    352         pjsua_acc_add_local(tid, PJ_TRUE, &g_acc_id); 
    353     } 
     322    pjsua_transport_config tcfg; 
     323    pjsua_transport_id tid; 
     324 
     325    pjsua_transport_config_default(&tcfg); 
     326    tcfg.port = SIP_PORT; 
     327    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &tcfg, &tid); 
     328    if (status != PJ_SUCCESS) { 
     329            pjsua_perror(THIS_FILE, "Error creating transport", status); 
     330            pjsua_destroy(); 
     331            return status; 
     332    } 
     333 
     334    /* Add account for the transport */ 
     335    pjsua_acc_add_local(tid, PJ_TRUE, &g_acc_id); 
     336 
    354337 
    355338    /* Initialization is done, now start pjsua */ 
     
    397380 
    398381//////////////////////////////////////////////////////////////////////////// 
     382/* 
     383 * The interractive console UI 
     384 */ 
    399385#include <e32base.h> 
    400386 
     
    402388{ 
    403389public: 
    404         ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con); 
    405      
    406         // Run console UI 
    407         void Run(); 
    408  
    409         // Stop 
    410         void Stop(); 
     390    ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con); 
     391 
     392    // Run console UI 
     393    void Run(); 
     394 
     395    // Stop 
     396    void Stop(); 
    411397     
    412398protected: 
    413         // Cancel asynchronous read. 
    414         void DoCancel(); 
    415  
    416         // Implementation: called when read has completed. 
    417         void RunL(); 
     399    // Cancel asynchronous read. 
     400    void DoCancel(); 
     401 
     402    // Implementation: called when read has completed. 
     403    void RunL(); 
    418404     
    419405private: 
    420         CActiveSchedulerWait *asw_; 
    421         CConsoleBase *con_; 
     406    CActiveSchedulerWait *asw_; 
     407    CConsoleBase *con_; 
    422408}; 
    423409 
     
    426412: CActive(EPriorityStandard), asw_(asw), con_(con) 
    427413{ 
    428         CActiveScheduler::Add(this); 
     414    CActiveScheduler::Add(this); 
    429415} 
    430416 
     
    432418void ConsoleUI::Run()  
    433419{ 
    434         con_->Read(iStatus); 
    435         SetActive(); 
     420    con_->Read(iStatus); 
     421    SetActive(); 
    436422} 
    437423 
     
    439425void ConsoleUI::Stop()  
    440426{ 
    441         DoCancel(); 
     427    DoCancel(); 
    442428} 
    443429 
     
    445431void ConsoleUI::DoCancel()  
    446432{ 
    447         con_->ReadCancel(); 
     433    con_->ReadCancel(); 
    448434} 
    449435 
    450436static void PrintMenu()  
    451437{ 
    452         PJ_LOG(3, (THIS_FILE, "\n\n" 
    453                 "Menu:\n" 
    454                 "  d    Dump states\n" 
    455                 "  D    Dump all states (detail)\n" 
    456                 "  P    Dump pool factory\n" 
    457                 "  m    Make call\n" 
    458                 "  a    Answer call\n" 
    459                 "  h    Hangup all calls\n" 
    460                 "  s    Subscribe to buddy presence\n" 
    461                 "  S    Unsubscribe buddy presence\n" 
    462                 "  o    Set account online\n" 
    463                 "  O    Set account offline\n" 
    464                 "  q    Quit\n")); 
     438    PJ_LOG(3, (THIS_FILE, "\n\n" 
     439            "Menu:\n" 
     440            "  d    Dump states\n" 
     441            "  D    Dump all states (detail)\n" 
     442            "  P    Dump pool factory\n" 
     443            "  m    Make call to " SIP_DST_URI "\n" 
     444            "  a    Answer call\n" 
     445            "  h    Hangup all calls\n" 
     446            "  s    Subscribe to " SIP_DST_URI "\n" 
     447            "  S    Unsubscribe presence\n" 
     448            "  o    Set account online\n" 
     449            "  O    Set account offline\n" 
     450            "  q    Quit\n")); 
    465451} 
    466452 
     
    468454void ConsoleUI::RunL()  
    469455{ 
    470         TKeyCode kc = con_->KeyCode(); 
    471         pj_bool_t reschedule = PJ_TRUE; 
    472          
    473         switch (kc) { 
    474         case 'q': 
    475                 asw_->AsyncStop(); 
    476                 reschedule = PJ_FALSE; 
    477                 break; 
    478         case 'D': 
    479         case 'd': 
    480                 pjsua_dump(kc == 'D'); 
    481                 break; 
    482         case 'P': 
    483                 pj_pool_factory_dump(&pjsua_var.cp.factory, PJ_TRUE); 
    484                 break; 
    485         case 'm': 
    486                 if (g_call_id != PJSUA_INVALID_ID) { 
    487                         PJ_LOG(3,(THIS_FILE, "Another call is active"));         
    488                         break; 
    489                 } 
    490          
    491                 if (pjsua_verify_sip_url(SIP_DST_URI) == PJ_SUCCESS) { 
    492                         pj_str_t dst = pj_str(SIP_DST_URI); 
    493                         pjsua_call_make_call(g_acc_id, &dst, 0, NULL, 
    494                                              NULL, &g_call_id); 
    495                 } else { 
    496                         PJ_LOG(3,(THIS_FILE, "Invalid SIP URI")); 
    497                 } 
    498                 break; 
    499         case 'a': 
    500                 if (g_call_id != PJSUA_INVALID_ID) 
    501                         pjsua_call_answer(g_call_id, 200, NULL, NULL); 
    502                 break; 
    503         case 'h': 
    504                 pjsua_call_hangup_all(); 
    505                 break; 
    506         case 's': 
    507         case 'S': 
    508                 if (g_buddy_id != PJSUA_INVALID_ID) 
    509                         pjsua_buddy_subscribe_pres(g_buddy_id, kc=='s'); 
    510                 break; 
    511         case 'o': 
    512         case 'O': 
    513                 pjsua_acc_set_online_status(g_acc_id, kc=='o'); 
    514                 break; 
    515         default: 
    516                 PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", 
    517                           kc, kc)); 
    518                 break; 
    519         } 
    520  
    521         PrintMenu(); 
    522          
    523         if (reschedule) 
    524                 Run(); 
     456    TKeyCode kc = con_->KeyCode(); 
     457    pj_bool_t reschedule = PJ_TRUE; 
     458     
     459    switch (kc) { 
     460    case 'q': 
     461            asw_->AsyncStop(); 
     462            reschedule = PJ_FALSE; 
     463            break; 
     464    case 'D': 
     465    case 'd': 
     466            pjsua_dump(kc == 'D'); 
     467            break; 
     468    case 'p': 
     469    case 'P': 
     470            pj_pool_factory_dump(&pjsua_var.cp.factory, PJ_TRUE); 
     471            break; 
     472    case 'm': 
     473            if (g_call_id != PJSUA_INVALID_ID) { 
     474                    PJ_LOG(3,(THIS_FILE, "Another call is active"));     
     475                    break; 
     476            } 
     477     
     478            if (pjsua_verify_sip_url(SIP_DST_URI) == PJ_SUCCESS) { 
     479                    pj_str_t dst = pj_str(SIP_DST_URI); 
     480                    pjsua_call_make_call(g_acc_id, &dst, 0, NULL, 
     481                                         NULL, &g_call_id); 
     482            } else { 
     483                    PJ_LOG(3,(THIS_FILE, "Invalid SIP URI")); 
     484            } 
     485            break; 
     486    case 'a': 
     487            if (g_call_id != PJSUA_INVALID_ID) 
     488                    pjsua_call_answer(g_call_id, 200, NULL, NULL); 
     489            break; 
     490    case 'h': 
     491            pjsua_call_hangup_all(); 
     492            break; 
     493    case 's': 
     494    case 'S': 
     495            if (g_buddy_id != PJSUA_INVALID_ID) 
     496                    pjsua_buddy_subscribe_pres(g_buddy_id, kc=='s'); 
     497            break; 
     498    case 'o': 
     499    case 'O': 
     500            pjsua_acc_set_online_status(g_acc_id, kc=='o'); 
     501            break; 
     502    default: 
     503            PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", 
     504                      kc, kc)); 
     505            break; 
     506    } 
     507 
     508    PrintMenu(); 
     509     
     510    if (reschedule) 
     511        Run(); 
    525512} 
    526513 
     
    529516int ua_main()  
    530517{ 
    531         pj_status_t status; 
    532          
    533         // Initialize pjsua 
    534         status  = app_startup(); 
    535         if (status != PJ_SUCCESS) 
    536                 return status; 
    537  
    538         // Run the UI 
    539         CActiveSchedulerWait *asw = new CActiveSchedulerWait; 
    540         ConsoleUI *con = new ConsoleUI(asw, console); 
    541          
    542         con->Run(); 
    543          
    544         PrintMenu(); 
    545         asw->Start(); 
    546          
    547         delete con; 
    548         delete asw; 
    549          
    550         // Shutdown pjsua 
    551         pjsua_destroy(); 
    552          
    553         return 0; 
    554 } 
    555  
     518    pj_status_t status; 
     519     
     520    // Initialize pjsua 
     521    status  = app_startup(); 
     522    if (status != PJ_SUCCESS) 
     523            return status; 
     524 
     525    // Run the UI 
     526    CActiveSchedulerWait *asw = new CActiveSchedulerWait; 
     527    ConsoleUI *con = new ConsoleUI(asw, console); 
     528     
     529    con->Run(); 
     530     
     531    PrintMenu(); 
     532    asw->Start(); 
     533     
     534    delete con; 
     535    delete asw; 
     536     
     537    // Shutdown pjsua 
     538    pjsua_destroy(); 
     539     
     540    return 0; 
     541} 
     542 
  • pjproject/trunk/pjsip-apps/src/symbian_ua/ua.h

    r1242 r1249  
    1 #include <e32cons.h>            // Console 
     1/* $Id$ */ 
     2/*  
     3 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> 
     4 * 
     5 * This program is free software; you can redistribute it and/or modify 
     6 * it under the terms of the GNU General Public License as published by 
     7 * the Free Software Foundation; either version 2 of the License, or 
     8 * (at your option) any later version. 
     9 * 
     10 * This program is distributed in the hope that it will be useful, 
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13 * GNU General Public License for more details. 
     14 * 
     15 * You should have received a copy of the GNU General Public License 
     16 * along with this program; if not, write to the Free Software 
     17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 */ 
     19#include <e32cons.h> 
    220 
    3 extern CConsoleBase* console;  // write all messages to this 
     21extern CConsoleBase* console; 
    422 
    523int ua_main(); 
Note: See TracChangeset for help on using the changeset viewer.