add a proof of concept on how to dynamically load plugin's debug categories
This commit is contained in:
parent
9213ef24dc
commit
515c3c0c2a
@ -226,6 +226,35 @@ DeviceManager::~DeviceManager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QJsonObject> DeviceManager::pluginNames()
|
||||||
|
{
|
||||||
|
QStringList searchDirs;
|
||||||
|
searchDirs << QCoreApplication::applicationDirPath() + "/../lib/guh/plugins";
|
||||||
|
searchDirs << QCoreApplication::applicationDirPath() + "/../plugins/";
|
||||||
|
searchDirs << QCoreApplication::applicationDirPath() + "/../plugins/deviceplugins";
|
||||||
|
searchDirs << QCoreApplication::applicationDirPath() + "/../../../plugins/deviceplugins";
|
||||||
|
|
||||||
|
QList<QJsonObject> pluginList;
|
||||||
|
foreach (const QString &path, searchDirs) {
|
||||||
|
QDir dir(path);
|
||||||
|
qCDebug(dcDeviceManager) << "Loading plugins from:" << dir.absolutePath();
|
||||||
|
foreach (const QString &entry, dir.entryList()) {
|
||||||
|
QFileInfo fi;
|
||||||
|
if (entry.startsWith("libguh_deviceplugin") && entry.endsWith(".so")) {
|
||||||
|
fi.setFile(path + "/" + entry);
|
||||||
|
} else {
|
||||||
|
fi.setFile(path + "/" + entry + "/libguh_deviceplugin" + entry + ".so");
|
||||||
|
}
|
||||||
|
if (!fi.exists()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QPluginLoader loader(fi.absoluteFilePath());
|
||||||
|
pluginList.append(loader.metaData().value("MetaData").toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pluginList;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Returns all the \l{DevicePlugin}{DevicePlugins} loaded in the system. */
|
/*! Returns all the \l{DevicePlugin}{DevicePlugins} loaded in the system. */
|
||||||
QList<DevicePlugin *> DeviceManager::plugins() const
|
QList<DevicePlugin *> DeviceManager::plugins() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QPluginLoader>
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class DevicePlugin;
|
class DevicePlugin;
|
||||||
@ -87,6 +88,8 @@ public:
|
|||||||
explicit DeviceManager(QObject *parent = 0);
|
explicit DeviceManager(QObject *parent = 0);
|
||||||
~DeviceManager();
|
~DeviceManager();
|
||||||
|
|
||||||
|
static QList<QJsonObject> pluginNames();
|
||||||
|
|
||||||
QList<DevicePlugin*> plugins() const;
|
QList<DevicePlugin*> plugins() const;
|
||||||
DevicePlugin* plugin(const PluginId &id) const;
|
DevicePlugin* plugin(const PluginId &id) const;
|
||||||
DeviceError setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig);
|
DeviceError setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig);
|
||||||
|
|||||||
@ -48,4 +48,4 @@ Q_LOGGING_CATEGORY(dcUdpCommander, "UdpCommander")
|
|||||||
Q_LOGGING_CATEGORY(dcWakeOnLan, "WakeOnLan")
|
Q_LOGGING_CATEGORY(dcWakeOnLan, "WakeOnLan")
|
||||||
Q_LOGGING_CATEGORY(dcWemo, "Wemo")
|
Q_LOGGING_CATEGORY(dcWemo, "Wemo")
|
||||||
Q_LOGGING_CATEGORY(dcWifiDetector, "WifiDetector")
|
Q_LOGGING_CATEGORY(dcWifiDetector, "WifiDetector")
|
||||||
Q_LOGGING_CATEGORY(dcKodi, "Kodi")
|
//Q_LOGGING_CATEGORY(dcKodi, "Kodi")
|
||||||
|
|||||||
@ -53,7 +53,7 @@ Q_DECLARE_LOGGING_CATEGORY(dcUdpCommander)
|
|||||||
Q_DECLARE_LOGGING_CATEGORY(dcWakeOnLan)
|
Q_DECLARE_LOGGING_CATEGORY(dcWakeOnLan)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcWemo)
|
Q_DECLARE_LOGGING_CATEGORY(dcWemo)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcWifiDetector)
|
Q_DECLARE_LOGGING_CATEGORY(dcWifiDetector)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcKodi)
|
//Q_DECLARE_LOGGING_CATEGORY(dcKodi)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Kodi",
|
"name": "Kodi",
|
||||||
|
"idName": "Kodi",
|
||||||
"id": "e7186890-99fa-4c5b-8247-09c6d450d490",
|
"id": "e7186890-99fa-4c5b-8247-09c6d450d490",
|
||||||
"vendors": [
|
"vendors": [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "jsonhandler.h"
|
#include "jsonhandler.h"
|
||||||
#include "loggingcategories.h"
|
#include "extern-plugininfo.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#include "kodiconnection.h"
|
#include "kodiconnection.h"
|
||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
#include "jsonhandler.h"
|
#include "jsonhandler.h"
|
||||||
|
#include "extern-plugininfo.h"
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import sys
|
|||||||
|
|
||||||
inputFile = open(sys.argv[1], "r")
|
inputFile = open(sys.argv[1], "r")
|
||||||
outputfile = open(sys.argv[2], "w")
|
outputfile = open(sys.argv[2], "w")
|
||||||
|
outputfile2 = open("extern-" + sys.argv[2], "w")
|
||||||
variableNames = []
|
variableNames = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -20,6 +21,9 @@ except ValueError as e:
|
|||||||
def out(line):
|
def out(line):
|
||||||
outputfile.write("%s\n" % line)
|
outputfile.write("%s\n" % line)
|
||||||
|
|
||||||
|
def out2(line):
|
||||||
|
outputfile2.write("%s\n" % line)
|
||||||
|
|
||||||
def extractVendors(pluginMap):
|
def extractVendors(pluginMap):
|
||||||
for vendor in pluginMap['vendors']:
|
for vendor in pluginMap['vendors']:
|
||||||
try:
|
try:
|
||||||
@ -117,12 +121,37 @@ out(" */")
|
|||||||
out("#ifndef PLUGININFO_H")
|
out("#ifndef PLUGININFO_H")
|
||||||
out("#define PLUGININFO_H")
|
out("#define PLUGININFO_H")
|
||||||
out("#include \"typeutils.h\"")
|
out("#include \"typeutils.h\"")
|
||||||
|
out("#include <QLoggingCategory>")
|
||||||
|
|
||||||
out("")
|
out("")
|
||||||
out("PluginId pluginId = PluginId(\"%s\");" % pluginMap['id'])
|
out("PluginId pluginId = PluginId(\"%s\");" % pluginMap['id'])
|
||||||
|
|
||||||
extractVendors(pluginMap)
|
extractVendors(pluginMap)
|
||||||
|
out("")
|
||||||
|
|
||||||
|
if 'idName' in pluginMap:
|
||||||
|
out("Q_DECLARE_LOGGING_CATEGORY(dc%s)" % pluginMap['idName'])
|
||||||
|
out("Q_LOGGING_CATEGORY(dc%s, \"dc%s\")" % (pluginMap['idName'], pluginMap['idName']))
|
||||||
|
|
||||||
out("")
|
out("")
|
||||||
out("#endif")
|
out("#endif")
|
||||||
|
|
||||||
|
|
||||||
|
out2("/* This file is generated by the guh build system. Any changes to this file will")
|
||||||
|
out2(" * be lost.")
|
||||||
|
out2(" *")
|
||||||
|
out2(" * If you want to change this file, edit the plugin's json file and add")
|
||||||
|
out2(" * idName tags where appropriate.")
|
||||||
|
out2(" */")
|
||||||
|
out2("#ifndef PLUGININFO_H")
|
||||||
|
out2("#define PLUGININFO_H")
|
||||||
|
out2("#include \"typeutils.h\"")
|
||||||
|
out2("#include <QLoggingCategory>")
|
||||||
|
out2("")
|
||||||
|
if 'idName' in pluginMap:
|
||||||
|
out2("Q_DECLARE_LOGGING_CATEGORY(dc%s)" % pluginMap['idName'])
|
||||||
|
out2("")
|
||||||
|
out2("#endif")
|
||||||
|
|
||||||
|
|
||||||
print " --> finished writing \"%s\"" % (sys.argv[2])
|
print " --> finished writing \"%s\"" % (sys.argv[2])
|
||||||
|
|||||||
@ -62,27 +62,9 @@ int main(int argc, char *argv[])
|
|||||||
s_loggingFilters.insert("Hardware", false);
|
s_loggingFilters.insert("Hardware", false);
|
||||||
s_loggingFilters.insert("LogEngine", false);
|
s_loggingFilters.insert("LogEngine", false);
|
||||||
|
|
||||||
// plugins
|
foreach (const QJsonObject &object, DeviceManager::pluginNames()) {
|
||||||
#ifdef boblight
|
s_loggingFilters.insert("dc" + object.value("idName").toString(), false);
|
||||||
s_loggingFilters.insert("Boblight", false);
|
}
|
||||||
#endif
|
|
||||||
s_loggingFilters.insert("CommandLauncher", false);
|
|
||||||
s_loggingFilters.insert("RF433", false);
|
|
||||||
s_loggingFilters.insert("DateTime", false);
|
|
||||||
s_loggingFilters.insert("EQ-3", false);
|
|
||||||
s_loggingFilters.insert("LgSmartTv", false);
|
|
||||||
s_loggingFilters.insert("Lircd", false);
|
|
||||||
s_loggingFilters.insert("MailNotification", false);
|
|
||||||
s_loggingFilters.insert("Mock", false);
|
|
||||||
s_loggingFilters.insert("Openweahtermap", false);
|
|
||||||
s_loggingFilters.insert("PhilipsHue", false);
|
|
||||||
s_loggingFilters.insert("Tune", false);
|
|
||||||
s_loggingFilters.insert("UdpCommander", false);
|
|
||||||
s_loggingFilters.insert("WakeOnLan", false);
|
|
||||||
s_loggingFilters.insert("Wemo", false);
|
|
||||||
s_loggingFilters.insert("WifiDetector", false);
|
|
||||||
s_loggingFilters.insert("Kodi", false);
|
|
||||||
|
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
|
|||||||
Reference in New Issue
Block a user