diff options
author | Yordan Karadzhov (VMware) <y.karadz@gmail.com> | 2022-02-11 14:09:56 +0200 |
---|---|---|
committer | Yordan Karadzhov (VMware) <y.karadz@gmail.com> | 2022-02-16 10:06:09 +0200 |
commit | e35970770b71f0cc849870512a806dff96bf19e1 (patch) | |
tree | ac54e28c8a8417df61d6c0e291b3b986ea8678de | |
parent | 59b5763c7c52b703e3b8e05be801f7c85365c9d3 (diff) | |
download | kernel-shark-e35970770b71f0cc849870512a806dff96bf19e1.tar.gz |
kernel-shark: Load 'ctrl' interface for user plugins
Currently, the 'ctrl' interface of all plugins gets called in the
constructor of the MainWindow widget. This works well for the built-in
plugins because the list of those plugins is known in advance. However,
the list of user plugins is populated dynamically, hence it is not known
by the time the constructor of the widget is called. The problem is
solved by making sure we call the 'ctrl' interface every time we load
a user plugin from the menus of the GUI or at start as a command line
option.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
-rw-r--r-- | src/KsUtils.cpp | 35 | ||||
-rw-r--r-- | src/KsUtils.hpp | 2 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/KsUtils.cpp b/src/KsUtils.cpp index a22c445d..e3e16ae5 100644 --- a/src/KsUtils.cpp +++ b/src/KsUtils.cpp @@ -1190,6 +1190,20 @@ QVector<int> KsPluginManager::getPluginsByStatus(int sd, int status) const return vec; } +void KsPluginManager::_registerCtrlInterface(kshark_plugin_list *plugin) +{ + if (!plugin->handle || !plugin->ctrl_interface) + return; + + void *dialogPtr = plugin->ctrl_interface(parent()); + if (dialogPtr) { + QWidget *dialog = static_cast<QWidget *>(dialogPtr); + + if (dialog && _pluginDialogs.indexOf(dialog) < 0) + _pluginDialogs.append(dialog); + } +} + /** * @brief Loop over the registered plugins and register all plugin-defined * menus (if any). @@ -1203,14 +1217,7 @@ void KsPluginManager::registerPluginMenues() return; for (plugin = kshark_ctx->plugins; plugin; plugin = plugin->next) - if (plugin->handle && plugin->ctrl_interface) { - void *dialogPtr = plugin->ctrl_interface(parent()); - if (dialogPtr) { - QWidget *dialog = - static_cast<QWidget *>(dialogPtr); - _pluginDialogs.append(dialog); - } - } + _registerCtrlInterface(plugin); } std::string KsPluginManager::_pluginLibFromName(const QString &plugin) @@ -1247,11 +1254,17 @@ std::string KsPluginManager::_pluginNameFromLib(const QString &plugin) * @param pluginNames: Provide here the names of the plugin (as in the * CMake-generated header file) or the names of the * plugin's library files (.so including path). - * The names must be comma separated. + * The names must be comma separated. */ void KsPluginManager::registerPlugins(const QString &pluginNames) { - _userPlugins.append(_loadPluginList(pluginNames.split(','))); + QVector<kshark_plugin_list *> plugins; + + plugins = _loadPluginList(pluginNames.split(',')); + for (auto const &p: plugins) + _registerCtrlInterface(p); + + _userPlugins.append(plugins); } /** @@ -1369,6 +1382,8 @@ void KsPluginManager::addPlugins(const QStringList &fileNames, return; plugins = _loadPluginList(fileNames); + for (auto const &p: plugins) + _registerCtrlInterface(p); _userPlugins.append(plugins); if (streamIds.isEmpty()) diff --git a/src/KsUtils.hpp b/src/KsUtils.hpp index 1a97d9ea..e42b6da0 100644 --- a/src/KsUtils.hpp +++ b/src/KsUtils.hpp @@ -330,6 +330,8 @@ private: QVector<kshark_plugin_list *> _loadPluginList(const QStringList &plugins); + void _registerCtrlInterface(kshark_plugin_list *plugin); + std::string _pluginLibFromName(const QString &plugin); std::string _pluginNameFromLib(const QString &plugin); |