/** * @brief write cyc buffer is data to file * * @author hankejia * @date 2012-07-05 * @param[in] pthis the pointer point to the CCycBuffer. * @param[in] fd file is descriptor.the cyc buffer is data will write to this file * @param[in] iSize how many data in bytes from cyc buffer you want to write to the file * @param[in] pWriteBuffer the space alloc by caller,fuction will use this space to load the data,and write to file system, * if this param is NULL, function will alloc space by himself * @return T_S32 * @retval return >=0 the size of bytes write to file, < 0 failed */ static T_S32 WriteToFs( T_pVOID pthis, T_S32 fd, T_S32 iSize ) { CCycBuffer *this = ( CCycBuffer * )pthis; CycBuffer_handle * handle = (CycBuffer_handle *)this->handle; T_CHR * pBuffer = NULL; T_S32 iLineSize = 0, iLeavings = 0; Condition_Lock( handle->mWriteDataCon ); //need to flash all data if ( -1 == iSize ) { iSize = handle->mUseSize; } pBuffer = PopSingle( pthis, iSize ); if ( pBuffer == NULL ) { ResumeForceQuitState( pthis ); Condition_Unlock( handle->mWriteDataCon ); delay_loop( 0, 10000 ); // 10ms return 0; } iLeavings = iSize; while( iLeavings > 0 ) { iLineSize = ( handle->mCycBuffer + handle->mBufferSize ) - pBuffer; if ( iLineSize == 0 ) { pBuffer = handle->mCycBuffer; continue; } else if ( iLineSize > iLeavings ) { iLineSize = iLeavings; } if ( WriteComplete( fd, pBuffer, iLineSize ) < 0 ) { Condition_Unlock( handle->mWriteDataCon ); loge( "WriteToFs::WriteComplete error!\n" ); return -1; } pBuffer += iLineSize; iLeavings -= iLineSize; } Condition_Lock( handle->mDataCon ); handle->mRead = pBuffer; handle->mUseSize -= iSize; handle->mPopComplete = AK_TRUE; Condition_Unlock( handle->mDataCon ); Condition_Unlock( handle->mWriteDataCon ); //logi( "pop signal send!\n" ); Condition_Signal( &(handle->mDataCon) ); return iSize; }
// ========================================================================== // METHOD: Destructor // // DESIGN: // ========================================================================== EXPORT_C RDebugLog::~RDebugLog() { if( iLogFileHandler ) { // Error! This means that Open was called, but not Close. if( PrepareForWrite() ) { _LIT8( KDummyFuncName, "***" ); _LIT8( KErrorText, "DEBUG LOG NOT CLOSED!" ); iLogFileHandler->Write( iClassName8, KDummyFuncName, KErrorText ); WriteComplete(); } // end if Close(); } } // END Destructor