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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/*
processtracker.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2016 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Filipe Azevedo <filipe.azevedo@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include "processtracker.h"
#include <QDebug>
#include <QTimer>
using namespace GammaRay;
class ProcessTracker::D : public QObject
{
Q_OBJECT
public:
GammaRay::ProcessTracker *tracker;
GammaRay::ProcessTrackerBackend *backend;
QTimer *ticker;
GammaRay::ProcessTrackerInfo previousInfo;
qint64 pid;
explicit D(GammaRay::ProcessTracker *tracker)
: QObject(tracker)
, tracker(tracker)
, backend(nullptr)
, ticker(new QTimer(this))
, pid(-1)
{
ticker->setSingleShot(false);
connect(ticker, &QTimer::timeout, this, &D::requestUpdate);
}
public slots:
void requestUpdate() const
{
if (!backend) {
qWarning("%s: Backend not set", Q_FUNC_INFO);
return;
}
if (pid < 0) {
qWarning("%s: Pid not set", Q_FUNC_INFO);
return;
}
backend->checkProcess(pid);
}
void processChecked(const GammaRay::ProcessTrackerInfo &info)
{
if (pid != info.pid) {
return;
}
if (info != previousInfo) {
previousInfo = info;
emit tracker->infoChanged(info);
}
}
};
ProcessTracker::ProcessTracker(QObject *parent)
: QObject(parent)
, d(new D(this))
{
qRegisterMetaType<GammaRay::ProcessTrackerInfo>("GammaRay::ProcessTrackerInfo");
}
ProcessTracker::~ProcessTracker()
{
stop();
}
GammaRay::ProcessTrackerBackend *ProcessTracker::backend() const
{
return d->backend;
}
void ProcessTracker::setBackend(GammaRay::ProcessTrackerBackend *backend)
{
if (backend == d->backend) {
return;
}
if (d->backend) {
disconnect(d->backend, &ProcessTrackerBackend::processChecked,
d.data(), &D::processChecked);
}
d->backend = backend;
if (d->backend) {
connect(d->backend, &ProcessTrackerBackend::processChecked,
d.data(), &D::processChecked, Qt::QueuedConnection);
}
emit backendChanged(d->backend);
}
qint64 ProcessTracker::pid() const
{
return d->pid;
}
bool ProcessTracker::isActive() const
{
return d->ticker->isActive();
}
void ProcessTracker::setPid(qint64 pid)
{
d->previousInfo = ProcessTrackerInfo();
d->pid = pid;
}
void ProcessTracker::start(int msecs)
{
d->previousInfo = ProcessTrackerInfo();
d->ticker->start(msecs);
}
void ProcessTracker::stop()
{
d->previousInfo = ProcessTrackerInfo();
d->ticker->stop();
}
bool ProcessTrackerInfo::operator==(const GammaRay::ProcessTrackerInfo &other) const
{
return pid == other.pid && traced == other.traced && state == other.state;
}
bool ProcessTrackerInfo::operator!=(const GammaRay::ProcessTrackerInfo &other) const
{
return !operator==(other);
}
ProcessTrackerBackend::ProcessTrackerBackend(QObject *parent)
: QObject(parent)
{
}
#include "processtracker.moc"
|