Skip to content

Commit

Permalink
core/scopymainwindow_api: Implemented new API's
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Lie <[email protected]>
  • Loading branch information
liealex authored and adisuciu committed Sep 6, 2024
1 parent a4aff37 commit 4811f7c
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 21 deletions.
3 changes: 2 additions & 1 deletion core/include/core/devicemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class SCOPY_CORE_EXPORT DeviceManager : public QObject
public Q_SLOTS:

void addDevice(Device *d);
QString createDevice(QString category, QString param, bool async = true);
QString createDevice(QString category, QString param, bool async = true,
QList<QString> plugins = QList<QString>());
void removeDevice(QString category, QString id);

void removeDeviceById(QString id);
Expand Down
28 changes: 25 additions & 3 deletions core/include/core/scopymainwindow_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "scopy-core_export.h"
#include "scopymainwindow.h"
#include "scanbuttoncontroller.h"
#include "iioutil/connectionprovider.h"
#include <QFile>

namespace scopy {
Expand All @@ -14,19 +16,39 @@ class SCOPY_CORE_EXPORT ScopyMainWindow_API : public ApiObject
~ScopyMainWindow_API();

Q_INVOKABLE void acceptLicense();
Q_INVOKABLE QString addDevice(QString cat, QString uri);
Q_INVOKABLE QString addDevice(QString uri, QString cat = "iio", bool async = false);
Q_INVOKABLE QString addDevice(QString uri, QList<QString> plugins, QString cat = "iio", bool async = false);
Q_INVOKABLE bool removeDevice(QString uri, QString cat = "iio");
Q_INVOKABLE bool removeDevice(int idx);
Q_INVOKABLE bool startScan(bool scanState);
Q_INVOKABLE QStringList getDevicesName();
Q_INVOKABLE bool connectDevice(int idx);
Q_INVOKABLE bool connectDevice(QString devID);
Q_INVOKABLE bool disconnectDevice(QString devID);
Q_INVOKABLE bool disconnectDevice();
Q_INVOKABLE void switchTool(QString devID, QString toolName);
Q_INVOKABLE void switchTool(QString toolName);
Q_INVOKABLE bool switchTool(QString devID, QString toolName);
Q_INVOKABLE bool switchTool(QString toolName);
Q_INVOKABLE void runScript(QString scriptPath, bool exitApp = true);
Q_INVOKABLE void runScriptList(QStringList scriptPathList, bool exitApp = true);
Q_INVOKABLE void exit();
Q_INVOKABLE QStringList getTools();
Q_INVOKABLE QStringList getToolsForPlugin(QString plugin);
Q_INVOKABLE QPair<QString, QVariant> getPreference(QString prfName);
Q_INVOKABLE QMap<QString, QVariant> getPreferences();
Q_INVOKABLE void setPreference(QString preName, QVariant value);
Q_INVOKABLE void aboutPage();
Q_INVOKABLE QStringList getPlugins(int idx);
Q_INVOKABLE QStringList getPlugins(QString param, QString cat = "iio");
Q_INVOKABLE bool getToolBtnState(QString tool);
Q_INVOKABLE bool runTool(QString tool, bool flag);
Q_INVOKABLE bool loadSetup(QString fileName, QString path = QCoreApplication::applicationDirPath());
Q_INVOKABLE bool saveSetup(QString fileName, QString path = QCoreApplication::applicationDirPath());

private:
static bool sortByUUID(const QString &k1, const QString &k2);
const QString getScriptContent(QFile *file);
QStringList availablePlugins(QString param, QString cat, Device *dev);
Device *getDevice(int idx);
ScopyMainWindow *m_w;
};

Expand Down
15 changes: 12 additions & 3 deletions core/src/devicemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,25 @@ void DeviceManager::addDevice(Device *d)
Q_EMIT deviceAdded(id, d);
}

QString DeviceManager::createDevice(QString category, QString param, bool async)
QString DeviceManager::createDevice(QString category, QString param, bool async, QList<QString> plugins)
{
qInfo(CAT_DEVICEMANAGER) << category << "device with params" << param << "added";
Q_EMIT deviceAddStarted(param);

DeviceImpl *d = DeviceFactory::build(param, pm, category);
DeviceLoader *dl = new DeviceLoader(d, this);

connect(dl, &DeviceLoader::initialized, this,
[=]() { addDevice(d); }); // add device to manager once it is initialized
connect(dl, &DeviceLoader::initialized, this, [=]() {
QList<Plugin *> availablePlugins = d->plugins();
if(!plugins.isEmpty()) {
for(Plugin *p : qAsConst(availablePlugins)) {
if(!plugins.contains(p->name())) {
p->setEnabled(false);
}
}
}
addDevice(d);
}); // add device to manager once it is initialized
connect(dl, &DeviceLoader::initialized, dl,
&QObject::deleteLater); // don't forget to delete loader once we're done
dl->init(async);
Expand Down
Loading

0 comments on commit 4811f7c

Please sign in to comment.