diff --git a/tapeserver/daemon/DriveHandler.cpp b/tapeserver/daemon/DriveHandler.cpp index e975e0cfaffea09709ed1402d9c131b034a32886..afb869ed8261a573c3f810ca98596baa3090ec64 100644 --- a/tapeserver/daemon/DriveHandler.cpp +++ b/tapeserver/daemon/DriveHandler.cpp @@ -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; diff --git a/tapeserver/daemon/SourcedParameter.cpp b/tapeserver/daemon/SourcedParameter.cpp index c0d1c0cdb25af2ea889ab3368a2d31e23a600164..e1acc547470d6594c9b86ca1c62e619a8e68e531 100644 --- a/tapeserver/daemon/SourcedParameter.cpp +++ b/tapeserver/daemon/SourcedParameter.cpp @@ -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 diff --git a/tapeserver/daemon/Tpconfig.cpp b/tapeserver/daemon/Tpconfig.cpp index abfd9fdfbc7a480496dea150959300cbecc8e608..c80fdf9885b6714d0c1fb60ee7009dc8815a2cae 100644 --- a/tapeserver/daemon/Tpconfig.cpp +++ b/tapeserver/daemon/Tpconfig.cpp @@ -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 diff --git a/tapeserver/daemon/TpconfigLine.cpp b/tapeserver/daemon/TpconfigLine.cpp index 0026913df0cae35bb42a30a683300fd918128cbf..434e04fde6d56f5f81422bb5e69294bb54084042 100644 --- a/tapeserver/daemon/TpconfigLine.cpp +++ b/tapeserver/daemon/TpconfigLine.cpp @@ -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 diff --git a/tapeserver/daemon/TpconfigLine.hpp b/tapeserver/daemon/TpconfigLine.hpp index 9c77107edbbda2a7fc12647f0241dfa8f9c80834..49639094e300baaae8fab7ecbc93cf68b5afb5cb 100644 --- a/tapeserver/daemon/TpconfigLine.hpp +++ b/tapeserver/daemon/TpconfigLine.hpp @@ -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 diff --git a/tapeserver/daemon/TpconfigTests.cpp b/tapeserver/daemon/TpconfigTests.cpp index 53395f74286535138ee4e23c32725c0272265209..7fc9b48b44adcd56e67c0d1bbd396e702bfe7f62 100644 --- a/tapeserver/daemon/TpconfigTests.cpp +++ b/tapeserver/daemon/TpconfigTests.cpp @@ -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++; } }