Rabbit Remote Control 0.1.0-bate10
Loading...
Searching...
No Matches
Stats.h
1// Author: Kang Lin <kl222@126.com>
2
3#pragma once
4
5#include <QAtomicInteger>
6#include <QAtomicInt>
7#include <QDateTime>
8#include "ParameterOperate.h"
9
10class PLUGIN_EXPORT CStats : public CParameterOperate
11{
12 Q_OBJECT
13
14public:
15 explicit CStats(CParameterOperate* parent = nullptr,
16 const QString& szPrefix = QString());
17
18 [[nodiscard]] static QString Convertbytes(quint64 bytes);
19
20 QString TotalSends();
21 QString TotalReceives();
22 quint64 GetTotalSends();
23 quint64 GetTotalReceives();
24
25 QString SendRate();
26 QString ReceiveRate();
31 [[nodiscard]] virtual double GetSendRate();
32 [[nodiscard]] virtual double GetReceiveRate();
33
37 [[nodiscard]] int GetInterval();
41 int SetInterval(int interval = 1);
42
43Q_SIGNALS:
50
51public Q_SLOTS:
55 virtual void slotCalculating();
56 virtual void AddSends(quint64 size);
57 virtual void AddReceives(quint64 size);
58
59private:
60 QAtomicInteger<quint64> m_TotalSends;
61 QAtomicInteger<quint64> m_TotalReceives;
62 int m_tmInterval;
63 QDateTime m_lastTime;
64 QAtomicInteger<quint64> m_lastSends;
65 QAtomicInteger<quint64> m_lastReceives;
66 double m_dbSendRate;
67 double m_dbReceiveRate;
68
69 // CParameter interface
70protected:
71 virtual int OnLoad(QSettings &set) override;
72 virtual int OnSave(QSettings &set) override;
73};
74
75class PLUGIN_EXPORT CStatsSever : public CStats {
76 Q_OBJECT
77
78public:
79 explicit CStatsSever(CParameterOperate* parent = nullptr,
80 const QString& szPrefix = QString());
81 QString ToString() const;
82 quint64 GetTotalConnects() const;
83 quint64 GetConnects() const;
84 quint64 GetDisconnects() const;
85 void AddConnects(quint64 c = 1);
86 void Disconnects(quint64 c = 1);
87
88private:
89 QAtomicInteger<quint64> m_TotalConnects;
90 QAtomicInteger<quint64> m_Disconnects;
91};
92
97class PLUGIN_EXPORT CSecurityLevel : public QObject {
98 Q_OBJECT
99
100public:
101 enum Level {
102 No = 0x8000, // No the function
103 Risk = 0x00,
104 Authentication = 0x01,
105 SecureChannel = 0x02,
106 Proxy = 0x04,
107 Gateway = 0x08,
108 Redirect = 0x010,
109
110 SecureMask = Authentication | SecureChannel, // Green
111 NormalMask = Proxy | Gateway | Redirect, // Yellow
112 RiskyMask = ~SecureMask // Red
113 };
114 Q_ENUM(Level)
115 Q_DECLARE_FLAGS(Levels, Level)
116 Q_FLAG(Levels)
117
118 CSecurityLevel(Levels level = Level::No, QObject* parent = nullptr);
120
121 [[nodiscard]] virtual Levels GetLevel() const;
122 [[nodiscard]] virtual QString GetString() const;
123 [[nodiscard]] virtual QColor GetColor() const;
124 [[nodiscard]] virtual QString GetUnicodeIcon() const;
125 [[nodiscard]] virtual QIcon GetIcon() const;
126 [[nodiscard]] static QString GetString(const Levels &level);
127 [[nodiscard]] static QString GetUnicodeIcon(const Levels &level);
128 [[nodiscard]] static QIcon GetIcon(const Levels &level);
129 [[nodiscard]] static QColor GetColor(const Levels &level);
130
131Q_SIGNALS:
136 void sigSecurityLevel(Levels level);
137
138private:
139 Levels m_Level;
140};
141
142// 在类外部声明操作符(通常放在头文件末尾)
143Q_DECLARE_OPERATORS_FOR_FLAGS(CSecurityLevel::Levels)
Operational parameter interface.
Security level.
Definition Stats.h:97
void sigSecurityLevel(Levels level)
Triggered when the security level changes.
Definition Stats.h:11
void sigDataChanged()
Triggered when data changes, used to notify users to call slotCalculating(true) in real time for calc...