allow registering json handlers in experience plugins

This commit is contained in:
Michael Zanetti 2019-10-22 20:53:37 +02:00
parent fab1871ea1
commit f8d23db584
4 changed files with 35 additions and 5 deletions

View File

@ -11,10 +11,14 @@
namespace nymeaserver {
ExperienceManager::ExperienceManager(JsonRPCServer *jsonRpcServer, QObject *parent) : QObject(parent)
ExperienceManager::ExperienceManager(JsonRPCServer *jsonRpcServer, QObject *parent) : QObject(parent),
m_jsonRpcServer(jsonRpcServer)
{
// jsonRpcServer->registerHandler();
staticMetaObject.invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
}
void ExperienceManager::loadPlugins()
{
foreach (const QString &path, pluginSearchDirs()) {
QDir dir(path);
qCDebug(dcExperiences) << "Loading experience plugins from:" << dir.absolutePath();
@ -69,6 +73,10 @@ void ExperienceManager::loadExperiencePlugin(const QString &file)
plugin->setParent(this);
m_plugins.append(plugin);
foreach (JsonHandler *handler, plugin->jsonHandlers()) {
m_jsonRpcServer->registerHandler(handler);
}
}
}

View File

@ -19,9 +19,15 @@ signals:
public slots:
private slots:
void loadPlugins();
private:
QStringList pluginSearchDirs() const;
private:
JsonRPCServer *m_jsonRpcServer = nullptr;
void loadExperiencePlugin(const QString &file);
private:

View File

@ -4,3 +4,13 @@ ExperiencePlugin::ExperiencePlugin(QObject *parent) : QObject(parent)
{
}
QList<JsonHandler *> ExperiencePlugin::jsonHandlers() const
{
return m_jsonHandlers;
}
void ExperiencePlugin::registerJsonHandler(JsonHandler *handler)
{
m_jsonHandlers.append(handler);
}

View File

@ -3,15 +3,21 @@
#include <QObject>
class ExperiencePlugin : public JsonHandler
class JsonHandler;
class ExperiencePlugin : public QObject
{
Q_OBJECT
public:
explicit ExperiencePlugin(QObject *parent = nullptr);
signals:
QList<JsonHandler*> jsonHandlers() const;
public slots:
protected:
void registerJsonHandler(JsonHandler *handler);
private:
QList<JsonHandler*> m_jsonHandlers;
};
Q_DECLARE_INTERFACE(ExperiencePlugin, "io.nymea.ExperiencePlugin")