static void makeExtObj(std::ostream &fout, const std::vector<std::string> &externalfiles) { bool start = true; std::ostringstream libNames; std::string libName; for (unsigned int i = 0; i < externalfiles.size(); ++i) { if (start) { libName = getLibName(externalfiles[i]); fout << "ifndef " << libName << "\n"; fout << " " << libName << " = " << objfile(externalfiles[i]); libNames << "EXTOBJ += $(" << libName << ")\n"; start = false; } else { fout << std::string(14, ' ') << objfile(externalfiles[i]); } if (i+1 >= externalfiles.size() || libName != getLibName(externalfiles[i+1])) { // This was the last file for this library fout << "\nendif\n\n\n"; start = true; } else { // There are more files for this library fout << " \\\n"; } } fout << libNames.str(); }
/* determine if hybrid platform, then actually load the DSO. */ static PRStatus freebl_LoadDSO(void) { PRLibrary *handle; const char *name = getLibName(); if (!name) { /*PR_SetError(PR_LOAD_LIBRARY_ERROR,0); */ return PR_FAILURE; } handle = loader_LoadLibrary(name); if (handle) { void *address = dlsym(handle, "NSSLOW_GetVector"); if (address) { NSSLOWGetVectorFn *getVector = (NSSLOWGetVectorFn *)address; const NSSLOWVector *dsoVector = getVector(); if (dsoVector) { unsigned short dsoVersion = dsoVector->version; unsigned short myVersion = NSSLOW_VERSION; if (MSB(dsoVersion) == MSB(myVersion) && LSB(dsoVersion) >= LSB(myVersion) && dsoVector->length >= sizeof(NSSLOWVector)) { vector = dsoVector; libraryName = name; blLib = handle; return PR_SUCCESS; } } } (void)dlclose(handle); } return PR_FAILURE; }
const CHR *AudioIO::detectSourceType(const CHR *const fileName, const bool verbose) { if (verbose) { PRINT_NFO(TXT("------- Audio I/O -------")); } uint8_t type = AUDIO_LIB_NULL; const bool bStdIn = (STRCASECMP(fileName, TXT("-")) == 0); if (bStdIn || PATH_ISREG(fileName)) { if (FILE *const file = bStdIn ? stdin : FOPEN(fileName, TXT("rb"))) { if (FD_ISREG(FILENO(file))) { for (size_t i = 0; g_audioIO_mapping[i].id; ++i) { if (verbose) { PRINT2_NFO(TXT("Trying input module ") FMT_CHR TXT("..."), g_audioIO_mapping[i].name); } if (checkFileType(g_audioIO_mapping[i].checkFileType, file)) { type = g_audioIO_mapping[i].id; if (verbose) { PRINT_NFO(TXT("succeeded.")); } break; } } } if (!bStdIn) { fclose(file); } } } if (verbose) { if(type == AUDIO_LIB_NULL) { PRINT_NFO(TXT("No suitable input module found -> falling back to default!")); } PRINT_NFO(TXT("------- Audio I/O -------\n")); } return getLibName(type); }
/*============================================================================== * FUNCTION - OMX_GetHandle - * * DESCRIPTION: *============================================================================*/ OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(OMX_OUT OMX_HANDLETYPE *handle, OMX_IN OMX_STRING componentName, OMX_IN OMX_PTR appData, OMX_IN OMX_CALLBACKTYPE *callBacks) { OMX_ERRORTYPE rc = OMX_ErrorNone; OMX_COMPONENTTYPE *component_fns = NULL; char libName[BUFF_SIZE] = {0}; void *libHandle; void (*LINK_get_component_fns)(OMX_COMPONENTTYPE *component_fns); OMX_DBG_ERROR("%s: E\n", __func__); component_fns = (OMX_COMPONENTTYPE *)malloc(sizeof(OMX_COMPONENTTYPE)); if(!component_fns) return OMX_ErrorInsufficientResources; getLibName(componentName, libName); if (libName == NULL) { OMX_DBG_ERROR("%s:L#%d: Failed to get libName\n", __func__, __LINE__); return OMX_ErrorInvalidComponent; } libHandle = dlopen(libName, RTLD_NOW); if (!libHandle) { OMX_DBG_ERROR("%s:L#%d: Failed to dlopen %s: %s\n", __func__, __LINE__, libName, dlerror()); free(component_fns); return OMX_ErrorInvalidComponent; } OMX_DBG_ERROR("%s: dlopen for %s is successful.\n", __func__, libName); char *symbolName = "get_component_fns"; *(void **)&LINK_get_component_fns = dlsym(libHandle, symbolName); if (LINK_get_component_fns != NULL) { LINK_get_component_fns((OMX_COMPONENTTYPE *)component_fns); *handle = (OMX_HANDLETYPE *)component_fns; OMX_DBG_ERROR("here address is %p ", component_fns->GetParameter); } else { OMX_DBG_ERROR("%s:L#%d: Failed to find symbol %s dlerror=%s\n", __func__, __LINE__, symbolName, dlerror()); free(component_fns); return OMX_ErrorInvalidComponent; } local_fns = component_fns; local_libHandle = libHandle; component_fns->SetCallbacks(component_fns, callBacks, appData); OMX_DBG_ERROR("%s: dlopen for %s is successful.\n", __func__, libName); return rc; }
void loadService(const char * path) { if(path==NULL || strlen(path)==0) { logN(TAG ,LOG_LEVEL_WARNING," path is empty"); return; } logI(TAG," prepare to load service from library:%s",path); void * dlHandler=NULL; char * errmsg; #ifdef LINUX dlHandler=dlopen(path,RTLD_NOW); if(dlHandler==NULL) { errmsg=dlerror(); logN("SERVICE",LOG_LEVEL_WARNING," can not open library:%s %s",path,errmsg); return; } #elif WIN32 #endif struct TGService * pService=NULL; if(checkLib(dlHandler,&pService)==0) { logD(TAG,"check lib successfully"); //FIXME use system seportor char * pLibName=NULL; getLibName(path,&pLibName); if(pLibName==NULL) { pLibName=(char *)malloc(sizeof(5)); memset(pLibName,0,10); sprintf(pLibName,"%d",pService->sID); } pService->serviceName=pLibName; addService(pService); } else { logW(TAG,"check library error"); } }
/* determine if hybrid platform, then actually load the DSO. */ static PRStatus freebl_LoadDSO( void ) { PRLibrary * handle; const char * name = getLibName(); if (!name) { PR_SetError(PR_LOAD_LIBRARY_ERROR, 0); return PR_FAILURE; } handle = loader_LoadLibrary(name); if (handle) { PRFuncPtr address = PR_FindFunctionSymbol(handle, "FREEBL_GetVector"); PRStatus status; if (address) { FREEBLGetVectorFn * getVector = (FREEBLGetVectorFn *)address; const FREEBLVector * dsoVector = getVector(); if (dsoVector) { unsigned short dsoVersion = dsoVector->version; unsigned short myVersion = FREEBL_VERSION; if (MSB(dsoVersion) == MSB(myVersion) && LSB(dsoVersion) >= LSB(myVersion) && dsoVector->length >= sizeof(FREEBLVector)) { vector = dsoVector; libraryName = name; blLib = handle; return PR_SUCCESS; } } } status = PR_UnloadLibrary(handle); PORT_Assert(PR_SUCCESS == status); } return PR_FAILURE; }
void elog::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* _funcName, const char* _log) { // special callback mode: if (callbackUserLog != nullptr) { const char* libName = ""; if (_id >= 0) { libName = getList()[_id].first.c_str(); } g_lock.lock(); if (callbackUserLog != nullptr) { callbackUserLog(libName, elog::level(_level), _ligne, _funcName, _log); } g_lock.unlock(); return; } char handle[LENGHT_MAX_LOG] = ""; memset(handle, ' ', LENGHT_MAX_LOG); handle[0] = '\0'; char* pointer = handle; if(getColor() == true) { switch(_level) { default: // nothing to do ... break; case elog::level_critical: strcat(pointer, ETK_BASH_COLOR_BOLD_RED); break; case elog::level_error: strcat(pointer, ETK_BASH_COLOR_RED); break; case elog::level_warning: strcat(pointer, ETK_BASH_COLOR_MAGENTA); break; case elog::level_info: strcat(pointer, ETK_BASH_COLOR_CYAN); break; case elog::level_debug: strcat(pointer, ETK_BASH_COLOR_YELLOW); break; case elog::level_verbose: strcat(pointer, ETK_BASH_COLOR_WHITE); break; case elog::level_print: strcat(pointer, ETK_BASH_COLOR_WHITE); break; } pointer = handle+strlen(handle); } if(getTime() == true) { getDisplayTime(pointer); pointer = handle+strlen(handle); } #ifndef __TARGET_OS__Android switch(_level) { default: strcat(pointer, "[?] "); break; case elog::level_print: strcat(pointer, "[P] "); break; case elog::level_critical: strcat(pointer, "[C] "); break; case elog::level_error: strcat(pointer, "[E] "); break; case elog::level_warning: strcat(pointer, "[W] "); break; case elog::level_info: strcat(pointer, "[I] "); break; case elog::level_debug: strcat(pointer, "[D] "); break; case elog::level_verbose: strcat(pointer, "[V] "); break; } pointer = handle+strlen(handle); #endif if (getLibName() == true) { if (_id >= 0) { int32_t len = strlen(handle); strcat(pointer, getList()[_id].first.c_str()); pointer = handle+strlen(handle); while (strlen(handle) - len < getNameSizeLog()) { *pointer++ = ' '; *pointer = '\0'; } *pointer++ = '|'; *pointer++ = ' '; *pointer = '\0'; } } #ifdef ELOG_BUILD_ETHREAD if(getThreadId() == true) { // display thread ID uint32_t iddd = ethread::getId(); sprintf(pointer, "%3d", iddd); pointer = handle+strlen(handle); *pointer++ = ' '; *pointer++ = '|'; *pointer++ = ' '; *pointer = '\0'; } if(getThreadNameEnable() == true) { // display thread ID std::string name = ethread::getName(); if (name.size() >= getThreadSizeLog() ) { getThreadSizeLog() = name.size() + 1; } sprintf(pointer, "%s", name.c_str()); pointer = handle+strlen(handle); size_t nbSpaceToAdd = getThreadSizeLog()-name.size(); for (size_t iii=0; iii<nbSpaceToAdd; ++iii) { *pointer++ = ' '; *pointer = '\0'; } *pointer++ = '|'; *pointer++ = ' '; *pointer = '\0'; } #endif if(getLine() == true) { if (_ligne >= 0) { sprintf(pointer, "(l=%5d)", _ligne); pointer = handle+strlen(handle); *pointer++ = ' '; *pointer = '\0'; } } // TODO :Maybe optimize this one ... if(getFunction() == true) { int32_t len = strlen(handle); char tmpName[1024]; char *tmpPointer = tmpName; if (_funcName != nullptr) { // cleen for android : char* startPos = strchr((char*)_funcName, ' '); char* stopPos = strchr((char*)_funcName, '('); if (startPos != nullptr) { if (stopPos != nullptr) { char* startPos2 = strchr(startPos+1, ' '); while ( startPos2 != nullptr && startPos2 < stopPos) { startPos = startPos2; startPos2 = strchr(startPos+1, ' '); } if(uint64_t(stopPos) < uint64_t(startPos)) { snprintf(tmpPointer, std::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(_funcName)), "%s", _funcName); } else { snprintf(tmpPointer, std::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(startPos)), "%s", startPos+1); } } else { snprintf(tmpPointer, 1024, "%s", startPos); } } else { if (stopPos != nullptr) { snprintf(tmpPointer, std::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(_funcName)+1), "%s", _funcName); } else { snprintf(tmpPointer, 1024, "%s", _funcName); } } tmpPointer = tmpPointer+strlen(tmpPointer); } size_t lenFunc = strlen(tmpName); if (lenFunc >= getFunctionSizeLog()) { getFunctionSizeLog() = lenFunc+1; } size_t nbSpaceToAdd = getFunctionSizeLog() - lenFunc; for (size_t iii=0; iii<nbSpaceToAdd; ++iii) { *tmpPointer++ = ' '; *tmpPointer = '\0'; } *tmpPointer++ = '|'; *tmpPointer++ = ' '; *tmpPointer = '\0'; strcat(pointer, tmpName); pointer += strlen(tmpName); } if (strlen(_log) > LENGHT_MAX_LOG - strlen(handle)-20) { memcpy(pointer, _log, LENGHT_MAX_LOG - strlen(handle)-21); handle[1024-25] = ' '; handle[1024-24] = '.'; handle[1024-23] = '.'; handle[1024-22] = '.'; handle[1024-21] = '\0'; } else { strcat(pointer, _log); } pointer = handle+strlen(handle); if(getColor() == true) { strcat(pointer, ETK_BASH_COLOR_NORMAL); } g_lock.lock(); { FILE*& file = getLogFile(); // close file only if needed ... if (file != nullptr) { *pointer++ = '\n'; *pointer = '\0'; fprintf(file, handle); switch(_level) { default: break; case elog::level_critical: case elog::level_error: fflush(file); break; } // if we log in file, we have no need to log otherwise ... just "tail -f log.txt" g_lock.unlock(); return; } } #if defined(__TARGET_OS__Android) switch(_level) { default: __android_log_print(ANDROID_LOG_VERBOSE, "EWOL", "%s", handle); break; case elog::level_print: __android_log_print(ANDROID_LOG_INFO, "EWOL", "%s", handle); break; case elog::level_critical: __android_log_print(ANDROID_LOG_FATAL, "EWOL", "%s", handle); break; case elog::level_error: __android_log_print(ANDROID_LOG_ERROR, "EWOL", "%s", handle); break; case elog::level_warning: __android_log_print(ANDROID_LOG_WARN, "EWOL", "%s", handle); break; case elog::level_info: __android_log_print(ANDROID_LOG_INFO, "EWOL", "%s", handle); break; case elog::level_debug: __android_log_print(ANDROID_LOG_DEBUG, "EWOL", "%s", handle); break; case elog::level_verbose: __android_log_print(ANDROID_LOG_VERBOSE, "EWOL", "%s", handle); break; } #elif defined(__TARGET_OS__IOs) iosNSLog(handle); #else std::cout << handle << std::endl; #endif g_lock.unlock(); if (_level == level_critical) { std::this_thread::sleep_for(std::chrono::milliseconds(700)); displayBacktrace(true, 2); } // Display backtrace to facilitate the error problems if ( _level == level_error && getDisplayBackTrace() == true) { displayBacktrace(false, 2); } }
void elog::setLibName(bool _status) { getLibName() = _status; }