Ignore:
Timestamp:
Mar 2, 2009 3:50:12 PM (15 years ago)
Author:
nanang
Message:

Ticket #733:

  • Added new Symbian specific API in PJLIB, pj_symbianos_set_connection_status(), to let PJLIB knows the connection status.
  • Added connection status checks before Symbian socket operations.
  • Added loop limiter in Symbian busy_sleep() to avoid the possibility of infinite loop.
  • Added sample of connection monitor in Symbian sample application (ua.cpp).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.0/pjsip-apps/src/symbian_ua/ua.cpp

    r2394 r2482  
    442442public: 
    443443    ConsoleUI(CConsoleBase *con); 
     444    ~ConsoleUI(); 
    444445 
    445446    // Run console UI 
     
    467468} 
    468469 
     470ConsoleUI::~ConsoleUI()  
     471{ 
     472    Stop(); 
     473} 
     474 
    469475// Run console UI 
    470476void ConsoleUI::Run()  
     
    477483void ConsoleUI::Stop()  
    478484{ 
    479     DoCancel(); 
     485    Cancel(); 
    480486} 
    481487 
     
    731737 
    732738 
     739// Class CConnMon to monitor network connection (RConnection). Whenever 
     740// the connection is down, it will notify PJLIB and restart PJSUA-LIB. 
     741class CConnMon : public CActive { 
     742public: 
     743    static CConnMon* NewL(RConnection &conn, RSocketServ &sserver) { 
     744        CConnMon *self = new (ELeave) CConnMon(conn, sserver); 
     745        CleanupStack::PushL(self); 
     746        self->ConstructL(); 
     747        CleanupStack::Pop(self); 
     748        return self; 
     749    } 
     750     
     751    void Start() { 
     752        conn_.ProgressNotification(nif_progress_, iStatus); 
     753        SetActive(); 
     754    } 
     755     
     756    void Stop() { 
     757        Cancel(); 
     758    } 
     759     
     760    ~CConnMon() { Stop(); } 
     761     
     762private: 
     763    CConnMon(RConnection &conn, RSocketServ &sserver) :  
     764        CActive(EPriorityHigh),  
     765        conn_(conn),  
     766        sserver_(sserver) 
     767    { 
     768        CActiveScheduler::Add(this); 
     769    } 
     770     
     771    void ConstructL() {} 
     772 
     773    void DoCancel() { 
     774        conn_.CancelProgressNotification(); 
     775    } 
     776 
     777    void RunL() { 
     778        int stage = nif_progress_().iStage; 
     779         
     780        if (stage == KLinkLayerClosed) { 
     781            pj_status_t status; 
     782            TInt err; 
     783 
     784            // Tell pjlib that connection is down. 
     785            pj_symbianos_set_connection_status(PJ_FALSE); 
     786             
     787            PJ_LOG(3, (THIS_FILE, "RConnection closed, restarting PJSUA..")); 
     788             
     789            // Destroy pjsua 
     790            pjsua_destroy(); 
     791            PJ_LOG(3, (THIS_FILE, "PJSUA destroyed.")); 
     792 
     793            // Reopen the connection 
     794            err = conn_.Open(sserver_); 
     795            if (err == KErrNone) 
     796                err = conn_.Start(); 
     797            if (err != KErrNone) { 
     798                CActiveScheduler::Stop(); 
     799                return; 
     800            } 
     801 
     802            // Reinit Symbian OS param before pj_init() 
     803            pj_symbianos_params sym_params; 
     804            pj_bzero(&sym_params, sizeof(sym_params)); 
     805            sym_params.rsocketserv = &sserver_; 
     806            sym_params.rconnection = &conn_; 
     807            pj_symbianos_set_params(&sym_params); 
     808 
     809            // Reinit pjsua 
     810            status = app_startup(); 
     811            if (status != PJ_SUCCESS) { 
     812                pjsua_perror(THIS_FILE, "app_startup() error", status); 
     813                CActiveScheduler::Stop(); 
     814                return; 
     815            } 
     816             
     817            PJ_LOG(3, (THIS_FILE, "PJSUA restarted.")); 
     818            PrintMenu(); 
     819        } 
     820         
     821        Start(); 
     822    } 
     823     
     824    RConnection& conn_; 
     825    RSocketServ& sserver_; 
     826    TNifProgressBuf nif_progress_; 
     827}; 
     828 
    733829//////////////////////////////////////////////////////////////////////////// 
    734830int ua_main()  
     
    773869    } 
    774870 
     871     
    775872    // Run the UI 
    776873    ConsoleUI *con = new ConsoleUI(console); 
     
    779876    PrintMenu(); 
    780877 
     878    // Init & start connection monitor 
     879    CConnMon *connmon = CConnMon::NewL(aConn, aSocketServer); 
     880    connmon->Start(); 
     881 
    781882    CActiveScheduler::Start(); 
    782883     
     884    delete connmon; 
    783885    delete con; 
    784886 
Note: See TracChangeset for help on using the changeset viewer.