added logging category to core and lib

This commit is contained in:
Simon Stürz 2015-06-20 22:01:13 +02:00 committed by Michael Zanetti
parent f566867f88
commit a8727407eb
31 changed files with 427 additions and 261 deletions

View File

@ -169,6 +169,7 @@
*/
#include "devicemanager.h"
#include "loggingcategorys.h"
#include "hardware/radio433/radio433.h"
@ -219,7 +220,7 @@ DeviceManager::DeviceManager(QObject *parent) :
/*! Destructor of the DeviceManager. Each loaded \l{DevicePlugin} will be deleted. */
DeviceManager::~DeviceManager()
{
qDebug() << "Shutting down DeviceManager";
qCDebug(dcDeviceManager) << "Shutting down DeviceManager";
foreach (DevicePlugin *plugin, m_devicePlugins) {
delete plugin;
}
@ -284,7 +285,7 @@ QList<DeviceClass> DeviceManager::supportedDevices(const VendorId &vendorId) con
* and the given \a params.*/
DeviceManager::DeviceError DeviceManager::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{
qDebug() << "DeviceManager discoverdevices" << params;
qCDebug(dcDeviceManager) << "discover devices" << params;
// Create a copy of the parameter list because we might modify it (fillig in default values etc)
ParamList effectiveParams = params;
DeviceClass deviceClass = findDeviceClass(deviceClassId);
@ -406,13 +407,13 @@ DeviceManager::DeviceError DeviceManager::editDevice(const DeviceId &deviceId, c
DeviceSetupStatus status = plugin->setupDevice(device);
switch (status) {
case DeviceSetupStatusFailure:
qWarning() << "Device edit failed. Not saving changes of device paramters. Device setup incomplete.";
qCWarning(dcDeviceManager) << "Device edit failed. Not saving changes of device paramters. Device setup incomplete.";
return DeviceErrorSetupFailed;
case DeviceSetupStatusAsync:
m_asyncDeviceEdit.append(device);
return DeviceErrorAsync;
case DeviceSetupStatusSuccess:
qDebug() << "Device edit complete.";
qCDebug(dcDeviceManager) << "Device edit complete.";
break;
}
@ -460,7 +461,7 @@ DeviceManager::DeviceError DeviceManager::pairDevice(const PairingTransactionId
{
DeviceClass deviceClass = findDeviceClass(deviceClassId);
if (deviceClass.id().isNull()) {
qWarning() << "cannot find a device class with id" << deviceClassId;
qCWarning(dcDeviceManager) << "cannot find a device class with id" << deviceClassId;
return DeviceErrorDeviceClassNotFound;
}
@ -468,16 +469,16 @@ DeviceManager::DeviceError DeviceManager::pairDevice(const PairingTransactionId
Q_UNUSED(params)
switch (deviceClass.setupMethod()) {
case DeviceClass::SetupMethodJustAdd:
qWarning() << "Cannot setup this device this way. No need to pair this device.";
qCWarning(dcDeviceManager) << "Cannot setup this device this way. No need to pair this device.";
return DeviceErrorSetupMethodNotSupported;
case DeviceClass::SetupMethodDisplayPin:
qWarning() << "SetupMethodDisplayPin not implemented yet for this CreateMethod";
qCWarning(dcDeviceManager) << "SetupMethodDisplayPin not implemented yet for this CreateMethod";
return DeviceErrorSetupFailed;
case DeviceClass::SetupMethodEnterPin:
qWarning() << "SetupMethodEnterPin not implemented yet for this CreateMethod";
qCWarning(dcDeviceManager) << "SetupMethodEnterPin not implemented yet for this CreateMethod";
return DeviceErrorSetupFailed;
case DeviceClass::SetupMethodPushButton:
qWarning() << "SetupMethodPushButton not implemented yet for this CreateMethod";
qCWarning(dcDeviceManager) << "SetupMethodPushButton not implemented yet for this CreateMethod";
return DeviceErrorSetupFailed;
}
@ -490,17 +491,17 @@ DeviceManager::DeviceError DeviceManager::pairDevice(const PairingTransactionId
{
DeviceClass deviceClass = findDeviceClass(deviceClassId);
if (deviceClass.id().isNull()) {
qWarning() << "cannot find a device class with id" << deviceClassId;
qCWarning(dcDeviceManager) << "Cannot find a device class with id" << deviceClassId;
return DeviceErrorDeviceClassNotFound;
}
if (deviceClass.setupMethod() == DeviceClass::SetupMethodJustAdd) {
qWarning() << "Cannot setup this device this way. No need to pair this device.";
qCWarning(dcDeviceManager) << "Cannot setup this device this way. No need to pair this device.";
return DeviceErrorCreationMethodNotSupported;
}
if (!m_discoveredDevices.contains(deviceDescriptorId)) {
qWarning() << "Cannot find a DeviceDescriptor with ID" << deviceClassId.toString();
qCWarning(dcDeviceManager) << "Cannot find a DeviceDescriptor with ID" << deviceClassId.toString();
return DeviceErrorDeviceDescriptorNotFound;
}
@ -508,7 +509,7 @@ DeviceManager::DeviceError DeviceManager::pairDevice(const PairingTransactionId
if (deviceClass.setupMethod() == DeviceClass::SetupMethodDisplayPin) {
// TODO: fetch PIN from device plugin
qWarning() << "SetupMethodDisplayPin not implemented yet";
qCWarning(dcDeviceManager) << "SetupMethodDisplayPin not implemented yet";
return DeviceErrorSetupFailed;
}
@ -521,7 +522,7 @@ DeviceManager::DeviceError DeviceManager::confirmPairing(const PairingTransactio
{
Q_UNUSED(secret)
if (m_pairingsJustAdd.contains(pairingTransactionId)) {
qWarning() << "this SetupMethod is not implemented yet";
qCWarning(dcDeviceManager) << "this SetupMethod is not implemented yet";
m_pairingsJustAdd.remove(pairingTransactionId);
return DeviceErrorSetupFailed;
}
@ -535,7 +536,7 @@ DeviceManager::DeviceError DeviceManager::confirmPairing(const PairingTransactio
DevicePlugin *plugin = m_devicePlugins.value(m_supportedDevices.value(deviceClassId).pluginId());
if (!plugin) {
qWarning() << "Can't find a plugin for this device class";
qCWarning(dcDeviceManager) << "Can't find a plugin for this device class";
return DeviceErrorPluginNotFound;
}
@ -592,13 +593,13 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const Devi
DeviceSetupStatus status = setupDevice(device);
switch (status) {
case DeviceSetupStatusFailure:
qWarning() << "Device setup failed. Not adding device to system.";
qCWarning(dcDeviceManager) << "Device setup failed. Not adding device to system.";
delete device;
return DeviceErrorSetupFailed;
case DeviceSetupStatusAsync:
return DeviceErrorAsync;
case DeviceSetupStatusSuccess:
qDebug() << "Device setup complete.";
qCDebug(dcDeviceManager) << "Device setup complete.";
break;
}
@ -740,7 +741,7 @@ void DeviceManager::loadPlugins()
foreach (const QString &path, searchDirs) {
QDir dir(path);
qDebug() << "Loading plugins from:" << dir.absolutePath();
qCDebug(dcDeviceManager) << "Loading plugins from:" << dir.absolutePath();
foreach (const QString &entry, dir.entryList()) {
QFileInfo fi;
if (entry.startsWith("libguh_deviceplugin") && entry.endsWith(".so")) {
@ -756,11 +757,11 @@ void DeviceManager::loadPlugins()
DevicePlugin *pluginIface = qobject_cast<DevicePlugin*>(loader.instance());
if (verifyPluginMetadata(loader.metaData().value("MetaData").toObject()) && pluginIface) {
pluginIface->initPlugin(loader.metaData().value("MetaData").toObject(), this);
qDebug() << "*** Loaded plugin" << pluginIface->pluginName();
qCDebug(dcDeviceManager) << "*** Loaded plugin" << pluginIface->pluginName();
foreach (const Vendor &vendor, pluginIface->supportedVendors()) {
qDebug() << "* Loaded vendor:" << vendor.name();
qCDebug(dcDeviceManager) << "* Loaded vendor:" << vendor.name();
if (m_supportedVendors.contains(vendor.id())) {
//qWarning() << "! Duplicate vendor. Ignoring vendor" << vendor.name();
//qCWarning(dcDeviceManager) << "! Duplicate vendor. Ignoring vendor" << vendor.name();
continue;
}
m_supportedVendors.insert(vendor.id(), vendor);
@ -768,12 +769,12 @@ void DeviceManager::loadPlugins()
foreach (const DeviceClass &deviceClass, pluginIface->supportedDevices()) {
if (!m_supportedVendors.contains(deviceClass.vendorId())) {
qWarning() << "! Vendor not found. Ignoring device. VendorId:" << deviceClass.vendorId() << "DeviceClass:" << deviceClass.name() << deviceClass.id();
qCWarning(dcDeviceManager) << "! Vendor not found. Ignoring device. VendorId:" << deviceClass.vendorId() << "DeviceClass:" << deviceClass.name() << deviceClass.id();
continue;
}
m_vendorDeviceMap[deviceClass.vendorId()].append(deviceClass.id());
m_supportedDevices.insert(deviceClass.id(), deviceClass);
qDebug() << "* Loaded device class:" << deviceClass.name();
qCDebug(dcDeviceManager) << "* Loaded device class:" << deviceClass.name();
}
QSettings settings(m_settingsFile);
settings.beginGroup("PluginConfig");
@ -793,9 +794,9 @@ void DeviceManager::loadPlugins()
}
}
settings.endGroup();
QPair<DeviceError, QString> status = pluginIface->setConfiguration(params);
if (status.first != DeviceErrorNoError) {
qWarning() << "Error setting params to plugin. Broken configuration?" << status.second;
DeviceError status = pluginIface->setConfiguration(params);
if (status != DeviceErrorNoError) {
qCWarning(dcDeviceManager) << "Error setting params to plugin. Broken configuration?";
}
}
settings.endGroup();
@ -820,7 +821,7 @@ void DeviceManager::loadConfiguredDevices()
{
QSettings settings(m_settingsFile);
settings.beginGroup("DeviceConfig");
qDebug() << "loading devices from" << settings.fileName();
qCDebug(dcDeviceManager) << "loading devices from" << settings.fileName();
foreach (const QString &idString, settings.childGroups()) {
settings.beginGroup(idString);
Device *device = new Device(PluginId(settings.value("pluginid").toString()), DeviceId(idString), DeviceClassId(settings.value("deviceClassId").toString()), this);
@ -888,18 +889,18 @@ void DeviceManager::slotDeviceSetupFinished(Device *device, DeviceManager::Devic
{
Q_ASSERT_X(device, "DeviceManager", "Device must be a valid pointer.");
if (!device) {
qWarning() << "Received deviceSetupFinished for an invalid device... ignoring...";
qCWarning(dcDeviceManager) << "Received deviceSetupFinished for an invalid device... ignoring...";
return;
}
if (device->setupComplete()) {
qWarning() << "Received a deviceSetupFinished event, but this Device has been set up before... ignoring...";
qCWarning(dcDeviceManager) << "Received a deviceSetupFinished event, but this Device has been set up before... ignoring...";
return;
}
Q_ASSERT_X(status != DeviceSetupStatusAsync, "DeviceManager", "Bad plugin implementation. You should not emit deviceSetupFinished with status DeviceSetupStatusAsync.");
if (status == DeviceSetupStatusAsync) {
qWarning() << "Bad plugin implementation. Received a deviceSetupFinished event with status Async... ignoring...";
qCWarning(dcDeviceManager) << "Bad plugin implementation. Received a deviceSetupFinished event with status Async... ignoring...";
return;
}
@ -907,7 +908,7 @@ void DeviceManager::slotDeviceSetupFinished(Device *device, DeviceManager::Devic
if (m_configuredDevices.contains(device)) {
if (m_asyncDeviceEdit.contains(device)) {
m_asyncDeviceEdit.removeAll(device);
qWarning() << QString("Error in device setup after edit params. Device %1 (%2) would not be functional.").arg(device->name()).arg(device->id().toString());
qCWarning(dcDeviceManager) << QString("Error in device setup after edit params. Device %1 (%2) would not be functional.").arg(device->name()).arg(device->id().toString());
storeConfiguredDevices();
@ -916,11 +917,11 @@ void DeviceManager::slotDeviceSetupFinished(Device *device, DeviceManager::Devic
emit deviceParamsChanged(device);
emit deviceEditFinished(device, DeviceError::DeviceErrorSetupFailed);
}
qWarning() << QString("Error in device setup. Device %1 (%2) will not be functional.").arg(device->name()).arg(device->id().toString());
qCWarning(dcDeviceManager) << QString("Error in device setup. Device %1 (%2) will not be functional.").arg(device->name()).arg(device->id().toString());
emit deviceSetupFinished(device, DeviceError::DeviceErrorSetupFailed);
return;
} else {
qWarning() << QString("Error in device setup. Device %1 (%2) will not be added to the configured devices.").arg(device->name()).arg(device->id().toString());
qCWarning(dcDeviceManager) << QString("Error in device setup. Device %1 (%2) will not be added to the configured devices.").arg(device->name()).arg(device->id().toString());
emit deviceSetupFinished(device, DeviceError::DeviceErrorSetupFailed);
return;
}
@ -966,9 +967,9 @@ void DeviceManager::slotPairingFinished(const PairingTransactionId &pairingTrans
if (!m_pairingsJustAdd.contains(pairingTransactionId) && !m_pairingsDiscovery.contains(pairingTransactionId)) {
DevicePlugin *plugin = dynamic_cast<DevicePlugin*>(sender());
if (plugin) {
qWarning() << "Received a pairing finished without waiting for it from plugin:" << plugin->metaObject()->className();
qCWarning(dcDeviceManager) << "Received a pairing finished without waiting for it from plugin:" << plugin->metaObject()->className();
} else {
qWarning() << "Received a pairing finished without waiting for it.";
qCWarning(dcDeviceManager) << "Received a pairing finished without waiting for it.";
}
return;
}
@ -1001,7 +1002,7 @@ void DeviceManager::slotPairingFinished(const PairingTransactionId &pairingTrans
DeviceClass deviceClass = findDeviceClass(deviceClassId);
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
if (!plugin) {
qWarning() << "Cannot find a plugin for this device class!";
qCWarning(dcDeviceManager) << "Cannot find a plugin for this device class!";
emit pairingFinished(pairingTransactionId, DeviceErrorPluginNotFound, deviceClass.pluginId().toString());
return;
}
@ -1018,14 +1019,14 @@ void DeviceManager::slotPairingFinished(const PairingTransactionId &pairingTrans
DeviceSetupStatus setupStatus = setupDevice(device);
switch (setupStatus) {
case DeviceSetupStatusFailure:
qWarning() << "Device setup failed. Not adding device to system.";
qCWarning(dcDeviceManager) << "Device setup failed. Not adding device to system.";
emit deviceSetupFinished(device, DeviceError::DeviceErrorSetupFailed);
delete device;
break;
case DeviceSetupStatusAsync:
return;
case DeviceSetupStatusSuccess:
qDebug() << "Device setup complete.";
qCDebug(dcDeviceManager) << "Device setup complete.";
newDevices.append(id);
break;
}
@ -1056,14 +1057,14 @@ void DeviceManager::autoDevicesAppeared(const DeviceClassId &deviceClassId, cons
DeviceSetupStatus setupStatus = setupDevice(device);
switch (setupStatus) {
case DeviceSetupStatusFailure:
qWarning() << "Device setup failed. Not adding device to system.";
qCWarning(dcDeviceManager) << "Device setup failed. Not adding device to system.";
emit deviceSetupFinished(device, DeviceError::DeviceErrorSetupFailed);
delete device;
break;
case DeviceSetupStatusAsync:
break;
case DeviceSetupStatusSuccess:
qDebug() << "Device setup complete.";
qCDebug(dcDeviceManager) << "Device setup complete.";
m_configuredDevices.append(device);
storeConfiguredDevices();
emit deviceSetupFinished(device, DeviceError::DeviceErrorNoError);
@ -1150,7 +1151,7 @@ bool DeviceManager::verifyPluginMetadata(const QJsonObject &data)
foreach (const QString &field, requiredFields) {
if (!data.contains("name")) {
qWarning() << "Error loading plugin. Incomplete metadata. Missing field:" << field;
qCWarning(dcDeviceManager) << "Error loading plugin. Incomplete metadata. Missing field:" << field;
return false;
}
}
@ -1163,7 +1164,7 @@ DeviceManager::DeviceSetupStatus DeviceManager::setupDevice(Device *device)
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
if (!plugin) {
qWarning() << "Can't find a plugin for this device" << device->id();
qCWarning(dcDeviceManager) << "Can't find a plugin for this device" << device->id();
return DeviceSetupStatusFailure;
}
@ -1231,7 +1232,7 @@ DeviceManager::DeviceError DeviceManager::verifyParams(const QList<ParamType> pa
}
if (!found) {
qWarning() << "Missing parameter:" << paramType.name();
qCWarning(dcDeviceManager) << "Missing parameter:" << paramType.name();
return DeviceErrorMissingParameter;
}
}
@ -1245,7 +1246,7 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const QList<ParamType> par
return verifyParam(paramType, param);
}
}
qWarning() << "Invalid parameter" << param.name() << "in parameter list";
qCWarning(dcDeviceManager) << "Invalid parameter" << param.name() << "in parameter list";
return DeviceErrorInvalidParameter;
}
@ -1253,16 +1254,16 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const ParamType &paramType
{
if (paramType.name() == param.name()) {
if (!param.value().canConvert(paramType.type())) {
qWarning() << "Wrong parameter type for param" << param.name() << " Got:" << param.value() << " Expected:" << QVariant::typeToName(paramType.type());
qCWarning(dcDeviceManager) << "Wrong parameter type for param" << param.name() << " Got:" << param.value() << " Expected:" << QVariant::typeToName(paramType.type());
return DeviceErrorInvalidParameter;
}
if (paramType.maxValue().isValid() && param.value().convert(paramType.type()) > paramType.maxValue().convert(paramType.type())) {
qWarning() << "Value out of range for param" << param.name() << " Got:" << param.value() << " Max:" << paramType.maxValue();
qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Max:" << paramType.maxValue();
return DeviceErrorInvalidParameter;
}
if (paramType.minValue().isValid() && param.value() < paramType.minValue()) {
qWarning() << "Value out of range for param" << param.name() << " Got:" << param.value().convert(paramType.type()) << " Min:" << paramType.minValue().convert(paramType.type());
qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value().convert(paramType.type()) << " Min:" << paramType.minValue().convert(paramType.type());
return DeviceErrorInvalidParameter;
}
if (!paramType.allowedValues().isEmpty() && !paramType.allowedValues().contains(param.value())) {
@ -1271,11 +1272,11 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const ParamType &paramType
allowedValues.append(value.toString());
}
qWarning() << "Value not in allowed values for param" << param.name() << " Got:" << param.value() << " Allowed:" << allowedValues.join(",");
qCWarning(dcDeviceManager) << "Value not in allowed values for param" << param.name() << " Got:" << param.value() << " Allowed:" << allowedValues.join(",");
return DeviceErrorInvalidParameter;
}
return DeviceErrorNoError;
}
qWarning() << "Parameter name" << param.name() << "does not match with ParamType name" << paramType.name();
qCWarning(dcDeviceManager) << "Parameter name" << param.name() << "does not match with ParamType name" << paramType.name();
return DeviceErrorInvalidParameter;
}

View File

@ -67,6 +67,8 @@
*/
#include "gpio.h"
#include "loggingcategorys.h"
#include <QDebug>
/*! Constructs a \l{Gpio} object to represent a GPIO with the given \a gpio number and the \a parent. */
@ -90,13 +92,13 @@ bool Gpio::exportGpio()
int fd = open("/sys/class/gpio/export", O_WRONLY);
if (fd < 0) {
//qDebug() << "ERROR: could not open /sys/class/gpio/export";
//qCWarning(dcHardware) << "could not open /sys/class/gpio/export";
return false;
}
ssize_t len = snprintf(buf, sizeof(buf), "%d", m_gpio);
if(write(fd, buf, len) != len){
qDebug() << "ERROR: could not write to gpio (export)";
qCWarning(dcHardware) << "could not write to gpio (export)";
close(fd);
return false;
}
@ -111,13 +113,13 @@ bool Gpio::unexportGpio()
int fd = open("/sys/class/gpio/unexport", O_WRONLY);
if (fd < 0) {
//qDebug() << "ERROR: could not open /sys/class/gpio/unexport";
//qCWarning(dcHardware) << "could not open /sys/class/gpio/unexport";
return false;
}
ssize_t len = snprintf(buf, sizeof(buf), "%d", m_gpio);
if(write(fd, buf, len) != len){
//qDebug() << "ERROR: could not write to gpio (unexport)";
//qCWarning(dcHardware) << "could not write to gpio (unexport)";
close(fd);
return false;
}
@ -134,7 +136,7 @@ int Gpio::openGpio()
int fd = open(buf, O_RDONLY | O_NONBLOCK );
if (fd < 0) {
qDebug() << "ERROR: could not open /sys/class/gpio" << m_gpio << "/direction";
qCWarning(dcHardware) << "could not open /sys/class/gpio" << m_gpio << "/direction";
return fd;
}
return fd;
@ -162,12 +164,12 @@ bool Gpio::setDirection(int dir)
int fd = open(buf, O_WRONLY);
if (fd < 0) {
qDebug() << "ERROR: could not open /sys/class/gpio" << m_gpio << "/direction";
qCWarning(dcHardware) << "could not open /sys/class/gpio" << m_gpio << "/direction";
return false;
}
if(dir == INPUT){
if(write(fd, "in", 3) != 3){
qDebug() << "ERROR: could not write to gpio (set INPUT)";
qCWarning(dcHardware) << "could not write to gpio (set INPUT)";
close(fd);
return false;
}
@ -177,7 +179,7 @@ bool Gpio::setDirection(int dir)
}
if(dir == OUTPUT){
if(write(fd, "out", 4) != 4){
qDebug() << "ERROR: could not write to gpio (set OUTPUT)";
qCWarning(dcHardware) << "could not write to gpio (set OUTPUT)";
close(fd);
return false;
}
@ -221,13 +223,13 @@ bool Gpio::setValue(unsigned int value)
int fd = open(buf, O_WRONLY);
if (fd < 0) {
qDebug() << "ERROR: could not open /sys/class/gpio" << m_gpio << "/value";
qCWarning(dcHardware) << "could not open /sys/class/gpio" << m_gpio << "/value";
return false;
}
if(value == LOW){
if(write(fd, "0", 2) != 2){
qDebug() << "ERROR: could not write to gpio (set LOW)";
qCWarning(dcHardware) << "could not write to gpio (set LOW)";
close(fd);
return false;
}
@ -236,7 +238,7 @@ bool Gpio::setValue(unsigned int value)
}
if(value == HIGH){
if(write(fd, "1", 2) != 2){
qDebug() << "ERROR: could not write to gpio (set HIGH)";
qCWarning(dcHardware) << "could not write to gpio (set HIGH)";
close(fd);
return false;
}
@ -246,7 +248,7 @@ bool Gpio::setValue(unsigned int value)
close(fd);
return false;
}else{
qDebug() << "ERROR: Gpio" << m_gpio << "is not an OUTPUT.";
qCWarning(dcHardware) << "Gpio" << m_gpio << "is not an OUTPUT.";
return false;
}
}
@ -274,7 +276,7 @@ int Gpio::getValue()
int fd = open(buf, O_RDONLY);
if (fd < 0) {
qDebug() << "ERROR: could not open /sys/class/gpio" << m_gpio << "/value";
qCWarning(dcHardware) << "could not open /sys/class/gpio" << m_gpio << "/value";
return -1;
}
char ch;
@ -320,13 +322,13 @@ bool Gpio::setEdgeInterrupt(int edge)
int fd = open(buf, O_WRONLY);
if (fd < 0) {
qDebug() << "ERROR: could not open /sys/class/gpio" << m_gpio << "/edge";
qCWarning(dcHardware) << "could not open /sys/class/gpio" << m_gpio << "/edge";
return false;
}
if(edge == EDGE_FALLING){
if(write(fd, "falling", 8) != 8){
qDebug() << "ERROR: could not write to gpio (set EDGE_FALLING)";
qCWarning(dcHardware) << "could not write to gpio (set EDGE_FALLING)";
close(fd);
return false;
}
@ -335,7 +337,7 @@ bool Gpio::setEdgeInterrupt(int edge)
}
if(edge == EDGE_RISING){
if(write(fd, "rising", 7) != 7){
qDebug() << "ERROR: could not write to gpio (set EDGE_RISING)";
qCWarning(dcHardware) << "could not write to gpio (set EDGE_RISING)";
close(fd);
return false;
}
@ -344,7 +346,7 @@ bool Gpio::setEdgeInterrupt(int edge)
}
if(edge == EDGE_BOTH){
if(write(fd, "both", 5) != 5){
qDebug() << "ERROR: could not write to gpio (set EDGE_BOTH)";
qCWarning(dcHardware) << "could not write to gpio (set EDGE_BOTH)";
close(fd);
return false;
}
@ -364,13 +366,13 @@ bool Gpio::setActiveLow(bool activeLow)
snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/active_low", m_gpio);
int fd = open(buf, O_WRONLY);
if (fd < 0) {
qDebug() << "ERROR: could not open /sys/class/gpio" << m_gpio << "/active_low";
qCWarning(dcHardware) << "could not open /sys/class/gpio" << m_gpio << "/active_low";
return false;
}
if(activeLow){
if(write(fd, "0", 2) != 2){
qDebug() << "ERROR: could not write to gpio (set Active LOW)";
qCWarning(dcHardware) << "could not write to gpio (set Active LOW)";
close(fd);
return false;
}
@ -379,7 +381,7 @@ bool Gpio::setActiveLow(bool activeLow)
}
if(!activeLow){
if(write(fd, "1", 2) != 2){
qDebug() << "ERROR: could not write to gpio (set Active HIGH)";
qCWarning(dcHardware) << "could not write to gpio (set Active HIGH)";
close(fd);
return false;
}

View File

@ -148,6 +148,7 @@
*/
#include "gpiomonitor.h"
#include "loggingcategorys.h"
/*! Constructs a \l{GpioMonitor} object with the given \a parent. */
GpioMonitor::GpioMonitor(QObject *parent) :
@ -246,12 +247,12 @@ void GpioMonitor::run()
emit changed(m_gpioList[i]->gpioNumber(), m_gpioList[i]->getValue());
if (retVal < 0) {
qWarning() << "ERROR: poll failed";
qCWarning(dcHardware) << "GpioMonitor poll failed";
}
}
}
} else if (ret < 0) {
qWarning() << "ERROR: poll failed: " << errno;
qCWarning(dcHardware) << "poll failed: " << errno;
}
m_gpioListMutex.unlock();

View File

@ -50,6 +50,8 @@
*/
#include "radio433.h"
#include "loggingcategorys.h"
#include <QFileInfo>
/*! Construct the hardware resource Radio433 with the given \a parent. Each possible 433 MHz hardware will be initialized here. */
@ -90,20 +92,20 @@ bool Radio433::enable()
if (gpioFile.exists()) {
// bool receiverAvailable = m_receiver->startReceiver();
// if (!receiverAvailable) {
// //qWarning() << "ERROR: radio 433 MHz receiver not available on GPIO's";
// //qCWarning(dcHardware) << "ERROR: radio 433 MHz receiver not available on GPIO's";
// }
// bool transmitterAvailable = m_transmitter->startTransmitter();
// if (!transmitterAvailable) {
// //qWarning() << "ERROR: radio 433 MHz transmitter not available on GPIO's";
// //qCWarning(dcHardware) << "ERROR: radio 433 MHz transmitter not available on GPIO's";
// }
// if (!receiverAvailable && !transmitterAvailable) {
// qWarning() << "--> Radio 433 MHz GPIO's not available.";
// qCWarning(dcHardware) << "--> Radio 433 MHz GPIO's not available.";
// return false;
// }
}
qDebug() << "--> Radio 433 MHz GPIO's enabled.";
qCDebug(dcHardware) << "--> Radio 433 MHz GPIO's enabled.";
#endif
return true;
@ -126,9 +128,9 @@ bool Radio433::disabel()
void Radio433::brennenstuhlAvailableChanged(const bool &available)
{
if (available) {
qDebug() << "--> Radio 433 MHz Brennenstuhl LAN Gateway available.";
qCDebug(dcHardware) << "--> Radio 433 MHz Brennenstuhl LAN Gateway available.";
} else {
qDebug() << "--> Radio 433 MHz Brennenstuhl LAN Gateway NOT available.";
qCWarning(dcHardware) << "--> Radio 433 MHz Brennenstuhl LAN Gateway NOT available.";
}
}

View File

@ -19,6 +19,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "radio433brennenstuhlgateway.h"
#include "loggingcategorys.h"
Radio433BrennenstuhlGateway::Radio433BrennenstuhlGateway(QObject *parent) :
QObject(parent)
@ -71,7 +72,7 @@ bool Radio433BrennenstuhlGateway::sendData(int delay, QList<int> rawData, int re
if (m_gateway->writeDatagram(message, m_gatewayAddress, m_port) > 0) {
m_available = true;
} else {
qDebug() << "ERROR: could not send command to Brennenstihl Gateway";
qCWarning(dcHardware) << "could not send command to Brennenstihl Gateway";
m_available = false;
emit availableChanged(false);
return false;
@ -84,7 +85,7 @@ bool Radio433BrennenstuhlGateway::enable()
m_available = false;
if (!m_gateway->bind(m_port, QUdpSocket::ShareAddress)) {
qWarning() << "ERROR: Radio 433 MHz Brennenstuhl LAN Gateway discovery could not bind to port " << m_port;
qCWarning(dcHardware) << "Radio 433 MHz Brennenstuhl LAN Gateway discovery could not bind to port " << m_port;
return false;
}
@ -139,7 +140,7 @@ void Radio433BrennenstuhlGateway::gatewayError(QAbstractSocket::SocketError erro
Q_UNUSED(error)
QUdpSocket *gateway = static_cast<QUdpSocket*>(sender());
if (m_available) {
qWarning() << "--> ERROR: Radio 433 MHz Brennenstuhl LAN Gateway socket error: " << gateway->errorString();
qCWarning(dcHardware) << "--> ERROR: Radio 433 MHz Brennenstuhl LAN Gateway socket error: " << gateway->errorString();
m_available = false;
emit availableChanged(false);
}

View File

@ -24,6 +24,7 @@
#include <sys/time.h>
#include "radio433receiver.h"
#include "loggingcategorys.h"
Radio433Receiver::Radio433Receiver(QObject *parent, int gpio) :
QThread(parent),m_gpioPin(gpio)
@ -81,7 +82,7 @@ void Radio433Receiver::run()
int rc = poll(fdset, 2, 1000);
if (rc < 0) {
qDebug() << "ERROR: poll failed";
qCWarning(dcHardware) << "ERROR: poll failed";
return;
}
if(rc == 0){
@ -89,7 +90,7 @@ void Radio433Receiver::run()
}
if (fdset[1].revents & POLLPRI){
if(read(fdset[1].fd, buf, 1) != 1){
qWarning() << "ERROR: could not read GPIO";
qCWarning(dcHardware) << "could not read GPIO";
}
int currentTime = micros();
int duration = currentTime - lastTime;
@ -215,14 +216,14 @@ void Radio433Receiver::handleTiming(int duration)
if(!m_timings.isEmpty() && sync){
// 1 sync bit + 48 data bit
if(m_timings.count() == 49 && checkValues(Protocol48)){
//qDebug() << "48 bit ->" << m_timings << "\n--------------------------";
//qCWarning(dcHardware) << "48 bit ->" << m_timings << "\n--------------------------";
changeReading(false);
emit dataReceived(m_timings);
}
// 1 sync bit + 64 data bit
if(m_timings.count() == 65 && checkValues(Protocol64)){
//qDebug() << "64 bit ->" << m_timings << "\n--------------------------";
//qCWarning(dcHardware) << "64 bit ->" << m_timings << "\n--------------------------";
changeReading(false);
emit dataReceived(m_timings);
}
@ -254,13 +255,13 @@ void Radio433Receiver::handleTiming(int duration)
// check if we have already a vallid protocol
// 1 sync bit + 48 data bit
if(m_timings.count() == 49 && checkValues(Protocol48)){
//qDebug() << "48 bit -> " << m_timings << "\n--------------------------";
//qCWarning(dcHardware) << "48 bit -> " << m_timings << "\n--------------------------";
emit dataReceived(m_timings);
}
// 1 sync bit + 64 data bit
if(m_timings.count() == 65 && checkValues(Protocol64)){
//qDebug() << "64 bit -> " << m_timings << "\n--------------------------";
//qCWarning(dcHardware) << "64 bit -> " << m_timings << "\n--------------------------";
changeReading(false);
emit dataReceived(m_timings);
m_timings.clear();

View File

@ -37,7 +37,7 @@ SOURCES += plugin/device.cpp \
types/ruleaction.cpp \
types/ruleactionparam.cpp \
types/statedescriptor.cpp \
network/networkmanager.cpp \
loggingcategorys.cpp \
HEADERS += plugin/device.h \
plugin/deviceclass.h \
@ -70,5 +70,5 @@ HEADERS += plugin/device.h \
types/ruleactionparam.h \
types/statedescriptor.h \
typeutils.h \
network/networkmanager.h \
loggingcategorys.h \

View File

@ -0,0 +1,30 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <simon.stuerz@guh.guru> *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "loggingcategorys.h"
Q_LOGGING_CATEGORY(dcApplication, "Application")
Q_LOGGING_CATEGORY(dcDeviceManager,"DeviceManager")
Q_LOGGING_CATEGORY(dcRuleEngine,"RuleEngine")
Q_LOGGING_CATEGORY(dcHardware,"Hardware")
Q_LOGGING_CATEGORY(dcConnection,"Connection")
Q_LOGGING_CATEGORY(dcJsonRpc,"JsonRpc")
Q_LOGGING_CATEGORY(dcLogEngine,"LogEngine")

34
libguh/loggingcategorys.h Normal file
View File

@ -0,0 +1,34 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <simon.stuerz@guh.guru> *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef LOGGINGCATEGORYS_H
#define LOGGINGCATEGORYS_H
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(dcApplication)
Q_DECLARE_LOGGING_CATEGORY(dcDeviceManager)
Q_DECLARE_LOGGING_CATEGORY(dcRuleEngine)
Q_DECLARE_LOGGING_CATEGORY(dcHardware)
Q_DECLARE_LOGGING_CATEGORY(dcConnection)
Q_DECLARE_LOGGING_CATEGORY(dcJsonRpc)
Q_DECLARE_LOGGING_CATEGORY(dcLogEngine)
#endif // LOGGINGCATEGORYS_H

View File

@ -37,6 +37,7 @@
*/
#include "networkmanager.h"
#include "loggingcategorys.h"
/*! Construct the hardware resource NetworkManager with the given \a parent. */
NetworkManager::NetworkManager(QObject *parent) :
@ -45,7 +46,7 @@ NetworkManager::NetworkManager(QObject *parent) :
m_manager = new QNetworkAccessManager(this);
connect(m_manager, &QNetworkAccessManager::finished, this, &NetworkManager::replyFinished);
qDebug() << "--> Network manager created successfully.";
qCDebug(dcHardware) << "--> Network manager created successfully.";
}
/*! Posts a request to obtain the contents of the target \a request from the plugin with the given \a pluginId

View File

@ -48,6 +48,7 @@
#include "upnpdiscovery.h"
#include "loggingcategorys.h"
/*! Construct the hardware resource UpnpDiscovery with the given \a parent. */
UpnpDiscovery::UpnpDiscovery(QObject *parent) :
@ -61,12 +62,12 @@ UpnpDiscovery::UpnpDiscovery(QObject *parent) :
setSocketOption(QAbstractSocket::MulticastLoopbackOption,QVariant(1));
if(!bind(QHostAddress::AnyIPv4, m_port, QUdpSocket::ShareAddress)){
qWarning() << "ERROR: UPnP discovery could not bind to port" << m_port;
qCWarning(dcHardware) << "UPnP discovery could not bind to port" << m_port;
return;
}
if(!joinMulticastGroup(m_host)){
qWarning() << "ERROR: UPnP discovery could not join multicast group" << m_host;
qCWarning(dcHardware) << "UPnP discovery could not join multicast group" << m_host;
return;
}
@ -77,7 +78,7 @@ UpnpDiscovery::UpnpDiscovery(QObject *parent) :
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(error(QAbstractSocket::SocketError)));
connect(this, &UpnpDiscovery::readyRead, this, &UpnpDiscovery::readData);
qDebug() << "--> UPnP discovery created successfully.";
qCDebug(dcHardware) << "--> UPnP discovery created successfully.";
}
/*! Returns false, if the \l{UpnpDiscovery} resource is not available. Returns true, if a device with
@ -85,7 +86,7 @@ UpnpDiscovery::UpnpDiscovery(QObject *parent) :
bool UpnpDiscovery::discoverDevices(const QString &searchTarget, const QString &userAgent, const PluginId &pluginId)
{
if(state() != BoundState){
qWarning() << "ERROR: UPnP not bound to port 1900";
qCWarning(dcHardware) << "UPnP not bound to port 1900";
return false;
}
@ -114,7 +115,7 @@ void UpnpDiscovery::sendToMulticast(const QByteArray &data)
void UpnpDiscovery::error(QAbstractSocket::SocketError error)
{
qWarning() << errorString() << error;
qCWarning(dcHardware) << "UPnP socket error:" << error << errorString();
}
void UpnpDiscovery::readData()
@ -129,9 +130,6 @@ void UpnpDiscovery::readData()
readDatagram(data.data(), data.size(), &hostAddress);
}
//qDebug() << "======================";
//qDebug() << data;
if (data.contains("NOTIFY")) {
emit upnpNotify(data);
return;
@ -231,7 +229,7 @@ void UpnpDiscovery::replyFinished(QNetworkReply *reply)
break;
}
default:
qWarning() << "HTTP request error " << status;
qCWarning(dcHardware) << "HTTP request error " << status;
m_informationRequestList.remove(reply);
}

View File

@ -19,6 +19,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "upnpdiscoveryrequest.h"
#include "loggingcategorys.h"
UpnpDiscoveryRequest::UpnpDiscoveryRequest(UpnpDiscovery *upnpDiscovery, PluginId pluginId, QString searchTarget, QString userAgent):
QObject(upnpDiscovery),
@ -42,7 +43,7 @@ void UpnpDiscoveryRequest::discover()
"USR-AGENT: " + m_userAgent.toUtf8() + "\r\n\r\n");
m_upnpDiscovery->sendToMulticast(ssdpSearchMessage);
qDebug() << "--> UPnP discovery called.";
qCDebug(dcHardware) << "--> UPnP discovery called.";
m_timer->start(3000);
}

View File

@ -40,6 +40,7 @@
#include "device.h"
#include "types/event.h"
#include "loggingcategorys.h"
#include <QDebug>
@ -187,7 +188,6 @@ void Device::setStateValue(const StateTypeId &stateTypeId, const QVariant &value
for (int i = 0; i < m_states.count(); ++i) {
if (m_states.at(i).stateTypeId() == stateTypeId) {
if (m_states.at(i).value() == value) {
//qDebug() << name() << m_states.at(i).value() << "-----> value unchanged";
return;
}
State newState(stateTypeId, m_id);
@ -197,7 +197,7 @@ void Device::setStateValue(const StateTypeId &stateTypeId, const QVariant &value
return;
}
}
qWarning() << "failed setting state for" << m_name;
qCWarning(dcDeviceManager) << "failed setting state for" << m_name;
}
/*! Returns the \l{State} with the given \a stateTypeId of this Device. */

View File

@ -137,6 +137,7 @@
*/
#include "deviceplugin.h"
#include "loggingcategorys.h"
#include "devicemanager.h"
#include "hardware/radio433/radio433.h"
@ -228,7 +229,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
QJsonObject st = stateTypesJson.toObject();
QStringList missingFields = verifyFields(QStringList() << "type" << "id" << "name", st);
if (!missingFields.isEmpty()) {
qWarning() << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in stateTypes";
qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in stateTypes";
broken = true;
break;
}
@ -267,7 +268,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
QJsonObject at = actionTypesJson.toObject();
QStringList missingFields = verifyFields(QStringList() << "id" << "name", at);
if (!missingFields.isEmpty()) {
qWarning() << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes";
qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes";
broken = true;
break;
}
@ -284,7 +285,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
QJsonObject et = eventTypesJson.toObject();
QStringList missingFields = verifyFields(QStringList() << "id" << "name", et);
if (!missingFields.isEmpty()) {
qWarning() << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes";
qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes";
broken = true;
break;
}
@ -363,7 +364,7 @@ DeviceManager::DeviceSetupStatus DevicePlugin::confirmPairing(const PairingTrans
Q_UNUSED(deviceClassId)
Q_UNUSED(params)
qWarning() << "Plugin does not implement pairing.";
qCWarning(dcDeviceManager) << "Plugin does not implement pairing.";
return DeviceManager::DeviceSetupStatusFailure;
}
@ -471,7 +472,7 @@ QVariant DevicePlugin::configValue(const QString &paramName) const
DeviceManager::DeviceError DevicePlugin::setConfiguration(const ParamList &configuration)
{
foreach (const Param &param, configuration) {
qDebug() << "setting config" << param;
qCDebug(dcDeviceManager) << "setting config" << param;
DeviceManager::DeviceError result = setConfigValue(param.name(), param.value());
if (result != DeviceManager::DeviceErrorNoError) {
return result;
@ -487,18 +488,18 @@ DeviceManager::DeviceError DevicePlugin::setConfigValue(const QString &paramName
foreach (const ParamType &paramType, configurationDescription()) {
if (paramType.name() == paramName) {
if (!value.canConvert(paramType.type())) {
qWarning() << QString("Wrong parameter type for param %1. Got %2. Expected %3.")
qCWarning(dcDeviceManager) << QString("Wrong parameter type for param %1. Got %2. Expected %3.")
.arg(paramName).arg(value.toString()).arg(QVariant::typeToName(paramType.type()));
return DeviceManager::DeviceErrorInvalidParameter;
}
if (paramType.maxValue().isValid() && value > paramType.maxValue()) {
qWarning() << QString("Value out of range for param %1. Got %2. Max: %3.")
qCWarning(dcDeviceManager) << QString("Value out of range for param %1. Got %2. Max: %3.")
.arg(paramName).arg(value.toString()).arg(paramType.maxValue().toString());
return DeviceManager::DeviceErrorInvalidParameter;
}
if (paramType.minValue().isValid() && value < paramType.minValue()) {
qWarning() << QString("Value out of range for param %1. Got: %2. Min: %3.")
qCWarning(dcDeviceManager) << QString("Value out of range for param %1. Got: %2. Min: %3.")
.arg(paramName).arg(value.toString()).arg(paramType.minValue().toString());
return DeviceManager::DeviceErrorInvalidParameter;
}
@ -507,7 +508,7 @@ DeviceManager::DeviceError DevicePlugin::setConfigValue(const QString &paramName
}
}
if (!found) {
qWarning() << QString("Invalid parameter %1.").arg(paramName);
qCWarning(dcDeviceManager) << QString("Invalid parameter %1.").arg(paramName);
return DeviceManager::DeviceErrorInvalidParameter;
}
for (int i = 0; i < m_config.count(); i++) {
@ -581,9 +582,12 @@ bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
{
switch (requiredHardware()) {
case DeviceManager::HardwareResourceRadio433:
return deviceManager()->m_radio433->sendData(delay, rawData);
return deviceManager()->m_radio433->sendData(delay, rawData, repetitions);
case DeviceManager::HardwareResourceRadio868:
qCDebug(dcDeviceManager) << "Radio868 not connected yet";
return false;
default:
qWarning() << "Unknown harware type. Cannot send.";
qCWarning(dcDeviceManager) << "Unknown harware type. Cannot send.";
}
return false;
}
@ -600,7 +604,7 @@ QNetworkReply *DevicePlugin::networkManagerGet(const QNetworkRequest &request)
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
return deviceManager()->m_networkManager->get(pluginId(), request);
} else {
qWarning() << "ERROR: network manager resource missing for plugin " << pluginName();
qCWarning(dcDeviceManager) << "network manager resource missing for plugin " << pluginName();
}
return nullptr;
}
@ -617,7 +621,7 @@ QNetworkReply *DevicePlugin::networkManagerPost(const QNetworkRequest &request,
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
return deviceManager()->m_networkManager->post(pluginId(), request, data);
} else {
qWarning() << "ERROR: network manager resource missing for plugin " << pluginName();
qCWarning(dcDeviceManager) << "network manager resource missing for plugin " << pluginName();
}
return nullptr;
}
@ -633,7 +637,7 @@ QNetworkReply *DevicePlugin::networkManagerPut(const QNetworkRequest &request, c
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
return deviceManager()->m_networkManager->put(pluginId(), request, data);
} else {
qWarning() << "ERROR: network manager resource missing for plugin " << pluginName();
qCWarning(dcDeviceManager) << "network manager resource missing for plugin " << pluginName();
}
return nullptr;
}
@ -728,7 +732,7 @@ Types::Unit DevicePlugin::unitStringToUnit(const QString &unitString) const
} else if (unitString == "Dollar") {
return Types::UnitDollar;
} else {
qWarning() << "Could not parse unit:" << unitString << "in plugin" << this->pluginName();
qCWarning(dcDeviceManager) << "Could not parse unit:" << unitString << "in plugin" << this->pluginName();
}
return Types::UnitNone;
}

View File

@ -100,6 +100,7 @@
*/
#include "guhcore.h"
#include "loggingcategorys.h"
#include "jsonrpcserver.h"
#include "ruleengine.h"
#include "logging/logengine.h"
@ -107,8 +108,6 @@
#include "devicemanager.h"
#include "plugin/device.h"
#include <QDebug>
GuhCore* GuhCore::s_instance = 0;
/*! Returns a pointer to the single \l{GuhCore} instance. */
@ -124,7 +123,7 @@ GuhCore *GuhCore::instance()
GuhCore::~GuhCore()
{
m_logger->logSystemEvent(false);
qDebug() << "Shutting down. Bye.";
qCDebug(dcApplication) << "Shutting down. Bye.";
}
/*! Destroyes the \l{GuhCore} instance. */
@ -194,7 +193,7 @@ DeviceManager::DeviceError GuhCore::removeConfiguredDevice(const DeviceId &devic
}
if (!unhandledRules.isEmpty()) {
qWarning() << "There are unhandled rules which depend on this device.";
qCWarning(dcDeviceManager) << "There are unhandled rules which depend on this device.";
return DeviceManager::DeviceErrorDeviceInUse;
}
@ -381,25 +380,17 @@ RuleEngine *GuhCore::ruleEngine() const
GuhCore::GuhCore(QObject *parent) :
QObject(parent)
{
qDebug() << "*****************************************";
qDebug() << "* GUH version:" << GUH_VERSION_STRING << "starting up. *";
qDebug() << "*****************************************";
qCDebug(dcApplication) << "guh version:" << GUH_VERSION_STRING << "starting up.";
m_logger = new LogEngine(this);
qDebug() << "*****************************************";
qDebug() << "* Creating Device Manager *";
qDebug() << "*****************************************";
qCDebug(dcApplication) << "Creating Device Manager";
m_deviceManager = new DeviceManager(this);
qDebug() << "*****************************************";
qDebug() << "* Creating Rule Engine *";
qDebug() << "*****************************************";
qCDebug(dcApplication) << "Creating Rule Engine";
m_ruleEngine = new RuleEngine(this);
qDebug() << "*****************************************";
qDebug() << "* Starting JSON RPC Server *";
qDebug() << "*****************************************";
qCDebug(dcApplication) << "Starting JSON RPC Server";
m_jsonServer = new JsonRPCServer(this);
connect(m_deviceManager, &DeviceManager::eventTriggered, this, &GuhCore::gotEvent);
@ -466,7 +457,7 @@ void GuhCore::gotEvent(const Event &event)
// something like a EventParamDescriptor
ruleActionParam.setValue(eventValue);
qDebug() << "take over event param value" << ruleActionParam.value();
qCDebug(dcRuleEngine) << "take over event param value" << ruleActionParam.value();
}
newParams.append(ruleActionParam);
}
@ -477,22 +468,22 @@ void GuhCore::gotEvent(const Event &event)
// Now execute all the associated actions
foreach (const RuleAction &ruleAction, actions) {
Action action = ruleAction.toAction();
qDebug() << "executing action" << ruleAction.actionTypeId();
qCDebug(dcRuleEngine) << "executing action" << ruleAction.actionTypeId();
DeviceManager::DeviceError status = m_deviceManager->executeAction(action);
switch(status) {
case DeviceManager::DeviceErrorNoError:
break;
case DeviceManager::DeviceErrorSetupFailed:
qWarning() << "Error executing action. Device setup failed.";
qCWarning(dcRuleEngine) << "Error executing action. Device setup failed.";
break;
case DeviceManager::DeviceErrorAsync:
qDebug() << "Executing asynchronous action.";
qCDebug(dcRuleEngine) << "Executing asynchronous action.";
break;
case DeviceManager::DeviceErrorInvalidParameter:
qWarning() << "Error executing action. Invalid action parameter.";
qCWarning(dcRuleEngine) << "Error executing action. Invalid action parameter.";
break;
default:
qDebug() << "Error executing action:" << status;
qCWarning(dcRuleEngine) << "Error executing action:" << status;
}
m_logger->logAction(action, status == DeviceManager::DeviceErrorNoError ? Logging::LoggingLevelInfo : Logging::LoggingLevelAlert, status);
}

View File

@ -31,6 +31,7 @@
#include "ruleengine.h"
#include <QObject>
#include <QDebug>
class JsonRPCServer;
class Device;

View File

@ -20,6 +20,7 @@
#include <unistd.h>
#include "guhservice.h"
#include "loggingcategorys.h"
GuhService::GuhService(int argc, char **argv):
QtService<QCoreApplication>(argc, argv, "guh daemon")

View File

@ -24,6 +24,7 @@
#include "guhcore.h"
#include "devicemanager.h"
#include "types/action.h"
#include "loggingcategorys.h"
#include <QDebug>
@ -77,7 +78,7 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap &params)
JsonReply *ActionHandler::GetActionType(const QVariantMap &params) const
{
qDebug() << "asked for action type" << params;
qCDebug(dcJsonRpc) << "asked for action type" << params;
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
foreach (const DeviceClass &deviceClass, GuhCore::instance()->supportedDevices()) {
foreach (const ActionType &actionType, deviceClass.actionTypes()) {

View File

@ -22,6 +22,7 @@
#include "devicehandler.h"
#include "guhcore.h"
#include "devicemanager.h"
#include "loggingcategorys.h"
#include "plugin/device.h"
#include "plugin/deviceclass.h"
#include "plugin/deviceplugin.h"
@ -621,7 +622,7 @@ void DeviceHandler::devicesDiscovered(const DeviceClassId &deviceClassId, const
void DeviceHandler::deviceSetupFinished(Device *device, DeviceManager::DeviceError status)
{
qDebug() << "got a device setup finished";
qCDebug(dcJsonRpc) << "got a device setup finished";
if (!m_asynDeviceAdditions.contains(device->id())) {
return; // Not the device we're waiting for...
}
@ -641,7 +642,7 @@ void DeviceHandler::deviceSetupFinished(Device *device, DeviceManager::DeviceErr
void DeviceHandler::deviceEditFinished(Device *device, DeviceManager::DeviceError status)
{
qDebug() << "got async edit finished";
qCDebug(dcJsonRpc) << "got async edit finished";
if (!m_asynDeviceEditAdditions.contains(device->id())) {
return;
}
@ -655,10 +656,9 @@ void DeviceHandler::deviceEditFinished(Device *device, DeviceManager::DeviceErro
void DeviceHandler::pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId)
{
qDebug() << "handler: pairing finished";
qCDebug(dcJsonRpc) << "got pairing finished";
JsonReply *reply = m_asyncPairingRequests.take(pairingTransactionId);
if (!reply) {
qDebug() << "not for me";
return;
}

View File

@ -21,6 +21,7 @@
#include "eventhandler.h"
#include "guhcore.h"
#include "loggingcategorys.h"
EventHandler::EventHandler(QObject *parent) :
JsonHandler(parent)
@ -59,6 +60,7 @@ void EventHandler::eventTriggered(const Event &event)
JsonReply* EventHandler::GetEventType(const QVariantMap &params) const
{
qCDebug(dcJsonRpc) << "asked for event type" << params;
EventTypeId eventTypeId(params.value("eventTypeId").toString());
foreach (const DeviceClass &deviceClass, GuhCore::instance()->supportedDevices()) {
foreach (const EventType &eventType, deviceClass.eventTypes()) {

View File

@ -20,6 +20,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "jsonhandler.h"
#include "loggingcategorys.h"
#include <QMetaMethod>
#include <QDebug>
@ -45,6 +46,7 @@ QVariantMap JsonHandler::introspect(QMetaMethod::MethodType type)
if (!m_descriptions.contains(method.name()) || !m_params.contains(method.name()) || !m_returns.contains(method.name())) {
continue;
}
qCDebug(dcJsonRpc) << "got method" << method.name();
QVariantMap methodData;
methodData.insert("description", m_descriptions.value(method.name()));
methodData.insert("params", m_params.value(method.name()));
@ -57,7 +59,7 @@ QVariantMap JsonHandler::introspect(QMetaMethod::MethodType type)
continue;
}
if (QString(method.name()).contains(QRegExp("^[A-Z]"))) {
qDebug() << "got signal" << method.name();
qCDebug(dcJsonRpc) << "got signal" << method.name();
QVariantMap methodData;
methodData.insert("description", m_descriptions.value(method.name()));
methodData.insert("params", m_params.value(method.name()));
@ -98,7 +100,7 @@ void JsonHandler::setDescription(const QString &methodName, const QString &descr
return;
}
}
qWarning() << "Cannot set description. No such method:" << methodName;
qCWarning(dcJsonRpc) << "Cannot set description. No such method:" << methodName;
}
void JsonHandler::setParams(const QString &methodName, const QVariantMap &params)
@ -110,7 +112,7 @@ void JsonHandler::setParams(const QString &methodName, const QVariantMap &params
return;
}
}
qWarning() << "Cannot set params. No such method:" << methodName;
qCWarning(dcJsonRpc) << "Cannot set params. No such method:" << methodName;
}
void JsonHandler::setReturns(const QString &methodName, const QVariantMap &returns)
@ -122,7 +124,7 @@ void JsonHandler::setReturns(const QString &methodName, const QVariantMap &retur
return;
}
}
qWarning() << "Cannot set returns. No such method:" << methodName;
qCWarning(dcJsonRpc) << "Cannot set returns. No such method:" << methodName;
}
JsonReply *JsonHandler::createReply(const QVariantMap &data) const

View File

@ -36,6 +36,7 @@
#include "plugin/device.h"
#include "rule.h"
#include "ruleengine.h"
#include "loggingcategorys.h"
#include "devicehandler.h"
#include "actionhandler.h"
@ -129,7 +130,6 @@ JsonReply* JsonRPCServer::Version(const QVariantMap &params) const
JsonReply* JsonRPCServer::SetNotificationStatus(const QVariantMap &params)
{
QUuid clientId = this->property("clientId").toUuid();
// qDebug() << "got client socket" << clientId;
m_clients[clientId] = params.value("enabled").toBool();
QVariantMap returns;
returns.insert("enabled", m_clients[clientId]);
@ -153,23 +153,22 @@ void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &jsonDat
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &error);
if(error.error != QJsonParseError::NoError) {
qDebug() << "failed to parse data" << jsonData << ":" << error.errorString();
qCWarning(dcJsonRpc) << "failed to parse data" << jsonData << ":" << error.errorString();
}
// qDebug() << "-------------------------\n" << jsonDoc.toJson();
QVariantMap message = jsonDoc.toVariant().toMap();
bool success;
int commandId = message.value("id").toInt(&success);
if (!success) {
qWarning() << "Error parsing command. Missing \"id\":" << jsonData;
qCWarning(dcJsonRpc) << "Error parsing command. Missing \"id\":" << jsonData;
sendErrorResponse(clientId, commandId, "Error parsing command. Missing 'id'");
return;
}
QStringList commandList = message.value("method").toString().split('.');
if (commandList.count() != 2) {
qWarning() << "Error parsing method.\nGot:" << message.value("method").toString() << "\nExpected: \"Namespace.method\"";
qCWarning(dcJsonRpc) << "Error parsing method.\nGot:" << message.value("method").toString() << "\nExpected: \"Namespace.method\"";
sendErrorResponse(clientId, commandId, QString("Error parsing method. Got: '%1'', Expected: 'Namespace.method'").arg(message.value("method").toString()));
return;
}

View File

@ -24,6 +24,7 @@
#include "plugin/device.h"
#include "devicemanager.h"
#include "ruleengine.h"
#include "loggingcategorys.h"
#include <QStringList>
#include <QJsonDocument>
@ -419,7 +420,7 @@ QVariantMap JsonTypes::packStateEvaluator(const StateEvaluator &stateEvaluator)
foreach (const StateEvaluator &childEvaluator, stateEvaluator.childEvaluators()) {
childEvaluators.append(packStateEvaluator(childEvaluator));
}
qDebug() << "state operator:" << stateOperator() << stateEvaluator.operatorType();
qCDebug(dcJsonRpc) << "state operator:" << stateOperator() << stateEvaluator.operatorType();
variantMap.insert("operator", stateOperator().at(stateEvaluator.operatorType()));
if (childEvaluators.count() > 0) {
variantMap.insert("childEvaluators", childEvaluators);
@ -508,7 +509,6 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
}
QVariantList discoveryParamTypes;
foreach (const ParamType &paramType, deviceClass.discoveryParamTypes()) {
qDebug() << "packing discoverparam" << packParamType(paramType);
discoveryParamTypes.append(packParamType(paramType));
}
@ -525,7 +525,7 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
QVariantMap JsonTypes::packPlugin(DevicePlugin *plugin)
{
Q_UNUSED(plugin)
qWarning() << "packPlugin not implemented yet!";
qCWarning(dcDeviceManager) << "packPlugin not implemented yet!";
return QVariantMap();
}
@ -752,23 +752,22 @@ StateDescriptor JsonTypes::unpackStateDescriptor(const QVariantMap &stateDescrip
QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, const QVariantMap &map)
{
s_lastError.clear();
// qDebug() << "validating Map" << templateMap << map;
// Make sure all values defined in the template are around
foreach (const QString &key, templateMap.keys()) {
QString strippedKey = key;
strippedKey.remove(QRegExp("^o:"));
if (!key.startsWith("o:") && !map.contains(strippedKey)) {
qDebug() << "*** missing key" << key;
qDebug() << "Expected: " << templateMap;
qDebug() << "Got: " << map;
qCWarning(dcJsonRpc) << "*** missing key" << key;
qCWarning(dcJsonRpc) << "Expected: " << templateMap;
qCWarning(dcJsonRpc) << "Got: " << map;
QJsonDocument jsonDoc = QJsonDocument::fromVariant(map);
return report(false, QString("Missing key %1 in %2").arg(key).arg(QString(jsonDoc.toJson())));
}
if (map.contains(strippedKey)) {
QPair<bool, QString> result = validateVariant(templateMap.value(key), map.value(strippedKey));
if (!result.first) {
qDebug() << "Object not matching template" << templateMap.value(key) << map.value(strippedKey);
qCWarning(dcJsonRpc) << "Object not matching template" << templateMap.value(key) << map.value(strippedKey);
return result;
}
}
@ -779,7 +778,7 @@ QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, cons
QString optKey = "o:" + key;
if (!templateMap.contains(key) && !templateMap.contains(optKey)) {
qDebug() << "Forbidden param" << key << "in params";
qCWarning(dcJsonRpc) << "Forbidden param" << key << "in params";
QJsonDocument jsonDoc = QJsonDocument::fromVariant(map);
return report(false, QString("Forbidden key \"%1\" in %2").arg(key).arg(QString(jsonDoc.toJson())));
}
@ -790,7 +789,6 @@ QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, cons
QPair<bool, QString> JsonTypes::validateProperty(const QVariant &templateValue, const QVariant &value)
{
//qDebug() << "validating property. template:" << templateValue << "got:" << value;
QString strippedTemplateValue = templateValue.toString();
if (strippedTemplateValue == JsonTypes::basicTypeToString(JsonTypes::Variant)) {
@ -812,7 +810,7 @@ QPair<bool, QString> JsonTypes::validateProperty(const QVariant &templateValue,
QString errorString = QString("Param %1 is not a int.").arg(value.toString());
return report(value.canConvert(QVariant::Int), errorString);
}
qWarning() << QString("Unhandled property type: %1 (expected: %2)").arg(value.toString()).arg(strippedTemplateValue);
qCWarning(dcJsonRpc) << QString("Unhandled property type: %1 (expected: %2)").arg(value.toString()).arg(strippedTemplateValue);
QString errorString = QString("Unhandled property type: %1 (expected: %2)").arg(value.toString()).arg(strippedTemplateValue);
return report(false, errorString);
}
@ -824,10 +822,9 @@ QPair<bool, QString> JsonTypes::validateList(const QVariantList &templateList, c
for (int i = 0; i < list.count(); ++i) {
QVariant listEntry = list.at(i);
// qDebug() << "validating" << list << templateList;
QPair<bool, QString> result = validateVariant(entryTemplate, listEntry);
if (!result.first) {
qDebug() << "List entry not matching template";
qCWarning(dcJsonRpc) << "List entry not matching template";
return result;
}
}
@ -841,17 +838,15 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
if (templateVariant.toString().startsWith("$ref:")) {
QString refName = templateVariant.toString();
if (refName == actionRef()) {
// qDebug() << "validating action";
QPair<bool, QString> result = validateMap(actionDescription(), variant.toMap());
if (!result.first) {
qDebug() << "Error validating action";
qCWarning(dcJsonRpc) << "Error validating action";
return result;
}
} else if (refName == eventRef()) {
// qDebug() << "validating event";
QPair<bool, QString> result = validateMap(eventDescription(), variant.toMap());
if (!result.first) {
qDebug() << "event not valid";
qCWarning(dcJsonRpc) << "event not valid";
return result;
}
} else if (refName == paramRef()) {
@ -861,186 +856,186 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
} else if (refName == paramDescriptorRef()) {
QPair<bool, QString> result = validateMap(paramDescriptorDescription(), variant.toMap());
if (!result.first) {
qDebug() << "ParamDescriptor not valid";
qCWarning(dcJsonRpc) << "ParamDescriptor not valid";
return result;
}
} else if (refName == deviceRef()) {
QPair<bool, QString> result = validateMap(deviceDescription(), variant.toMap());
if (!result.first) {
qDebug() << "device not valid";
qCWarning(dcJsonRpc) << "device not valid";
return result;
}
} else if (refName == deviceDescriptorRef()) {
QPair<bool, QString> result = validateMap(deviceDescriptorDescription(), variant.toMap());
if (!result.first) {
qDebug() << "devicedescription not valid";
qCWarning(dcJsonRpc) << "devicedescription not valid";
return result;
}
} else if (refName == vendorRef()) {
QPair<bool, QString> result = validateMap(vendorDescription(), variant.toMap());
if (!result.first) {
qDebug() << "value not allowed in" << vendorRef();
qCWarning(dcJsonRpc) << "value not allowed in" << vendorRef();
}
} else if (refName == deviceClassRef()) {
QPair<bool, QString> result = validateMap(deviceClassDescription(), variant.toMap());
if (!result.first) {
qDebug() << "device class not valid";
qCWarning(dcJsonRpc) << "device class not valid";
return result;
}
} else if (refName == paramTypeRef()) {
QPair<bool, QString> result = validateMap(paramTypeDescription(), variant.toMap());
if (!result.first) {
qDebug() << "param types not matching";
qCWarning(dcJsonRpc) << "param types not matching";
return result;
}
} else if (refName == ruleActionRef()) {
QPair<bool, QString> result = validateMap(ruleActionDescription(), variant.toMap());
if (!result.first) {
qDebug() << "ruleAction type not matching";
qCWarning(dcJsonRpc) << "ruleAction type not matching";
return result;
}
} else if (refName == ruleActionParamRef()) {
QPair<bool, QString> result = validateMap(ruleActionParamDescription(), variant.toMap());
if (!result.first) {
qDebug() << "ruleActionParam type not matching";
qCWarning(dcJsonRpc) << "ruleActionParam type not matching";
return result;
}
} else if (refName == actionTypeRef()) {
QPair<bool, QString> result = validateMap(actionTypeDescription(), variant.toMap());
if (!result.first) {
qDebug() << "action type not matching";
qCWarning(dcJsonRpc) << "action type not matching";
return result;
}
} else if (refName == eventTypeRef()) {
QPair<bool, QString> result = validateMap(eventTypeDescription(), variant.toMap());
if (!result.first) {
qDebug() << "event type not matching";
qCWarning(dcJsonRpc) << "event type not matching";
return result;
}
} else if (refName == stateTypeRef()) {
QPair<bool, QString> result = validateMap(stateTypeDescription(), variant.toMap());
if (!result.first) {
qDebug() << "state type not matching";
qCWarning(dcJsonRpc) << "state type not matching";
return result;
}
} else if (refName == stateEvaluatorRef()) {
QPair<bool, QString> result = validateMap(stateEvaluatorDescription(), variant.toMap());
if (!result.first) {
qDebug() << "stateEvaluator type not matching";
qCWarning(dcJsonRpc) << "stateEvaluator type not matching";
return result;
}
} else if (refName == stateDescriptorRef()) {
QPair<bool, QString> result = validateMap(stateDescriptorDescription(), variant.toMap());
if (!result.first) {
qDebug() << "stateDescriptor type not matching";
qCWarning(dcJsonRpc) << "stateDescriptor type not matching";
return result;
}
} else if (refName == pluginRef()) {
QPair<bool, QString> result = validateMap(pluginDescription(), variant.toMap());
if (!result.first) {
qDebug() << "plugin not matching";
qCWarning(dcJsonRpc) << "plugin not matching";
return result;
}
} else if (refName == ruleRef()) {
QPair<bool, QString> result = validateMap(ruleDescription(), variant.toMap());
if (!result.first) {
qDebug() << "rule type not matching";
qCWarning(dcJsonRpc) << "rule type not matching";
return result;
}
} else if (refName == ruleDescriptionRef()) {
QPair<bool, QString> result = validateMap(s_ruleDescription, variant.toMap());
if (!result.first) {
qDebug() << "ruleDescription type not matching";
qCWarning(dcJsonRpc) << "ruleDescription type not matching";
return result;
}
} else if (refName == eventDescriptorRef()) {
QPair<bool, QString> result = validateMap(eventDescriptorDescription(), variant.toMap());
if (!result.first) {
qDebug() << "evendescriptor not matching";
qCWarning(dcJsonRpc) << "evendescriptor not matching";
return result;
}
} else if (refName == logEntryRef()) {
QPair<bool, QString> result = validateMap(logEntryDescription(), variant.toMap());
if (!result.first) {
qDebug() << "logEntry not matching";
qCWarning(dcJsonRpc) << "logEntry not matching";
return result;
}
} else if (refName == basicTypeRef()) {
QPair<bool, QString> result = validateBasicType(variant);
if (!result.first) {
qDebug() << "value not allowed in" << basicTypeRef();
qCWarning(dcJsonRpc) << "value not allowed in" << basicTypeRef();
return result;
}
} else if (refName == stateOperatorRef()) {
QPair<bool, QString> result = validateEnum(s_stateOperator, variant);
if (!result.first) {
qDebug() << "value not allowed in" << stateOperatorRef();
qCWarning(dcJsonRpc) << "value not allowed in" << stateOperatorRef();
return result;
}
} else if (refName == createMethodRef()) {
QPair<bool, QString> result = validateEnum(s_createMethod, variant);
if (!result.first) {
qDebug() << "value not allowed in" << createMethodRef() << variant;
qCWarning(dcJsonRpc) << "value not allowed in" << createMethodRef() << variant;
return result;
}
} else if (refName == setupMethodRef()) {
QPair<bool, QString> result = validateEnum(s_setupMethod, variant);
if (!result.first) {
qDebug() << "value not allowed in" << createMethodRef();
qCWarning(dcJsonRpc) << "value not allowed in" << createMethodRef();
return result;
}
} else if (refName == valueOperatorRef()) {
QPair<bool, QString> result = validateEnum(s_valueOperator, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(valueOperatorRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(valueOperatorRef());
return result;
}
} else if (refName == deviceErrorRef()) {
QPair<bool, QString> result = validateEnum(s_deviceError, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(deviceErrorRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(deviceErrorRef());
return result;
}
} else if (refName == ruleErrorRef()) {
QPair<bool, QString> result = validateEnum(s_ruleError, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(ruleErrorRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(ruleErrorRef());
return result;
}
} else if (refName == loggingErrorRef()) {
QPair<bool, QString> result = validateEnum(s_loggingError, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingErrorRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingErrorRef());
return result;
}
} else if (refName == loggingSourceRef()) {
QPair<bool, QString> result = validateEnum(s_loggingSource, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingSourceRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingSourceRef());
return result;
}
} else if (refName == loggingLevelRef()) {
QPair<bool, QString> result = validateEnum(s_loggingLevel, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingLevelRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingLevelRef());
return result;
}
} else if (refName == loggingEventTypeRef()) {
QPair<bool, QString> result = validateEnum(s_loggingEventType, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingEventTypeRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(loggingEventTypeRef());
return result;
}
} else if (refName == inputTypeRef()) {
QPair<bool, QString> result = validateEnum(s_inputType, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(inputTypeRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(inputTypeRef());
return result;
}
} else if (refName == unitRef()) {
QPair<bool, QString> result = validateEnum(s_unit, variant);
if (!result.first) {
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(unitRef());
qCWarning(dcJsonRpc) << QString("value %1 not allowed in %2").arg(variant.toString()).arg(unitRef());
return result;
}
} else {
@ -1051,7 +1046,7 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
} else {
QPair<bool, QString> result = JsonTypes::validateProperty(templateVariant, variant);
if (!result.first) {
qDebug() << "property not matching:" << templateVariant << "!=" << variant;
qCWarning(dcJsonRpc) << "property not matching:" << templateVariant << "!=" << variant;
return result;
}
}
@ -1071,7 +1066,7 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
break;
}
default:
qDebug() << "unhandled value" << templateVariant;
qCWarning(dcJsonRpc) << "unhandled value" << templateVariant;
return report(false, QString("Unhandled value %1.").arg(templateVariant.toString()));
}
return report(true, "");

View File

@ -22,6 +22,7 @@
#include "logginghandler.h"
#include "logging/logengine.h"
#include "guhcore.h"
#include "loggingcategorys.h"
LoggingHandler::LoggingHandler(QObject *parent) :
JsonHandler(parent)
@ -60,8 +61,7 @@ void LoggingHandler::logEntryAdded(const LogEntry &logEntry)
JsonReply* LoggingHandler::GetLogEntries(const QVariantMap &params) const
{
Q_UNUSED(params)
qCDebug(dcJsonRpc) << "asked for log entries" << params;
QVariantList entries;
foreach (const LogEntry &entry, GuhCore::instance()->logEngine()->logEntries()) {
entries.append(JsonTypes::packLogEntry(entry));

View File

@ -23,6 +23,7 @@
#include "guhcore.h"
#include "ruleengine.h"
#include "loggingcategorys.h"
#include <QDebug>
@ -150,7 +151,7 @@ JsonReply* RulesHandler::AddRule(const QVariantMap &params)
{
if (params.contains("eventDescriptor") && params.contains("eventDescriptorList")) {
QVariantMap returns;
qWarning() << "Only one of eventDesciptor or eventDescriptorList may be used.";
qCWarning(dcJsonRpc) << "Only one of eventDesciptor or eventDescriptorList may be used.";
returns.insert("ruleError", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidParameter));
return createReply(returns);
}
@ -158,7 +159,7 @@ JsonReply* RulesHandler::AddRule(const QVariantMap &params)
if (params.contains("eventDescriptor") || params.contains("eventDescriptorList")) {
if (params.contains("exitActions")) {
QVariantMap returns;
qWarning() << "The exitActions will never be executed if the rule contains an eventDescriptor.";
qCWarning(dcJsonRpc) << "The exitActions will never be executed if the rule contains an eventDescriptor.";
returns.insert("ruleError", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidRuleFormat));
return createReply(returns);
}
@ -168,11 +169,11 @@ JsonReply* RulesHandler::AddRule(const QVariantMap &params)
QList<EventDescriptor> eventDescriptorList;
if (params.contains("eventDescriptor")) {
QVariantMap eventMap = params.value("eventDescriptor").toMap();
qDebug() << "unpacking eventDescriptor" << eventMap;
qCDebug(dcJsonRpc) << "unpacking eventDescriptor" << eventMap;
eventDescriptorList.append(JsonTypes::unpackEventDescriptor(eventMap));
} else if (params.contains("eventDescriptorList")) {
QVariantList eventDescriptors = params.value("eventDescriptorList").toList();
qDebug() << "unpacking eventDescriptorList:" << eventDescriptors;
qCDebug(dcJsonRpc) << "unpacking eventDescriptorList:" << eventDescriptors;
foreach (const QVariant &eventVariant, eventDescriptors) {
QVariantMap eventMap = eventVariant.toMap();
eventDescriptorList.append(JsonTypes::unpackEventDescriptor(eventMap));
@ -180,20 +181,20 @@ JsonReply* RulesHandler::AddRule(const QVariantMap &params)
}
// Check and unpack stateEvaluator
qDebug() << "unpacking stateEvaluator:" << params.value("stateEvaluator").toMap();
qCDebug(dcJsonRpc) << "unpacking stateEvaluator:" << params.value("stateEvaluator").toMap();
StateEvaluator stateEvaluator = JsonTypes::unpackStateEvaluator(params.value("stateEvaluator").toMap());
// Check and unpack actions
QList<RuleAction> actions;
QVariantList actionList = params.value("actions").toList();
qDebug() << "unpacking actions:" << actionList;
qCDebug(dcJsonRpc) << "unpacking actions:" << actionList;
foreach (const QVariant &actionVariant, actionList) {
QVariantMap actionMap = actionVariant.toMap();
RuleAction action(ActionTypeId(actionMap.value("actionTypeId").toString()), DeviceId(actionMap.value("deviceId").toString()));
RuleActionParamList actionParamList = JsonTypes::unpackRuleActionParams(actionMap.value("ruleActionParams").toList());
foreach (const RuleActionParam &ruleActionParam, actionParamList) {
if (!ruleActionParam.isValid()) {
qWarning() << "ERROR: got actionParam with value AND eventTypeId!";
qCWarning(dcJsonRpc) << "got an actionParam with value AND eventTypeId!";
QVariantMap returns;
returns.insert("ruleError", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidRuleActionParameter));
return createReply(returns);
@ -212,14 +213,14 @@ JsonReply* RulesHandler::AddRule(const QVariantMap &params)
// We have an eventTypeId
if (eventDescriptorList.isEmpty()) {
QVariantMap returns;
qWarning() << "RuleAction" << ruleAction.actionTypeId() << "contains an eventTypeId, but there are no eventDescriptors.";
qCWarning(dcJsonRpc) << "RuleAction" << ruleAction.actionTypeId() << "contains an eventTypeId, but there are no eventDescriptors.";
returns.insert("ruleError", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidRuleActionParameter));
return createReply(returns);
}
// now check if this eventType is in the eventDescriptorList of this rule
if (!checkEventDescriptors(eventDescriptorList, ruleActionParam.eventTypeId())) {
QVariantMap returns;
qWarning() << "eventTypeId from RuleAction" << ruleAction.actionTypeId() << "missing in eventDescriptors.";
qCWarning(dcJsonRpc) << "eventTypeId from RuleAction" << ruleAction.actionTypeId() << "missing in eventDescriptors.";
returns.insert("ruleError", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidRuleActionParameter));
return createReply(returns);
}
@ -229,9 +230,9 @@ JsonReply* RulesHandler::AddRule(const QVariantMap &params)
QVariant::Type actionParamType = getActionParamType(ruleAction.actionTypeId(), ruleActionParam.name());
if (eventParamType != actionParamType) {
QVariantMap returns;
qWarning() << "RuleActionParam" << ruleActionParam.name() << " and given event param " << ruleActionParam.eventParamName() << "have not the same type:";
qWarning() << " -> actionParamType:" << actionParamType;
qWarning() << " -> eventParamType:" << eventParamType;
qCWarning(dcJsonRpc) << "RuleActionParam" << ruleActionParam.name() << " and given event param " << ruleActionParam.eventParamName() << "have not the same type:";
qCWarning(dcJsonRpc) << " -> actionParamType:" << actionParamType;
qCWarning(dcJsonRpc) << " -> eventParamType:" << eventParamType;
returns.insert("ruleError", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorTypesNotMatching));
return createReply(returns);
}
@ -251,18 +252,18 @@ JsonReply* RulesHandler::AddRule(const QVariantMap &params)
QList<RuleAction> exitActions;
if (params.contains("exitActions")) {
QVariantList exitActionList = params.value("exitActions").toList();
qDebug() << "unpacking exitActions:" << exitActionList;
qCDebug(dcJsonRpc) << "unpacking exitActions:" << exitActionList;
foreach (const QVariant &actionVariant, exitActionList) {
QVariantMap actionMap = actionVariant.toMap();
RuleAction action(ActionTypeId(actionMap.value("actionTypeId").toString()), DeviceId(actionMap.value("deviceId").toString()));
if (action.isEventBased()) {
qWarning() << "ERROR: got exitAction with a param value containing an eventTypeId!";
qCWarning(dcJsonRpc) << "got exitAction with a param value containing an eventTypeId!";
QVariantMap returns;
returns.insert("ruleError", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidRuleActionParameter));
return createReply(returns);
}
action.setRuleActionParams(JsonTypes::unpackRuleActionParams(actionMap.value("ruleActionParams").toList()));
qDebug() << "params in exitAction" << action.ruleActionParams();
qCDebug(dcJsonRpc) << "params in exitAction" << action.ruleActionParams();
exitActions.append(action);
}
}

View File

@ -21,6 +21,7 @@
#include "statehandler.h"
#include "guhcore.h"
#include "loggingcategorys.h"
StateHandler::StateHandler(QObject *parent) :
JsonHandler(parent)
@ -44,6 +45,7 @@ QString StateHandler::name() const
JsonReply* StateHandler::GetStateType(const QVariantMap &params) const
{
qCDebug(dcJsonRpc) << "asked for state type" << params;
StateTypeId stateTypeId(params.value("stateTypeId").toString());
foreach (const DeviceClass &deviceClass, GuhCore::instance()->supportedDevices()) {
foreach (const StateType &stateType, deviceClass.stateTypes()) {

View File

@ -19,6 +19,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "logengine.h"
#include "loggingcategorys.h"
#include "logging.h"
#include <QSqlDatabase>
@ -35,7 +36,7 @@ LogEngine::LogEngine(QObject *parent):
m_db = QSqlDatabase::addDatabase("QSQLITE");
m_db.setDatabaseName("/tmp/guhd-logs.sqlite");
if (!m_db.open()) {
qWarning() << "Error opening log database:" << m_db.lastError().driverText() << m_db.lastError().databaseText();
qCWarning(dcLogEngine) << "Error opening log database:" << m_db.lastError().driverText() << m_db.lastError().databaseText();
return;
}
@ -141,7 +142,7 @@ void LogEngine::appendLogEntry(const LogEntry &entry)
query.exec(queryString);
if (query.lastError().isValid()) {
qWarning() << "Error writing log entry. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
qCWarning(dcLogEngine) << "Error writing log entry. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
}
}
@ -161,17 +162,17 @@ void LogEngine::initDB()
if (query.next()) {
int version = query.value("data").toInt();
if (version != DB_SCHEMA_VERSION) {
qWarning() << "Log schema version not matching! Schema upgrade not implemented yet. Logging might fail.";
qCWarning(dcLogEngine) << "Log schema version not matching! Schema upgrade not implemented yet. Logging might fail.";
} else {
qDebug() << "version matches";
qCDebug(dcLogEngine) << "Log database schema version matches";
}
} else {
qWarning() << "Broken log database. Version not found in metadata table.";
qCWarning(dcLogEngine) << "Broken log database. Version not found in metadata table.";
}
if (!m_db.tables().contains("sourceTypes")) {
query.exec("CREATE TABLE sourceTypes (id int, name varchar(20), PRIMARY KEY(id));");
qDebug() << query.lastError().databaseText();
qCDebug(dcLogEngine) << query.lastError().databaseText();
QMetaEnum logTypes = Logging::staticMetaObject.enumerator(Logging::staticMetaObject.indexOfEnumerator("LoggingSource"));
Q_ASSERT_X(logTypes.isValid(), "LogEngine", "Logging has no enum LoggingSource");
for (int i = 0; i < logTypes.keyCount(); i++) {
@ -181,7 +182,7 @@ void LogEngine::initDB()
if (!m_db.tables().contains("loggingEventTypes")) {
query.exec("CREATE TABLE loggingEventTypes (id int, name varchar(20), PRIMARY KEY(id));");
qDebug() << query.lastError().databaseText();
qCDebug(dcLogEngine) << query.lastError().databaseText();
QMetaEnum logTypes = Logging::staticMetaObject.enumerator(Logging::staticMetaObject.indexOfEnumerator("LoggingEventType"));
Q_ASSERT_X(logTypes.isValid(), "LogEngine", "Logging has no enum LoggingEventType");
for (int i = 0; i < logTypes.keyCount(); i++) {
@ -205,7 +206,7 @@ void LogEngine::initDB()
"FOREIGN KEY(loggingEventType) REFERENCES loggingEventTypes(id)"
");");
if (query.lastError().isValid()) {
qWarning() << "Error creating log table in database. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
qCWarning(dcLogEngine) << "Error creating log table in database. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
}
}
}

View File

@ -21,33 +21,79 @@
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QLoggingCategory>
#include <QCommandLineOption>
#include <QMessageLogger>
#include <QtPlugin>
#include "guhcore.h"
#include "guhservice.h"
#include "loggingcategorys.h"
QHash<QString, bool> s_loggingFilters;
void loggingCategoryFilter(QLoggingCategory *category)
{
if (s_loggingFilters.contains(category->categoryName())) {
bool debugEnabled = s_loggingFilters.value(category->categoryName());
category->setEnabled(QtDebugMsg, debugEnabled);
category->setEnabled(QtWarningMsg, debugEnabled || s_loggingFilters.value("Warnings"));
} else {
category->setEnabled(QtDebugMsg, false);
category->setEnabled(QtWarningMsg, s_loggingFilters.value("qml") || s_loggingFilters.value("Warnings"));
}
}
int main(int argc, char *argv[])
{
//qInstallMessageHandler(myMessageOutput);
QCoreApplication application(argc, argv);
application.setOrganizationName("guh");
application.setApplicationName("guhd");
application.setApplicationVersion(GUH_VERSION_STRING);
s_loggingFilters.insert("Application", true);
s_loggingFilters.insert("Warnings", true);
s_loggingFilters.insert("DeviceManager", true);
s_loggingFilters.insert("RuleEngine", true);
s_loggingFilters.insert("Connection", true);
s_loggingFilters.insert("JsonRpc", false);
s_loggingFilters.insert("Hardware", false);
s_loggingFilters.insert("LogEngine", false);
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
QString description = QString("\nguh ( /[guːh]/ ) is an open source home automation server, which allows to\n"
QString applicationDescription = QString("\nguh ( /[guːh]/ ) is an open source home automation server, which allows to\n"
"control a lot of different devices from many different manufacturers.\n"
"guhd %1 (C) 2014-2015 guh\n"
"Released under the GNU GENERAL PUBLIC LICENSE Version 2.").arg(GUH_VERSION_STRING);
parser.setApplicationDescription(description);
parser.setApplicationDescription(applicationDescription);
QString debugDescription = QString("Debug categories to enable. Prefix with \"No\" to disable. Warnings from all categories will be printed unless explicitly muted with \"NoWarnings\". \nCategories are:");
foreach (const QString &filterName, s_loggingFilters.keys()) {
debugDescription += "\n" + filterName + " (" + (s_loggingFilters.value(filterName) ? "yes" : "no") + ")";
}
QCommandLineOption debugOption(QStringList() << "d" << "debug", debugDescription, "[No]DebugCategory");
parser.addOption(debugOption);
QCommandLineOption foregroundOption(QStringList() << "n" << "no-daemon", QCoreApplication::translate("main", "Run guhd in the foreground, not as daemon."));
parser.addOption(foregroundOption);
parser.process(application);
foreach (QString debugArea, parser.values(debugOption)) {
bool enable = !debugArea.startsWith("No");
debugArea.remove(QRegExp("^No"));
if (s_loggingFilters.contains(debugArea)) {
s_loggingFilters[debugArea] = enable;
} else {
qWarning() << "No such debug category:" << debugArea;
}
}
QLoggingCategory::installFilter(loggingCategoryFilter);
bool startForeground = parser.isSet(foregroundOption);
if (startForeground) {
GuhCore::instance()->setRunningMode(GuhCore::RunningModeApplication);

View File

@ -76,6 +76,7 @@
#include "ruleengine.h"
#include "loggingcategorys.h"
#include "types/paramdescriptor.h"
#include "types/eventdescriptor.h"
@ -98,14 +99,14 @@ RuleEngine::RuleEngine(QObject *parent) :
{
m_settingsFile = QCoreApplication::instance()->organizationName() + "/rules";
QSettings settings(m_settingsFile);
qDebug() << "laoding rules from" << settings.fileName();
qCDebug(dcRuleEngine) << "laoding rules from" << settings.fileName();
foreach (const QString &idString, settings.childGroups()) {
settings.beginGroup(idString);
QString name = settings.value("name", idString).toString();
bool enabled = settings.value("enabled", true).toBool();
qDebug() << "found rule" << name << idString;
qCDebug(dcRuleEngine) << "load rule" << name << idString;
QList<EventDescriptor> eventDescriptorList;
settings.beginGroup("events");
@ -203,7 +204,7 @@ QList<Rule> RuleEngine::evaluateEvent(const Event &event)
{
Device *device = GuhCore::instance()->findConfiguredDevice(event.deviceId());
qDebug() << "got event:" << event << device->name() << event.eventTypeId();
qCDebug(dcRuleEngine) << "got event:" << event << device->name() << event.eventTypeId();
QList<Rule> rules;
foreach (const RuleId &id, m_ruleIds) {
@ -217,9 +218,9 @@ QList<Rule> RuleEngine::evaluateEvent(const Event &event)
if (containsState(rule.stateEvaluator(), event)) {
if (rule.stateEvaluator().evaluate()) {
if (m_activeRules.contains(rule.id())) {
qDebug() << "Rule" << rule.id() << "still in active state.";
qCDebug(dcRuleEngine) << "Rule" << rule.id() << "still in active state.";
} else {
qDebug() << "Rule" << rule.id() << "entered active state.";
qCDebug(dcRuleEngine) << "Rule" << rule.id() << "entered active state.";
rule.setActive(true);
m_rules[rule.id()] = rule;
m_activeRules.append(rule.id());
@ -227,7 +228,7 @@ QList<Rule> RuleEngine::evaluateEvent(const Event &event)
}
} else {
if (m_activeRules.contains(rule.id())) {
qDebug() << "Rule" << rule.id() << "left active state.";
qCDebug(dcRuleEngine) << "Rule" << rule.id() << "left active state.";
rule.setActive(false);
m_rules[rule.id()] = rule;
m_activeRules.removeAll(rule.id());
@ -238,7 +239,7 @@ QList<Rule> RuleEngine::evaluateEvent(const Event &event)
} else {
if (containsEvent(rule, event)) {
if (rule.stateEvaluator().evaluate()) {
qDebug() << "Rule" << rule.id() << "contains event" << event.eventId() << "and all states match.";
qCDebug(dcRuleEngine) << "Rule" << rule.id() << "contains event" << event.eventId() << "and all states match.";
rules.append(rule);
}
}
@ -261,7 +262,7 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
return RuleErrorInvalidRuleId;
}
if (!findRule(ruleId).id().isNull()) {
qWarning() << "Already have a rule with this id!";
qCWarning(dcRuleEngine) << "Already have a rule with this id!";
return RuleErrorInvalidRuleId;
}
@ -270,7 +271,7 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
foreach (const EventDescriptor &eventDescriptor, eventDescriptorList) {
Device *device = GuhCore::instance()->findConfiguredDevice(eventDescriptor.deviceId());
if (!device) {
qWarning() << "Cannot create rule. No configured device for eventTypeId" << eventDescriptor.eventTypeId();
qCWarning(dcRuleEngine) << "Cannot create rule. No configured device for eventTypeId" << eventDescriptor.eventTypeId();
return RuleErrorDeviceNotFound;
}
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(device->deviceClassId());
@ -282,7 +283,7 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
}
}
if (!eventTypeFound) {
qWarning() << "Cannot create rule. Device " + device->name() + " has no event type:" << eventDescriptor.eventTypeId();
qCWarning(dcRuleEngine) << "Cannot create rule. Device " + device->name() + " has no event type:" << eventDescriptor.eventTypeId();
return RuleErrorEventTypeNotFound;
}
}
@ -290,7 +291,7 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
foreach (const RuleAction &action, actions) {
Device *device = GuhCore::instance()->findConfiguredDevice(action.deviceId());
if (!device) {
qWarning() << "Cannot create rule. No configured device for actionTypeId" << action.actionTypeId();
qCWarning(dcRuleEngine) << "Cannot create rule. No configured device for actionTypeId" << action.actionTypeId();
return RuleErrorDeviceNotFound;
}
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(device->deviceClassId());
@ -302,18 +303,18 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
}
}
if (!actionTypeFound) {
qWarning() << "Cannot create rule. Device " + device->name() + " has no action type:" << action.actionTypeId();
qCWarning(dcRuleEngine) << "Cannot create rule. Device " + device->name() + " has no action type:" << action.actionTypeId();
return RuleErrorActionTypeNotFound;
}
}
if (actions.count() > 0) {
qDebug() << "***** actions" << actions.last().actionTypeId() << actions.last().ruleActionParams();
qCDebug(dcRuleEngine) << "actions" << actions.last().actionTypeId() << actions.last().ruleActionParams();
}
foreach (const RuleAction &action, exitActions) {
Device *device = GuhCore::instance()->findConfiguredDevice(action.deviceId());
if (!device) {
qWarning() << "Cannot create rule. No configured device for actionTypeId" << action.actionTypeId();
qCWarning(dcRuleEngine) << "Cannot create rule. No configured device for actionTypeId" << action.actionTypeId();
return RuleErrorDeviceNotFound;
}
DeviceClass deviceClass = GuhCore::instance()->findDeviceClass(device->deviceClassId());
@ -325,12 +326,12 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
}
}
if (!actionTypeFound) {
qWarning() << "Cannot create rule. Device " + device->name() + " has no action type:" << action.actionTypeId();
qCWarning(dcRuleEngine) << "Cannot create rule. Device " + device->name() + " has no action type:" << action.actionTypeId();
return RuleErrorActionTypeNotFound;
}
}
if (exitActions.count() > 0) {
qDebug() << "***** exitActions" << actions.last().actionTypeId() << actions.last().ruleActionParams();
qCDebug(dcRuleEngine) << "exit actions" << exitActions.last().actionTypeId() << exitActions.last().ruleActionParams();
}
Rule rule = Rule(ruleId, name, eventDescriptorList, stateEvaluator, actions, exitActions);
@ -442,6 +443,50 @@ RuleEngine::RuleError RuleEngine::removeRule(const RuleId &ruleId)
return RuleErrorNoError;
}
/*! Enables the rule with the given \a ruleId that has been previously disabled.
\sa disableRule(), */
RuleEngine::RuleError RuleEngine::enableRule(const RuleId &ruleId)
{
if (!m_rules.contains(ruleId)) {
qCWarning(dcRuleEngine) << "Rule not found. Can't enable it";
return RuleErrorRuleNotFound;
}
Rule rule = m_rules.value(ruleId);
rule.setEnabled(true);
m_rules[ruleId] = rule;
QSettings settings(m_settingsFile);
settings.beginGroup(ruleId.toString());
if (!settings.value("enabled", true).toBool()) {
settings.setValue("enabled", true);
emit ruleChanged(ruleId);
}
settings.endGroup();
return RuleErrorNoError;
}
/*! Disables the rule with the given \a ruleId. Disabled rules won't be triggered.
\sa enableRule(), */
RuleEngine::RuleError RuleEngine::disableRule(const RuleId &ruleId)
{
if (!m_rules.contains(ruleId)) {
qCWarning(dcRuleEngine) << "Rule not found. Can't disable it";
return RuleErrorRuleNotFound;
}
Rule rule = m_rules.value(ruleId);
rule.setEnabled(false);
m_rules[ruleId] = rule;
QSettings settings(m_settingsFile);
settings.beginGroup(ruleId.toString());
if (settings.value("enabled", true).toBool()) {
settings.setValue("enabled", false);
emit ruleChanged(ruleId);
}
settings.endGroup();
return RuleErrorNoError;
}
/*! Returns the \l{Rule} with the given \a ruleId. If the \l{Rule} does not exist, it will return \l{Rule::Rule()} */
Rule RuleEngine::findRule(const RuleId &ruleId)
{

View File

@ -22,6 +22,7 @@
#include "stateevaluator.h"
#include "guhcore.h"
#include "devicemanager.h"
#include "loggingcategorys.h"
StateEvaluator::StateEvaluator(const StateDescriptor &stateDescriptor):
m_stateDescriptor(stateDescriptor),
@ -72,11 +73,11 @@ bool StateEvaluator::evaluate() const
if (m_stateDescriptor.isValid()) {
Device *device = GuhCore::instance()->findConfiguredDevice(m_stateDescriptor.deviceId());
if (!device) {
qWarning() << "Device not existing!";
qCWarning(dcRuleEngine) << "Device not existing!";
return false;
}
if (!device->hasState(m_stateDescriptor.stateTypeId())) {
qWarning() << "Device found, but it does not appear to have such a state!";
qCWarning(dcRuleEngine) << "Device found, but it does not appear to have such a state!";
return false;
}
if (m_stateDescriptor != device->state(m_stateDescriptor.stateTypeId())) {

View File

@ -20,6 +20,8 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "tcpserver.h"
#include "loggingcategorys.h"
#include <QDebug>
#include <QJsonDocument>
#include <QSettings>
@ -27,17 +29,17 @@
TcpServer::TcpServer(QObject *parent) :
QObject(parent)
{
qDebug() << "----------------------------";
qDebug() << "network interfaces:";
qCDebug(dcConnection) << "----------------------------";
qCDebug(dcConnection) << "network interfaces:";
foreach(const QNetworkInterface &interface, QNetworkInterface::allInterfaces()){
qDebug() << " -------------------------";
qDebug() << " name :" << interface.name();
qCDebug(dcConnection) << " -------------------------";
qCDebug(dcConnection) << " name :" << interface.name();
if(!interface.addressEntries().isEmpty()){
qDebug() << " ip :" << interface.addressEntries().first().ip().toString();
qCDebug(dcConnection) << " ip :" << interface.addressEntries().first().ip().toString();
}
qDebug() << " mac : " << interface.hardwareAddress();
qCDebug(dcConnection) << " mac : " << interface.hardwareAddress();
}
qDebug() << "----------------------------";
qCDebug(dcConnection) << "----------------------------";
// load settings
bool ok;
@ -75,7 +77,7 @@ void TcpServer::newClientConnected()
// got a new client connected
QTcpServer *server = qobject_cast<QTcpServer*>(sender());
QTcpSocket *newConnection = server->nextPendingConnection();
qDebug() << "new client connected:" << newConnection->peerAddress().toString();
qCDebug(dcConnection) << "new client connected:" << newConnection->peerAddress().toString();
QUuid clientId = QUuid::createUuid();
@ -92,11 +94,11 @@ void TcpServer::newClientConnected()
void TcpServer::readPackage()
{
QTcpSocket *client = qobject_cast<QTcpSocket*>(sender());
qDebug() << "-----------> data comming from" << client->peerAddress().toString();
qCDebug(dcConnection) << "data comming from" << client->peerAddress().toString();
QByteArray message;
while(client->canReadLine()){
QByteArray dataLine = client->readLine();
qDebug() << "line in:" << dataLine;
qCDebug(dcConnection) << "line in:" << dataLine;
message.append(dataLine);
if(dataLine.endsWith('\n')){
emit dataAvailable(m_clientList.key(client), message);
@ -108,7 +110,7 @@ void TcpServer::readPackage()
void TcpServer::slotClientDisconnected()
{
QTcpSocket *client = qobject_cast<QTcpSocket*>(sender());
qDebug() << "client disconnected:" << client->peerAddress().toString();
qCDebug(dcConnection) << "client disconnected:" << client->peerAddress().toString();
QUuid clientId = m_clientList.key(client);
m_clientList.take(clientId)->deleteLater();
}
@ -119,11 +121,11 @@ bool TcpServer::startServer()
foreach(const QHostAddress &address, QNetworkInterface::allAddresses()){
QTcpServer *server = new QTcpServer(this);
if(server->listen(address, m_port)) {
qDebug() << "JSON-RPC server listening on" << address.toString() << ":" << m_port;
qCDebug(dcConnection) << "JSON-RPC server listening on" << address.toString() << ":" << m_port;
connect(server, SIGNAL(newConnection()), SLOT(newClientConnected()));
m_serverList.insert(QUuid::createUuid(), server);
} else {
qDebug() << "ERROR: can not listening to" << address.toString();
qCWarning(dcConnection) << "can not listening to" << address.toString() << ":" << m_port;
delete server;
}
}
@ -137,7 +139,7 @@ bool TcpServer::stopServer()
{
// Listen on all Networkinterfaces
foreach(QTcpServer *server, m_serverList){
qDebug() << "close server " << server->serverAddress().toString();
qCDebug(dcConnection) << "close server " << server->serverAddress().toString();
server->close();
delete server;
}