1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
4 ** Contact: BlackBerry Limited (blackberry-qt@qnx.com), KDAB (info@kdab.com)
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "qnxdeviceprocesslist.h"
27 
28 #include <utils/algorithm.h>
29 #include <utils/fileutils.h>
30 
31 #include <QRegularExpression>
32 #include <QStringList>
33 
34 using namespace Qnx;
35 using namespace Qnx::Internal;
36 
QnxDeviceProcessList(const ProjectExplorer::IDevice::ConstPtr & device,QObject * parent)37 QnxDeviceProcessList::QnxDeviceProcessList(
38         const ProjectExplorer::IDevice::ConstPtr &device, QObject *parent)
39     : ProjectExplorer::SshDeviceProcessList(device, parent)
40 {
41 }
42 
listProcessesCommandLine() const43 QString QnxDeviceProcessList::listProcessesCommandLine() const
44 {
45     return QLatin1String("pidin -F '%a %A {/%n}'");
46 }
47 
buildProcessList(const QString & listProcessesReply) const48 QList<ProjectExplorer::DeviceProcessItem> QnxDeviceProcessList::buildProcessList(
49         const QString &listProcessesReply) const
50 {
51     QList<ProjectExplorer::DeviceProcessItem> processes;
52     QStringList lines = listProcessesReply.split(QLatin1Char('\n'));
53     if (lines.isEmpty())
54         return processes;
55 
56     lines.pop_front(); // drop headers
57     const QRegularExpression re("\\s*(\\d+)\\s+(.*){(.*)}");
58 
59     for (const QString &line : qAsConst(lines)) {
60         const QRegularExpressionMatch match = re.match(line);
61         if (match.hasMatch()) {
62             const QStringList captures = match.capturedTexts();
63             if (captures.size() == 4) {
64                 const int pid = captures[1].toInt();
65                 const QString args = captures[2];
66                 const QString exe = captures[3];
67                 ProjectExplorer::DeviceProcessItem deviceProcess;
68                 deviceProcess.pid = pid;
69                 deviceProcess.exe = exe.trimmed();
70                 deviceProcess.cmdLine = args.trimmed();
71                 processes.append(deviceProcess);
72             }
73         }
74     }
75 
76     Utils::sort(processes);
77     return processes;
78 }
79