Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
H3DS-72 Added support for multiple interfaces in the plugin system
Browse files Browse the repository at this point in the history
  • Loading branch information
rabits committed Jul 26, 2020
1 parent 6d3882b commit 756d5ae
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 22 deletions.
2 changes: 1 addition & 1 deletion common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_definitions(-DPROJECT_VERSION="${PROJECT_VERSION}")
Expand Down
8 changes: 7 additions & 1 deletion include/PluginInterface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PLUGININTERFACE_H
#define PLUGININTERFACE_H

#include <QtPlugin>
#include <QStringList>

/**
Expand All @@ -11,10 +12,15 @@ class PluginInterface
public:
virtual ~PluginInterface() {};

/**
* Return plugin type
*/
static QLatin1String type() { return QLatin1String("io.stateoftheart.handy3dscanner.Plugin"); }

/**
* Plugin identify name
*/
virtual QString name() const = 0;
virtual QLatin1String name() const = 0;

/**
* List of the plugins required by the plugin
Expand Down
18 changes: 18 additions & 0 deletions include/plugins/PointCloudSourceInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef POINTCLOUDSOURCEINTERFACE_H
#define POINTCLOUDSOURCEINTERFACE_H

#include "PluginInterface.h"

#define PointCloudSourceInterface_iid "io.stateoftheart.handy3dscanner.plugins.PointCloudSourceInterface"

class PointCloudSourceInterface : public PluginInterface
{
public:
static QLatin1String type() { return QLatin1String(PointCloudSourceInterface_iid); }

virtual uint8_t* getPCData() const = 0;
};

Q_DECLARE_INTERFACE(PointCloudSourceInterface, PointCloudSourceInterface_iid)

#endif // POINTCLOUDSOURCEINTERFACE_H
5 changes: 3 additions & 2 deletions include/plugins/VideoSourceInterface.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#ifndef VIDEOSOURCEINTERFACE_H
#define VIDEOSOURCEINTERFACE_H

#include <QtPlugin>
#include <QStringList>
#include "PluginInterface.h"

#define VideoSourceInterface_iid "io.stateoftheart.handy3dscanner.plugins.VideoSourcePlugin"
#define VideoSourceInterface_iid "io.stateoftheart.handy3dscanner.plugins.VideoSourceInterface"

class VideoSourceInterface : public PluginInterface
{
public:
static QLatin1String type() { return QLatin1String(VideoSourceInterface_iid); }

virtual QStringList getAvailableStreams() const = 0;
};

Expand Down
31 changes: 21 additions & 10 deletions platform/src/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Q_LOGGING_CATEGORY(plugins, "Plugins")
#include <QPluginLoader>

#include "plugins/VideoSourceInterface.h"
#include "plugins/PointCloudSourceInterface.h"

Plugins* Plugins::s_pInstance = nullptr;

Expand Down Expand Up @@ -45,21 +46,31 @@ void Plugins::refreshPluginsList()
}

qCDebug(plugins) << " loading plugin:" << lib_name;
if( !addPlugin(qobject_cast<VideoSourceInterface *>(plugin)) )
bool loaded = addPlugin<VideoSourceInterface>(qobject_cast<VideoSourceInterface *>(plugin));
loaded = addPlugin<PointCloudSourceInterface>(qobject_cast<PointCloudSourceInterface *>(plugin)) || loaded;

if( !loaded ) {
plugin_loader.unload();
qCWarning(plugins) << " no supported interfaces found for plugin:" << lib_name;
}
}
}
}

bool Plugins::addPlugin(PluginInterface *plugin)
template<class T>
bool Plugins::addPlugin(T *plugin)
{
if( plugin ) {
if( !m_plugins.contains(plugin->name()) ) {
m_plugins[plugin->name()] = plugin;
qCDebug(plugins) << " loaded plugin:" << plugin->name();
return true;
}
qCWarning(plugins) << " plugin already loaded, skipping:" << plugin->name();
static_assert(std::is_base_of<PluginInterface, T>::value, "Unable to add non-PluginInterface object as plugin");

if( !plugin )
return false;

if( m_plugins.contains(plugin->name()) && m_plugins[plugin->name()].contains(plugin->type()) ) {
qCWarning(plugins, " plugin already loaded, skipping: %s::%s", plugin->name().data(), plugin->type().data());
return false;
}
return false;

m_plugins[plugin->name()][plugin->type()] = plugin;
qCDebug(plugins, " loaded plugin: %s::%s", plugin->name().data(), plugin->type().data());
return true;
}
5 changes: 3 additions & 2 deletions platform/src/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class Plugins
~Plugins() override;

void refreshPluginsList();
bool addPlugin(PluginInterface* plugin);
template<class T> bool addPlugin(T* plugin);

QMap<QString, PluginInterface*> m_plugins;
QMap<QLatin1String, QMap<QLatin1String, PluginInterface*>> m_plugins; // name : interface_id : plugin instance
QMap<QLatin1String, QList<PluginInterface*>> m_plugins_active; // interface_id : list of plugins
};

#endif // PLUGINS_H
10 changes: 8 additions & 2 deletions plugins/realsense/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Q_LOGGING_CATEGORY(plugin, "RealSensePlugin")

QString RealSensePlugin::name() const
QLatin1String RealSensePlugin::name() const
{
return plugin().categoryName();
return QLatin1String(plugin().categoryName());
}

QStringList RealSensePlugin::requirements() const
Expand All @@ -32,3 +32,9 @@ QStringList RealSensePlugin::getAvailableStreams() const
qCDebug(plugin) << "getAvailableStreams()";
return QStringList();
}

uint8_t *RealSensePlugin::getPCData() const
{
qCDebug(plugin) << "getAvailableStreams()";
return nullptr;
}
16 changes: 12 additions & 4 deletions plugins/realsense/src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@

#include <QObject>
#include "plugins/VideoSourceInterface.h"
#include "plugins/PointCloudSourceInterface.h"

class RealSensePlugin : public QObject, public VideoSourceInterface
class RealSensePlugin : public QObject, public VideoSourceInterface, public PointCloudSourceInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID VideoSourceInterface_iid)
Q_INTERFACES(VideoSourceInterface)
Q_PLUGIN_METADATA(IID "io.stateoftheart.handy3dscanner.plugins.RealSensePlugin")
Q_INTERFACES(VideoSourceInterface PointCloudSourceInterface)

public:
~RealSensePlugin() override {}
QString name() const override;

// PluginInterface
QLatin1String name() const override;
QStringList requirements() const override;
bool init() override;
bool configure() override;

// VideoSourceInterface
QStringList getAvailableStreams() const override;

// PointCloudSourceInterface
uint8_t* getPCData() const override;
};
#endif // REALSENSEPLUGIN_H

0 comments on commit 756d5ae

Please sign in to comment.