summaryrefslogtreecommitdiffstats
path: root/app/taskmanager.h
blob: 87ca4b29ce5ecf3d348fb78de8636eb8c8caa24e (plain)
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
#include <QObject>
#include <QString>
#include <QSharedPointer>
#include <QStringList>
#include <QVector>
#include <QtCore>
#include <memory>
#include <messageengine.h>
#include "procinfo.h"

#ifndef TASKMANAGER_H
#define TASKMANAGER_H

class TaskManager : public QObject
{
	Q_OBJECT

public:
	explicit TaskManager(QObject* parent = nullptr);
	virtual ~TaskManager();

	Q_INVOKABLE void open(const QUrl& url);
	Q_INVOKABLE void kill(int tid);
	Q_INVOKABLE void getExtraInfo(int tid);
	QTimer *timer;
	QTimer *loadAvgTimer;

signals:
	void updateProcess(const QString& cmd_, int tid_, int euid_, double scpu_, double ucpu_, double resident_memory_, const QString& state_);
	void addProcess(const QString& cmd_, int tid_, int euid_, double scpu_, double ucpu_, double resident_memory_, const QString& state_);
	void removeProcess(int tid_);
	void showProcessInfo(const QString info_);
	void updateLoadAverage(double value_);
	void updateNetworkStats(unsigned int in_, unsigned int out_);

private slots:
	void query();
	void callService(const QString&, QJsonValue);
	void onConnected();
	void onMessageReceived(std::shared_ptr<Message>);
	void loadAvg();

private:
	MessageEngine *m_loop;
	std::vector<ProcInfo> m_procinfos;
	unsigned int inOctets, outOctets;

	void ProcessResponse(std::shared_ptr<Message>);
	void ProcessResponseTasklist(QJsonArray& processes);
	void ProcessResponseExtraInfo(QJsonObject& info);
	void ProcessResponseLoadAvg(QJsonObject& loadInfo);
	void ProcessResponseNetStat(QJsonObject& netstat);
};

#endif // TASKMANAGER_H