Commit a578e3c9 authored by Eric Cano's avatar Eric Cano
Browse files

Added a parsed library slot memeber to TpConfigLine so it can replace the DriveConfig class.

parent b493aa20
......@@ -779,7 +779,7 @@ int DriveHandler::runChild() {
castor::tape::tapeserver::daemon::DriveConfig driveConfig;
driveConfig.m_unitName = m_configLine.unitName;
driveConfig.m_librarySlot = cta::mediachanger::LibrarySlotParser::parse(m_configLine.librarySlot);
driveConfig.m_librarySlot = cta::mediachanger::LibrarySlotParser::parse(m_configLine.rawLibrarySlot);
driveConfig.m_devFilename = m_configLine.devFilename;
driveConfig.m_logicalLibrary = m_configLine.logicalLibrary;
......@@ -829,7 +829,7 @@ int DriveHandler::runChild() {
castor::tape::tapeserver::daemon::DriveConfig driveConfig;
driveConfig.m_unitName = m_configLine.unitName;
driveConfig.m_librarySlot = cta::mediachanger::LibrarySlotParser::parse(m_configLine.librarySlot);
driveConfig.m_librarySlot = cta::mediachanger::LibrarySlotParser::parse(m_configLine.rawLibrarySlot);
driveConfig.m_devFilename = m_configLine.devFilename;
driveConfig.m_logicalLibrary = m_configLine.logicalLibrary;
......
......@@ -120,7 +120,7 @@ void SourcedParameter<TpconfigLine>::addLogParamForValue(log::LogContext & lc) {
lc.pushOrReplace({"unitName", m_value.unitName});
lc.pushOrReplace({"logicalLibrary", m_value.logicalLibrary});
lc.pushOrReplace({"devFilename", m_value.devFilename});
lc.pushOrReplace({"librarySlot", m_value.librarySlot});
lc.pushOrReplace({"librarySlot", m_value.rawLibrarySlot});
}
}}} // namespace cta::tape::daemon
\ No newline at end of file
......@@ -99,7 +99,7 @@ Tpconfig Tpconfig::parseFile(const std::string &filename) {
{
auto i = std::find_if(ret.begin(), ret.end(),
[&](decltype(*ret.begin()) i)
{return i.second.value().librarySlot == configLine.librarySlot;});
{return i.second.value().rawLibrarySlot == configLine.rawLibrarySlot;});
if (ret.end() != i) {
DuplicateEntry ex("In Tpconfig::parseFile(): duplicate library slot for unit ");
ex.getMessage() << configLine.unitName << " at " << filename << ":" << lineNumber
......
......@@ -18,6 +18,9 @@
#include "tapeserver/daemon/TpconfigLine.hpp"
#include "common/exception/Exception.hpp"
#include "mediachanger/LibrarySlotParser.hpp"
namespace cta { namespace tape { namespace daemon {
//------------------------------------------------------------------------------
// Constructor.
......@@ -30,7 +33,8 @@ cta::tape::daemon::TpconfigLine::TpconfigLine(
unitName(unitName),
logicalLibrary(logicalLibrary),
devFilename(devFilename),
librarySlot(librarySlot) {
rawLibrarySlot(librarySlot),
m_librarySlot(mediachanger::LibrarySlotParser::parse(rawLibrarySlot)){
if (unitName.size() > maxNameLen)
throw cta::exception::Exception("In TpconfigLine::TpconfigLine: unitName too long");
if (logicalLibrary.size() > maxNameLen)
......@@ -40,3 +44,17 @@ cta::tape::daemon::TpconfigLine::TpconfigLine(
if (librarySlot.size() > maxNameLen)
throw cta::exception::Exception("In TpconfigLine::TpconfigLine: librarySlot too long");
}
//------------------------------------------------------------------------------
// Copy constructor.
//------------------------------------------------------------------------------
TpconfigLine::TpconfigLine(const TpconfigLine& o): TpconfigLine(o.unitName, o.logicalLibrary,
o.devFilename, o.rawLibrarySlot) {}
//------------------------------------------------------------------------------
// TpconfigLine::librarySlot
//------------------------------------------------------------------------------
const cta::mediachanger::LibrarySlot& TpconfigLine::librarySlot() {
return *m_librarySlot;
}
}}} // namespace cta::tape::daemon
......@@ -19,6 +19,8 @@
#pragma once
#include <string>
#include "mediachanger/LibrarySlot.hpp"
#include <memory>
namespace cta { namespace tape { namespace daemon {
......@@ -26,27 +28,41 @@ namespace cta { namespace tape { namespace daemon {
* The data stored in a data-line (as opposed to a comment-line) from a
* TPCONFIG file (/etc/cta/TPCONFIG).
*/
struct TpconfigLine {
class TpconfigLine {
public:
/**
* The unit name of the tape drive.
*/
std::string unitName;
const std::string unitName;
/**
* The logical library of the tape drive.
*/
std::string logicalLibrary;
const std::string logicalLibrary;
/**
* The filename of the device file of the tape drive.
*/
std::string devFilename;
const std::string devFilename;
/**
* The slot in the tape library that contains the tape drive.
* The slot in the tape library that contains the tape drive (string encoded).
*/
std::string librarySlot;
const std::string rawLibrarySlot;
/**
* Accessor method to the library slot strcuture.
* @return reference to the library slot.
*/
const cta::mediachanger::LibrarySlot & librarySlot();
private:
/**
* The library slot structure.
*/
std::unique_ptr <cta::mediachanger::LibrarySlot> m_librarySlot;
public:
/**
* Constructor.
*
......@@ -61,7 +77,12 @@ struct TpconfigLine {
const std::string &logicalLibrary,
const std::string &devFilename,
const std::string &librarySlot);
/**
* Copy constructor
* @param o the other TpConfigLine to be copied.
*/
TpconfigLine(const TpconfigLine& o);
static const size_t maxNameLen = 100;
}; // struct TpconfigLine
......
......@@ -78,10 +78,10 @@ TEST(cta_Daemon, Tpconfig_base) {
ASSERT_EQ("drive", t.second.value().unitName.substr(0,5));
ASSERT_EQ("lib0", t.second.value().logicalLibrary);
ASSERT_EQ("/dev/tape", t.second.value().devFilename.substr(0,9));
ASSERT_EQ("lib0slot", t.second.value().librarySlot.substr(0,8));
ASSERT_EQ("lib0slot", t.second.value().rawLibrarySlot.substr(0,8));
ASSERT_EQ('0'+i, t.second.value().unitName.back());
ASSERT_EQ('0'+i, t.second.value().devFilename.back());
ASSERT_EQ('0'+i, t.second.value().librarySlot.back());
ASSERT_EQ('0'+i, t.second.value().rawLibrarySlot.back());
i++;
}
}
......
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