mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-10-22 14:33:25 +02:00
Fix memory leak on failed setup, reconfigure
This commit is contained in:
parent
40ba9031e0
commit
9c87f4c470
@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QDataStream>
|
||||||
|
|
||||||
IntegrationPluginOwlet::IntegrationPluginOwlet()
|
IntegrationPluginOwlet::IntegrationPluginOwlet()
|
||||||
{
|
{
|
||||||
@ -568,10 +569,32 @@ void IntegrationPluginOwlet::setupThing(ThingSetupInfo *info)
|
|||||||
|
|
||||||
OwletTransport *transport = new OwletTcpTransport(ip, port, this);
|
OwletTransport *transport = new OwletTcpTransport(ip, port, this);
|
||||||
|
|
||||||
|
if (m_clients.contains(info->thing())) {
|
||||||
|
delete m_clients.take(info->thing());
|
||||||
|
}
|
||||||
OwletClient *client = new OwletClient(transport, this);
|
OwletClient *client = new OwletClient(transport, this);
|
||||||
|
|
||||||
|
connect(client, &OwletClient::error, info, [=](){
|
||||||
|
delete client;
|
||||||
|
info->finish(Thing::ThingErrorHardwareFailure);
|
||||||
|
});
|
||||||
|
connect(info, &ThingSetupInfo::aborted, client, [=](){
|
||||||
|
delete client;
|
||||||
|
});
|
||||||
|
|
||||||
connect(client, &OwletClient::connected, info, [=](){
|
connect(client, &OwletClient::connected, info, [=](){
|
||||||
qCDebug(dcOwlet()) << "Connected to owlet";
|
qCDebug(dcOwlet()) << "Connected to owlet";
|
||||||
m_clients.insert(thing, client);
|
m_clients.insert(thing, client);
|
||||||
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
connect(client, &OwletClient::connected, thing, [=](){
|
||||||
|
thing->setStateValue("connected", true);
|
||||||
|
|
||||||
|
pluginStorage()->beginGroup(thing->id().toString());
|
||||||
|
pluginStorage()->setValue("cachedIP", ip.toString());
|
||||||
|
pluginStorage()->endGroup();
|
||||||
|
|
||||||
if (thing->thingClassId() == digitalOutputThingClassId) {
|
if (thing->thingClassId() == digitalOutputThingClassId) {
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
@ -595,19 +618,6 @@ void IntegrationPluginOwlet::setupThing(ThingSetupInfo *info)
|
|||||||
client->sendCommand("GPIO.ConfigurePin", params);
|
client->sendCommand("GPIO.ConfigurePin", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(client, &OwletClient::error, info, [=](){
|
|
||||||
info->finish(Thing::ThingErrorHardwareFailure);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(client, &OwletClient::connected, thing, [=](){
|
|
||||||
thing->setStateValue("connected", true);
|
|
||||||
|
|
||||||
pluginStorage()->beginGroup(thing->id().toString());
|
|
||||||
pluginStorage()->setValue("cachedIP", ip.toString());
|
|
||||||
pluginStorage()->endGroup();
|
|
||||||
|
|
||||||
qCDebug(dcOwlet()) << "Sending get platform information request...";
|
qCDebug(dcOwlet()) << "Sending get platform information request...";
|
||||||
int id = client->sendCommand("Platform.GetInformation");
|
int id = client->sendCommand("Platform.GetInformation");
|
||||||
|
|||||||
@ -9,6 +9,8 @@ OwletClient::OwletClient(OwletTransport *transport, QObject *parent) :
|
|||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_transport(transport)
|
m_transport(transport)
|
||||||
{
|
{
|
||||||
|
transport->setParent(this);
|
||||||
|
|
||||||
connect(m_transport, &OwletTransport::dataReceived, this, &OwletClient::dataReceived);
|
connect(m_transport, &OwletTransport::dataReceived, this, &OwletClient::dataReceived);
|
||||||
connect(m_transport, &OwletTransport::error, this, &OwletClient::error);
|
connect(m_transport, &OwletTransport::error, this, &OwletClient::error);
|
||||||
connect(m_transport, &OwletTransport::connectedChanged, this, [=](bool isConnected){
|
connect(m_transport, &OwletTransport::connectedChanged, this, [=](bool isConnected){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user