From 3d8be0c891c4a3f8a931057b337a2af0a340aa3e Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 19 Feb 2012 12:43:15 +0100 Subject: [PATCH] Added: Tool logger and path macros. --HG-- branch : build_pipeline_v3 --- code/nel/src/misc/displayer.cpp | 1 + .../pipeline_service/database_status.cpp | 18 +-- .../pipeline_service/database_status.h | 9 +- .../pipeline_service/pipeline_service.cpp | 19 +++ .../pipeline_service/pipeline_service.h | 9 ++ .../pipeline/pipeline_service/tool_logger.cpp | 47 ++++++ .../pipeline/pipeline_service/tool_logger.h | 148 ++++++++++++++++++ 7 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 code/nel/tools/pipeline/pipeline_service/tool_logger.cpp create mode 100644 code/nel/tools/pipeline/pipeline_service/tool_logger.h diff --git a/code/nel/src/misc/displayer.cpp b/code/nel/src/misc/displayer.cpp index c50935b8f..49d806994 100644 --- a/code/nel/src/misc/displayer.cpp +++ b/code/nel/src/misc/displayer.cpp @@ -483,6 +483,7 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes if (_NeedHeader) { const char *hs = HeaderString(); + // TODO: I think strlen(hs), 1 should be swapped (might have influence on "t" usage). fwrite (hs, strlen (hs), 1, _FilePointer); _NeedHeader = false; } diff --git a/code/nel/tools/pipeline/pipeline_service/database_status.cpp b/code/nel/tools/pipeline/pipeline_service/database_status.cpp index 3bd28ee19..5e056ac61 100644 --- a/code/nel/tools/pipeline/pipeline_service/database_status.cpp +++ b/code/nel/tools/pipeline/pipeline_service/database_status.cpp @@ -130,9 +130,9 @@ CDatabaseStatus::~CDatabaseStatus() bool CDatabaseStatus::getFileStatus(CFileStatus &fileStatus, const std::string &filePath) const { bool seemsValid = false; - std::string stdPath = CPath::standardizePath(filePath, false); + std::string stdPath = unMacroPath(filePath); std::string statusPath = getStatusFilePath(filePath); - m_StatusMutex.enter(); + m_StatusMutex.enterReader(); if (CFile::fileExists(statusPath)) { CIFile ifs(statusPath, false); @@ -152,7 +152,7 @@ bool CDatabaseStatus::getFileStatus(CFileStatus &fileStatus, const std::string & fileStatus.LastUpdate = 0; fileStatus.CRC32 = 0; } - m_StatusMutex.leave(); + m_StatusMutex.leaveReader(); return seemsValid; } @@ -166,7 +166,7 @@ public: TFileStatusCallback Callback; std::string FilePath; // Standardized! - CMutex *StatusMutex; + CReaderWriter *StatusMutex; virtual void run() { @@ -177,7 +177,7 @@ public: uint32 time = CTime::getSecondsSince1970(); uint32 fmdt = CFile::getFileModificationDate(FilePath); std::string statusPath = getStatusFilePath(FilePath); // g_PipelineDirectory + PIPELINE_DATABASE_STATUS_SUBDIR + dropDatabaseDirectory(FilePath) + ".status"; - StatusMutex->enter(); + StatusMutex->enterReader(); if (CFile::fileExists(statusPath)) { CIFile ifs(statusPath, false); @@ -190,7 +190,7 @@ public: fs.LastChangedReference = 0; fs.LastFileSizeReference = ~0; } - StatusMutex->leave(); + StatusMutex->leaveReader(); if (fs.LastChangedReference == fmdt && fs.LastFileSizeReference == CFile::getFileSize(FilePath)) { nlinfo("Skipping already updated status, may have been queued twice (%s)", FilePath.c_str()); @@ -227,14 +227,14 @@ public: fs.LastFileSizeReference = fisz; } - StatusMutex->enter(); + StatusMutex->enterWriter(); { COFile ofs(statusPath, false, false, true); fs.serial(ofs); ofs.flush(); ofs.close(); } - StatusMutex->leave(); + StatusMutex->leaveWriter(); } Callback(FilePath, fs, true); } @@ -258,7 +258,7 @@ IRunnable *CDatabaseStatus::updateFileStatus(const TFileStatusCallback &callback CUpdateFileStatus *ufs = new CUpdateFileStatus(); ufs->StatusMutex = &m_StatusMutex; - ufs->FilePath = filePath; + ufs->FilePath = unMacroPath(filePath); ufs->Callback = callback; CAsyncFileManager::getInstance().addLoadTask(ufs); return ufs; diff --git a/code/nel/tools/pipeline/pipeline_service/database_status.h b/code/nel/tools/pipeline/pipeline_service/database_status.h index 7bd0b3ac0..d935c34c4 100644 --- a/code/nel/tools/pipeline/pipeline_service/database_status.h +++ b/code/nel/tools/pipeline/pipeline_service/database_status.h @@ -34,6 +34,7 @@ // NeL includes #include +#include #include // Project includes @@ -47,8 +48,14 @@ namespace PIPELINE { #define PIPELINE_DATABASE_STATUS_SUBDIR "database.status/" #define PIPELINE_DATABASE_ERRORS_SUBDIR "database.errors/" +#define PIPELINE_DATABASE_DEPEND_SUFFIX "database.depend/" #define PIPELINE_DATABASE_STATUS_SUFFIX ".status" #define PIPELINE_DATABASE_ERRORS_SUFFIX ".errors" +#define PIPELINE_DATABASE_DEPEND_SUFFIX ".depend" + +// Status is generated CRC32 for reference. +// Errors are errors caused by using this file as an input or output file. + struct CFileError { @@ -87,7 +94,7 @@ typedef CCallback #include #include +#include // Project includes #include "pipeline_workspace.h" @@ -61,6 +62,24 @@ std::string g_DatabaseDirectory; std::string g_PipelineDirectory; bool g_IsExiting = false; +std::string unMacroPath(const std::string &path) +{ + std::string result = path; + strFindReplace(result, PIPELINE_MACRO_DATABASE_DIRECTORY, g_DatabaseDirectory); + strFindReplace(result, PIPELINE_MACRO_PIPELINE_DIRECTORY, g_PipelineDirectory); + return CPath::standardizePath(result, false); +} + +std::string macroPath(const std::string &path) +{ + std::string result = CPath::standardizePath(path, false); + strFindReplace(result, g_DatabaseDirectory, PIPELINE_MACRO_DATABASE_DIRECTORY "/"); + strFindReplace(result, g_PipelineDirectory, PIPELINE_MACRO_PIPELINE_DIRECTORY "/"); + return result; +} + +// ****************************************************************** + namespace { #define PIPELINE_LONG_SERVICE_NAME "pipeline_service" diff --git a/code/nel/tools/pipeline/pipeline_service/pipeline_service.h b/code/nel/tools/pipeline/pipeline_service/pipeline_service.h index 0d4636aac..0223ff622 100644 --- a/code/nel/tools/pipeline/pipeline_service/pipeline_service.h +++ b/code/nel/tools/pipeline/pipeline_service/pipeline_service.h @@ -42,6 +42,15 @@ extern bool g_IsMaster; extern std::string g_DatabaseDirectory; extern std::string g_PipelineDirectory; +#define PIPELINE_MACRO_DATABASE_DIRECTORY "{{DatabaseDirectory}}" +#define PIPELINE_MACRO_PIPELINE_DIRECTORY "{{PipelineDirectory}}" + +/// Unmacros a path, and standardizes it as well. +std::string unMacroPath(const std::string &path); + +/// Macros a path, and standardizes it in advance. +std::string macroPath(const std::string &path); + extern bool g_IsExiting; } /* namespace PIPELINE */ diff --git a/code/nel/tools/pipeline/pipeline_service/tool_logger.cpp b/code/nel/tools/pipeline/pipeline_service/tool_logger.cpp new file mode 100644 index 000000000..271891b25 --- /dev/null +++ b/code/nel/tools/pipeline/pipeline_service/tool_logger.cpp @@ -0,0 +1,47 @@ +/** + * \file tool_logger.cpp + * \brief CToolLogger + * \date 2012-02-19 10:33GMT + * \author Jan Boon (Kaetemi) + * CToolLogger + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 2 of + * the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RYZOM CORE PIPELINE; see the file COPYING. If not, see + * . + */ + +#include +#include "tool_logger.h" + +// STL includes + +// NeL includes +// #include + +// Project includes + +using namespace std; +// using namespace NLMISC; + +namespace PIPELINE { + +void dummmmmmmyyyyyyyyyyyyyyyyy_tool_logger_cpp() { } + +} /* namespace PIPELINE */ + +/* end of file */ diff --git a/code/nel/tools/pipeline/pipeline_service/tool_logger.h b/code/nel/tools/pipeline/pipeline_service/tool_logger.h new file mode 100644 index 000000000..fae38d0c7 --- /dev/null +++ b/code/nel/tools/pipeline/pipeline_service/tool_logger.h @@ -0,0 +1,148 @@ +/** + * \file tool_logger.h + * \brief CToolLogger + * \date 2012-02-19 10:33GMT + * \author Jan Boon (Kaetemi) + * CToolLogger + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 2 of + * the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RYZOM CORE PIPELINE; see the file COPYING. If not, see + * . + */ + +#ifndef PIPELINE_TOOL_LOGGER_H +#define PIPELINE_TOOL_LOGGER_H +#include + +// STL includes +#include + +// NeL includes +#include + +// Project includes + +namespace PIPELINE { + +enum EError +{ + ERROR, + WARNING, + MESSAGE, +}; + +namespace { + +const std::string s_Error = "ERROR"; +const std::string s_Warning = "WARNING"; +const std::string s_Message = "MESSAGE"; + +const std::string s_ErrorHeader = "type\tfile\ttime\terror"; +const std::string s_DependHeader = "output_file\tinput_file"; + +} + +/** + * \brief CToolLogger + * \date 2012-02-19 10:33GMT + * \author Jan Boon (Kaetemi) + * CToolLogger + */ +class CToolLogger +{ +public: + FILE *m_ErrorLog; + FILE *m_DependLog; + + CToolLogger() + { + + } + + virtual ~CToolLogger() + { + releaseError(); + releaseDepend(); + } + + void initError(const std::string &errorLog) + { + releaseError(); + + m_ErrorLog = fopen(errorLog.c_str(), "wt"); + fwrite(s_ErrorHeader.c_str(), 1, s_ErrorHeader.length(), m_ErrorLog); + fwrite("\n", 1, 1, m_ErrorLog); + fflush(m_ErrorLog); + + } + + void initDepend(const std::string &dependLog) + { + releaseDepend(); + + m_DependLog = fopen(dependLog.c_str(), "wt"); + fwrite(s_DependHeader.c_str(), 1, s_DependHeader.length(), m_DependLog); + fwrite("\n", 1, 1, m_DependLog); + fflush(m_DependLog); + } + + void writeError(EError type, const std::string &file, const std::string &error) + { + if (m_ErrorLog) + { + // TODO_ERROR_LOG + } + } + + void writeDepend(const std::string &outputFile, const std::string &inputFile) + { + if (m_DependLog) + { + fwrite(outputFile.c_str(), 1, outputFile.length(), m_DependLog); + fwrite("\t", 1, 1, m_DependLog); + fwrite(inputFile.c_str(), 1, inputFile.length(), m_DependLog); + fwrite("\n", 1, 1, m_DependLog); + } + } + + void releaseError() + { + if (m_ErrorLog) + { + fflush(m_ErrorLog); + fclose(m_ErrorLog); + m_ErrorLog = NULL; + } + } + + void releaseDepend() + { + if (m_DependLog) + { + fflush(m_DependLog); + fclose(m_DependLog); + m_DependLog = NULL; + } + } +}; /* class CToolLogger */ + +} /* namespace PIPELINE */ + +#endif /* #ifndef PIPELINE_TOOL_LOGGER_H */ + +/* end of file */