LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / libs / extensionsystem / pluginmanager.h
blob215ae4e0f3aee5671647942775fc221afab7eba8
1 /**
2 ******************************************************************************
4 * @file pluginmanager.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @brief
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup
10 * @{
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef EXTENSIONSYSTEM_PLUGINMANAGER_H
30 #define EXTENSIONSYSTEM_PLUGINMANAGER_H
32 #include "extensionsystem_global.h"
33 #include <aggregation/aggregate.h>
35 #include <QtCore/QObject>
36 #include <QtCore/QStringList>
37 #include <QtCore/QReadWriteLock>
39 QT_BEGIN_NAMESPACE
40 class QTextStream;
41 QT_END_NAMESPACE
43 namespace ExtensionSystem {
44 namespace Internal {
45 class PluginManagerPrivate;
48 class IPlugin;
49 class PluginSpec;
51 class EXTENSIONSYSTEM_EXPORT PluginManager : public QObject {
52 Q_DISABLE_COPY(PluginManager)
53 Q_OBJECT
55 public:
56 static PluginManager *instance();
57 bool allPluginsLoaded()
59 return m_allPluginsLoaded;
61 PluginManager();
62 virtual ~PluginManager();
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
70 QReadLocker lock(&m_lock);
72 QList<T *> results;
73 QList<QObject *> all = allObjects();
74 QList<T *> result;
75 foreach(QObject * obj, all) {
76 result = Aggregation::query_all<T>(obj);
77 if (!result.isEmpty()) {
78 results += result;
81 return results;
83 template <typename T> T *getObject() const
85 QReadLocker lock(&m_lock);
87 QList<QObject *> all = allObjects();
88 T *result = 0;
89 foreach(QObject * obj, all) {
90 if ((result = Aggregation::query<T>(obj)) != 0) {
91 break;
94 return result;
97 // Plugin operations
98 void loadPlugins();
99 QStringList pluginPaths() const;
100 void setPluginPaths(const QStringList &paths);
101 QList<PluginSpec *> plugins() const;
102 void setFileExtension(const QString &extension);
103 QString fileExtension() const;
105 // command line arguments
106 QStringList arguments() const;
107 bool parseOptions(const QStringList &args,
108 const QMap<QString, bool> &appOptions,
109 QMap<QString, QString> *foundAppOptions,
110 QString *errorString);
111 static void formatOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
112 void formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation) const;
113 void formatPluginVersions(QTextStream &str) const;
115 bool runningTests() const;
116 QString testDataDirectory() const;
118 signals:
119 void objectAdded(QObject *obj);
120 void aboutToRemoveObject(QObject *obj);
122 void pluginAboutToBeLoaded(ExtensionSystem::PluginSpec *pluginSpec);
123 void pluginsChanged();
124 void pluginsLoadEnded();
125 private slots:
126 void startTests();
128 private:
129 Internal::PluginManagerPrivate *d;
130 static PluginManager *m_instance;
131 mutable QReadWriteLock m_lock;
132 bool m_allPluginsLoaded;
134 friend class Internal::PluginManagerPrivate;
136 } // namespace ExtensionSystem
138 #endif // EXTENSIONSYSTEM_PLUGINMANAGER_H