Skip to content

Commit

Permalink
pluginbase/plugin: Added pausePing signal and slot.
Browse files Browse the repository at this point in the history
This signal-slot pair offers the possibility to pause/resume the ping task
from another plugin(not only from the plugin that contains the ping).

Signed-off-by: andrei.danila <[email protected]>
  • Loading branch information
andreidanila1 committed Jun 19, 2024
1 parent ad991b1 commit 466ab7d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
6 changes: 4 additions & 2 deletions core/include/core/deviceimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public Q_SLOTS:
void loadPages();
void loadToolList();
void loadBadges();
void setHighPriorPlugin(Plugin *plugin);
void setPingPlugin(Plugin *plugin);
void connPluginPingPause();
void disconnPluginPingPause();

protected:
PluginManager *p;
Expand All @@ -77,7 +79,7 @@ public Q_SLOTS:
QWidget *m_icon;
QWidget *m_page;
QPushButton *connbtn, *discbtn;
Plugin *m_highPriorPlugin = nullptr;
Plugin *m_pingPlugin = nullptr;
};
} // namespace scopy

Expand Down
45 changes: 33 additions & 12 deletions core/src/deviceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,32 @@ void DeviceImpl::loadBadges()
connect(this, &DeviceImpl::connected, warningHover, &HoverWidget::hide);
}

void DeviceImpl::setHighPriorPlugin(Plugin *plugin)
void DeviceImpl::setPingPlugin(Plugin *plugin)
{
int priority = plugin->metadata().value("priority").toInt();
int highestPriority = (m_highPriorPlugin) ? m_highPriorPlugin->metadata().value("priority").toInt() : -1;
if(!m_pingPlugin && plugin->pingTask()) {
m_pingPlugin = plugin;
}
}

if(plugin->pingTask() && priority > highestPriority) {
m_highPriorPlugin = plugin;
void DeviceImpl::connPluginPingPause()
{
if(!m_pingPlugin) {
return;
}
for(auto &&p : m_connectedPlugins) {
connect(dynamic_cast<QObject *>(p), SIGNAL(pausePingTask(bool)), dynamic_cast<QObject *>(m_pingPlugin),
SLOT(onPausePingTask(bool)));
}
}

void DeviceImpl::disconnPluginPingPause()
{
if(!m_pingPlugin) {
return;
}
for(auto &&p : m_connectedPlugins) {
disconnect(dynamic_cast<QObject *>(p), SIGNAL(pausePingTask(bool)),
dynamic_cast<QObject *>(m_pingPlugin), SLOT(onPausePingTask(bool)));
}
}

Expand Down Expand Up @@ -290,7 +309,7 @@ void DeviceImpl::connectDev()
p->loadSettings(s);
}
m_connectedPlugins.push_back(p);
setHighPriorPlugin(p);
setPingPlugin(p);
} else {
disconnectDevice = p->metadata().value("disconnectDevOnConnectFailure").toBool();
if(disconnectDevice) {
Expand All @@ -304,9 +323,10 @@ void DeviceImpl::connectDev()
connbtn->hide();
discbtn->show();
discbtn->setFocus();
if(m_highPriorPlugin) {
connect(m_highPriorPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
m_highPriorPlugin->startPingTask();
connPluginPingPause();
if(m_pingPlugin) {
connect(m_pingPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
m_pingPlugin->startPingTask();
}
Q_EMIT connected();
}
Expand All @@ -318,9 +338,10 @@ void DeviceImpl::disconnectDev()
QElapsedTimer pluginTimer;
QElapsedTimer timer;
timer.start();
if(m_highPriorPlugin) {
m_highPriorPlugin->stopPingTask();
disconnect(m_highPriorPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
disconnPluginPingPause();
if(m_pingPlugin) {
m_pingPlugin->stopPingTask();
disconnect(m_pingPlugin->pingTask(), &PingTask::pingFailed, this, &DeviceImpl::disconnectDev);
}
connbtn->show();
discbtn->hide();
Expand Down
2 changes: 2 additions & 0 deletions iioutil/src/pingtask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ PingTask::PingTask(QObject *parent)
PingTask::~PingTask() {}

void PingTask::run() {}

#include "moc_pingtask.cpp"
15 changes: 15 additions & 0 deletions pluginbase/include/pluginbase/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ public Q_SLOTS:
*/
virtual void stopPingTask() = 0;

/**
* @brief onPausePingTask
* Plugin can have a ping task which checks if the device is alive.
* This method pauses/resumes the ping task.
*/
virtual void onPausePingTask(bool) = 0;

// Q_SIGNALS:

/**
Expand Down Expand Up @@ -394,6 +401,14 @@ public Q_SLOTS:
*/
virtual void toolListChanged() = 0;

/**
* @brief pausePingTask
* Plugin can emit this signal if it requests to pause/resume the ping task
* If the argument is False, the resume will be attempted
* It works only if a ping task exists at device level
*/
virtual void pausePingTask(bool) = 0;

virtual void restartDevice() = 0;
};
} // namespace scopy
Expand Down
2 changes: 2 additions & 0 deletions pluginbase/include/pluginbase/pluginbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public Q_SLOTS:
virtual void requestTool(QString);
virtual void startPingTask() override;
virtual void stopPingTask() override;
virtual void onPausePingTask(bool) override;

protected:
QString m_param;
Expand Down Expand Up @@ -112,6 +113,7 @@ Q_SIGNALS:
void restartDevice() override; \
void toolListChanged() override; \
void requestToolByUuid(QString) override; \
void pausePingTask(bool) override; \
\
private:

Expand Down
2 changes: 2 additions & 0 deletions pluginbase/src/pluginbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ void PluginBase::startPingTask() {}

void PluginBase::stopPingTask() {}

void PluginBase::onPausePingTask(bool) {}

bool PluginBase::enabled() { return m_enabled; }

QString PluginBase::param() { return m_param; }
Expand Down

0 comments on commit 466ab7d

Please sign in to comment.