##// END OF EJS Templates
Adds logs in plugin loading method
Alexandre Leroux -
r68:b0fc434fbc92
parent child
Show More
@@ -16,6 +16,38 const auto PLUGIN_METADATA_KEY = QStringLiteral("MetaData");
16 16 /// Key for retrieving the name of the plugin in its metadata
17 17 const auto PLUGIN_NAME_KEY = QStringLiteral("name");
18 18
19 /// Helper to state the plugin loading operation
20 struct LoadPluginState {
21 explicit LoadPluginState(const QString &pluginPath)
22 : m_PluginPath{pluginPath}, m_Valid{true}, m_ErrorMessage{}
23 {
24 }
25
26 void log() const
27 {
28 if (m_Valid) {
29 qCDebug(LOG_PluginManager())
30 << QObject::tr("File '%1' has been loaded as a plugin").arg(m_PluginPath);
31 }
32 else {
33 qCWarning(LOG_PluginManager())
34 << QObject::tr("File '%1' can't be loaded as a plugin: %2")
35 .arg(m_PluginPath)
36 .arg(m_ErrorMessage);
37 }
38 }
39
40 void setError(const QString &errorMessage)
41 {
42 m_Valid = false;
43 m_ErrorMessage = errorMessage;
44 }
45
46 QString m_PluginPath;
47 bool m_Valid;
48 QString m_ErrorMessage;
49 };
50
19 51 } // namespace
20 52
21 53 struct PluginManager::PluginManagerPrivate {
@@ -29,6 +61,8 struct PluginManager::PluginManagerPrivate {
29 61 qCDebug(LOG_PluginManager())
30 62 << QObject::tr("Attempting to load file '%1' as a plugin").arg(pluginPath);
31 63
64 LoadPluginState loadState{pluginPath};
65
32 66 if (QLibrary::isLibrary(pluginPath)) {
33 67 QPluginLoader pluginLoader{pluginPath};
34 68
@@ -38,10 +72,10 struct PluginManager::PluginManagerPrivate {
38 72 auto pluginName = metadata.value(PLUGIN_NAME_KEY).toString();
39 73
40 74 if (pluginName.isEmpty()) {
41 /// @todo ALX : log error
75 loadState.setError(QObject::tr("empty file name"));
42 76 }
43 77 else if (m_RegisteredPlugins.contains(pluginName)) {
44 /// @todo ALX : log error
78 loadState.setError(QObject::tr("name '%1' already registered").arg(pluginName));
45 79 }
46 80 else {
47 81 if (auto pluginInstance = qobject_cast<IPlugin *>(pluginLoader.instance())) {
@@ -49,13 +83,16 struct PluginManager::PluginManagerPrivate {
49 83 m_RegisteredPlugins.insert(pluginName, pluginPath);
50 84 }
51 85 else {
52 /// @todo ALX : log error
86 loadState.setError(QObject::tr("the file is not a Sciqlop plugin"));
53 87 }
54 88 }
55 89 }
56 90 else {
57 /// @todo ALX : log error
91 loadState.setError(QObject::tr("the file is not a library"));
58 92 }
93
94 // Log loading result
95 loadState.log();
59 96 }
60 97
61 98 /// Registered plugins (key: plugin name, value: plugin path)
General Comments 5
Under Review
author

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 1 added
  * 0 removed

Changed files:
  * M core/CMakeLists.txt
Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now