xptiAutoLog::xptiAutoLog(xptiInterfaceInfoManager* mgr, nsILocalFile* logfile, PRBool append) : mMgr(nsnull), mOldFileDesc(nsnull) { MOZ_COUNT_CTOR(xptiAutoLog); if(mgr && logfile) { PRFileDesc* fd; if(NS_SUCCEEDED(logfile-> OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_APPEND | (append ? 0 : PR_TRUNCATE), 0666, &fd)) && fd) { #ifdef DEBUG m_DEBUG_FileDesc = fd; #endif mMgr = mgr; mOldFileDesc = mMgr->SetOpenLogFile(fd); if(append) PR_Seek(fd, 0, PR_SEEK_END); WriteTimestamp(fd, "++++ start logging "); } else { #ifdef DEBUG printf("xpti failed to open log file for writing\n"); #endif } } }
xptiAutoLog::~xptiAutoLog() { MOZ_COUNT_DTOR(xptiAutoLog); if(mMgr) { PRFileDesc* fd = mMgr->SetOpenLogFile(mOldFileDesc); NS_ASSERTION(fd == m_DEBUG_FileDesc, "bad unravel"); if(fd) { WriteTimestamp(fd, "---- end logging "); PR_Close(fd); } } }
/** * \brief Internal conversion function, uses already prepared blf library and output file * \param pBlfLib blf library with loaded input file * \param stream Output file stream * \return Result code * */ HRESULT CBlfLogConverter::WriteToLog(BLF::IBlfLibrary* pBlfLib, std::ofstream& stream) const { if(pBlfLib == NULL) { return E_INVALIDARG; } SYSTEMTIME startTime = pBlfLib->GetStartTime(); size_t objectsCount = pBlfLib->GetBlfObjectsCount(); if(objectsCount <= 0) { return ERR_PROTOCOL_NOT_SUPPORTED; } AddFunctionHeader(stream, startTime.wDay, startTime.wMonth, startTime.wYear, startTime.wHour, startTime.wMinute, startTime.wSecond); for(size_t i = 0; i < objectsCount; i++) { BLF::IBlfObject* object = pBlfLib->GetBlfObject(i); if(object == NULL) { continue; } if(object->GetKind() == BLF::bokCanMessage) { BLF::ICanMessage* canMessage = object->GetICanMessage(); // It is should be impossible, that object has CanMessage type, but return NULL for GetICanMessage() ASSERT(canMessage != NULL); if(canMessage == NULL) { continue; } WriteTimestamp(canMessage->GetTimestamp(), stream); if(canMessage->GetDirection()==BLF::mdRx) { stream << " Rx "; } else { stream << " Tx "; } stream << canMessage->GetChannelNo() << " "; // suppress extended message bit stream << std::hex << (canMessage->GetId() & 0x7FFFFFFF ) << " "; stream.setf(ios::uppercase); // checks extended bit if((canMessage->GetId() & 0x80000000) == 0) { stream << "s "; // Standard message } else { stream << "x "; // Extended message } stream << (int)canMessage->GetDLC(); for (int i = 0 ; (i < canMessage->GetDLC()) ; ++i) { stream << " "; if (canMessage->GetData()[i] <= 0xf) { stream << '0'; } stream << std::hex; stream << (int)canMessage->GetData()[i]; stream.setf(ios::uppercase); } stream << "\n"; } } stream << "***END DATE AND TIME ***\n"; // Everythere above \n is used, but here \r\n like in asc to log parser stream << "***[STOP LOGGING SESSION]***\r\n"; return S_OK; }