forked from qt-creator/qt-creator
Devices: Unify Port Gathering method
All devices that support it use the same mechanism to gather ports so this patch removes the individual implementations in favor of a single one in IDevice.cpp. This patch also removes: * canAutodetectPorts() as it was not used. * Port::parseFrom...Output as they are not used anymore. Change-Id: I8ecedec2d71e60985402387982c64311c5a651e6 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -33,56 +33,6 @@ quint16 Port::number() const
|
||||
QTC_ASSERT(isValid(), return -1); return quint16(m_port);
|
||||
}
|
||||
|
||||
QList<Port> Port::parseFromSedOutput(const QByteArray &output)
|
||||
{
|
||||
QList<Port> ports;
|
||||
const QList<QByteArray> portStrings = output.split('\n');
|
||||
for (const QByteArray &portString : portStrings) {
|
||||
if (portString.size() != 4)
|
||||
continue;
|
||||
bool ok;
|
||||
const Port port(portString.toInt(&ok, 16));
|
||||
if (ok) {
|
||||
if (!ports.contains(port))
|
||||
ports << port;
|
||||
} else {
|
||||
qWarning("%s: Unexpected string '%s' is not a port.",
|
||||
Q_FUNC_INFO, portString.data());
|
||||
}
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
||||
QList<Port> Port::parseFromCatOutput(const QByteArray &output)
|
||||
{
|
||||
// Parse something like
|
||||
// sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
|
||||
// : 00000000:2717 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1001 0 3995881 1 0000000000000000 100 0 0 10 0
|
||||
// : 00000000:2716 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1001 0 3594482 1 0000000000000000 100 0 0 10 0
|
||||
const QRegularExpression re(".*: [[:xdigit:]]*:([[:xdigit:]]{4}).*");
|
||||
|
||||
QList<Port> ports;
|
||||
const QStringList lines = QString::fromLocal8Bit(output).split('\n');
|
||||
for (const QString &line : lines) {
|
||||
const QRegularExpressionMatch match = re.match(line);
|
||||
if (!match.hasMatch())
|
||||
continue;
|
||||
const QString portString = match.captured(1);
|
||||
if (portString.size() != 4)
|
||||
continue;
|
||||
bool ok;
|
||||
const Port port(portString.toInt(&ok, 16));
|
||||
if (ok) {
|
||||
if (!ports.contains(port))
|
||||
ports << port;
|
||||
} else {
|
||||
qWarning("%s: Unexpected string '%s' is not a port.",
|
||||
Q_FUNC_INFO, qPrintable(portString));
|
||||
}
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
||||
QList<Port> Port::parseFromNetstatOutput(const QByteArray &output)
|
||||
{
|
||||
QList<Port> ports;
|
||||
|
||||
Reference in New Issue
Block a user