swift
pluginmanager.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_CORE_PLUGIN_MANAGER_H
7 #define SWIFT_CORE_PLUGIN_MANAGER_H
8 
9 #include <QJsonObject>
10 #include <QMap>
11 #include <QObject>
12 #include <QString>
13 
14 #include "core/swiftcoreexport.h"
15 #include "misc/sequence.h"
16 
17 namespace swift::core
18 {
23  class SWIFT_CORE_EXPORT IPluginManager : public QObject
24  {
25  Q_OBJECT
26 
27  public:
29  IPluginManager(QObject *parent = nullptr);
30 
32  virtual void collectPlugins();
33 
37  QString getPluginConfigId(const QString &identifier);
38 
41  template <class T>
42  T *getPluginById(const QString &identifier)
43  {
44  return qobject_cast<T *>(getPluginByIdImpl(identifier));
45  }
46 
47  protected:
50 
53  virtual const QString &pluginDirectory() const;
54 
60  virtual bool isValid(const QJsonObject &metadata) const;
61 
63  QString pluginIdentifier(const QJsonObject &metadata) const;
64 
66  QString getIdByPlugin(const QObject *instance) const;
67 
69  const swift::misc::CSequence<QJsonObject> &getPlugins() const { return m_metadata; }
70 
71  private:
73  bool tryLoad(const QString &path);
74 
77  QObject *getPluginByIdImpl(const QString &identifier);
78 
80  QMap<QString, QString> m_paths;
81  QMap<QString, QObject *> m_instances;
82  QMap<QString, QString> m_configs;
83  QMap<const QObject *, QString> m_instanceIds;
84  };
85 } // namespace swift::core
86 
87 #endif // SWIFT_CORE_PLUGIN_MANAGER_H
Base class for all contexts that provide plugin support.
Definition: pluginmanager.h:24
const swift::misc::CSequence< QJsonObject > & getPlugins() const
Gets direct access to all plugins' metadata.
Definition: pluginmanager.h:69
T * getPluginById(const QString &identifier)
Loads the given plugin (if necessary), casts it to the desired type and returns its instance....
Definition: pluginmanager.h:42
virtual swift::misc::CSequence< QString > acceptedIids() const =0
Returns the list of valid IIDs for the implementation.
Generic sequential container with value semantics.
Definition: sequence.h:86
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
#define SWIFT_CORE_EXPORT
Export a class or function from the library.