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(
//-----------------------------------------------------------------------------
std::string castor::log::LoggerImplementation::cleanString(const std::string &s,
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;
if (std::string::npos != beginpos)
it1 = beginpos + s.begin();
else
it1 = s.begin();
//find last non white char
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)
it2 = endpos + 1 + s.begin();
else
......@@ -334,10 +338,12 @@ std::string castor::log::LoggerImplementation::cleanString(const std::string &s,
std::string result(it1, it2);
//if (s.begin() == it1 && it2 == s.end())
// result.clear();
// if (s.begin() == it1 && it2 == s.end())
// result="";
for (std::string::iterator it = result.begin(); it != result.end(); ++it) {
// Replace newline and tab with a space
if (replaceSpaces) {
if ('\t' == *it)
*it = ' ';
......@@ -346,8 +352,11 @@ std::string castor::log::LoggerImplementation::cleanString(const std::string &s,
*it = ' ';
}
// Replace spaces with underscore
if (' ' == *it)
*it = '_';
// Replace double quotes with single quotes
if ('"' == *it)
*it = '\'';
}
......
......@@ -211,15 +211,19 @@ std::string castor::log::StringLogger::buildSyslogHeader(
//-----------------------------------------------------------------------------
std::string castor::log::StringLogger::cleanString(const std::string &s,
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;
if (std::string::npos != beginpos)
it1 = beginpos + s.begin();
else
it1 = s.begin();
//find last non white char
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)
it2 = endpos + 1 + s.begin();
else
......@@ -227,10 +231,12 @@ std::string castor::log::StringLogger::cleanString(const std::string &s,
std::string result(it1, it2);
//if (s.begin() == it1 && it2 == s.end())
// result.clear();
// if (s.begin() == it1 && it2 == s.end())
// result="";
for (std::string::iterator it = result.begin(); it != result.end(); ++it) {
// Replace newline and tab with a space
if (replaceSpaces) {
if ('\t' == *it)
*it = ' ';
......@@ -239,8 +245,11 @@ std::string castor::log::StringLogger::cleanString(const std::string &s,
*it = ' ';
}
// Replace spaces with underscore
if (' ' == *it)
*it = '_';
// Replace double quotes with single quotes
if ('"' == *it)
*it = '\'';
}
......
/******************************************************************************
* DiskReadTask.hpp
* DiskReadFileTask.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -24,20 +24,34 @@
#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 tape {
namespace tapeserver {
namespace daemon {
class DiskReadTask {
class DiskReadFileTask :public DiskReadTask {
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() {
throw MemException("Tring to execute a non-execuatble DiskReadTask");
};
virtual ~DiskReadTask() {}
for (int blockId=0; blockId < m_nbBlocks; blockId++) {
MemBlock * mb = m_fifo.getFreeBlock();
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.
* See http://castor.web.cern.ch/castor
......@@ -24,34 +24,20 @@
#pragma once
#include "castor/tape/tapeserver/daemon/DiskReadTask.hpp"
#include "castor/tape/tapeserver/daemon/DataFifo.hpp"
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
#include "castor/tape/tapeserver/daemon/Exception.hpp"
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
class DiskReadFileTask :public DiskReadTask {
class DiskReadTask {
public:
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 bool endOfWork() = 0;
virtual void execute() {
for (int blockId=0; blockId < m_nbBlocks; blockId++) {
MemBlock * mb = m_fifo.getFreeBlock();
mb->m_fileid = m_fileId;
mb->m_fileBlock = blockId;
m_fifo.pushDataBlock(mb);
}
}
private:
int m_fileId;
int m_nbBlocks;
DataConsumer & m_fifo;
throw MemException("Tring to execute a non-execuatble DiskReadTask");
};
virtual ~DiskReadTask() {}
};
}}}}
/******************************************************************************
* DiskWriteTask.hpp
* DiskWriteFileTask.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -24,7 +24,10 @@
#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 tape {
......@@ -32,43 +35,103 @@ namespace tapeserver {
namespace daemon {
/**
* Abstract class describing the interface for a task that wants to write to disk.
* This is inherited exclusively by DiskWriteFileTask.
* The DiskWriteFileTask is responsible to write a single file onto disk as part of a recall
* 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:
/**
* 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() {
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.
* See http://castor.web.cern.ch/castor
......@@ -24,10 +24,7 @@
#pragma once
#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"
#include "castor/tape/tapeserver/daemon/Exception.hpp"
namespace castor {
namespace tape {
......@@ -35,103 +32,43 @@ namespace tapeserver {
namespace daemon {
/**
* The DiskWriteFileTask is responsible to write a single file onto disk as part of a recall
* 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?).
* Abstract class describing the interface for a task that wants to write to disk.
* This is inherited exclusively by DiskWriteFileTask.
*/
class DiskWriteFileTask: public DiskWriteTask, public DataConsumer {
class DiskWriteTask {
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?
* @return always false
* TODO: see comment on the same function in DiskWriteFileTask.
*/
virtual bool endOfWork() { return false; }
/**
* Return the numebr of files to write to disk
* @return always 1
*/
virtual int files() { return 1; };
virtual bool endOfWork() = 0;
/**
* @return the number of memory blocks to be used
*/
virtual int blocks() { return m_blockCount; }
/**
* 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);
}
virtual int blocks() { return 0; }
/**
* 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); }
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;
virtual void execute() {
throw MemException("Trying to execute a non-executable DiskWriteTask");
};
/**
* 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