Warning, file /plasma/libksysguard/systemstats/AggregateSensor.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 Arjen Hiemstra <ahiemsta@heimr.nl> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <functional> 0010 #include <iterator> 0011 #include <memory> 0012 0013 #include <QPointer> 0014 #include <QRegularExpression> 0015 #include <QVariant> 0016 #include <QVector> 0017 0018 #include "SensorObject.h" 0019 #include "SensorPlugin.h" 0020 #include "SensorProperty.h" 0021 0022 #include "systemstats_export.h" 0023 0024 namespace KSysGuard 0025 { 0026 0027 using SensorHash = QHash<QString, QPointer<SensorProperty>>; 0028 0029 /** 0030 * @todo write docs 0031 */ 0032 class SYSTEMSTATS_EXPORT AggregateSensor : public SensorProperty 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 AggregateSensor(SensorObject *provider, const QString &id, const QString &name); 0038 AggregateSensor(SensorObject *provider, const QString &id, const QString &name, const QVariant &initialValue); 0039 ~AggregateSensor() override; 0040 0041 QVariant value() const override; 0042 void subscribe() override; 0043 void unsubscribe() override; 0044 0045 class SensorIterator 0046 { 0047 public: 0048 using iterator_category = std::input_iterator_tag; 0049 using value_type = QVariant; 0050 using difference_type = SensorHash::size_type; 0051 using pointer = void; 0052 using reference = QVariant &; 0053 0054 SensorIterator(const SensorIterator &) = default; 0055 SensorIterator &operator=(const SensorIterator &) = default; 0056 ~SensorIterator() = default; 0057 0058 SensorIterator(SensorHash::const_iterator begin, const SensorHash::const_iterator end) 0059 : m_it(begin) 0060 , m_end(end){}; 0061 0062 value_type operator*() const; 0063 SensorIterator &operator++(); 0064 SensorIterator operator++(int); 0065 bool operator==(const SensorIterator &other) const; 0066 bool operator!=(const SensorIterator &other) const; 0067 0068 private: 0069 SensorHash::const_iterator m_it; 0070 const SensorHash::const_iterator m_end; 0071 }; 0072 0073 QRegularExpression matchSensors() const; 0074 void setMatchSensors(const QRegularExpression &objectMatch, const QString &propertyId); 0075 std::function<QVariant(SensorIterator, const SensorIterator)> aggregateFunction() const; 0076 void setAggregateFunction(const std::function<QVariant(QVariant, QVariant)> &function); 0077 void setAggregateFunction(const std::function<QVariant(SensorIterator, const SensorIterator)> &function); 0078 0079 void addSensor(SensorProperty *sensor); 0080 void removeSensor(const QString &sensorPath); 0081 0082 int matchCount() const; 0083 0084 private: 0085 void updateSensors(); 0086 void sensorDataChanged(SensorProperty *sensor); 0087 void delayedEmitDataChanged(); 0088 0089 class Private; 0090 const std::unique_ptr<Private> d; 0091 }; 0092 0093 class Q_DECL_EXPORT PercentageSensor : public SensorProperty 0094 { 0095 Q_OBJECT 0096 public: 0097 PercentageSensor(SensorObject *provider, const QString &id, const QString &name); 0098 ~PercentageSensor() override; 0099 0100 QVariant value() const override; 0101 void subscribe() override; 0102 void unsubscribe() override; 0103 0104 void setBaseSensor(SensorProperty *sensor); 0105 0106 private: 0107 class Private; 0108 const std::unique_ptr<Private> d; 0109 }; 0110 0111 } // namespace KSysGuard