pluginmanager_p.h 5.03 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
Eike Ziller's avatar
Eike Ziller committed
13 14
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
hjk's avatar
hjk committed
25 26
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

con's avatar
con committed
31 32 33 34 35
#ifndef PLUGINMANAGER_P_H
#define PLUGINMANAGER_P_H

#include "pluginspec.h"

36 37 38 39
#include <QSet>
#include <QStringList>
#include <QObject>
#include <QScopedPointer>
40
#include <QReadWriteLock>
41 42 43

QT_BEGIN_NAMESPACE
class QTime;
44
class QTimer;
45
class QSettings;
Friedemann Kleint's avatar
Friedemann Kleint committed
46
class QEventLoop;
47
QT_END_NAMESPACE
con's avatar
con committed
48 49 50 51

namespace ExtensionSystem {

class PluginManager;
52
class PluginCollection;
con's avatar
con committed
53 54 55 56 57

namespace Internal {

class PluginSpecPrivate;

58
class EXTENSIONSYSTEM_EXPORT PluginManagerPrivate : QObject
con's avatar
con committed
59
{
60
    Q_OBJECT
con's avatar
con committed
61 62 63 64 65 66 67 68 69 70
public:
    PluginManagerPrivate(PluginManager *pluginManager);
    virtual ~PluginManagerPrivate();

    // Object pool operations
    void addObject(QObject *obj);
    void removeObject(QObject *obj);

    // Plugin operations
    void loadPlugins();
71
    void shutdown();
con's avatar
con committed
72 73 74 75
    void setPluginPaths(const QStringList &paths);
    QList<PluginSpec *> loadQueue();
    void loadPlugin(PluginSpec *spec, PluginSpec::State destState);
    void resolveDependencies();
76
    void initProfiling();
77
    void profilingSummary() const;
78
    void profilingReport(const char *what, const PluginSpec *spec = 0);
79
    void setSettings(QSettings *settings);
80
    void setGlobalSettings(QSettings *settings);
81
    void readSettings();
82
    void writeSettings();
83
    void disablePluginIndirectly(PluginSpec *spec);
con's avatar
con committed
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    class TestSpec {
    public:
        TestSpec(PluginSpec *pluginSpec, const QStringList &testFunctions = QStringList())
            : pluginSpec(pluginSpec), testFunctions(testFunctions) {}
        PluginSpec *pluginSpec;
        QStringList testFunctions;
    };

    bool containsTestSpec(PluginSpec *pluginSpec) const
    {
        foreach (const TestSpec &testSpec, testSpecs) {
            if (testSpec.pluginSpec == pluginSpec)
                return true;
        }
        return false;
    }

102
    QHash<QString, PluginCollection *> pluginCategories;
103
    QList<PluginSpec *> pluginSpecs;
104
    QList<TestSpec> testSpecs;
con's avatar
con committed
105
    QStringList pluginPaths;
106
    QString pluginIID;
con's avatar
con committed
107
    QList<QObject *> allObjects; // ### make this a QList<QPointer<QObject> > > ?
108 109
    QStringList defaultDisabledPlugins; // Plugins/Ignored from install settings
    QStringList defaultEnabledPlugins; // Plugins/ForceEnabled from install settings
con's avatar
con committed
110
    QStringList disabledPlugins;
111
    QStringList forceEnabledPlugins;
112 113 114 115
    // delayed initialization
    QTimer *delayedInitializeTimer;
    QList<PluginSpec *> delayedInitializeQueue;
    // ansynchronous shutdown
116 117
    QList<PluginSpec *> asynchronousPlugins; // plugins that have requested async shutdown
    QEventLoop *shutdownEventLoop; // used for async shutdown
con's avatar
con committed
118 119

    QStringList arguments;
120
    QScopedPointer<QTime> m_profileTimer;
121
    QHash<const PluginSpec *, int> m_profileTotal;
122
    int m_profileElapsedMS;
123
    unsigned m_profilingVerbosity;
124
    QSettings *settings;
125
    QSettings *globalSettings;
con's avatar
con committed
126 127 128 129 130 131 132 133

    // Look in argument descriptions of the specs for the option.
    PluginSpec *pluginForOption(const QString &option, bool *requiresArgument) const;
    PluginSpec *pluginByName(const QString &name) const;

    // used by tests
    static PluginSpec *createSpec();
    static PluginSpecPrivate *privateSpec(PluginSpec *spec);
134

135 136
    mutable QReadWriteLock m_lock;

137
private slots:
138
    void nextDelayedInitialize();
139 140
    void asyncShutdownFinished();

con's avatar
con committed
141
private:
142
    PluginCollection *defaultCollection;
con's avatar
con committed
143 144 145 146 147 148 149
    PluginManager *q;

    void readPluginPaths();
    bool loadQueue(PluginSpec *spec,
            QList<PluginSpec *> &queue,
            QList<PluginSpec *> &circularityCheckQueue);
    void stopAll();
150
    void deleteAll();
con's avatar
con committed
151 152 153 154 155 156
};

} // namespace Internal
} // namespace ExtensionSystem

#endif // PLUGINMANAGER_P_H