void SymbianLog::printMessage(const char* level, const char* msg, PLATFORM_VA_LIST argList) { iSemaphore.Wait(); StringBuffer currentTime = createCurrentTime(true); TInt err = file.Open(fsSession, iLogName, EFileWrite|EFileShareAny); TInt pos = 0; if (err == KErrNotFound) { // First time: file does not exist. Create it. err = file.Create(fsSession, iLogName, EFileWrite|EFileShareAny); if (err != KErrNone) { setErrorF(err, "SymbianLog: could not open log file (code %d)", err); goto finally; } StringBuffer header = createHeader(); RBuf8 data; data.Assign(stringBufferToNewBuf8(header)); file.Write(data); data.Close(); } else { err = file.Seek(ESeekEnd, pos); if (err != KErrNone) { setErrorF(err, "SymbianLog: seek error on log file (code %d)", err); goto finally; } } { // Write the data StringBuffer line, data; line.sprintf("%s -%s- %s", currentTime.c_str(), level, msg); data.vsprintf(line.c_str(), argList); data.append("\n"); RBuf8 buf; buf.Assign(stringBufferToNewBuf8(data)); file.Write(buf); buf.Close(); } finally: file.Close(); // we need closed file to operate on it if ( LogSize() > SYMBIAN_LOG_SIZE ){ // roll log file RollLogFile(); } iSemaphore.Signal(); }
QNdefMessage QNFCNdefUtility::CNdefMsg2QNdefMsgL( const CNdefMessage& msg ) { BEGIN QNdefMessage result; LOG("CNdefMessage size is "<<msg.SizeL()); HBufC8* newBuf = HBufC8::NewL(msg.SizeL()); RBuf8 buf; buf.Assign(newBuf); buf.CleanupClosePushL(); LOG("export msg to raw data"); msg.ExportRawDataL(buf,0); LOG("import raw data to msg"); QByteArray qtArray; qtArray.append(reinterpret_cast<const char*>(newBuf->Ptr()),newBuf->Size()); result = QNdefMessage::fromByteArray(qtArray); CleanupStack::PopAndDestroy(&buf); END return result; }
void SymbianLog::reset(const char* title) { iSemaphore.Wait(); TInt err = file.Replace(fsSession, iLogName, EFileWrite|EFileShareAny); if (err != KErrNone) { setErrorF(err, "SymbianLog: error resetting the log file (code %d)", err); return; } // Write the Header StringBuffer header = createHeader(title); RBuf8 buf; buf.Assign(stringBufferToNewBuf8(header)); file.Write(buf); buf.Close(); file.Close(); iSemaphore.Signal(); }
void SymbianLog::RollLogFile(void) { CFileMan* fileMan = CFileMan::NewL(fsSession); CleanupStack::PushL(fileMan); //copy the current file into the roll file, file must be open TInt err = KErrNone; err = file.Open(fsSession, iLogName, EFileWrite|EFileShareAny); if (err != KErrNone) { setErrorF(err, "SymbianLog: could not open log file (code %d)", err); } else { err = fileMan->Copy(file,iRollLogName,CFileMan::EOverWrite); } if (err != KErrNone) { setErrorF(err, "SymbianLog: copy error on roll log file (code %d)", err); } file.Close(); // reset the current file // we don't use reset() method because we don't want // nested semaphores err = KErrNone; err = file.Replace(fsSession, iLogName, EFileWrite|EFileShareAny); if (err != KErrNone) { setErrorF(err, "SymbianLog: error resetting the log file (code %d)", err); return; } // Write the Header StringBuffer header = createHeader(); RBuf8 buf; buf.Assign(stringBufferToNewBuf8(header)); file.Write(buf); buf.Close(); file.Close(); CleanupStack::PopAndDestroy(fileMan); }
SymbianLog::SymbianLog(bool resetLog, const char* path, const char* name) { TInt err = KErrNone; const char* p = (path)? path : SYMBIAN_LOG_PATH; const char* n = (name)? name : SYMBIAN_LOG_NAME; // assign all the paths and names StringBuffer logName(p); logName += n; iLogName.Assign(charToNewBuf(logName.c_str())); StringBuffer rollName(logName); rollName += ".0"; iRollLogName.Assign(charToNewBuf(rollName.c_str())); StringBuffer pathSb(p); iLogPathName.Assign(charToNewBuf(pathSb.c_str())); StringBuffer nameSb(n); iLogFileName.Assign(charToNewBuf(nameSb.c_str())); // try open log err = iSemaphore.OpenGlobal(KLogSemaphoreName); if (err == KErrNotFound) { // Create a semaphore, to avoid accessing the FileSystem at // the same time by different threads. // The semaphore is global, so that it could be used also by // other processes that (in future) will use this Log. err = iSemaphore.CreateGlobal(KLogSemaphoreName, 1); if (err != KErrNone) { setError(ERR_SEMAPHORE_CREATION, ERR_SEMAPHORE_CREATION_MSG); } } iSemaphore.Wait(); // Connect to the file server session. fsSession.Connect(); err = fsSession.ShareAuto(); if (err != KErrNone) { setErrorF(err, "SymbianLog error: unable to share RFs session (code %d)", err); return; } // ensure path exists! BaflUtils::EnsurePathExistsL(fsSession, iLogPathName); if (resetLog) { err = file.Replace(fsSession, iLogName, EFileWrite|EFileShareAny); if (err != KErrNone) { setErrorF(err, "SymbianLog: could not open the log file '%ls'", iLogName.Ptr()); return; } // Write the Header StringBuffer header = createHeader(); RBuf8 data; data.Assign(stringBufferToNewBuf8(header)); file.Write(data); data.Close(); file.Close(); } iSemaphore.Signal(); return; }