dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pluginmanager.h
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  */
29 
30 #ifndef EXTENSIONSYSTEM_PLUGINMANAGER_H
31 #define EXTENSIONSYSTEM_PLUGINMANAGER_H
32 
33 #include "extensionsystem_global.h"
34 #include <aggregation/aggregate.h>
35 
36 #include <QtCore/QObject>
37 #include <QtCore/QStringList>
38 #include <QtCore/QReadWriteLock>
39 
40 QT_BEGIN_NAMESPACE
41 class QTextStream;
42 QT_END_NAMESPACE
43 
44 namespace ExtensionSystem {
45 
46 namespace Internal {
47  class PluginManagerPrivate;
48 }
49 
50 class IPlugin;
51 class PluginSpec;
52 
53 class EXTENSIONSYSTEM_EXPORT PluginManager : public QObject
54 {
55  Q_DISABLE_COPY(PluginManager)
56  Q_OBJECT
57 
58 public:
59  static PluginManager *instance();
60  bool allPluginsLoaded(){return m_allPluginsLoaded;}
61  PluginManager();
62  virtual ~PluginManager();
63 
64  // Object pool operations
65  void addObject(QObject *obj);
66  void removeObject(QObject *obj);
67  QList<QObject *> allObjects() const;
68  template <typename T> QList<T *> getObjects() const
69  {
70  QReadLocker lock(&m_lock);
72  QList<QObject *> all = allObjects();
73  QList<T *> result;
74  foreach (QObject *obj, all) {
75  result = Aggregation::query_all<T>(obj);
76  if (!result.isEmpty())
77  results += result;
78  }
79  return results;
80  }
81  template <typename T> T *getObject() const
82  {
83  QReadLocker lock(&m_lock);
84  QList<QObject *> all = allObjects();
85  T *result = nullptr;
86  foreach (QObject *obj, all) {
87  if ((result = Aggregation::query<T>(obj)) != nullptr)
88  break;
89  }
90  return result;
91  }
92 
93  // Plugin operations
94  void loadPlugins();
95  QStringList pluginPaths() const;
96  void setPluginPaths(const QStringList &paths);
97  QList<PluginSpec *> plugins() const;
98  void setFileExtension(const QString &extension);
99  QString fileExtension() const;
100 
101  // command line arguments
102  QStringList arguments() const;
103  QStringList parseOptions(QStringList pluginOptions, QStringList pluginTests, QStringList pluginNoLoad);
104  void formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation) const;
105  void formatPluginVersions(QTextStream &str) const;
106 
107  bool runningTests() const;
108  QString testDataDirectory() const;
109 
110 signals:
111  void objectAdded(QObject *obj);
112  void aboutToRemoveObject(QObject *obj);
113 
114  void pluginsChanged();
115  void pluginsLoadEnded();
116  void splashMessages(QString);
117 
118  void hideSplash();
119  void showSplash();
120 private slots:
121  void startTests();
122 
123 private:
125  static PluginManager *m_instance;
126  mutable QReadWriteLock m_lock;
127  bool m_allPluginsLoaded;
128 
130 };
131 
132 } // namespace ExtensionSystem
133 
134 #endif // EXTENSIONSYSTEM_PLUGINMANAGER_H
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
end function found on Matlab s file exchange The two functions return identical results