Skip to content

Commit

Permalink
debugger: Add preferences for showing debugfs attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei-Fabian-Pop <[email protected]>
  • Loading branch information
Andrei-Fabian-Pop committed Sep 20, 2024
1 parent fa0c942 commit 66c9d13
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
2 changes: 0 additions & 2 deletions core/src/scopypreferencespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ QWidget *ScopyPreferencesPage::buildGeneralPreferencesPage()
PreferencesHelper::addPreferenceCheckBox(p, "show_graticule", "Show Graticule", generalSection));
generalSection->contentLayout()->addWidget(PreferencesHelper::addPreferenceCheckBox(
p, "iiowidgets_use_lazy_loading", "Use Lazy Loading", generalSection));
generalSection->contentLayout()->addWidget(PreferencesHelper::addPreferenceCheckBox(
p, "plugins_use_debugger_v2", "Use Debugger V2 plugin", generalSection));
generalSection->contentLayout()->addWidget(PreferencesHelper::addPreferenceCombo(
p, "general_theme", "Theme", {"default", "light"}, generalSection));
generalSection->contentLayout()->addWidget(PreferencesHelper::addPreferenceCombo(
Expand Down
9 changes: 9 additions & 0 deletions iio-widgets/include/iio-widgets/iiowidgetbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ class SCOPY_IIO_WIDGETS_EXPORT IIOWidgetBuilder : public QObject
*/
IIOWidgetBuilder &compactMode(bool isCompact);

/**
* @brief includeDebugAttributes If set to true, the buildAll function will
* also include the debugfs attributes when creating the IIOWidgets.
* @param isIncluded Default value is false.
* @return
*/
IIOWidgetBuilder &includeDebugAttributes(bool isIncluded);

/**
* @brief Sets the context that will be used, if no iio_device or iio_channel
* is set, the build functions will work with the context.
Expand Down Expand Up @@ -161,6 +169,7 @@ class SCOPY_IIO_WIDGETS_EXPORT IIOWidgetBuilder : public QObject

Connection *m_connection;
bool m_isCompact;
bool m_includeDebugAttrs;
struct iio_context *m_context;
struct iio_device *m_device;
struct iio_channel *m_channel;
Expand Down
36 changes: 36 additions & 0 deletions iio-widgets/src/iiowidgetbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "datastrategy/cmdqdeviceattrdatastrategy.h"
#include "guistrategy/comboguistrategy.h"
#include "guistrategy/rangeguistrategy.h"
#include <pluginbase/preferences.h>
#include <iioutil/connectionprovider.h>
#include <QLoggingCategory>

Expand All @@ -40,6 +41,7 @@ IIOWidgetBuilder::IIOWidgetBuilder(QObject *parent)
: QObject(parent)
, m_connection(nullptr)
, m_isCompact(false)
, m_includeDebugAttrs(Preferences::get("debugger_v2_include_debugfs").toBool())
, m_context(nullptr)
, m_device(nullptr)
, m_channel(nullptr)
Expand Down Expand Up @@ -143,6 +145,34 @@ QList<IIOWidget *> IIOWidgetBuilder::buildAll()
m_attribute = "";
m_optionsAttribute = "";
}

if(m_includeDebugAttrs) {
attrCount = iio_device_get_debug_attrs_count(m_device);
for(ssize_t i = 0; i < attrCount; ++i) {
attrName = iio_device_get_debug_attr(m_device, i);

if(!attrName) {
qWarning(CAT_ATTRBUILDER)
<< "Could not read the device DEBUG attribute name with index" << i;
continue;
}

m_attribute = attrName;
if(QString(attrName).endsWith("_available")) {
continue;
}

availableAttr = iio_device_find_debug_attr(
m_device, (QString(attrName) + "_available").toStdString().c_str());
if(availableAttr) {
m_optionsAttribute = availableAttr;
}

result.append(buildSingle());
m_attribute = "";
m_optionsAttribute = "";
}
}
} else if(m_context) {
attrCount = iio_context_get_attrs_count(m_context);
for(ssize_t i = 0; i < attrCount; ++i) {
Expand Down Expand Up @@ -199,6 +229,12 @@ IIOWidgetBuilder &IIOWidgetBuilder::compactMode(bool isCompact)
return *this;
}

IIOWidgetBuilder &IIOWidgetBuilder::includeDebugAttributes(bool isIncluded)
{
m_includeDebugAttrs = isIncluded;
return *this;
}

IIOWidgetBuilder &IIOWidgetBuilder::context(iio_context *context)
{
m_context = context;
Expand Down
2 changes: 2 additions & 0 deletions plugins/debugger/include/debugger/debuggerplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class SCOPY_DEBUGGER_EXPORT DebuggerPlugin : public QObject, public PluginBase

public:
friend class IIODebugPlugin_API;
void initPreferences() override;
bool compatible(QString m_param, QString category) override;
bool loadPreferencesPage() override;
bool loadPage() override;
bool loadIcon() override;
void loadToolList() override;
Expand Down
33 changes: 33 additions & 0 deletions plugins/debugger/src/debuggerplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QLabel>
#include <QLoggingCategory>
#include <QVBoxLayout>
#include <preferenceshelper.h>

#include <core/detachedtoolwindow.h>
#include <core/detachedtoolwindowmanager.h>
Expand All @@ -22,6 +23,13 @@ using namespace scopy::debugger;
Q_LOGGING_CATEGORY(CAT_DEBUGGERPLUGIN, "DEBUGGERPLUGIN");
Q_LOGGING_CATEGORY(CAT_BENCHMARK, "Benchmark");

void DebuggerPlugin::initPreferences()
{
Preferences *p = Preferences::GetInstance();
p->init("debugger_v2_include_debugfs", true);
p->init("plugins_use_debugger_v2", true);
}

bool DebuggerPlugin::compatible(QString m_param, QString category)
{
bool ret = true;
Expand All @@ -34,6 +42,31 @@ bool DebuggerPlugin::compatible(QString m_param, QString category)
return ret;
}

bool DebuggerPlugin::loadPreferencesPage()
{
Preferences *p = Preferences::GetInstance();

m_preferencesPage = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(m_preferencesPage);

MenuSectionCollapseWidget *generalSection =
new MenuSectionCollapseWidget("General", MenuCollapseSection::MHCW_NONE);
generalSection->contentLayout()->setSpacing(10);
layout->addWidget(generalSection);
layout->setSpacing(0);
layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));

auto use_debugger_v2 = PreferencesHelper::addPreferenceCheckBox(p, "plugins_use_debugger_v2",
"Use Debugger V2 plugin", generalSection);
auto debugger_include_debugfs = PreferencesHelper::addPreferenceCheckBox(
p, "debugger_v2_include_debugfs", "Include debug attributes in IIO Explorer", generalSection);

generalSection->contentLayout()->addWidget(use_debugger_v2);
generalSection->contentLayout()->addWidget(debugger_include_debugfs);

return true;
}

void DebuggerPlugin::loadToolList()
{
m_toolList.append(
Expand Down

0 comments on commit 66c9d13

Please sign in to comment.