Ignore:
Timestamp:
Oct 24, 2006 5:13:30 PM (17 years ago)
Author:
bennylp
Message:

Bulk of PJLIB implementations on Symbian: exception framework, errno, OS core, Unicode, pool backend, log (to console), socket, address resolution, select, etc. IOQueue still doesn't work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/symbian/pjlib/src/pj/os_core_symbian.cpp

    r692 r788  
    1818 */ 
    1919 
    20 #include <e32cmn.h> 
    21 #include <e32std.h> 
    22  
    2320#include <pj/os.h> 
    2421#include <pj/assert.h> 
     
    3128#include <pj/errno.h> 
    3229 
     30#include "os_symbian.h" 
     31 
    3332 
    3433#define PJ_MAX_TLS          32 
    3534#define DUMMY_MUTEX         ((pj_mutex_t*)101) 
    3635#define DUMMY_SEMAPHORE     ((pj_sem_t*)102) 
    37  
    38  
     36#define THIS_FILE           "os_core_symbian.c" 
     37  
    3938/* 
    4039 * Note: 
     
    6160 
    6261 
     62 
     63///////////////////////////////////////////////////////////////////////////// 
     64// 
     65// CPjTimeoutTimer implementation 
     66// 
     67 
     68CPjTimeoutTimer::CPjTimeoutTimer() 
     69: CActive(EPriorityNormal), hasTimedOut_(false) 
     70{ 
     71} 
     72 
     73CPjTimeoutTimer::~CPjTimeoutTimer() 
     74{ 
     75    if (IsActive()) 
     76        Cancel(); 
     77    timer_.Close(); 
     78} 
     79 
     80void CPjTimeoutTimer::ConstructL() 
     81{ 
     82    timer_.CreateLocal(); 
     83    CActiveScheduler::Add(this); 
     84} 
     85 
     86CPjTimeoutTimer *CPjTimeoutTimer::NewL() 
     87{ 
     88    CPjTimeoutTimer *self = new (ELeave) CPjTimeoutTimer; 
     89    CleanupStack::PushL(self); 
     90 
     91    self->ConstructL(); 
     92 
     93    CleanupStack::Pop(self); 
     94    return self; 
     95 
     96} 
     97 
     98void CPjTimeoutTimer::StartTimer(TUint miliSeconds) 
     99{ 
     100    if (IsActive()) 
     101        Cancel(); 
     102 
     103    hasTimedOut_ = false; 
     104    timer_.After(iStatus, miliSeconds * 1000); 
     105    SetActive(); 
     106} 
     107 
     108bool CPjTimeoutTimer::HasTimedOut() const 
     109{ 
     110    return hasTimedOut_; 
     111} 
     112 
     113void CPjTimeoutTimer::RunL() 
     114{ 
     115    hasTimedOut_ = true; 
     116} 
     117 
     118void CPjTimeoutTimer::DoCancel() 
     119{ 
     120    timer_.Cancel(); 
     121} 
     122 
     123TInt CPjTimeoutTimer::RunError(TInt aError) 
     124{ 
     125    PJ_UNUSED_ARG(aError); 
     126    return KErrNone; 
     127} 
     128 
     129 
     130 
     131///////////////////////////////////////////////////////////////////////////// 
     132// 
     133// PjSymbianOS implementation 
     134// 
     135 
     136PjSymbianOS::PjSymbianOS() 
     137: isSocketServInitialized_(false), isResolverInitialized_(false), 
     138  console_(NULL), selectTimeoutTimer_(NULL) 
     139{ 
     140} 
     141 
     142// Get PjSymbianOS instance 
     143PjSymbianOS *PjSymbianOS::Instance() 
     144{ 
     145    static PjSymbianOS instance_; 
     146    return &instance_; 
     147} 
     148 
     149 
     150// Initialize 
     151TInt PjSymbianOS::Initialize() 
     152{ 
     153    TInt err; 
     154 
     155    selectTimeoutTimer_ = CPjTimeoutTimer::NewL(); 
     156 
     157#if 0 
     158    pj_assert(console_ == NULL); 
     159    TRAPD(err, console_ = Console::NewL(_L("PJLIB"),  
     160                                        TSize(KConsFullScreen,KConsFullScreen))); 
     161    return err; 
     162#endif 
     163 
     164    if (!isSocketServInitialized_) { 
     165        err = socketServ_.Connect(); 
     166        if (err != KErrNone) 
     167            goto on_error; 
     168 
     169        isSocketServInitialized_ = true; 
     170    } 
     171 
     172    if (!isResolverInitialized_) { 
     173        err = hostResolver_.Open(SocketServ(), KAfInet, KSockStream); 
     174        if (err != KErrNone) 
     175            goto on_error; 
     176 
     177        isResolverInitialized_ = true; 
     178    } 
     179 
     180    return KErrNone; 
     181 
     182on_error: 
     183    Shutdown(); 
     184    return err; 
     185} 
     186 
     187// Shutdown 
     188void PjSymbianOS::Shutdown() 
     189{ 
     190    if (isResolverInitialized_) { 
     191        hostResolver_.Close(); 
     192        isResolverInitialized_ = false; 
     193    } 
     194 
     195    if (isSocketServInitialized_) { 
     196        socketServ_.Close(); 
     197        isSocketServInitialized_ = false; 
     198    } 
     199 
     200    if (console_) { 
     201        delete console_; 
     202        console_ = NULL; 
     203    } 
     204 
     205    if (selectTimeoutTimer_) { 
     206        delete selectTimeoutTimer_; 
     207        selectTimeoutTimer_ = NULL; 
     208    } 
     209} 
     210 
     211// Convert to Unicode 
     212TInt PjSymbianOS::ConvertToUnicode(TDes16 &aUnicode, const TDesC8 &aForeign) 
     213{ 
     214#if 0 
     215    pj_assert(conv_ != NULL); 
     216    return conv_->ConvertToUnicode(aUnicode, aForeign, convToUnicodeState_); 
     217#else 
     218    return CnvUtfConverter::ConvertToUnicodeFromUtf8(aUnicode, aForeign); 
     219#endif 
     220} 
     221 
     222// Convert from Unicode 
     223TInt PjSymbianOS::ConvertFromUnicode(TDes8 &aForeign, const TDesC16 &aUnicode) 
     224{ 
     225#if 0 
     226    pj_assert(conv_ != NULL); 
     227    return conv_->ConvertFromUnicode(aForeign, aUnicode, convToAnsiState_); 
     228#else 
     229    return CnvUtfConverter::ConvertFromUnicodeToUtf8(aForeign, aUnicode); 
     230#endif 
     231} 
     232 
     233 
     234///////////////////////////////////////////////////////////////////////////// 
     235// 
     236// PJLIB os.h implementation 
     237// 
     238 
    63239PJ_DEF(pj_uint32_t) pj_getpid(void) 
    64240{ 
     
    66242} 
    67243 
     244 
     245PJ_DECL(void) pj_shutdown(void); 
    68246 
    69247/* 
     
    74252{ 
    75253    pj_ansi_strcpy(main_thread.obj_name, "pjthread"); 
    76     return PJ_SUCCESS; 
     254 
     255    // Initialize PjSymbianOS instance 
     256    PjSymbianOS *os = PjSymbianOS::Instance(); 
     257 
     258    PJ_LOG(4,(THIS_FILE, "Initializing PJLIB for Symbian OS..")); 
     259 
     260    TInt err; 
     261    err = os->Initialize(); 
     262    if (err != KErrNone) 
     263        goto on_error; 
     264 
     265    PJ_LOG(5,(THIS_FILE, "PJLIB initialized.")); 
     266    return PJ_SUCCESS; 
     267 
     268on_error: 
     269    pj_shutdown(); 
     270    return PJ_RETURN_OS_ERROR(err); 
     271} 
     272 
     273 
     274PJ_DEF(void) pj_shutdown(void) 
     275{ 
     276    PjSymbianOS *os = PjSymbianOS::Instance(); 
     277    os->Shutdown(); 
     278} 
     279 
     280 
     281/* 
     282 * pj_thread_register(..) 
     283 */ 
     284PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name, 
     285                                         pj_thread_desc desc, 
     286                                         pj_thread_t **thread_ptr) 
     287{ 
     288    PJ_UNUSED_ARG(cstr_thread_name); 
     289    PJ_UNUSED_ARG(desc); 
     290    PJ_UNUSED_ARG(thread_ptr); 
     291    return PJ_EINVALIDOP; 
    77292} 
    78293 
     
    150365PJ_DEF(pj_status_t) pj_thread_sleep(unsigned msec) 
    151366{ 
    152     PJ_UNUSED_ARG(msec); 
    153  
    154     /* Not supported either */ 
    155     return PJ_EINVALIDOP; 
     367    User::After(msec*1000); 
     368    return PJ_SUCCESS; 
    156369} 
    157370 
Note: See TracChangeset for help on using the changeset viewer.