bool Brewtarget::ensureDataFilesExist() { QString logFileName; bool success = true; logFile = new QFile(); // Log file logFile->setFileName(getUserDataDir() + "brewtarget_log.txt"); if( logFile->open(QFile::WriteOnly | QFile::Truncate) ) logStream = new QTextStream(logFile); else { // Put the log in a temporary directory. logFile->setFileName(QDir::tempPath() + "/brewtarget_log.txt"); if( logFile->open(QFile::WriteOnly | QFile::Truncate ) ) { logW(QString("Log is in a temporary directory: %1").arg(logFile->fileName()) ); logStream = new QTextStream(logFile); } else logW(QString("Could not create a log file.")); } return success; }
static void copyService(struct TGService * pSource,struct TGService **ppDes) { if(pSource == NULL) { logW(TAG,"didn't copy service cause by source empty! "); return; } struct TGService * pService=(struct TGService *)malloc(sizeof(struct TGService)); memset(pService,0,sizeof(struct TGService)); memcpy(pService,pSource,sizeof(struct TGService)); // copy name if(pSource->serviceName!=NULL) { int nameSize=strlen(pSource->serviceName); char * buf=(char *)malloc(nameSize); memset(buf,0,nameSize); memcpy(buf,pSource->serviceName,nameSize); pService->serviceName=buf; } else { pService->serviceName=NULL; } *ppDes=pService; }
bool ida_dict_compare(dict_t * dst, dict_t * src) { if ((dst == NULL) || (src == NULL)) { return dst == src; } if (dst->count != src->count) { logW("dict-compare: mismatching number of items"); return false; } return dict_foreach(src, ida_dict_compare_enum, dst) == 0; }
static void error(GpsError e, void *ctx) { logI(MODULE, "sentence dump: %.*s", ptr - sentence, sentence); switch (e) { case GPS_ERR_FRAME_ERROR: stats.errors.frameErrors++; logW(MODULE, "gps error: GPS_ERR_FRAME_ERROR. Unexpected " "character ´%c´ (0x%02x)", *(char *)ctx, *(un8 *)ctx); return; case GPS_ERR_CHECKSUM_ERROR: stats.errors.checksumErrors++; logW(MODULE, "gps error: GPS_ERR_CHECKSUM_ERROR. " "Checksum is %02x", *(un8 *)ctx); return; case GPS_ERR_BUFFER_OVERFLOW: stats.errors.bufferOverflows++; logW(MODULE, "gps error: GPS_ERR_BUFFER_OVERFLOW"); return; default: logW(MODULE, "gps error: unknown error"); } }
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"); } }
/* @note Interrupt context */ static void rxCallback(struct VeSerialPortS* port, un8 byte) { VE_UNUSED(port); if (++rxHead >= ARRAY_LENGTH(rxBuffer)) rxHead = 0; /* * note: the old data is thrown away in case of a buffer overflow, * to make sure there is enough space to sync again, and subsequent * characters are not dropped again directly. */ if (rxHead == rxTail) logW(MODULE, "rx buffer overflow"); rxBuffer[rxHead] = byte; veTodo(); }
int StrobeGlobalDriver::closekd_nolock() { if(mUsers<=0) { logW("closekd_nolock user<=0"); return 0; } if(mUsers == 1) { if (mStrobeHandle > 0) { logI("close flash driver kd=%d", mStrobeHandle); close(mStrobeHandle); } mStrobeHandle = -1; } android_atomic_dec(&mUsers); return 0; }
void setServiceCreateParametersByN(const char * name,const char * para) { if(name==NULL || *name=='\0') { return; } if(g_services!=NULL) { struct TGService ** ppHead=g_services; struct TGService * pS=NULL; while((pS=*ppHead++)!=NULL && pS->serviceName!=NULL) { if(strcmp(pS->serviceName,name)==0) { setServiceCreateParameters(pS,para); return; } } } logW(TAG," can not set parameters for service cause by service not found:%s",name); }
QString Brewtarget::getConfigDir(bool *success) { #if defined(Q_OS_LINUX) || defined(Q_OS_MAC) // Linux OS or Mac OS. QDir dir; QFileInfo fileInfo; char* xdg_config_home = getenv("XDG_CONFIG_HOME"); bool tmp; QFile::Permissions sevenFiveFive = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadGroup | QFile::ExeGroup | QFile::ReadOther | QFile::ExeOther; // First, try XDG_CONFIG_HOME. // If that variable doesn't exist, create ~/.config if (xdg_config_home) { dir = xdg_config_home; } else { // Creating config directory. dir = QDir::home(); if( !dir.exists(".config") ) { logW( QString("Config dir \"%1\" did not exist...").arg(dir.absolutePath() + "/.config") ); tmp = dir.mkdir(".config"); logW( QString( tmp ? "...created it." : "...could not create it.") ); if( !tmp ) { // Failure. if( success != 0 ) *success = false; return ""; } // chmod 755 ~/.config QFile::setPermissions( dir.absolutePath() + "/.config", sevenFiveFive ); } // CD to config directory. if( ! dir.cd(".config") ) { logE( QString("Could not CD to \"%1\".").arg(dir.absolutePath() + "/.config") ); if( success != 0 ) *success = false; return ""; } } // See if brewtarget dir exists. if( !dir.exists("brewtarget") ) { logW( QString("\"%1\" does not exist...creating.").arg(dir.absolutePath() + "/brewtarget") ); // Try to make brewtarget dir. if( ! dir.mkdir("brewtarget") ) { logE( QString("Could not create \"%1\"").arg(dir.absolutePath() + "/brewtarget") ); if( success != 0 ) *success = false; return ""; } // chmod 755 ~/.config/brewtarget QFile::setPermissions( dir.absolutePath() + "/brewtarget", sevenFiveFive ); } if( ! dir.cd("brewtarget") ) { logE(QString("Could not CD into \"%1\"").arg(dir.absolutePath() + "/brewtarget")); if( success != 0 ) *success = false; return ""; } if( success != 0 ) *success = true; return dir.absolutePath() + "/"; #elif defined(Q_OS_WIN) // Windows OS. QDir dir; // This is the bin/ directory. dir = QDir(qApp->applicationDirPath()); dir.cdUp(); // Now we should be in the base directory (i.e. Brewtarget-2.0.0/) dir.cd("data"); if( success != 0 ) *success = true; return dir.absolutePath() + "/"; #else # error "Unsupported OS" #endif }