diff options
author | Marja Hassinen <ext-marja.2.hassinen@nokia.com> | 2009-09-10 16:00:14 +0300 |
---|---|---|
committer | Marja Hassinen <ext-marja.2.hassinen@nokia.com> | 2009-09-10 16:00:14 +0300 |
commit | fb4078667c37cb66a459209fb2b5837ce5128770 (patch) | |
tree | 1e56fc8845bf97c835ee8037cc362d1a5b26d3ea | |
parent | 5cc2564bd4360d38e21eead4aca08167972eeb0f (diff) |
libcontextsubscriber plugins: Draft implementation of the plugin loading system.
-rw-r--r-- | libcontextsubscriber/src/provider.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libcontextsubscriber/src/provider.cpp b/libcontextsubscriber/src/provider.cpp index c5e8b931..c39963bd 100644 --- a/libcontextsubscriber/src/provider.cpp +++ b/libcontextsubscriber/src/provider.cpp @@ -29,6 +29,7 @@ #include <QMutexLocker> #include <QCoreApplication> #include <QThread> +#include <QLibrary> namespace ContextSubscriber { @@ -91,6 +92,8 @@ namespace ContextSubscriber { \brief Emitted when the subscription procedure for \c keys finished (either succeeded, either failed) */ +typedef IProviderPlugin* (*PluginFactoryFunc)(const QString& constructionString); + /// Stores the passed plugin name and construction paramater, then /// moves into the main thread and queues a constructPlugin call. Provider::Provider(const QString &plugin, const QString &constructionString) @@ -111,7 +114,23 @@ void Provider::constructPlugin() { if (pluginName == "contextkit-dbus") { plugin = contextKitPluginFactory(constructionString); - } else ; // FIXME: implement plugin system in the else branch + } + else { + QLibrary library(pluginName); + library.load(); + if (library.isLoaded() == false) { + contextCritical() << "Error loading library:" << library.errorString(); + } + else { + PluginFactoryFunc factory = (PluginFactoryFunc) library.resolve("pluginFactory"); + if (factory) { + contextDebug() << "Resolved factory function"; + plugin = factory(constructionString); + } else { + contextCritical() << "Cannot resolve factory function pluginFactory"; + } + } + } if (plugin == 0) { pluginState = FAILED; |