Changeset View
Changeset View
Standalone View
Standalone View
sensors/SensorQuery.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2020 Arjen Hiemstra <ahiemstra@heimr.nl> | ||||
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 | | ||||
20 | #pragma once | ||||
21 | | ||||
22 | #include "sensors_export.h" | ||||
23 | #include <QObject> | ||||
24 | #include <memory> | ||||
25 | | ||||
26 | namespace KSysGuard | ||||
27 | { | ||||
28 | class SensorInfo; | ||||
29 | | ||||
30 | /** | ||||
31 | * An object to query the daemon for a list of sensors and their metadata. | ||||
32 | * | ||||
33 | * This class will request a list of sensors from the daemon, then filter them | ||||
34 | * based on the supplied path. The path can include the wildcard "*" to get a | ||||
35 | * list of all sensors matching the specified part of their path. In addition, | ||||
36 | * if left empty, all sensors will be returned. | ||||
37 | */ | ||||
38 | class SENSORS_EXPORT SensorQuery : public QObject | ||||
39 | { | ||||
40 | Q_OBJECT | ||||
41 | | ||||
42 | public: | ||||
43 | SensorQuery(const QString &path = QString{}, QObject *parent = nullptr); | ||||
44 | ~SensorQuery() override; | ||||
45 | | ||||
46 | QString path() const; | ||||
47 | void setPath(const QString &path); | ||||
48 | | ||||
49 | /** | ||||
50 | * A list of sensors ids that match the query. | ||||
51 | */ | ||||
52 | QStringList sensorIds() const; | ||||
53 | | ||||
54 | /** | ||||
55 | * Start processing the query. | ||||
56 | */ | ||||
57 | bool execute(); | ||||
58 | /** | ||||
59 | * Wait for the query to finish. | ||||
60 | * | ||||
61 | * Mostly useful for code that needs the result to be available before | ||||
62 | * continuing. Ideally the finished() signal should be used instead. | ||||
63 | */ | ||||
64 | bool waitForFinished(); | ||||
65 | | ||||
66 | Q_SIGNAL void finished(const SensorQuery *query); | ||||
67 | | ||||
68 | private: | ||||
69 | friend class Sensor; | ||||
70 | friend class SensorTreeModel; | ||||
71 | QVector<QPair<QString, SensorInfo>> result() const; | ||||
72 | | ||||
73 | class Private; | ||||
74 | const std::unique_ptr<Private> d; | ||||
75 | }; | ||||
76 | | ||||
77 | } // namespace KSysGuard |