adding basic structure of time management to the api

This commit is contained in:
Simon Stürz 2016-03-29 13:33:07 +02:00 committed by Michael Zanetti
parent ccdc2bd18e
commit 80e7d289f7
17 changed files with 372 additions and 7 deletions

View File

@ -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 =

View File

@ -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

View File

@ -917,6 +917,11 @@ DeviceManager::DeviceError DeviceManager::executeAction(const Action &action)
return DeviceErrorDeviceNotFound;
}
void DeviceManager::timeTick()
{
}
void DeviceManager::loadPlugins()
{
foreach (const QString &path, pluginSearchDirs()) {

View File

@ -153,6 +153,7 @@ signals:
public slots:
DeviceError executeAction(const Action &action);
void timeTick();
private slots:
void loadPlugins();

View File

@ -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
{

View File

@ -33,7 +33,7 @@
#include "servermanager.h"
#include <QObject>
#include <QDebug>
#include <QDateTime>
class Device;
@ -99,8 +99,13 @@ private:
QHash<ActionId, Action> 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);
};

View File

@ -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;
}

View File

@ -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 <QObject>
#include <QVariantMap>
@ -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);

View File

@ -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 \

View File

@ -0,0 +1,42 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 "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;
}
}

View File

@ -0,0 +1,44 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 CALENDARITEM_H
#define CALENDARITEM_H
#include <QTime>
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

View File

@ -0,0 +1,30 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 "repeatingoption.h"
namespace guhserver {
RepeatingOption::RepeatingOption()
{
}
}

View File

@ -0,0 +1,51 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 REPEATINGOPTION_H
#define REPEATINGOPTION_H
#include <QMetaType>
namespace guhserver {
class RepeatingOption
{
Q_GADGET
Q_ENUMS(RepeatingMode)
public:
enum RepeatingMode {
RepeatingModeNone,
RepeatingModeHourly,
RepeatingModeDaily,
RepeatingModeWeekly,
RepeatingModeMonthly
};
RepeatingOption();
};
}
#endif // REPEATINGOPTION_H

View File

@ -0,0 +1,30 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 "timedescriptor.h"
namespace guhserver {
TimeDescriptor::TimeDescriptor()
{
}
}

View File

@ -0,0 +1,35 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 TIMEDESCRIPTOR_H
#define TIMEDESCRIPTOR_H
namespace guhserver {
class TimeDescriptor
{
public:
explicit TimeDescriptor();
};
}
#endif // TIMEDESCRIPTOR_H

View File

@ -0,0 +1,30 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 "timeeventitem.h"
namespace guhserver {
TimeEventItem::TimeEventItem()
{
}
}

View File

@ -0,0 +1,35 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 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 TIMEEVENTITEM_H
#define TIMEEVENTITEM_H
namespace guhserver {
class TimeEventItem
{
public:
TimeEventItem();
};
}
#endif // TIMEEVENTITEM_H