-
Notifications
You must be signed in to change notification settings - Fork 18
/
diagnostics_service.h
87 lines (69 loc) · 2.19 KB
/
diagnostics_service.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef DIAGNOSTICSSERVICE_H
#define DIAGNOSTICSSERVICE_H
#include <QDateTime>
#include <QObject>
#include <QPointer>
#include <QsLog.h>
class DBusService;
class DBusServices;
class Mappings;
class QTimer;
class VeQItem;
/// Publishes a D-Bus serivce (com.victronenergy.modbustcp) which contains diagnostics information
/// on the modbus TCP services.
/// D-Bus paths:
/// /LastError/Message '' <- text of latest error message.
/// /LastError/Timestamp 1485350774 <- unix timestamp of the latest error (or invalid)
/// /Services/Count 3 <- number of services which can be queried.
/// /Services/0/ServiceName com.victronenergy.battery.ttyO2
/// /Services/0/UnitId 245
/// /Services/0/IsActive 1 <- 0 When service has existed in the past, but has
/// disappeared. Old values are still accessible.
/// /Service/1/ServiceName ...
class DiagnosticsService : public QObject
{
Q_OBJECT
public:
DiagnosticsService(DBusServices *services, Mappings *mappings, VeQItem *root, QObject *parent = 0);
void setError(const QString &error);
private slots:
void onServiceFound(DBusService *service);
void onDeviceInstanceChanged();
void onServiceStateChanged();
void onLastErrorTimer();
private:
VeQItem *getServiceItem(VeQItem *serviceRoot, VeQItem *deviceInstance);
VeQItem *getServiceItem(VeQItem *serviceRoot);
VeQItem *createServiceItem(VeQItem *deviceInstance);
void updateService(VeQItem *serviceEntry, VeQItem *serviceRoot);
QString mLastErrorText;
QDateTime mLastErrorTime;
/// This timer is used to ensure that mLastError is not updated more than once per second.
QTimer *mLastErrorTimer;
DBusServices *mServices;
Mappings *mMappings;
VeQItem *mRoot;
VeQItem *mLastError;
VeQItem *mLastErrorTimeStamp;
VeQItem *mServiceCount;
};
class DiagnosticsDestination : public QsLogging::Destination
{
public:
DiagnosticsDestination(DiagnosticsService *service):
mService(service)
{
}
virtual void write(const QString& message, QsLogging::Level level)
{
if (mService && level == QsLogging::ErrorLevel)
mService->setError(message);
}
virtual bool isValid()
{
return mService;
}
private:
QPointer<DiagnosticsService> mService;
};
#endif // DIAGNOSTICSSERVICE_H