Skip to content

Commit

Permalink
core/deviceimpl: Bind ping task to device.
Browse files Browse the repository at this point in the history
Signed-off-by: andrei.danila <[email protected]>
  • Loading branch information
andreidanila1 committed Jun 28, 2024
1 parent 0cea353 commit c527b7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/include/core/deviceimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public Q_SLOTS:
void loadToolList();
void loadBadges();
void setPingPlugin(Plugin *plugin);
void connPluginPingPause();
void disconnPluginPingPause();
void bindPing();
void unbindPing();

protected:
PluginManager *p;
Expand Down
21 changes: 9 additions & 12 deletions core/src/deviceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void DeviceImpl::setPingPlugin(Plugin *plugin)
}
}

void DeviceImpl::connPluginPingPause()
void DeviceImpl::bindPing()
{
if(!m_pingPlugin) {
return;
Expand All @@ -239,9 +239,11 @@ void DeviceImpl::connPluginPingPause()
connect(dynamic_cast<QObject *>(p), SIGNAL(pausePingTask(bool)), dynamic_cast<QObject *>(m_pingPlugin),
SLOT(onPausePingTask(bool)));
}
connect(m_pingPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
m_pingPlugin->startPingTask();
}

void DeviceImpl::disconnPluginPingPause()
void DeviceImpl::unbindPing()
{
if(!m_pingPlugin) {
return;
Expand All @@ -250,6 +252,9 @@ void DeviceImpl::disconnPluginPingPause()
disconnect(dynamic_cast<QObject *>(p), SIGNAL(pausePingTask(bool)),
dynamic_cast<QObject *>(m_pingPlugin), SLOT(onPausePingTask(bool)));
}
m_pingPlugin->stopPingTask();
disconnect(m_pingPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
m_pingPlugin = nullptr;
}

void DeviceImpl::onConnectionFailed() { disconnectDev(); }
Expand Down Expand Up @@ -323,11 +328,7 @@ void DeviceImpl::connectDev()
connbtn->hide();
discbtn->show();
discbtn->setFocus();
connPluginPingPause();
if(m_pingPlugin) {
connect(m_pingPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
m_pingPlugin->startPingTask();
}
bindPing();
Q_EMIT connected();
}
qInfo(CAT_BENCHMARK) << this->displayName() << " device connection took: " << timer.elapsed() << "ms";
Expand All @@ -338,11 +339,7 @@ void DeviceImpl::disconnectDev()
QElapsedTimer pluginTimer;
QElapsedTimer timer;
timer.start();
disconnPluginPingPause();
if(m_pingPlugin) {
m_pingPlugin->stopPingTask();
disconnect(m_pingPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
}
unbindPing();
connbtn->show();
discbtn->hide();
Preferences *pref = Preferences::GetInstance();
Expand Down

0 comments on commit c527b7c

Please sign in to comment.