allow registering json handlers in experience plugins
This commit is contained in:
parent
fab1871ea1
commit
f8d23db584
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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>
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user