MediaChangerFacade.cpp 3.54 KB
Newer Older
1
2
3
/*
 * The CERN Tape Archive(CTA) project
 * Copyright(C) 2015  CERN
4
 *
5
6
7
8
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 *(at your option) any later version.
9
10
11
12
13
14
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
15
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
18

19
#include "common/exception/Exception.hpp"
20
21
22
23
24
25
26
27
#include "mediachanger/MediaChangerFacade.hpp"

namespace cta {
namespace mediachanger {

//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
28
MediaChangerFacade::MediaChangerFacade(log::Logger &log):
29
  m_mmcProxy(log) {
30
31
32
33
34
}

//------------------------------------------------------------------------------
// mountTapeReadOnly
//------------------------------------------------------------------------------
35
void MediaChangerFacade::mountTapeReadOnly(const std::string &vid, const LibrarySlot &slot) {
36
  try {
37
    return getProxy(slot.getLibraryType()).mountTapeReadOnly(vid, slot);
38
39
  } catch(cta::exception::Exception &ne) {
    cta::exception::Exception ex;
40
    ex.getMessage() << "Failed to mount tape for read-only access: vid=" << vid << " slot=" << slot.str() << ": " <<
41
42
43
44
45
46
47
48
      ne.getMessage().str();
    throw ex;
  }
}

//------------------------------------------------------------------------------
// mountTapeReadWrite
//------------------------------------------------------------------------------
49
void MediaChangerFacade::mountTapeReadWrite(const std::string &vid, const LibrarySlot &slot) {
50
  try {
51
    return getProxy(slot.getLibraryType()).mountTapeReadWrite(vid, slot);
52
53
  } catch(cta::exception::Exception &ne) {
    cta::exception::Exception ex;
54
    ex.getMessage() << "Failed to mount tape for read/write access: vid=" << vid << " slot=" << slot.str() << ": " <<
55
56
57
58
59
60
61
62
      ne.getMessage().str();
    throw ex;
  }
}

//------------------------------------------------------------------------------
// dismountTape
//------------------------------------------------------------------------------
63
void MediaChangerFacade::dismountTape(const std::string &vid, const LibrarySlot &slot) {
64
  try {
65
    return getProxy(slot.getLibraryType()).dismountTape(vid, slot);
66
67
  } catch(cta::exception::Exception &ne) {
    cta::exception::Exception ex;
68
    ex.getMessage() << "Failed to dismount tape: vid=" << vid << " slot=" << slot.str() << ": " <<
69
70
71
72
73
      ne.getMessage().str();
    throw ex;
  }
}

74
//------------------------------------------------------------------------------
75
// getProxy
76
//------------------------------------------------------------------------------
77
MediaChangerProxy &MediaChangerFacade::getProxy(const TapeLibraryType libraryType) {
78
  try {
79
80
    switch(libraryType) {
    case TAPE_LIBRARY_TYPE_MANUAL:
81
      return m_mmcProxy;
82
    case TAPE_LIBRARY_TYPE_SCSI:
83
      return m_rmcProxy;
84
    default:
85
86
      // Should never get here
      throw exception::Exception("Library slot has an unexpected library type");
87
    }
88
89
  } catch(cta::exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
90
91
92
93
94
  }
}

} // namespace mediachanger
} // namespace cta