Ignore:
Timestamp:
Aug 13, 2014 9:14:53 AM (10 years ago)
Author:
nanang
Message:

Close #1779: Add APIs for external/native thread registration to pjsua2: Endpoint::libRegisterThread() & Endpoint::libIsThreadRegistered().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua2/endpoint.cpp

    r4847 r4887  
    2727using namespace std; 
    2828 
    29 #include <pjsua2/account.hpp> 
    30 #include <pjsua2/call.hpp> 
     29#include <pjsua-lib/pjsua_internal.h>   /* For retrieving pjsua threads */ 
    3130 
    3231#define THIS_FILE               "endpoint.cpp" 
     
    12181217    PJSUA2_CHECK_EXPR( pjsua_create() ); 
    12191218    mainThread = pj_thread_this(); 
     1219     
     1220    /* Register library main thread */ 
     1221    threadDescMap[pj_thread_this()] = NULL; 
    12201222} 
    12211223 
     
    12781280    /* Init! */ 
    12791281    PJSUA2_CHECK_EXPR( pjsua_init(&ua_cfg, &log_cfg, &med_cfg) ); 
     1282 
     1283    /* Register worker threads */ 
     1284    int i = pjsua_var.ua_cfg.thread_cnt; 
     1285    while (i) { 
     1286        pj_thread_t *t = pjsua_var.thread[--i]; 
     1287        if (t) 
     1288            threadDescMap[t] = NULL; 
     1289    } 
     1290 
     1291    /* Register media endpoint worker thread */ 
     1292    pjmedia_endpt *medept = pjsua_get_pjmedia_endpt(); 
     1293    i = pjmedia_endpt_get_thread_count(medept); 
     1294    while (i) { 
     1295        pj_thread_t *t = pjmedia_endpt_get_thread(medept, --i); 
     1296        if (t) 
     1297            threadDescMap[t] = NULL; 
     1298    } 
    12801299} 
    12811300 
     
    12851304} 
    12861305 
    1287 void Endpoint::libRegisterWorkerThread(const string &name) throw(Error) 
    1288 { 
    1289     PJSUA2_CHECK_EXPR(pjsua_register_worker_thread(name.c_str())); 
     1306void Endpoint::libRegisterThread(const string &name) throw(Error) 
     1307{ 
     1308    pj_thread_t *thread; 
     1309    pj_thread_desc *desc; 
     1310    pj_status_t status; 
     1311 
     1312    desc = (pj_thread_desc*)malloc(sizeof(pj_thread_desc)); 
     1313    status = pj_thread_register(name.c_str(), *desc, &thread); 
     1314    if (status == PJ_SUCCESS) { 
     1315        threadDescMap[thread] = desc; 
     1316    } else { 
     1317        free(desc); 
     1318        PJSUA2_RAISE_ERROR(status); 
     1319    } 
     1320} 
     1321 
     1322bool Endpoint::libIsThreadRegistered() 
     1323{ 
     1324    if (pj_thread_is_registered()) { 
     1325        /* Recheck again if it exists in the thread description map */ 
     1326        return (threadDescMap.find(pj_thread_this()) != threadDescMap.end()); 
     1327    } 
     1328 
     1329    return false; 
    12901330} 
    12911331 
     
    13151355    } 
    13161356#endif 
     1357 
     1358    /* Clean up thread descriptors */ 
     1359    std::map<pj_thread_t*, pj_thread_desc*>::iterator i; 
     1360    for (i = threadDescMap.begin(); i != threadDescMap.end(); ++i) { 
     1361        pj_thread_desc* d = (*i).second; 
     1362        if (d != NULL) 
     1363            free(d); 
     1364    } 
     1365    threadDescMap.clear(); 
    13171366 
    13181367    PJSUA2_CHECK_RAISE_ERROR(status); 
Note: See TracChangeset for help on using the changeset viewer.