allow registering json handlers in experience plugins
This commit is contained in:
parent
fab1871ea1
commit
f8d23db584
@ -11,10 +11,14 @@
|
|||||||
|
|
||||||
namespace nymeaserver {
|
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()) {
|
foreach (const QString &path, pluginSearchDirs()) {
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
qCDebug(dcExperiences) << "Loading experience plugins from:" << dir.absolutePath();
|
qCDebug(dcExperiences) << "Loading experience plugins from:" << dir.absolutePath();
|
||||||
@ -69,6 +73,10 @@ void ExperienceManager::loadExperiencePlugin(const QString &file)
|
|||||||
plugin->setParent(this);
|
plugin->setParent(this);
|
||||||
|
|
||||||
m_plugins.append(plugin);
|
m_plugins.append(plugin);
|
||||||
|
|
||||||
|
foreach (JsonHandler *handler, plugin->jsonHandlers()) {
|
||||||
|
m_jsonRpcServer->registerHandler(handler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,9 +19,15 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void loadPlugins();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList pluginSearchDirs() const;
|
QStringList pluginSearchDirs() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
JsonRPCServer *m_jsonRpcServer = nullptr;
|
||||||
|
|
||||||
void loadExperiencePlugin(const QString &file);
|
void loadExperiencePlugin(const QString &file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
|||||||
@ -3,15 +3,21 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class ExperiencePlugin : public JsonHandler
|
class JsonHandler;
|
||||||
|
|
||||||
|
class ExperiencePlugin : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ExperiencePlugin(QObject *parent = nullptr);
|
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")
|
Q_DECLARE_INTERFACE(ExperiencePlugin, "io.nymea.ExperiencePlugin")
|
||||||
|
|||||||
Reference in New Issue
Block a user