Libksysguard

SensorInfo_p.h
1 /*
2  Copyright (c) 2019 David Edmundson <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #pragma once
20 
21 #include <QDBusArgument>
22 #include <QDateTime>
23 #include <QDebug>
24 #include <QObject>
25 #include <QVariant>
26 
27 #include "formatter/Unit.h"
28 
29 namespace KSysGuard
30 {
31 constexpr uint BackendUpdateInterval = 500;
32 
33 // Data that is static for the lifespan of the sensor
34 class SensorInfo
35 {
36 public:
37  SensorInfo() = default;
38  QString name; // Translated name of the sensor.
39  QString shortName; // Shorter translated name of the sensor, to use when space is constrained.
40  QString description; // Translated description of the sensor.
41  QVariant::Type variantType = QVariant::Invalid;
42  KSysGuard::Unit unit = KSysGuard::UnitInvalid; // Both a format hint and implies data type (i.e double/string)
43  qreal min = 0;
44  qreal max = 0;
45 };
46 
47 class Q_DECL_EXPORT SensorData
48 {
49 public:
50  SensorData() = default;
51  SensorData(const QString &_attribute, const QVariant &_payload)
52  : attribute(_attribute)
53  , payload(_payload)
54  {
55  }
56  QString attribute;
57  QVariant payload;
58 };
59 
60 typedef QHash<QString, SensorInfo> SensorInfoMap;
61 typedef QList<SensorData> SensorDataList;
62 
63 inline QDBusArgument &operator<<(QDBusArgument &argument, const SensorInfo &s)
64 {
65  argument.beginStructure();
66  argument << s.name;
67  argument << s.shortName;
68  argument << s.description;
69  argument << s.variantType;
70  argument << s.unit;
71  argument << s.min;
72  argument << s.max;
73  argument.endStructure();
74  return argument;
75 }
76 
77 inline const QDBusArgument &operator>>(const QDBusArgument &argument, SensorInfo &s)
78 {
79  argument.beginStructure();
80  argument >> s.name;
81  argument >> s.shortName;
82  argument >> s.description;
83  uint32_t t;
84  argument >> t;
85  s.variantType = static_cast<QVariant::Type>(t);
86  argument >> t;
87  s.unit = static_cast<KSysGuard::Unit>(t);
88  argument >> s.min;
89  argument >> s.max;
90  argument.endStructure();
91  return argument;
92 }
93 
94 inline QDBusArgument &operator<<(QDBusArgument &argument, const SensorData &s)
95 {
96  argument.beginStructure();
97  argument << s.attribute;
98  argument << QDBusVariant(s.payload);
99  argument.endStructure();
100  return argument;
101 }
102 
103 inline const QDBusArgument &operator>>(const QDBusArgument &argument, SensorData &s)
104 {
105  argument.beginStructure();
106  argument >> s.attribute;
107  argument >> s.payload;
108  argument.endStructure();
109  return argument;
110 }
111 
112 } // namespace KSysGuard
113 
114 Q_DECLARE_METATYPE(KSysGuard::SensorInfo);
115 Q_DECLARE_METATYPE(KSysGuard::SensorData);
116 Q_DECLARE_METATYPE(KSysGuard::SensorDataList);
QString name(const QVariant &location)
QDataStream & operator>>(QDataStream &in, KDateTime::Spec &spec)
void beginStructure()
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
void endStructure()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Mar 2 2021 02:46:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.