Added: Tool logger and path macros.

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 13 years ago
parent ade48ff193
commit 3d8be0c891

@ -483,6 +483,7 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes
if (_NeedHeader) if (_NeedHeader)
{ {
const char *hs = HeaderString(); 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); fwrite (hs, strlen (hs), 1, _FilePointer);
_NeedHeader = false; _NeedHeader = false;
} }

@ -130,9 +130,9 @@ CDatabaseStatus::~CDatabaseStatus()
bool CDatabaseStatus::getFileStatus(CFileStatus &fileStatus, const std::string &filePath) const bool CDatabaseStatus::getFileStatus(CFileStatus &fileStatus, const std::string &filePath) const
{ {
bool seemsValid = false; bool seemsValid = false;
std::string stdPath = CPath::standardizePath(filePath, false); std::string stdPath = unMacroPath(filePath);
std::string statusPath = getStatusFilePath(filePath); std::string statusPath = getStatusFilePath(filePath);
m_StatusMutex.enter(); m_StatusMutex.enterReader();
if (CFile::fileExists(statusPath)) if (CFile::fileExists(statusPath))
{ {
CIFile ifs(statusPath, false); CIFile ifs(statusPath, false);
@ -152,7 +152,7 @@ bool CDatabaseStatus::getFileStatus(CFileStatus &fileStatus, const std::string &
fileStatus.LastUpdate = 0; fileStatus.LastUpdate = 0;
fileStatus.CRC32 = 0; fileStatus.CRC32 = 0;
} }
m_StatusMutex.leave(); m_StatusMutex.leaveReader();
return seemsValid; return seemsValid;
} }
@ -166,7 +166,7 @@ public:
TFileStatusCallback Callback; TFileStatusCallback Callback;
std::string FilePath; // Standardized! std::string FilePath; // Standardized!
CMutex *StatusMutex; CReaderWriter *StatusMutex;
virtual void run() virtual void run()
{ {
@ -177,7 +177,7 @@ public:
uint32 time = CTime::getSecondsSince1970(); uint32 time = CTime::getSecondsSince1970();
uint32 fmdt = CFile::getFileModificationDate(FilePath); uint32 fmdt = CFile::getFileModificationDate(FilePath);
std::string statusPath = getStatusFilePath(FilePath); // g_PipelineDirectory + PIPELINE_DATABASE_STATUS_SUBDIR + dropDatabaseDirectory(FilePath) + ".status"; std::string statusPath = getStatusFilePath(FilePath); // g_PipelineDirectory + PIPELINE_DATABASE_STATUS_SUBDIR + dropDatabaseDirectory(FilePath) + ".status";
StatusMutex->enter(); StatusMutex->enterReader();
if (CFile::fileExists(statusPath)) if (CFile::fileExists(statusPath))
{ {
CIFile ifs(statusPath, false); CIFile ifs(statusPath, false);
@ -190,7 +190,7 @@ public:
fs.LastChangedReference = 0; fs.LastChangedReference = 0;
fs.LastFileSizeReference = ~0; fs.LastFileSizeReference = ~0;
} }
StatusMutex->leave(); StatusMutex->leaveReader();
if (fs.LastChangedReference == fmdt && fs.LastFileSizeReference == CFile::getFileSize(FilePath)) if (fs.LastChangedReference == fmdt && fs.LastFileSizeReference == CFile::getFileSize(FilePath))
{ {
nlinfo("Skipping already updated status, may have been queued twice (%s)", FilePath.c_str()); nlinfo("Skipping already updated status, may have been queued twice (%s)", FilePath.c_str());
@ -227,14 +227,14 @@ public:
fs.LastFileSizeReference = fisz; fs.LastFileSizeReference = fisz;
} }
StatusMutex->enter(); StatusMutex->enterWriter();
{ {
COFile ofs(statusPath, false, false, true); COFile ofs(statusPath, false, false, true);
fs.serial(ofs); fs.serial(ofs);
ofs.flush(); ofs.flush();
ofs.close(); ofs.close();
} }
StatusMutex->leave(); StatusMutex->leaveWriter();
} }
Callback(FilePath, fs, true); Callback(FilePath, fs, true);
} }
@ -258,7 +258,7 @@ IRunnable *CDatabaseStatus::updateFileStatus(const TFileStatusCallback &callback
CUpdateFileStatus *ufs = new CUpdateFileStatus(); CUpdateFileStatus *ufs = new CUpdateFileStatus();
ufs->StatusMutex = &m_StatusMutex; ufs->StatusMutex = &m_StatusMutex;
ufs->FilePath = filePath; ufs->FilePath = unMacroPath(filePath);
ufs->Callback = callback; ufs->Callback = callback;
CAsyncFileManager::getInstance().addLoadTask(ufs); CAsyncFileManager::getInstance().addLoadTask(ufs);
return ufs; return ufs;

@ -34,6 +34,7 @@
// NeL includes // NeL includes
#include <nel/misc/mutex.h> #include <nel/misc/mutex.h>
#include <nel/misc/reader_writer.h>
#include <nel/misc/stream.h> #include <nel/misc/stream.h>
// Project includes // Project includes
@ -47,8 +48,14 @@ namespace PIPELINE {
#define PIPELINE_DATABASE_STATUS_SUBDIR "database.status/" #define PIPELINE_DATABASE_STATUS_SUBDIR "database.status/"
#define PIPELINE_DATABASE_ERRORS_SUBDIR "database.errors/" #define PIPELINE_DATABASE_ERRORS_SUBDIR "database.errors/"
#define PIPELINE_DATABASE_DEPEND_SUFFIX "database.depend/"
#define PIPELINE_DATABASE_STATUS_SUFFIX ".status" #define PIPELINE_DATABASE_STATUS_SUFFIX ".status"
#define PIPELINE_DATABASE_ERRORS_SUFFIX ".errors" #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 struct CFileError
{ {
@ -87,7 +94,7 @@ typedef CCallback<void, const std::string &/*filePath*/, const CFileStatus &/*fi
class CDatabaseStatus class CDatabaseStatus
{ {
protected: protected:
mutable NLMISC::CMutex m_StatusMutex; mutable NLMISC::CReaderWriter m_StatusMutex;
mutable NLMISC::CMutex m_ErrorMutex; mutable NLMISC::CMutex m_ErrorMutex;
public: public:

@ -44,6 +44,7 @@
#include <nel/misc/mutex.h> #include <nel/misc/mutex.h>
#include <nel/misc/task_manager.h> #include <nel/misc/task_manager.h>
#include <nel/misc/async_file_manager.h> #include <nel/misc/async_file_manager.h>
#include <nel/misc/algo.h>
// Project includes // Project includes
#include "pipeline_workspace.h" #include "pipeline_workspace.h"
@ -61,6 +62,24 @@ std::string g_DatabaseDirectory;
std::string g_PipelineDirectory; std::string g_PipelineDirectory;
bool g_IsExiting = false; 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 { namespace {
#define PIPELINE_LONG_SERVICE_NAME "pipeline_service" #define PIPELINE_LONG_SERVICE_NAME "pipeline_service"

@ -42,6 +42,15 @@ extern bool g_IsMaster;
extern std::string g_DatabaseDirectory; extern std::string g_DatabaseDirectory;
extern std::string g_PipelineDirectory; 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; extern bool g_IsExiting;
} /* namespace PIPELINE */ } /* namespace PIPELINE */

@ -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
* <http://www.gnu.org/licenses/>.
*/
#include <nel/misc/types_nl.h>
#include "tool_logger.h"
// STL includes
// NeL includes
// #include <nel/misc/debug.h>
// Project includes
using namespace std;
// using namespace NLMISC;
namespace PIPELINE {
void dummmmmmmyyyyyyyyyyyyyyyyy_tool_logger_cpp() { }
} /* namespace PIPELINE */
/* end of file */

@ -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
* <http://www.gnu.org/licenses/>.
*/
#ifndef PIPELINE_TOOL_LOGGER_H
#define PIPELINE_TOOL_LOGGER_H
#include <nel/misc/types_nl.h>
// STL includes
#include <string>
// NeL includes
#include <nel/misc/file.h>
// 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 */
Loading…
Cancel
Save