Merge PR #716: Fixes in NymeaConnection
This commit is contained in:
commit
e88de18d8f
@ -81,6 +81,17 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NymeaConnection::~NymeaConnection()
|
||||||
|
{
|
||||||
|
QList<NymeaTransportInterfaceFactory*> deletedTransports;
|
||||||
|
foreach (NymeaTransportInterfaceFactory* transport, m_transportFactories) {
|
||||||
|
if (!deletedTransports.contains(transport)) {
|
||||||
|
delete transport;
|
||||||
|
deletedTransports.append(transport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NymeaConnection::BearerTypes NymeaConnection::availableBearerTypes() const
|
NymeaConnection::BearerTypes NymeaConnection::availableBearerTypes() const
|
||||||
{
|
{
|
||||||
return m_availableBearerTypes;
|
return m_availableBearerTypes;
|
||||||
@ -312,7 +323,11 @@ void NymeaConnection::onDisconnected()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_transportCandidates.remove(m_currentTransport);
|
m_transportCandidates.remove(m_currentTransport);
|
||||||
delete m_currentTransport;
|
disconnect(m_currentTransport);
|
||||||
|
disconnect(m_currentTransport, nullptr, nullptr, nullptr);
|
||||||
|
// FIXME: directly deleting crashes with a stack trace that never passes any of our code.
|
||||||
|
// Seems to happen for both, Tcp and WebSocket
|
||||||
|
m_currentTransport->deleteLater();
|
||||||
m_currentTransport = nullptr;
|
m_currentTransport = nullptr;
|
||||||
|
|
||||||
foreach (NymeaTransportInterface *candidate, m_transportCandidates.keys()) {
|
foreach (NymeaTransportInterface *candidate, m_transportCandidates.keys()) {
|
||||||
@ -330,6 +345,7 @@ void NymeaConnection::onDisconnected()
|
|||||||
emit connectedChanged(false);
|
emit connectedChanged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!m_currentHost) {
|
if (!m_currentHost) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -345,6 +361,16 @@ void NymeaConnection::onDisconnected()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NymeaConnection::onDataAvailable(const QByteArray &data)
|
||||||
|
{
|
||||||
|
NymeaTransportInterface *t = static_cast<NymeaTransportInterface*>(sender());
|
||||||
|
if (t == m_currentTransport) {
|
||||||
|
emit dataAvailable(data);
|
||||||
|
} else {
|
||||||
|
qCDebug(dcNymeaConnection()) << "Received data from a transport that is not the current one:" << t->url();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NymeaConnection::updateActiveBearers()
|
void NymeaConnection::updateActiveBearers()
|
||||||
{
|
{
|
||||||
NymeaConnection::BearerTypes availableBearerTypes;
|
NymeaConnection::BearerTypes availableBearerTypes;
|
||||||
@ -502,12 +528,12 @@ bool NymeaConnection::connectInternal(Connection *connection)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new transport
|
// Create a new transport
|
||||||
NymeaTransportInterface* newTransport = m_transportFactories.value(connection->url().scheme())->createTransport();
|
NymeaTransportInterface* newTransport = m_transportFactories.value(connection->url().scheme())->createTransport(this);
|
||||||
QObject::connect(newTransport, &NymeaTransportInterface::sslErrors, this, &NymeaConnection::onSslErrors);
|
QObject::connect(newTransport, &NymeaTransportInterface::sslErrors, this, &NymeaConnection::onSslErrors);
|
||||||
QObject::connect(newTransport, &NymeaTransportInterface::error, this, &NymeaConnection::onError);
|
QObject::connect(newTransport, &NymeaTransportInterface::error, this, &NymeaConnection::onError);
|
||||||
QObject::connect(newTransport, &NymeaTransportInterface::connected, this, &NymeaConnection::onConnected);
|
QObject::connect(newTransport, &NymeaTransportInterface::connected, this, &NymeaConnection::onConnected);
|
||||||
QObject::connect(newTransport, &NymeaTransportInterface::disconnected, this, &NymeaConnection::onDisconnected);
|
QObject::connect(newTransport, &NymeaTransportInterface::disconnected, this, &NymeaConnection::onDisconnected);
|
||||||
QObject::connect(newTransport, &NymeaTransportInterface::dataReady, this, &NymeaConnection::dataAvailable);
|
QObject::connect(newTransport, &NymeaTransportInterface::dataReady, this, &NymeaConnection::onDataAvailable);
|
||||||
|
|
||||||
// // Load any certificate we might have for this url
|
// // Load any certificate we might have for this url
|
||||||
// QByteArray pem;
|
// QByteArray pem;
|
||||||
|
|||||||
@ -82,6 +82,7 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(ConnectionStatus)
|
Q_ENUM(ConnectionStatus)
|
||||||
explicit NymeaConnection(QObject *parent = nullptr);
|
explicit NymeaConnection(QObject *parent = nullptr);
|
||||||
|
~NymeaConnection();
|
||||||
|
|
||||||
void registerTransport(NymeaTransportInterfaceFactory *transportFactory);
|
void registerTransport(NymeaTransportInterfaceFactory *transportFactory);
|
||||||
|
|
||||||
@ -118,6 +119,7 @@ private slots:
|
|||||||
void onError(QAbstractSocket::SocketError error);
|
void onError(QAbstractSocket::SocketError error);
|
||||||
void onConnected();
|
void onConnected();
|
||||||
void onDisconnected();
|
void onDisconnected();
|
||||||
|
void onDataAvailable(const QByteArray &data);
|
||||||
|
|
||||||
void updateActiveBearers();
|
void updateActiveBearers();
|
||||||
void hostConnectionsUpdated();
|
void hostConnectionsUpdated();
|
||||||
|
|||||||
@ -258,7 +258,7 @@ bool NymeaHostsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
|
|||||||
if (m_jsonRpcClient && !m_showUneachableBearers) {
|
if (m_jsonRpcClient && !m_showUneachableBearers) {
|
||||||
bool hasReachableConnection = false;
|
bool hasReachableConnection = false;
|
||||||
for (int i = 0; i < host->connections()->rowCount(); i++) {
|
for (int i = 0; i < host->connections()->rowCount(); i++) {
|
||||||
qCritical() << "checking host for available bearer" << host->name() << host->connections()->get(i)->url() << "available bearer types:" << m_jsonRpcClient->availableBearerTypes() << "hosts bearer types" << host->connections()->get(i)->bearerType();
|
// qCritical() << "checking host for available bearer" << host->name() << host->connections()->get(i)->url() << "available bearer types:" << m_jsonRpcClient->availableBearerTypes() << "hosts bearer types" << host->connections()->get(i)->bearerType();
|
||||||
// Either enable a connection when the Bearer type is directly available
|
// Either enable a connection when the Bearer type is directly available
|
||||||
switch (host->connections()->get(i)->bearerType()) {
|
switch (host->connections()->get(i)->bearerType()) {
|
||||||
case Connection::BearerTypeLan:
|
case Connection::BearerTypeLan:
|
||||||
|
|||||||
Reference in New Issue
Block a user