File indexing completed on 2024-05-12 05:46:52
0001 /************************************************************************** 0002 ** 0003 ** This file is part of the KDE Frameworks 0004 ** 0005 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). 0006 ** Copyright (c) 2019 David Hallas <david@davidhallas.dk> 0007 ** 0008 ** GNU Lesser General Public License Usage 0009 ** 0010 ** This file may be used under the terms of the GNU Lesser General Public 0011 ** License version 2.1 as published by the Free Software Foundation and 0012 ** appearing in the file LICENSE.LGPL included in the packaging of this file. 0013 ** Please review the following information to ensure the GNU Lesser General 0014 ** Public License version 2.1 requirements will be met: 0015 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 0016 ** 0017 ** In addition, as a special exception, Nokia gives you certain additional 0018 ** rights. These rights are described in the Nokia Qt LGPL Exception 0019 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 0020 ** 0021 ** Other Usage 0022 ** 0023 ** Alternatively, this file may be used in accordance with the terms and 0024 ** conditions contained in a signed written agreement between you and Nokia. 0025 ** 0026 ** If you have questions regarding the use of this file, please contact 0027 ** Nokia at info@qt.nokia.com. 0028 ** 0029 **************************************************************************/ 0030 0031 #include "kprocesslist.h" 0032 #include "kprocesslist_p.h" 0033 #include <algorithm> 0034 0035 using namespace KProcessList; 0036 0037 KProcessInfoPrivate::KProcessInfoPrivate() : 0038 valid(false), 0039 pid(-1) 0040 { 0041 } 0042 0043 KProcessInfo::KProcessInfo() : 0044 d_ptr(new KProcessInfoPrivate) 0045 { 0046 } 0047 0048 KProcessInfo::KProcessInfo(qint64 pid, const QString& command, const QString& user) : 0049 KProcessInfo(pid, command, command, user) 0050 {} 0051 0052 0053 KProcessInfo::KProcessInfo(qint64 pid, const QString& command, const QString &name, const QString& user) : 0054 d_ptr(new KProcessInfoPrivate) 0055 { 0056 d_ptr->valid = true; 0057 d_ptr->pid = pid; 0058 d_ptr->name = name; 0059 d_ptr->command = command; 0060 d_ptr->user = user; 0061 } 0062 0063 KProcessInfo::KProcessInfo(const KProcessInfo &other) : 0064 d_ptr(new KProcessInfoPrivate) 0065 { 0066 *this = other; 0067 } 0068 0069 KProcessInfo::~KProcessInfo() 0070 { 0071 } 0072 0073 KProcessInfo &KProcessInfo::operator=(const KProcessInfo &other) 0074 { 0075 d_ptr = other.d_ptr; 0076 return *this; 0077 } 0078 0079 bool KProcessInfo::isValid() const 0080 { 0081 return d_ptr->valid; 0082 } 0083 0084 qint64 KProcessInfo::pid() const 0085 { 0086 return d_ptr->pid; 0087 } 0088 0089 QString KProcessInfo::name() const 0090 { 0091 return d_ptr->name; 0092 } 0093 0094 QString KProcessInfo::command() const 0095 { 0096 return d_ptr->command; 0097 } 0098 0099 QString KProcessInfo::user() const 0100 { 0101 return d_ptr->user; 0102 } 0103 0104 KProcessInfo KProcessList::processInfo(qint64 pid) 0105 { 0106 KProcessInfoList processInfoList = KProcessList::processInfoList(); 0107 auto testProcessIterator = std::find_if(processInfoList.begin(), processInfoList.end(), 0108 [pid](const KProcessList::KProcessInfo& info) 0109 { 0110 return info.pid() == pid; 0111 }); 0112 if (testProcessIterator != processInfoList.end()) { 0113 return *testProcessIterator; 0114 } 0115 return KProcessInfo(); 0116 }