Warning, file /plasma/libksysguard/systemstats/SensorInfo.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QDBusArgument>
0010 #include <QDateTime>
0011 #include <QDebug>
0012 #include <QObject>
0013 #include <QVariant>
0014 
0015 #include "formatter/Unit.h"
0016 
0017 #include "systemstats_export.h"
0018 
0019 namespace KSysGuard
0020 {
0021 constexpr uint BackendUpdateInterval = 500;
0022 
0023 // Data that is static for the lifespan of the sensor
0024 class SYSTEMSTATS_EXPORT SensorInfo
0025 {
0026 public:
0027     SensorInfo() = default;
0028 
0029     QString name; // Translated name of the sensor.
0030     QString shortName; // Shorter translated name of the sensor, to use when space is constrained.
0031     QString description; // Translated description of the sensor.
0032     QVariant::Type variantType = QVariant::Invalid;
0033     KSysGuard::Unit unit = KSysGuard::UnitInvalid; // Both a format hint and implies data type (i.e double/string)
0034     qreal min = 0;
0035     qreal max = 0;
0036 };
0037 
0038 class SYSTEMSTATS_EXPORT SensorData
0039 {
0040 public:
0041     SensorData() = default;
0042     SensorData(const QString &_sensorProperty, const QVariant &_payload)
0043         : sensorProperty(_sensorProperty)
0044         , payload(_payload)
0045     {
0046     }
0047     QString sensorProperty;
0048     QVariant payload;
0049 };
0050 
0051 typedef QHash<QString, SensorInfo> SensorInfoMap;
0052 typedef QVector<SensorData> SensorDataList;
0053 
0054 inline QDBusArgument &operator<<(QDBusArgument &argument, const SensorInfo &s)
0055 {
0056     argument.beginStructure();
0057     argument << s.name;
0058     argument << s.shortName;
0059     argument << s.description;
0060     argument << s.variantType;
0061     argument << s.unit;
0062     argument << s.min;
0063     argument << s.max;
0064     argument.endStructure();
0065     return argument;
0066 }
0067 
0068 inline const QDBusArgument &operator>>(const QDBusArgument &argument, SensorInfo &s)
0069 {
0070     argument.beginStructure();
0071     argument >> s.name;
0072     argument >> s.shortName;
0073     argument >> s.description;
0074     uint32_t t;
0075     argument >> t;
0076     s.variantType = static_cast<QVariant::Type>(t);
0077     argument >> t;
0078     s.unit = static_cast<KSysGuard::Unit>(t);
0079     argument >> s.min;
0080     argument >> s.max;
0081     argument.endStructure();
0082     return argument;
0083 }
0084 
0085 inline QDBusArgument &operator<<(QDBusArgument &argument, const SensorData &s)
0086 {
0087     argument.beginStructure();
0088     argument << s.sensorProperty;
0089     argument << QDBusVariant(s.payload);
0090     argument.endStructure();
0091     return argument;
0092 }
0093 
0094 inline const QDBusArgument &operator>>(const QDBusArgument &argument, SensorData &s)
0095 {
0096     argument.beginStructure();
0097     argument >> s.sensorProperty;
0098     argument >> s.payload;
0099     argument.endStructure();
0100     return argument;
0101 }
0102 
0103 } // namespace KSysGuard
0104 
0105 Q_DECLARE_METATYPE(KSysGuard::SensorInfo);
0106 Q_DECLARE_METATYPE(KSysGuard::SensorData);
0107 Q_DECLARE_METATYPE(KSysGuard::SensorDataList);