]> vaikene.ee Git - evaf/blobdiff - src/libs/Plugins/pluginmanager_p.h
First implementation of the Plugin manager library.
[evaf] / src / libs / Plugins / pluginmanager_p.h
diff --git a/src/libs/Plugins/pluginmanager_p.h b/src/libs/Plugins/pluginmanager_p.h
new file mode 100644 (file)
index 0000000..1fbdad0
--- /dev/null
@@ -0,0 +1,228 @@
+/**
+ * @file plugins/pluginmanager_p.h
+ * @brief Private implementation of the plugin manager
+ *
+ * Copyright (c) 2011 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#ifndef __PLUGINS_PLUGINMANAGER_P_H
+#define __PLUGINS_PLUGINMANAGER_P_H
+
+#include <QObject>
+#include <QSharedData>
+#include <QExplicitlySharedDataPointer>
+#include <QPluginLoader>
+
+namespace eVaf {
+namespace Plugins {
+
+class iPlugin;
+class iPluginFactory;
+
+namespace Internal {
+
+class Plugin;
+class Module;
+
+/**
+ * Internal implementation of the plugin manager
+ */
+class PluginManagerPrivate : public QObject
+{
+    Q_OBJECT
+
+public:
+
+    /// Ctr.
+    PluginManagerPrivate();
+
+    /// Dtr.
+    virtual ~PluginManagerPrivate();
+
+    /**
+     * Initializes the private plugin manager object
+     * @return True; false if failed
+     */
+    bool init();
+
+    /**
+     * Finalizes the private plugin manager object
+     */
+    void done();
+
+    /**
+     * Loads and initializes plugins
+     * @return True; false if failed
+     */
+    bool loadPlugins();
+
+    /**
+     * Finalizes and unloads plugins
+     */
+    void unloadPlugins();
+
+
+private: // Members
+
+    /// List of all the modules
+    QList<QExplicitlySharedDataPointer<Module> > mModules;
+
+    /// List of all the plugins
+    QList<QExplicitlySharedDataPointer<Plugin> > mPlugins;
+
+
+private: // Methods
+
+    /**
+     * Returns the module object by its name
+     * @param name Name of the module
+     * @return Module object or 0 if not found
+     */
+    Module * moduleByName(QString const & name) const;
+
+    /**
+     * Loads the Qt plugin
+     * @param Name of the Qt plugin
+     * @return True; false if failed
+     */
+    bool loadQtPlugin(QString const & name) const;
+
+};
+
+/**
+ * One external module implementing the iPluginFactory or the iPlugin interfaces.
+ *
+ * This class is a wrapper around the external module.
+ */
+class Module : public QSharedData
+{
+public:
+
+    /**
+     * Ctr.
+     * @param name Name of the module
+     */
+    Module(QString const & name);
+
+    /// Dtr.
+    ~Module();
+
+    /// Returns true if the module is loaded
+    bool isLoaded() const { return mLoader != 0; }
+
+    /// The name of the module
+    QString const & name() const { return mName; }
+
+    /**
+     * Loads the module
+     * @return True; false if failed
+     */
+    bool load();
+
+    /// Unloads the module
+    void unload();
+
+    /**
+     * Creates the requested iPlugin interface object
+     * @param name Name of the interface
+     * @return The iPlugin interface object or 0 if failed
+     */
+    iPlugin * create(QString const & name);
+
+
+private: // Members
+
+    /// Name of the module
+    QString mName;
+
+    /// Plugin loader
+    QPluginLoader * mLoader;
+
+    /// Plugin's root component
+    QObject * mRoot;
+
+    /// The iPlugin interface object if the module implements only one iPlugin interface
+    iPlugin * mPlugin;
+
+    /// The iPluginFactory interface object if the module implements more than one iPluginFactory interface
+    iPluginFactory * mPluginFactory;
+
+};
+
+/**
+ * One iPlugin interface object.
+ *
+ * This class is a wrapper around the plugin.
+ */
+class Plugin : public QSharedData
+{
+public:
+
+    /**
+     * Ctr.
+     * @param module The Module implementing this iPlugin interface
+     * @param name Name of the plugin
+     * @param args Arguments for the plugin initialization
+     */
+    Plugin(Module * module, QString const & name, QString const & args);
+
+    /// Dtr.
+    ~Plugin();
+
+    /// The iPlugin interface
+    iPlugin * plugin() const { return mPlugin; }
+
+    /// The name of the plugin
+    QString const & name() const { return mName; }
+
+    /**
+     * Loads the plugin
+     * @return True; false if failed
+     */
+    bool load();
+
+    /// Unloads the plugin
+    void unload();
+
+    /**
+     * Initializes the plugin
+     * @return True; false if failed
+     */
+    bool init();
+
+    /// Uninitializes the plugin
+    void done();
+
+
+private: // Members
+
+    /// Module implementing this iPlugin interface
+    Module * mModule;
+
+    /// Name of the plugin
+    QString mName;
+
+    /// Arguments for the initialization
+    QString mArgs;
+
+    /// The iPlugin interface object
+    iPlugin * mPlugin;
+
+};
+
+} // namespace eVaf::Plugins::Internal
+} // namespace eVaf::Plugins
+} // namespace eVaf
+
+#endif // pluginmanager_p.h