Libksysguard

SensorInfo_p.h
1/*
2 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#pragma once
7
8#include <QDBusArgument>
9#include <QDateTime>
10#include <QDebug>
11#include <QObject>
12#include <QVariant>
13
14#include "formatter/Unit.h"
15
16namespace KSysGuard
17{
18constexpr uint BackendUpdateInterval = 500;
19
20// Data that is static for the lifespan of the sensor
21class SensorInfo
22{
23public:
24 SensorInfo() = default;
25 QString name; // Translated name of the sensor.
26 QString shortName; // Shorter translated name of the sensor, to use when space is constrained.
27 QString description; // Translated description of the sensor.
29 KSysGuard::Unit unit = KSysGuard::UnitInvalid; // Both a format hint and implies data type (i.e double/string)
30 qreal min = 0;
31 qreal max = 0;
32};
33
34class Q_DECL_EXPORT SensorData
35{
36public:
37 SensorData() = default;
38 SensorData(const QString &_attribute, const QVariant &_payload)
39 : attribute(_attribute)
40 , payload(_payload)
41 {
42 }
43 QString attribute;
44 QVariant payload;
45};
46
47typedef QHash<QString, SensorInfo> SensorInfoMap;
48typedef QList<SensorData> SensorDataList;
49
50inline QDBusArgument &operator<<(QDBusArgument &argument, const SensorInfo &s)
51{
52 argument.beginStructure();
53 argument << s.name;
54 argument << s.shortName;
55 argument << s.description;
56 argument << s.variantType;
57 argument << s.unit;
58 argument << s.min;
59 argument << s.max;
60 argument.endStructure();
61 return argument;
62}
63
64inline const QDBusArgument &operator>>(const QDBusArgument &argument, SensorInfo &s)
65{
66 argument.beginStructure();
67 argument >> s.name;
68 argument >> s.shortName;
69 argument >> s.description;
70 uint32_t t;
71 argument >> t;
72 s.variantType = static_cast<QVariant::Type>(t);
73 argument >> t;
74 s.unit = static_cast<KSysGuard::Unit>(t);
75 argument >> s.min;
76 argument >> s.max;
77 argument.endStructure();
78 return argument;
79}
80
81inline QDBusArgument &operator<<(QDBusArgument &argument, const SensorData &s)
82{
83 argument.beginStructure();
84 argument << s.attribute;
85 argument << QDBusVariant(s.payload);
86 argument.endStructure();
87 return argument;
88}
89
90inline const QDBusArgument &operator>>(const QDBusArgument &argument, SensorData &s)
91{
92 argument.beginStructure();
93 argument >> s.attribute;
94 argument >> s.payload;
95 argument.endStructure();
96 return argument;
97}
98
99} // namespace KSysGuard
100
101Q_DECLARE_METATYPE(KSysGuard::SensorInfo);
102Q_DECLARE_METATYPE(KSysGuard::SensorData);
103Q_DECLARE_METATYPE(KSysGuard::SensorDataList);
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
void beginStructure()
void endStructure()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.