diff mbox series

[2/2] kernel-shark: Load 'ctrl' interface for user plugins

Message ID 20220216082909.614231-3-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit e35970770b71f0cc849870512a806dff96bf19e1
Headers show
Series kernel-shark: Fixes needed by the Xenomai plugin | expand

Commit Message

Yordan Karadzhov Feb. 16, 2022, 8:29 a.m. UTC
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.

Reported-by: Hongzhan Chen <hongzhan.chen@intel.com>
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsUtils.cpp | 35 +++++++++++++++++++++++++----------
 src/KsUtils.hpp |  2 ++
 2 files changed, 27 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/src/KsUtils.cpp b/src/KsUtils.cpp
index a22c445..e3e16ae 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 1a97d9e..e42b6da 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);