Commit e2e0148a authored by David COME's avatar David COME
Browse files

Added back removed comments from previous implementation of cleanString

parent 754d0c84
...@@ -318,15 +318,19 @@ std::string castor::log::LoggerImplementation::buildSyslogHeader( ...@@ -318,15 +318,19 @@ std::string castor::log::LoggerImplementation::buildSyslogHeader(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string castor::log::LoggerImplementation::cleanString(const std::string &s, std::string castor::log::LoggerImplementation::cleanString(const std::string &s,
const bool replaceSpaces) throw() { const bool replaceSpaces) throw() {
size_t beginpos = s.find_first_not_of(' '); const std::string& spaces="\t\n\v\f\r ";
//find first non white char
size_t beginpos = s.find_first_not_of(spaces);
std::string::const_iterator it1; std::string::const_iterator it1;
if (std::string::npos != beginpos) if (std::string::npos != beginpos)
it1 = beginpos + s.begin(); it1 = beginpos + s.begin();
else else
it1 = s.begin(); it1 = s.begin();
//find last non white char
std::string::const_iterator it2; std::string::const_iterator it2;
size_t endpos = s.find_last_not_of(' '); size_t endpos = s.find_last_not_of(spaces);
if (std::string::npos != endpos) if (std::string::npos != endpos)
it2 = endpos + 1 + s.begin(); it2 = endpos + 1 + s.begin();
else else
...@@ -334,10 +338,12 @@ std::string castor::log::LoggerImplementation::cleanString(const std::string &s, ...@@ -334,10 +338,12 @@ std::string castor::log::LoggerImplementation::cleanString(const std::string &s,
std::string result(it1, it2); std::string result(it1, it2);
//if (s.begin() == it1 && it2 == s.end()) // if (s.begin() == it1 && it2 == s.end())
// result.clear(); // result="";
for (std::string::iterator it = result.begin(); it != result.end(); ++it) { for (std::string::iterator it = result.begin(); it != result.end(); ++it) {
// Replace newline and tab with a space
if (replaceSpaces) { if (replaceSpaces) {
if ('\t' == *it) if ('\t' == *it)
*it = ' '; *it = ' ';
...@@ -346,8 +352,11 @@ std::string castor::log::LoggerImplementation::cleanString(const std::string &s, ...@@ -346,8 +352,11 @@ std::string castor::log::LoggerImplementation::cleanString(const std::string &s,
*it = ' '; *it = ' ';
} }
// Replace spaces with underscore
if (' ' == *it) if (' ' == *it)
*it = '_'; *it = '_';
// Replace double quotes with single quotes
if ('"' == *it) if ('"' == *it)
*it = '\''; *it = '\'';
} }
......
...@@ -211,15 +211,19 @@ std::string castor::log::StringLogger::buildSyslogHeader( ...@@ -211,15 +211,19 @@ std::string castor::log::StringLogger::buildSyslogHeader(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string castor::log::StringLogger::cleanString(const std::string &s, std::string castor::log::StringLogger::cleanString(const std::string &s,
const bool replaceSpaces) throw() { const bool replaceSpaces) throw() {
size_t beginpos = s.find_first_not_of(' ');
//find first non white char
const std::string& spaces="\t\n\v\f\r ";
size_t beginpos = s.find_first_not_of(spaces);
std::string::const_iterator it1; std::string::const_iterator it1;
if (std::string::npos != beginpos) if (std::string::npos != beginpos)
it1 = beginpos + s.begin(); it1 = beginpos + s.begin();
else else
it1 = s.begin(); it1 = s.begin();
//find last non white char
std::string::const_iterator it2; std::string::const_iterator it2;
size_t endpos = s.find_last_not_of(' '); size_t endpos = s.find_last_not_of(spaces);
if (std::string::npos != endpos) if (std::string::npos != endpos)
it2 = endpos + 1 + s.begin(); it2 = endpos + 1 + s.begin();
else else
...@@ -227,10 +231,12 @@ std::string castor::log::StringLogger::cleanString(const std::string &s, ...@@ -227,10 +231,12 @@ std::string castor::log::StringLogger::cleanString(const std::string &s,
std::string result(it1, it2); std::string result(it1, it2);
//if (s.begin() == it1 && it2 == s.end()) // if (s.begin() == it1 && it2 == s.end())
// result.clear(); // result="";
for (std::string::iterator it = result.begin(); it != result.end(); ++it) { for (std::string::iterator it = result.begin(); it != result.end(); ++it) {
// Replace newline and tab with a space
if (replaceSpaces) { if (replaceSpaces) {
if ('\t' == *it) if ('\t' == *it)
*it = ' '; *it = ' ';
...@@ -239,8 +245,11 @@ std::string castor::log::StringLogger::cleanString(const std::string &s, ...@@ -239,8 +245,11 @@ std::string castor::log::StringLogger::cleanString(const std::string &s,
*it = ' '; *it = ' ';
} }
// Replace spaces with underscore
if (' ' == *it) if (' ' == *it)
*it = '_'; *it = '_';
// Replace double quotes with single quotes
if ('"' == *it) if ('"' == *it)
*it = '\''; *it = '\'';
} }
......
/****************************************************************************** /******************************************************************************
* DiskReadTask.hpp * DiskReadFileTask.hpp
* *
* This file is part of the Castor project. * This file is part of the Castor project.
* See http://castor.web.cern.ch/castor * See http://castor.web.cern.ch/castor
...@@ -24,20 +24,34 @@ ...@@ -24,20 +24,34 @@
#pragma once #pragma once
#include "castor/tape/tapeserver/daemon/Exception.hpp" #include "castor/tape/tapeserver/daemon/DiskReadTask.hpp"
#include "castor/tape/tapeserver/daemon/DataFifo.hpp"
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
namespace castor { namespace castor {
namespace tape { namespace tape {
namespace tapeserver { namespace tapeserver {
namespace daemon { namespace daemon {
class DiskReadTask { class DiskReadFileTask :public DiskReadTask {
public: public:
virtual bool endOfWork() = 0; DiskReadFileTask(DataConsumer & destination, int fileId, int nbBlocks): m_fileId(fileId),
m_nbBlocks(nbBlocks), m_fifo(destination) {}
/* Implementation of the DiskReadTask interface*/
virtual bool endOfWork() { return false; }
virtual void execute() { virtual void execute() {
throw MemException("Tring to execute a non-execuatble DiskReadTask"); for (int blockId=0; blockId < m_nbBlocks; blockId++) {
}; MemBlock * mb = m_fifo.getFreeBlock();
virtual ~DiskReadTask() {} mb->m_fileid = m_fileId;
mb->m_fileBlock = blockId;
m_fifo.pushDataBlock(mb);
}
}
private:
int m_fileId;
int m_nbBlocks;
DataConsumer & m_fifo;
}; };
}}}} }}}}
/****************************************************************************** /******************************************************************************
* DiskReadFileTask.hpp * DiskReadTask.hpp
* *
* This file is part of the Castor project. * This file is part of the Castor project.
* See http://castor.web.cern.ch/castor * See http://castor.web.cern.ch/castor
...@@ -24,34 +24,20 @@ ...@@ -24,34 +24,20 @@
#pragma once #pragma once
#include "castor/tape/tapeserver/daemon/DiskReadTask.hpp" #include "castor/tape/tapeserver/daemon/Exception.hpp"
#include "castor/tape/tapeserver/daemon/DataFifo.hpp"
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
namespace castor { namespace castor {
namespace tape { namespace tape {
namespace tapeserver { namespace tapeserver {
namespace daemon { namespace daemon {
class DiskReadFileTask :public DiskReadTask { class DiskReadTask {
public: public:
DiskReadFileTask(DataConsumer & destination, int fileId, int nbBlocks): m_fileId(fileId), virtual bool endOfWork() = 0;
m_nbBlocks(nbBlocks), m_fifo(destination) {}
/* Implementation of the DiskReadTask interface*/
virtual bool endOfWork() { return false; }
virtual void execute() { virtual void execute() {
for (int blockId=0; blockId < m_nbBlocks; blockId++) { throw MemException("Tring to execute a non-execuatble DiskReadTask");
MemBlock * mb = m_fifo.getFreeBlock(); };
mb->m_fileid = m_fileId; virtual ~DiskReadTask() {}
mb->m_fileBlock = blockId;
m_fifo.pushDataBlock(mb);
}
}
private:
int m_fileId;
int m_nbBlocks;
DataConsumer & m_fifo;
}; };
}}}} }}}}
/****************************************************************************** /******************************************************************************
* DiskWriteTask.hpp * DiskWriteFileTask.hpp
* *
* This file is part of the Castor project. * This file is part of the Castor project.
* See http://castor.web.cern.ch/castor * See http://castor.web.cern.ch/castor
...@@ -24,7 +24,10 @@ ...@@ -24,7 +24,10 @@
#pragma once #pragma once
#include "castor/tape/tapeserver/daemon/Exception.hpp" #include "castor/tape/tapeserver/daemon/DiskWriteTask.hpp"
#include "castor/tape/tapeserver/daemon/DataFifo.hpp"
#include "castor/tape/tapeserver/daemon/MemManager.hpp"
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
namespace castor { namespace castor {
namespace tape { namespace tape {
...@@ -32,43 +35,103 @@ namespace tapeserver { ...@@ -32,43 +35,103 @@ namespace tapeserver {
namespace daemon { namespace daemon {
/** /**
* Abstract class describing the interface for a task that wants to write to disk. * The DiskWriteFileTask is responsible to write a single file onto disk as part of a recall
* This is inherited exclusively by DiskWriteFileTask. * session. Being a consumer of memory blocks, it inherits from the DataConsumer class. It also
* inherits several methods from the DiskWriteTask (TODO: do we really need this base class?).
*/ */
class DiskWriteTask { class DiskWriteFileTask: public DiskWriteTask, public DataConsumer {
public: public:
/**
* Constructor
* @param fileId: file id of the file to write to disk
* @param blockCount: number of memory blocks that will be used
* @param mm: memory manager of the session
*/
DiskWriteFileTask(int fileId, int blockCount, MemoryManager& mm): m_fifo(blockCount),
m_blockCount(blockCount), m_fileId(fileId),
m_memManager(mm) { mm.addClient(&m_fifo); }
/** /**
* TODO: see comment on the same function in DiskWriteFileTask. * TODO: Do we need this here?
* @return always false
*/ */
virtual bool endOfWork() = 0; virtual bool endOfWork() { return false; }
/** /**
* @return the number of memory blocks to be used * Return the numebr of files to write to disk
* @return always 1
*/ */
virtual int blocks() { return 0; } virtual int files() { return 1; };
/** /**
* @return the number of files to write to disk * @return the number of memory blocks to be used
*/ */
virtual int files() { return 0; } virtual int blocks() { return m_blockCount; }
/** /**
* Main routine of the task * Main routine: takes each memory block in the fifo and writes it to disk
*/ */
virtual void execute() { virtual void execute() {
throw MemException("Trying to execute a non-executable DiskWriteTask"); int blockId = 0;
}; while(!m_fifo.finished()) {
//printf("+++ In disk write file, id=%d\n",m_fileId);
MemBlock *mb = m_fifo.popDataBlock();
mb->m_fileid = m_fileId;
mb->m_fileBlock = blockId++;
}
}
/**
* Allows client code to return a reusable memory block
* @return the pointer to the memory block that can be reused
*/
virtual MemBlock *getFreeBlock() { return m_fifo.getFreeBlock(); }
/**
* Function used to enqueue a new memory block holding data to be written to disk
* @param mb: corresponding memory block
*/
virtual void pushDataBlock(MemBlock *mb) {
castor::tape::threading::MutexLocker ml(&m_producerProtection);
m_fifo.pushDataBlock(mb);
}
/**
* Function used to wait until the end of the write
*/
virtual void waitCompletion() { volatile castor::tape::threading::MutexLocker ml(&m_producerProtection); }
/**
* Destructor (also waiting for the end of the write operation)
*/
virtual ~DiskWriteFileTask() { volatile castor::tape::threading::MutexLocker ml(&m_producerProtection); }
private:
/**
* The fifo containing the memory blocks holding data to be written to disk
*/
DataFifo m_fifo;
/**
* Number of blocks in the fifo
*/
int m_blockCount;
/**
* File id of the file that will be written to disk
*/
int m_fileId;
/** /**
* Wait for the end of the task * Reference to the Memory Manager in use
*/ */
virtual void waitCompletion() {}; MemoryManager & m_memManager;
/** /**
* Destructor * Mutex forcing serial access to the fifo
*/ */
virtual ~DiskWriteTask() {}; castor::tape::threading::Mutex m_producerProtection;
}; };
}}}} }}}}
/****************************************************************************** /******************************************************************************
* DiskWriteFileTask.hpp * DiskWriteTask.hpp
* *
* This file is part of the Castor project. * This file is part of the Castor project.
* See http://castor.web.cern.ch/castor * See http://castor.web.cern.ch/castor
...@@ -24,10 +24,7 @@ ...@@ -24,10 +24,7 @@
#pragma once #pragma once
#include "castor/tape/tapeserver/daemon/DiskWriteTask.hpp" #include "castor/tape/tapeserver/daemon/Exception.hpp"
#include "castor/tape/tapeserver/daemon/DataFifo.hpp"
#include "castor/tape/tapeserver/daemon/MemManager.hpp"
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
namespace castor { namespace castor {
namespace tape { namespace tape {
...@@ -35,103 +32,43 @@ namespace tapeserver { ...@@ -35,103 +32,43 @@ namespace tapeserver {
namespace daemon { namespace daemon {
/** /**
* The DiskWriteFileTask is responsible to write a single file onto disk as part of a recall * Abstract class describing the interface for a task that wants to write to disk.
* session. Being a consumer of memory blocks, it inherits from the DataConsumer class. It also * This is inherited exclusively by DiskWriteFileTask.
* inherits several methods from the DiskWriteTask (TODO: do we really need this base class?).
*/ */
class DiskWriteFileTask: public DiskWriteTask, public DataConsumer { class DiskWriteTask {
public: public:
/**
* Constructor
* @param fileId: file id of the file to write to disk
* @param blockCount: number of memory blocks that will be used
* @param mm: memory manager of the session
*/
DiskWriteFileTask(int fileId, int blockCount, MemoryManager& mm): m_fifo(blockCount),
m_blockCount(blockCount), m_fileId(fileId),
m_memManager(mm) { mm.addClient(&m_fifo); }
/** /**
* TODO: Do we need this here? * TODO: see comment on the same function in DiskWriteFileTask.
* @return always false
*/ */
virtual bool endOfWork() { return false; } virtual bool endOfWork() = 0;
/**
* Return the numebr of files to write to disk
* @return always 1
*/
virtual int files() { return 1; };
/** /**
* @return the number of memory blocks to be used * @return the number of memory blocks to be used
*/ */
virtual int blocks() { return m_blockCount; } virtual int blocks() { return 0; }
/**
* Main routine: takes each memory block in the fifo and writes it to disk
*/
virtual void execute() {
int blockId = 0;
while(!m_fifo.finished()) {
//printf("+++ In disk write file, id=%d\n",m_fileId);
MemBlock *mb = m_fifo.popDataBlock();
mb->m_fileid = m_fileId;
mb->m_fileBlock = blockId++;
}
}
/**
* Allows client code to return a reusable memory block
* @return the pointer to the memory block that can be reused
*/
virtual MemBlock *getFreeBlock() { return m_fifo.getFreeBlock(); }
/**
* Function used to enqueue a new memory block holding data to be written to disk
* @param mb: corresponding memory block
*/
virtual void pushDataBlock(MemBlock *mb) {
castor::tape::threading::MutexLocker ml(&m_producerProtection);
m_fifo.pushDataBlock(mb);
}
/** /**
* Function used to wait until the end of the write * @return the number of files to write to disk
*/ */
virtual void waitCompletion() { volatile castor::tape::threading::MutexLocker ml(&m_producerProtection); } virtual int files() { return 0; }
/** /**
* Destructor (also waiting for the end of the write operation) * Main routine of the task
*/ */
virtual ~DiskWriteFileTask() { volatile castor::tape::threading::MutexLocker ml(&m_producerProtection); } virtual void execute() {
throw MemException("Trying to execute a non-executable DiskWriteTask");
private: };
/**
* The fifo containing the memory blocks holding data to be written to disk
*/
DataFifo m_fifo;
/**
* Number of blocks in the fifo
*/
int m_blockCount;
/**
* File id of the file that will be written to disk
*/
int m_fileId;
/** /**
* Reference to the Memory Manager in use * Wait for the end of the task
*/ */
MemoryManager & m_memManager; virtual void waitCompletion() {};
/** /**
* Mutex forcing serial access to the fifo * Destructor
*/ */
castor::tape::threading::Mutex m_producerProtection; virtual ~DiskWriteTask() {};
}; };
}}}} }}}}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment