diff --git a/guh.pri b/guh.pri index e6336256..3829b9b4 100644 --- a/guh.pri +++ b/guh.pri @@ -14,13 +14,16 @@ QT+= network QMAKE_CXXFLAGS += -Werror -std=c++11 -g QMAKE_LFLAGS += -std=c++11 +top_srcdir=$$PWD +top_builddir=$$shadowed($$PWD) + # Check for Bluetoot LE support (Qt >= 5.4) equals(QT_MAJOR_VERSION, 5):greaterThan(QT_MINOR_VERSION, 3) { QT += bluetooth DEFINES += BLUETOOTH_LE } -# Enable coverage option +# Enable coverage option coverage { OBJECTS_DIR = MOC_DIR = diff --git a/guh.pro b/guh.pro index ea5d323d..a0b90f4f 100644 --- a/guh.pro +++ b/guh.pro @@ -46,11 +46,12 @@ coverage { } # Build tests -!disabletesting { +disabletesting { + message("Building guh without tests") +} else { message("Building guh with tests") SUBDIRS += tests -} else { - message("Building guh without tests") + DEFINES += TESTING_ENABLED } # Bluetooth LE support diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index ced21cb5..0748d643 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -917,6 +917,11 @@ DeviceManager::DeviceError DeviceManager::executeAction(const Action &action) return DeviceErrorDeviceNotFound; } +void DeviceManager::timeTick() +{ + +} + void DeviceManager::loadPlugins() { foreach (const QString &path, pluginSearchDirs()) { diff --git a/libguh/devicemanager.h b/libguh/devicemanager.h index b40ad117..e2e89c15 100644 --- a/libguh/devicemanager.h +++ b/libguh/devicemanager.h @@ -153,6 +153,7 @@ signals: public slots: DeviceError executeAction(const Action &action); + void timeTick(); private slots: void loadPlugins(); diff --git a/server/guhcore.cpp b/server/guhcore.cpp index a0045401..897c1ad2 100644 --- a/server/guhcore.cpp +++ b/server/guhcore.cpp @@ -361,6 +361,12 @@ RuleEngine *GuhCore::ruleEngine() const GuhCore::GuhCore(QObject *parent) : QObject(parent) { + qCDebug(dcApplication) << "Creating centralized timer"; + m_guhTimer = new QTimer(this); + m_guhTimer->setInterval(1000); + m_guhTimer->setSingleShot(false); + m_currentDateTime = QDateTime::currentDateTime(); + qCDebug(dcApplication) << "Creating Log Engine"; m_logger = new LogEngine(this); @@ -388,7 +394,10 @@ GuhCore::GuhCore(QObject *parent) : connect(m_ruleEngine, &RuleEngine::ruleRemoved, this, &GuhCore::ruleRemoved); connect(m_ruleEngine, &RuleEngine::ruleConfigurationChanged, this, &GuhCore::ruleConfigurationChanged); + connect(m_guhTimer, &QTimer::timeout, this, &GuhCore::guhTimeout); + m_logger->logSystemEvent(true); + m_guhTimer->start(); } /*! Connected to the DeviceManager's emitEvent signal. Events received in @@ -449,6 +458,19 @@ void GuhCore::gotEvent(const Event &event) executeRuleActions(actions); } +void GuhCore::guhTimeout() +{ + m_deviceManager->timeTick(); + + // Minute based time -> only evaluate time based rules if the minute changed + if (m_currentDateTime.time().minute() != QDateTime::currentDateTime().time().minute()) { + qCDebug(dcApplication) << "Guh time changed" << QDateTime::currentDateTime().time().toString("hh:mm:ss"); + m_currentDateTime = QDateTime::currentDateTime(); + + } + +} + /*! Return the instance of the log engine */ LogEngine* GuhCore::logEngine() const { diff --git a/server/guhcore.h b/server/guhcore.h index 073b4787..54f03fa3 100644 --- a/server/guhcore.h +++ b/server/guhcore.h @@ -33,7 +33,7 @@ #include "servermanager.h" #include -#include +#include class Device; @@ -99,8 +99,13 @@ private: QHash m_pendingActions; + QTimer *m_guhTimer; + QDateTime m_currentDateTime; + + private slots: void gotEvent(const Event &event); + void guhTimeout(); void actionExecutionFinished(const ActionId &id, DeviceManager::DeviceError status); }; diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp index 0bfdb300..b529abfe 100644 --- a/server/jsonrpc/jsontypes.cpp +++ b/server/jsonrpc/jsontypes.cpp @@ -80,6 +80,7 @@ QVariantList JsonTypes::s_loggingError; QVariantList JsonTypes::s_loggingSource; QVariantList JsonTypes::s_loggingLevel; QVariantList JsonTypes::s_loggingEventType; +QVariantList JsonTypes::s_repeatingMode; QVariantMap JsonTypes::s_paramType; QVariantMap JsonTypes::s_param; @@ -103,6 +104,11 @@ QVariantMap JsonTypes::s_deviceDescriptor; QVariantMap JsonTypes::s_rule; QVariantMap JsonTypes::s_ruleDescription; QVariantMap JsonTypes::s_logEntry; +QVariantMap JsonTypes::s_timeDescriptor; +QVariantMap JsonTypes::s_calendarItem; +QVariantMap JsonTypes::s_timeEventItem; +QVariantMap JsonTypes::s_repeatingOption; + void JsonTypes::init() { @@ -123,6 +129,7 @@ void JsonTypes::init() s_loggingSource = enumToStrings(Logging::staticMetaObject, "LoggingSource"); s_loggingLevel = enumToStrings(Logging::staticMetaObject, "LoggingLevel"); s_loggingEventType = enumToStrings(Logging::staticMetaObject, "LoggingEventType"); + s_repeatingMode = enumToStrings(RepeatingOption::staticMetaObject, "RepeatingMode"); // ParamType s_paramType.insert("name", basicTypeToString(String)); @@ -140,7 +147,7 @@ void JsonTypes::init() s_param.insert("value", basicTypeRef()); // RuleAction - s_ruleAction.insert("actionTypeId", basicTypeToString(Uuid)); + s_ruleAction.insert(" actionTypeId", basicTypeToString(Uuid)); s_ruleAction.insert("deviceId", basicTypeToString(Uuid)); s_ruleAction.insert("o:ruleActionParams", QVariantList() << ruleActionParamRef()); @@ -318,6 +325,7 @@ QVariantMap JsonTypes::allTypes() allTypes.insert("LoggingLevel", loggingLevel()); allTypes.insert("LoggingSource", loggingSource()); allTypes.insert("LoggingEventType", loggingEventType()); + allTypes.insert("RepeatingMode", repeatingMode()); allTypes.insert("StateType", stateTypeDescription()); allTypes.insert("StateDescriptor", stateDescriptorDescription()); @@ -340,6 +348,11 @@ QVariantMap JsonTypes::allTypes() allTypes.insert("Rule", ruleDescription()); allTypes.insert("RuleDescription", ruleDescriptionDescription()); allTypes.insert("LogEntry", logEntryDescription()); + allTypes.insert("TimeDescriptor", timeDescriptorDescription()); + allTypes.insert("CalendarItem", calendarItemDescription()); + allTypes.insert("TimeEventItem", timeEventItemDescription()); + allTypes.insert("RepeatingOption", repeatingOptionDescription()); + return allTypes; } diff --git a/server/jsonrpc/jsontypes.h b/server/jsonrpc/jsontypes.h index 595a70cb..88f52e55 100644 --- a/server/jsonrpc/jsontypes.h +++ b/server/jsonrpc/jsontypes.h @@ -39,6 +39,11 @@ #include "logging/logentry.h" #include "logging/logfilter.h" +#include "time/calendaritem.h" +#include "time/repeatingoption.h" +#include "time/timedescriptor.h" +#include "time/timeeventitem.h" + #include #include @@ -115,6 +120,7 @@ public: DECLARE_TYPE(loggingSource, "LoggingSource", Logging, LoggingSource) DECLARE_TYPE(loggingLevel, "LoggingLevel", Logging, LoggingLevel) DECLARE_TYPE(loggingEventType, "LoggingEventType", Logging, LoggingEventType) + DECLARE_TYPE(repeatingMode, "RepeatingMode", RepeatingOption, RepeatingMode) DECLARE_OBJECT(paramType, "ParamType") DECLARE_OBJECT(param, "Param") @@ -138,8 +144,12 @@ public: DECLARE_OBJECT(rule, "Rule") DECLARE_OBJECT(ruleDescription, "RuleDescription") DECLARE_OBJECT(logEntry, "LogEntry") + DECLARE_OBJECT(timeDescriptor, "TimeDescriptor") + DECLARE_OBJECT(calendarItem, "CalendarItem") + DECLARE_OBJECT(timeEventItem, "TimeEventItem") + DECLARE_OBJECT(repeatingOption, "RepeatingOption") - // pack types + // pack types static QVariantMap packEventType(const EventType &eventType); static QVariantMap packEvent(const Event &event); static QVariantMap packEventDescriptor(const EventDescriptor &event); diff --git a/server/server.pri b/server/server.pri index 91e4374a..9e9230c1 100644 --- a/server/server.pri +++ b/server/server.pri @@ -37,6 +37,10 @@ SOURCES += $$top_srcdir/server/guhcore.cpp \ $$top_srcdir/server/rest/logsresource.cpp \ $$top_srcdir/server/rest/pluginsresource.cpp \ $$top_srcdir/server/rest/rulesresource.cpp \ + $$top_srcdir/server/time/timedescriptor.cpp \ + $$top_srcdir/server/time/calendaritem.cpp \ + $$top_srcdir/server/time/repeatingoption.cpp \ + $$top_srcdir/server/time/timeeventitem.cpp \ HEADERS += $$top_srcdir/server/guhcore.h \ @@ -70,5 +74,9 @@ HEADERS += $$top_srcdir/server/guhcore.h \ $$top_srcdir/server/rest/logsresource.h \ $$top_srcdir/server/rest/pluginsresource.h \ $$top_srcdir/server/rest/rulesresource.h \ + $$top_srcdir/server/time/timedescriptor.h \ + $$top_srcdir/server/time/calendaritem.h \ + $$top_srcdir/server/time/repeatingoption.h \ + $$top_srcdir/server/time/timeeventitem.h \ diff --git a/server/time/calendaritem.cpp b/server/time/calendaritem.cpp new file mode 100644 index 00000000..e1aedea1 --- /dev/null +++ b/server/time/calendaritem.cpp @@ -0,0 +1,42 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "calendaritem.h" + +namespace guhserver { + +CalendarItem::CalendarItem(const QTime startTime, const QTime duration) : + m_startTime(startTime), + m_duration(duration) +{ + +} + +QTime CalendarItem::startTime() const +{ + return m_startTime; +} + +QTime CalendarItem::duration() const +{ + return m_duration; +} + +} diff --git a/server/time/calendaritem.h b/server/time/calendaritem.h new file mode 100644 index 00000000..1df12187 --- /dev/null +++ b/server/time/calendaritem.h @@ -0,0 +1,44 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef CALENDARITEM_H +#define CALENDARITEM_H + +#include + +namespace guhserver { + +class CalendarItem +{ +public: + CalendarItem(const QTime startTime, const QTime duration); + + QTime startTime() const; + QTime duration() const; + +private: + QTime m_startTime; + QTime m_duration; + +}; + +} + +#endif // CALENDARITEM_H diff --git a/server/time/repeatingoption.cpp b/server/time/repeatingoption.cpp new file mode 100644 index 00000000..e3e02bee --- /dev/null +++ b/server/time/repeatingoption.cpp @@ -0,0 +1,30 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "repeatingoption.h" + +namespace guhserver { + +RepeatingOption::RepeatingOption() +{ + +} + +} diff --git a/server/time/repeatingoption.h b/server/time/repeatingoption.h new file mode 100644 index 00000000..c32edd85 --- /dev/null +++ b/server/time/repeatingoption.h @@ -0,0 +1,51 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef REPEATINGOPTION_H +#define REPEATINGOPTION_H + +#include + +namespace guhserver { + +class RepeatingOption +{ + Q_GADGET + Q_ENUMS(RepeatingMode) + +public: + enum RepeatingMode { + RepeatingModeNone, + RepeatingModeHourly, + RepeatingModeDaily, + RepeatingModeWeekly, + RepeatingModeMonthly + }; + + RepeatingOption(); + + + + +}; + +} + +#endif // REPEATINGOPTION_H diff --git a/server/time/timedescriptor.cpp b/server/time/timedescriptor.cpp new file mode 100644 index 00000000..1cbc6b33 --- /dev/null +++ b/server/time/timedescriptor.cpp @@ -0,0 +1,30 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "timedescriptor.h" + +namespace guhserver { + +TimeDescriptor::TimeDescriptor() +{ + +} + +} diff --git a/server/time/timedescriptor.h b/server/time/timedescriptor.h new file mode 100644 index 00000000..8bde04d9 --- /dev/null +++ b/server/time/timedescriptor.h @@ -0,0 +1,35 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef TIMEDESCRIPTOR_H +#define TIMEDESCRIPTOR_H + +namespace guhserver { + +class TimeDescriptor +{ +public: + explicit TimeDescriptor(); + +}; + +} + +#endif // TIMEDESCRIPTOR_H diff --git a/server/time/timeeventitem.cpp b/server/time/timeeventitem.cpp new file mode 100644 index 00000000..feabba25 --- /dev/null +++ b/server/time/timeeventitem.cpp @@ -0,0 +1,30 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "timeeventitem.h" + +namespace guhserver { + +TimeEventItem::TimeEventItem() +{ + +} + +} diff --git a/server/time/timeeventitem.h b/server/time/timeeventitem.h new file mode 100644 index 00000000..c31770a8 --- /dev/null +++ b/server/time/timeeventitem.h @@ -0,0 +1,35 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2016 Simon Stuerz * + * * + * 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 . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef TIMEEVENTITEM_H +#define TIMEEVENTITEM_H + +namespace guhserver { + +class TimeEventItem +{ +public: + TimeEventItem(); + +}; + +} + +#endif // TIMEEVENTITEM_H