File indexing completed on 2024-04-21 16:19:53

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org>
0003 
0004 #ifndef SMARTDATA_H
0005 #define SMARTDATA_H
0006 
0007 #include <QObject>
0008 #include <QString>
0009 
0010 #include "smartfailure.h"
0011 
0012 class QJsonDocument;
0013 class QJsonObject;
0014 
0015 /** Models "smart_status" blobs */
0016 class SMARTStatus
0017 {
0018 public:
0019     explicit SMARTStatus(const QJsonObject &object);
0020 
0021     bool m_passed;
0022 };
0023 
0024 /** Models "smartctl" blobs */
0025 class SMARTCtlData
0026 {
0027 public:
0028     explicit SMARTCtlData(const QJsonObject &object);
0029 
0030     SMART::Failures failure() const;
0031 
0032 private:
0033     int m_exitStatus = -1; // only 8 least significant are filled for posix reasons.
0034 };
0035 
0036 /** Models the entire json output document */
0037 class SMARTData
0038 {
0039 public:
0040     explicit SMARTData(const QJsonDocument &document);
0041 
0042     SMARTCtlData m_smartctl;
0043     SMARTStatus m_status;
0044     QString m_device;
0045 
0046     // Keep at end so it's initialized last. m_valid is initialized
0047     // from checkValid() and that requires other members to have been
0048     // initialized already.
0049     const bool m_valid = false;
0050 
0051 private:
0052     bool checkValid(const QJsonDocument &document) const;
0053 };
0054 
0055 #endif // SMARTDATA_H