Exception.hpp 4.22 KB
Newer Older
1
2
/*
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2003-2021 CERN
4
5
6
7
 * @license        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.
8
 *
9
10
11
12
 *                 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.
13
 *
14
15
16
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17

18
#include "common/exception/Exception.hpp"
19
20
#include "Structures.hpp"
#include "Constants.hpp"
21
22
23

#include <sstream>

24
25
namespace castor {
namespace tape {
26
27
28
29
namespace SCSI {
  /**
   * An exception class turning SCSI sense data into a loggable string
   */
30
  class Exception: public cta::exception::Exception {
31
  public:
32
    Exception(unsigned char status, castor::tape::SCSI::Structures::senseData_t<255> * sense,
33
            const std::string & context = "");
34
    virtual ~Exception() throw () {}
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  }; // class Exception
  
  /**
   * Failed with NotReady error.
   */
  class NotReadyException : public castor::tape::SCSI::Exception {
  public: 
    /**
     * Constructor
     */
    NotReadyException(unsigned char status, 
      castor::tape::SCSI::Structures::senseData_t<255> * sense,
      const std::string & context = ""):
      Exception(status, sense, context) {};
  }; // class NotReadyException
  
  /**
   * Failed with UnitAttention error.
   */
  class UnitAttentionException : public castor::tape::SCSI::Exception {
  public: 
    /**
     * Constructor
     */
    UnitAttentionException(unsigned char status, 
      castor::tape::SCSI::Structures::senseData_t<255> * sense,
      const std::string & context = ""):
      Exception(status, sense, context) {};
  }; // class UnitAttentionException
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

  /**
   * Failed with host error.
   */
  class HostException: public cta::exception::Exception {
  public:
    HostException(const unsigned short int host_status,
      const std::string & context = "");
    virtual ~HostException() throw () {}
  }; // class HostException

  /**
   * Failed with driver error.
   */
  class DriverException: public cta::exception::Exception {
  public:
    DriverException(const unsigned short int driver_status,
      castor::tape::SCSI::Structures::senseData_t<255> * sense,
      const std::string & context = "");
    virtual ~DriverException() throw () {}
  }; // class DriverException

86
87
88
89
90
91
  /**
   * Automated exception launcher in case of SCSI command error. Does nothing 
   * in the absence of errors.
   * @param sgio the sgio struct.
   */
  void ExceptionLauncher (const SCSI::Structures::LinuxSGIO_t & sgio, std::string context = "");
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

  /**
   * Check and throw exception in case of SCSI command error with bad status.
   * Does nothing in the absence of errors.
   * @param sgio the sgio struct.
   * @param context The string to be used as the beginning for the exception
   *                message.
   */
  void checkAndThrowSgStatus(const SCSI::Structures::LinuxSGIO_t & sgio,
    const std::string context);

  /**
   * Check and throw exception in case of SCSI command error with bad host
   * status. Does nothing in the absence of errors.
   * @param sgio the sgio struct.
   * @param context The string to be used as the beginning for the exception
   *                message.
   */
  void checkAndThrowSgHostStatus(const SCSI::Structures::LinuxSGIO_t & sgio,
    const std::string context);

  /**
   * Check and throw exception in case of SCSI command error with bad driver
   * status. Does nothing in the absence of errors.
   * @param sgio the sgio struct.
   * @param context The string to be used as the beginning for the exception
   *                message.
   */
  void checkAndThrowSgDriverStatus(const SCSI::Structures::LinuxSGIO_t & sgio,
    const std::string context);
122
123
124
} // namespace SCSI
} // namespace tape
} // namespace castor