Warning, file /plasma/libksysguard/systemstats/SysFsSensor.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: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include <QObject>
0012 
0013 #include "SensorProperty.h"
0014 #include "systemstats_export.h"
0015 
0016 namespace KSysGuard
0017 {
0018 /**
0019  * Convenience subclass of SensorProperty that reads a sysfs file and uses the result as value.
0020  */
0021 class SYSTEMSTATS_EXPORT SysFsSensor : public SensorProperty
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     SysFsSensor(const QString &id, const QString &path, SensorObject *parent);
0027     SysFsSensor(const QString &id, const QString &path, const QVariant &initialValue, SensorObject *parent);
0028     ~SysFsSensor() override;
0029 
0030     /**
0031      * Set the function used to convert the data from sysfs to the value of this sensor.
0032      *
0033      * This accepts a function that takes a QByteArray and converts that to a QVariant.
0034      * By default this is set to `std::atoll` or in other words, any numeric value
0035      * should automatically be converted to a proper QVariant.
0036      */
0037     void setConvertFunction(const std::function<QVariant(const QByteArray &)> &function);
0038 
0039     /**
0040      * Update this sensor.
0041      *
0042      * This will cause the sensor to read sysfs and update the value from that.
0043      * It should be called periodically so values are updated properly.
0044      */
0045     void update() override;
0046 
0047 private:
0048     class Private;
0049     const std::unique_ptr<Private> d;
0050 };
0051 
0052 } // namespace KSysGuard