Provide plugin load state

This commit is contained in:
Dale Glass 2023-11-12 20:08:47 +01:00
parent 1de6e6d418
commit 111cea477d
3 changed files with 95 additions and 8 deletions

View file

@ -370,6 +370,17 @@ int main(int argc, const char* argv[]) {
if (parser.isSet(getPluginsOption)) {
auto pluginManager = PluginManager::getInstance();
QJsonObject pluginsJson;
for (const auto &plugin : pluginManager->getPluginInfo()) {
QJsonObject data;
data["data"] = plugin.metaData;
data["loaded"] = plugin.loaded;
data["disabled"] = plugin.disabled;
data["filteredOut"] = plugin.filteredOut;
data["wrongVersion"] = plugin.wrongVersion;
pluginsJson[plugin.name] = data;
}
QJsonObject inputJson;
for (const auto &plugin : pluginManager->getInputPlugins()) {
QJsonObject data;
@ -406,15 +417,16 @@ int main(int argc, const char* argv[]) {
codecsJson[plugin->getName()] = data;
}
QJsonObject staticJson;
staticJson["steamAvailable"] = (pluginManager->getSteamClientPlugin() != nullptr);
staticJson["oculusAvailable"] = (pluginManager->getOculusPlatformPlugin() != nullptr);
QJsonObject platformsJson;
platformsJson["steamAvailable"] = (pluginManager->getSteamClientPlugin() != nullptr);
platformsJson["oculusAvailable"] = (pluginManager->getOculusPlatformPlugin() != nullptr);
QJsonObject root;
root["input"] = inputJson;
root["display"] = displayJson;
root["codec"] = codecsJson;
root["staticPlugins"] = staticJson;
root["plugins"] = pluginsJson;
root["inputs"] = inputJson;
root["displays"] = displayJson;
root["codecs"] = codecsJson;
root["platforms"] = platformsJson;
std::cout << QJsonDocument(root).toJson().toStdString() << "\n";

View file

@ -72,12 +72,12 @@ int getPluginInterfaceVersionFromMetaData(const QJsonObject& object) {
QStringList preferredDisplayPlugins;
QStringList disabledDisplays;
QStringList disabledInputs;
std::vector<PluginManager::PluginInfo> pluginInfo;
bool isDisabled(QJsonObject metaData) {
auto name = getPluginNameFromMetaData(metaData);
auto iid = getPluginIIDFromMetaData(metaData);
qDebug() << "Name = " << name << "; iid =" << iid;
if (iid == DisplayProvider_iid || iid == SteamClientProvider_iid || iid == OculusPlatformProvider_iid) {
return disabledDisplays.contains(name);
} else if (iid == InputProvider_iid) {
@ -127,18 +127,28 @@ int PluginManager::instantiate() {
qCDebug(plugins) << "Attempting plugin" << qPrintable(plugin);
auto loader = QSharedPointer<QPluginLoader>::create(pluginPath + plugin);
const QJsonObject pluginMetaData = loader->metaData();
PluginInfo info;
info.name = plugin;
info.metaData = pluginMetaData;
#if defined(HIFI_PLUGINMANAGER_DEBUG)
QJsonDocument metaDataDoc(pluginMetaData);
qCInfo(plugins) << "Metadata for " << qPrintable(plugin) << ": " << QString(metaDataDoc.toJson());
#endif
if (isDisabled(pluginMetaData)) {
qCWarning(plugins) << "Plugin" << qPrintable(plugin) << "is disabled";
info.disabled = true;
pluginInfo.push_back(info);
// Skip this one, it's disabled
continue;
}
if (!_pluginFilter(pluginMetaData)) {
qCDebug(plugins) << "Plugin" << qPrintable(plugin) << "doesn't pass provided filter";
info.filteredOut = true;
pluginInfo.push_back(info);
continue;
}
@ -146,16 +156,22 @@ int PluginManager::instantiate() {
qCWarning(plugins) << "Plugin" << qPrintable(plugin) << "interface version doesn't match, not loading:"
<< getPluginInterfaceVersionFromMetaData(pluginMetaData)
<< "doesn't match" << HIFI_PLUGIN_INTERFACE_VERSION;
info.wrongVersion = true;
pluginInfo.push_back(info);
continue;
}
if (loader->load()) {
qCDebug(plugins) << "Plugin" << qPrintable(plugin) << "loaded successfully";
info.loaded = true;
loadedPlugins.push_back(loader);
} else {
qCDebug(plugins) << "Plugin" << qPrintable(plugin) << "failed to load:";
qCDebug(plugins) << " " << qPrintable(loader->errorString());
}
pluginInfo.push_back(info);
}
} else {
qWarning() << "pluginPath does not exit..." << pluginDir;
@ -164,6 +180,11 @@ int PluginManager::instantiate() {
return loadedPlugins;
}
std::vector<PluginManager::PluginInfo> PluginManager::getPluginInfo() const {
getLoadedPlugins(); // This builds the pluginInfo list
return pluginInfo;
}
const CodecPluginList& PluginManager::getCodecPlugins() {
static CodecPluginList codecPlugins;
static std::once_flag once;

View file

@ -12,6 +12,8 @@
#include <DependencyManager.h>
#include <SettingHandle.h>
#include <QJsonDocument>
#include <QJsonObject>
#include "Forward.h"
@ -39,6 +41,49 @@ class PluginManager : public QObject, public Dependency {
Q_OBJECT
public:
/**
* @brief Information about known plugins
*
*/
struct PluginInfo {
/**
* @brief Plugin metadata
*/
QJsonObject metaData;
/**
* @brief Filename
*
*/
QString name;
/**
* @brief Whether the plugin has been disabled
*
*/
bool disabled = false;
/**
* @brief Whether the plugin has been filtered out by a filter
*
*/
bool filteredOut = false;
/**
* @brief Whether the plugin has been not loaded because it's the wrong version
*
*/
bool wrongVersion = false;
/**
* @brief Whether the plugin has been loaded successfully
*
*/
bool loaded = false;
};
static PluginManagerPointer getInstance();
/**
@ -217,6 +262,15 @@ public:
bool getEnableOculusPluginSetting() { return _enableOculusPluginSetting.get(); }
void setEnableOculusPluginSetting(bool value);
/**
* @brief Returns information about known plugins
*
* This is a function for informative/debugging purposes.
*
* @return std::vector<PluginInfo>
*/
std::vector<PluginInfo> getPluginInfo() const;
signals:
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);