📄 symbian_os.cpp
字号:
{ Thread_Stop(t, 0);}GF_EXPORTvoid gf_th_del(GF_Thread *t){ Thread_Stop(t, 0); free(t);}GF_EXPORTvoid gf_th_set_priority(GF_Thread *t, s32 priority){ /*FIXEME: tune priorities on symbian*/#if 0 if (priority > 200) t->threadH->SetPriority(EPriorityRealTime); else t->threadH->SetPriority(EPriorityNormal);#endif}GF_EXPORTu32 gf_th_status(GF_Thread *t){ if (!t) return 0; return t->status;}GF_EXPORTu32 gf_th_id(){ return RThread().Id();}/********************************************************************* OS-Specific Mutex Object**********************************************************************/struct __tag_mutex{ RMutex *hMutex; /* We filter recursive calls (1 thread calling Lock several times in a row only locks ONCE the mutex. Holder is the current ThreadID of the mutex holder*/ u32 Holder, HolderCount;};GF_EXPORTGF_Mutex *gf_mx_new(){ GF_Mutex *tmp = (GF_Mutex *)malloc(sizeof(GF_Mutex)); if (!tmp) return NULL; memset(tmp, 0, sizeof(GF_Mutex)); tmp->hMutex = new RMutex(); if( tmp->hMutex->CreateLocal() != KErrNone){ free(tmp); return NULL; } return tmp;}GF_EXPORTvoid gf_mx_del(GF_Mutex *mx){ mx->hMutex->Close(); free(mx);}GF_EXPORTvoid gf_mx_v(GF_Mutex *mx){ u32 caller; if (!mx) return; caller = gf_th_id(); /*only if we own*/ if (caller != mx->Holder) { GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Invalid mutex release - owner PID %d - caller PID %d\n", mx->Holder, caller)); return; } if (!mx->HolderCount) { GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Invalid mutex release - mutex not locked\n")); return; } mx->HolderCount -= 1; if (mx->HolderCount == 0) { mx->Holder = 0; mx->hMutex->Signal(); }}GF_EXPORTu32 gf_mx_p(GF_Mutex *mx){ u32 caller; if (!mx) return 0; caller = gf_th_id(); if (caller == mx->Holder) { mx->HolderCount += 1; return 1; } mx->hMutex->Wait(); mx->Holder = caller; mx->HolderCount = 1; return 1;}GF_EXPORTBool gf_mx_try_lock(GF_Mutex *mx){ u32 caller; if (!mx) return 0; caller = gf_th_id(); if (caller == mx->Holder) { mx->HolderCount += 1; return 1; } /*FIXME !! WE MUST HAVE tryLock*/ gf_mx_p(mx); return 1;}/********************************************************************* OS-Specific Semaphore Object**********************************************************************/struct __tag_semaphore{ RSemaphore *hSemaphore;};GF_EXPORTGF_Semaphore *gf_sema_new(u32 MaxCount, u32 InitCount){ GF_Semaphore *tmp = (GF_Semaphore *) malloc(sizeof(GF_Semaphore)); if (!tmp) return NULL; tmp->hSemaphore = new RSemaphore(); if (!tmp->hSemaphore) { free(tmp); return NULL; } TBuf<32> semaName; semaName.Format(_L("GPAC_SEM%d"), (u32) tmp); tmp->hSemaphore->CreateGlobal(semaName, InitCount); return tmp;}GF_EXPORTvoid gf_sema_del(GF_Semaphore *sm){ sm->hSemaphore->Close(); free(sm);}GF_EXPORTu32 gf_sema_notify(GF_Semaphore *sm, u32 NbRelease){ u32 prevCount; if (!sm) return 0; sm->hSemaphore->Signal(NbRelease);#ifdef __SERIES60_3X__ prevCount = 0;#else prevCount = sm->hSemaphore->Count();#endif return (u32) prevCount;}GF_EXPORTvoid gf_sema_wait(GF_Semaphore *sm){ sm->hSemaphore->Wait();}GF_EXPORTBool gf_sema_wait_for(GF_Semaphore *sm, u32 TimeOut){ return 0;}static u32 sys_init = 0;GF_SystemRTInfo the_rti;GF_EXPORTvoid gf_sys_init(){ if (!sys_init) { memset(&the_rti, 0, sizeof(GF_SystemRTInfo)); the_rti.pid = getpid(); sys_start_time = gf_sys_clock(); } sys_init += 1;}GF_EXPORTvoid gf_sys_close(){ if (sys_init > 0) { sys_init --; if (sys_init) return; }}#if GPAC_MEMORY_TRACKINGextern size_t gpac_allocated_memory;#endif/*CPU and Memory Usage*/GF_EXPORTBool gf_sys_get_rti(u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags){ TInt ram, ram_free; u32 now, time; TModuleMemoryInfo mi; TTimeIntervalMicroSeconds tims; RProcess cur_process; RThread cur_th; now = gf_sys_clock(); if (!rti->sampling_instant) { rti->sampling_instant = now; if (cur_th.GetCpuTime(tims) != KErrNone) { return 0; } rti->process_cpu_time = (u32) (tims.Int64() / 1000); return 0; } if (rti->sampling_instant + refresh_time_ms > now) return 0; rti->sampling_period_duration = now - rti->sampling_instant; rti->sampling_instant = now; if (cur_th.Process(cur_process) != KErrNone) { return 0; } if (cur_process.GetMemoryInfo(mi) != KErrNone) { return 0; } rti->process_memory = mi.iCodeSize + mi.iConstDataSize + mi.iInitialisedDataSize + mi.iUninitialisedDataSize; if (cur_th.GetCpuTime(tims) != KErrNone) { return 0; } time = (u32) (tims.Int64() / 1000); rti->process_cpu_time_diff = time - rti->process_cpu_time; rti->process_cpu_time = time; rti->process_cpu_usage = 100*rti->process_cpu_time_diff / rti->sampling_period_duration; if (rti->process_cpu_usage > 100) rti->process_cpu_usage = 100; HAL::Get(HALData::EMemoryRAM, ram); HAL::Get(HALData::EMemoryRAMFree, ram_free); rti->physical_memory = ram; rti->physical_memory_avail = ram_free;#if GPAC_MEMORY_TRACKING rti->gpac_memory = gpac_allocated_memory;#endif return 1;}GF_EXPORTBool gf_sys_get_battery_state(Bool *onBattery, u32 *state, u32*level) { return 1;}/*delete all interfaces loaded on object*/void gf_modules_free_module(ModuleInstance *inst){ void *objinterface; while (gf_list_count(inst->interfaces)) { objinterface = gf_list_get(inst->interfaces, 0); gf_list_rem(inst->interfaces, 0); inst->destroy_func(objinterface); } if (inst->lib_handle){ RLibrary* pLibrary = (RLibrary *) inst->lib_handle; pLibrary->Close(); } gf_list_del(inst->interfaces); free(inst);}Bool gf_modules_load_library(ModuleInstance *inst){ const TUid KGPACModuleUid={0x10000080}; char s_path[GF_MAX_PATH]; HBufC *path; TInt e; if (inst->lib_handle) return 1; sprintf(s_path, "%s%c%s", inst->plugman->dir, GF_PATH_SEPARATOR, inst->szName); path = HBufC::NewL( User::StringLength( ( TUint8* ) s_path) + 1 ); path->Des().Copy( TPtrC8(( TText8* ) s_path) ); RLibrary* pLibrary = new RLibrary(); e = pLibrary->Load(*path); delete path; if (e != KErrNone) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] Cannot load library %s: %d", s_path, e)); delete pLibrary; goto err_exit; } /*check UID 2 is GPAC's identifier*/ if (pLibrary->Type()[1] != KGPACModuleUid) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] Invalid library UID %x", (u32) pLibrary->Type()[1].iUid)); pLibrary->Close(); delete pLibrary; goto err_exit; } inst->query_func = (QueryInterface) pLibrary->Lookup(1); inst->load_func = (LoadInterface) pLibrary->Lookup(2); inst->destroy_func = (ShutdownInterface) pLibrary->Lookup(3); if ((inst->query_func==NULL) || (inst->load_func==NULL) || (inst->destroy_func==NULL) ) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] Library %s has invalid interfaces", inst->szName)); pLibrary->Close(); delete pLibrary; goto err_exit; } //store library handle inst->lib_handle = (void*) pLibrary; //GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Module %s loaded\n", inst->szName)); return 1;err_exit: gf_cfg_set_key(inst->plugman->cfg, "SymbianDLLs", inst->szName, "no"); return 0;}void gf_modules_unload_library(ModuleInstance *inst){ if (!inst->lib_handle || gf_list_count(inst->interfaces)) return; RLibrary* pLibrary = (RLibrary *) inst->lib_handle; pLibrary->Close(); delete pLibrary; inst->lib_handle = NULL; inst->load_func = NULL; inst->destroy_func = NULL; inst->query_func = NULL; //GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Module %s unloaded\n", inst->szName));}static Bool enum_modules(void *cbck, char *item_name, char *item_path){ ModuleInstance *inst; GF_ModuleManager *pm = (GF_ModuleManager *) cbck; if (strstr(item_name, "nposmozilla")) return 0; if (strncmp(item_name, "gm_", 3)) return 0; if (gf_module_is_loaded(pm, item_name) ) return 0; /*TODO FIXME: add module check for symbian */ GF_SAFEALLOC(inst, ModuleInstance); inst->interfaces = gf_list_new(); inst->plugman = pm; strcpy((char*)inst->szName, item_name); gf_list_add(pm->plug_list, inst); return 0;}/*refresh modules - note we don't check for deleted modules but since we've open them the OS should forbid delete*/GF_EXPORTu32 gf_modules_refresh(GF_ModuleManager *pm){ if (!pm) return 0; //!! symbian 9.1 doesn't allow for DLL browsing in /sys/bin, and can only load DLLs in /sys/bin !!#if 0 gf_enum_directory((char*)pm->dir, 0, enum_modules, pm, ".dll");#else u32 i, mod_count; mod_count = gf_cfg_get_key_count(pm->cfg, "SymbianDLLs"); for (i=0; i<mod_count; i++) { const char *mod = gf_cfg_get_key_name(pm->cfg, "SymbianDLLs", i); if (stricmp(gf_cfg_get_key(pm->cfg, "SymbianDLLs", mod), "yes")) continue; enum_modules(pm, (char*)mod, NULL); }#endif return gf_list_count(pm->plug_list);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -