mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
/* Copyright (C) 2016
|
|
* swift project Community / Contributors
|
|
*
|
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
|
* or distributed except according to the terms contained in the LICENSE file.
|
|
*/
|
|
|
|
//! \file
|
|
|
|
#ifndef BLACKMISC_PROCESSINFO_H
|
|
#define BLACKMISC_PROCESSINFO_H
|
|
|
|
#include "blackmisc/valueobject.h"
|
|
#include <QCoreApplication>
|
|
#include <QString>
|
|
|
|
namespace BlackMisc
|
|
{
|
|
/*!
|
|
* Value class identifying a process, with a PID and a name.
|
|
*/
|
|
class BLACKMISC_EXPORT CProcessInfo : public CValueObject<CProcessInfo>
|
|
{
|
|
public:
|
|
//! Construct an object identifying an invalid process.
|
|
CProcessInfo() {}
|
|
|
|
//! Construct an object identifying the process with the given PID.
|
|
explicit CProcessInfo(qint64 pid) : m_pid(pid), m_name(processNameFromId(pid)) {}
|
|
|
|
//! Construct an object identifying a process with the given PID and name.
|
|
CProcessInfo(qint64 pid, const QString &name) : m_pid(pid), m_name(name) {}
|
|
|
|
//! Return an object identifying the current process.
|
|
static CProcessInfo currentProcess() { return CProcessInfo(QCoreApplication::applicationPid()); }
|
|
|
|
//! True if this object identifies a process that exists.
|
|
bool exists() const { return ! m_name.isEmpty() && *this == CProcessInfo(m_pid); }
|
|
|
|
//! Get the pid.
|
|
qint64 processId() const { return m_pid; }
|
|
|
|
//! Empty process info
|
|
bool isNull() const { return m_pid == 0 && m_name.isEmpty(); }
|
|
|
|
//! Get the process name.
|
|
const QString &processName() const { return m_name; }
|
|
|
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
|
QString convertToQString(bool i18n = false) const;
|
|
|
|
private:
|
|
static QString processNameFromId(qint64 pid);
|
|
|
|
qint64 m_pid = 0;
|
|
QString m_name;
|
|
|
|
BLACK_METACLASS(
|
|
CProcessInfo,
|
|
BLACK_METAMEMBER(pid),
|
|
BLACK_METAMEMBER(name)
|
|
);
|
|
};
|
|
}
|
|
|
|
Q_DECLARE_METATYPE(BlackMisc::CProcessInfo)
|
|
|
|
#endif
|