Loading...
Searching...
No Matches
XrdCl::CheckSumManager Class Reference

Manage the checksum calc objects. More...

`#include <XrdClCheckSumManager.hh>`

Collaboration diagram for XrdCl::CheckSumManager:

## Public Member Functions

| CheckSumManager ()
| Constructor.
virtual | ~CheckSumManager ()
bool | Calculate (XrdCksData &result, const std::string &algName, const std::string &filePath)
| Calculate a checksum of for a given file.
XrdCksCalc * | GetCalculator (const std::string &algName)

## Detailed Description

Manage the checksum calc objects.

Definition at line 41 of file XrdClCheckSumManager.hh.

## Constructor & Destructor Documentation

## CheckSumManager()

XrdCl::CheckSumManager::CheckSumManager | ( |  | ) |

Constructor.

Definition at line 47 of file XrdClCheckSumManager.cc.

{
pLoader = new XrdCksLoader( XrdVERSIONINFOVAR( XrdCl ) );
pCalculators["md5"] = new XrdCksCalcmd5();
pCalculators["crc32"] = new XrdCksCalccrc32;
pCalculators["crc32c"] = new XrdCksCalccrc32C;
pCalculators["adler32"] = new XrdCksCalcadler32;
}

## ~CheckSumManager()

XrdCl::CheckSumManager::~CheckSumManager | ( |  | ) |

virtual

Definition at line 59 of file XrdClCheckSumManager.cc.

{
CalcMap::iterator it;
for( it = pCalculators.begin(); it != pCalculators.end(); ++it )
delete it->second;
delete pLoader;
}

## Member Function Documentation

## Calculate()

bool XrdCl::CheckSumManager::Calculate | ( | XrdCksData & | result,
|  | const std::string & | algName,
|  | const std::string & | filePath )

Calculate a checksum of for a given file.

Definition at line 100 of file XrdClCheckSumManager.cc.

{
//--------------------------------------------------------------------------
// Get a calculator
//--------------------------------------------------------------------------
Log *log = DefaultEnv::GetLog();
XrdCksCalc *calc = GetCalculator( algName );
if( !calc )
{
log->Error( UtilityMsg, "Unable to get a calculator for %s",
algName.c_str() );
return false;
}
std::unique_ptr<XrdCksCalc> calcPtr( calc );
//--------------------------------------------------------------------------
// Open the file
//--------------------------------------------------------------------------
log->Debug( UtilityMsg, "Opening %s for reading (checksum calc)",
filePath.c_str() );
int fd = open( filePath.c_str(), O_RDONLY );
if( fd == -1 )
{
log->Error( UtilityMsg, "Unable to open %s: %s", filePath.c_str(),
XrdSysE2T( errno ) );
return false;
}
//--------------------------------------------------------------------------
// Calculate the checksum
//--------------------------------------------------------------------------
const uint32_t buffSize = 2*1024*1024;
char *buffer = new char[buffSize];
int64_t bytesRead = 0;
while( (bytesRead = read( fd, buffer, buffSize )) )
{
if( bytesRead == -1 )
{
log->Error( UtilityMsg, "Unable read from %s: %s", filePath.c_str(),
XrdSysE2T( errno ) );
close( fd );
delete [] buffer;
return false;
}
calc->Update( buffer, bytesRead );
}
int size;
calc->Type( size );
result.Set( (void*)calc->Final(), size );
//--------------------------------------------------------------------------
// Clean up
//--------------------------------------------------------------------------
delete [] buffer;
close( fd );
return true;
}
close
#define close(a)
Definition XrdPosix.hh:48
open
#define open
Definition XrdPosix.hh:76
read
#define read(a, b, c)
Definition XrdPosix.hh:82
XrdSysE2T
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
XrdCksCalc::Update
virtual void Update(const char *Buff, int BLen)=0
XrdCksCalc::Type
virtual const char * Type(int &csSize)=0
XrdCksCalc::Final
virtual char * Final()=0
XrdCksData::Set
int Set(const char *csName)
Definition XrdCksData.hh:81
XrdCl::CheckSumManager::GetCalculator
XrdCksCalc * GetCalculator(const std::string &algName)
Definition XrdClCheckSumManager.cc:70
XrdCl::DefaultEnv::GetLog
static Log * GetLog()
Get default log.
Definition XrdClDefaultEnv.cc:493
XrdCl::UtilityMsg
const uint64_t UtilityMsg
Definition XrdClConstants.hh:33
XrdGlobal::Log
XrdSysError Log
Definition XrdConfig.cc:113

References close, XrdCl::Log::Debug(), XrdCl::Log::Error(), XrdCksCalc::Final(), GetCalculator(), XrdCl::DefaultEnv::GetLog(), open, read, XrdCksData::Set(), XrdCksCalc::Type(), XrdCksCalc::Update(), XrdCl::UtilityMsg, and XrdSysE2T().

Referenced by XrdCl::Utils::GetLocalCheckSum().

Here is the call graph for this function:
Here is the caller graph for this function:

## GetCalculator()

XrdCksCalc * XrdCl::CheckSumManager::GetCalculator | ( | const std::string & | algName | ) |

Get the check sum calc object for a given checksum type

Parameters

  algName | name of the checksumming algorithm

Returns
  the appropriate calc object (must be deleted by the user) or 0 if a calculator cannot be obtained

Definition at line 70 of file XrdClCheckSumManager.cc.

{
Log *log = DefaultEnv::GetLog();
XrdSysMutexHelper scopedLock( pMutex );
CalcMap::iterator it = pCalculators.find( algName );
if( it == pCalculators.end() )
{
char *errBuff = new char[1024];
log->Dump( UtilityMsg, "Attempting to load a calculator for: %s",
algName.c_str() );
XrdCksCalc *c = pLoader->Load( algName.c_str(), "", errBuff, 1024 );
if( !c )
{
log->Error( UtilityMsg, "Unable to load %s calculator: %s",
algName.c_str(), errBuff );
delete [] errBuff;
return 0;
}
delete [] errBuff;
pCalculators[algName] = c;
return c->New();
}
return it->second->New();;
}
XrdCksCalc::New
virtual XrdCksCalc * New()=0

References XrdCl::Log::Dump(), XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCksCalc::New(), and XrdCl::UtilityMsg.

Referenced by Calculate(), and XrdCl::CheckSumHelper::Initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files:

- XrdClCheckSumManager.hh
- XrdClCheckSumManager.cc