Add clang-format
This commit is contained in:
parent
2c235b75aa
commit
4384c4e6a8
265
.clang-format
Normal file
265
.clang-format
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveMacros:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveShortCaseStatements:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCaseColons: false
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments:
|
||||||
|
Kind: Always
|
||||||
|
OverEmptyLines: 0
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
BreakAfterAttributes: Never
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakArrays: true
|
||||||
|
BreakBeforeBinaryOperators: All
|
||||||
|
BreakBeforeConceptDeclarations: Always
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeComma
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 180
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: true
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- forever
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<Q.*'
|
||||||
|
Priority: 200
|
||||||
|
SortPriority: 200
|
||||||
|
CaseSensitive: true
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequiresClause: true
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertBraces: false
|
||||||
|
InsertNewlineAtEOF: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
IntegerLiteralSeparator:
|
||||||
|
Binary: 0
|
||||||
|
BinaryMinDigits: 0
|
||||||
|
Decimal: 0
|
||||||
|
DecimalMinDigits: 0
|
||||||
|
Hex: 0
|
||||||
|
HexMinDigits: 0
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
KeepEmptyLinesAtEOF: false
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
LineEnding: DeriveLF
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PackConstructorInitializers: BinPack
|
||||||
|
PenaltyBreakAssignment: 150
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 300
|
||||||
|
PenaltyBreakComment: 500
|
||||||
|
PenaltyBreakFirstLessLess: 400
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakString: 600
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 50
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 300
|
||||||
|
PointerAlignment: Right
|
||||||
|
PPIndentWidth: -1
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: false
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
RemoveParentheses: Leave
|
||||||
|
RemoveSemicolon: false
|
||||||
|
RequiresClausePosition: OwnLine
|
||||||
|
RequiresExpressionIndentation: OuterScope
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: Lexicographic
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeJsonColon: false
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterForeachMacros: true
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterIfMacros: true
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
AfterRequiresInClause: false
|
||||||
|
AfterRequiresInExpression: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParens: Never
|
||||||
|
SpacesInParensOptions:
|
||||||
|
InCStyleCasts: false
|
||||||
|
InConditionalStatements: false
|
||||||
|
InEmptyParentheses: false
|
||||||
|
Other: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Auto
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
- Q_CLASSINFO
|
||||||
|
- Q_ENUM
|
||||||
|
- Q_ENUM_NS
|
||||||
|
- Q_FLAG
|
||||||
|
- Q_FLAG_NS
|
||||||
|
- Q_GADGET
|
||||||
|
- Q_GADGET_EXPORT
|
||||||
|
- Q_INTERFACES
|
||||||
|
- Q_MOC_INCLUDE
|
||||||
|
- Q_NAMESPACE
|
||||||
|
- Q_NAMESPACE_EXPORT
|
||||||
|
- Q_OBJECT
|
||||||
|
- Q_PROPERTY
|
||||||
|
- Q_REVISION
|
||||||
|
- Q_DISABLE_COPY
|
||||||
|
- Q_SET_OBJECT_NAME
|
||||||
|
- QT_BEGIN_NAMESPACE
|
||||||
|
- QT_END_NAMESPACE
|
||||||
|
- QML_ADDED_IN_MINOR_VERSION
|
||||||
|
- QML_ANONYMOUS
|
||||||
|
- QML_ATTACHED
|
||||||
|
- QML_DECLARE_TYPE
|
||||||
|
- QML_DECLARE_TYPEINFO
|
||||||
|
- QML_ELEMENT
|
||||||
|
- QML_EXTENDED
|
||||||
|
- QML_EXTENDED_NAMESPACE
|
||||||
|
- QML_EXTRA_VERSION
|
||||||
|
- QML_FOREIGN
|
||||||
|
- QML_FOREIGN_NAMESPACE
|
||||||
|
- QML_IMPLEMENTS_INTERFACES
|
||||||
|
- QML_INTERFACE
|
||||||
|
- QML_NAMED_ELEMENT
|
||||||
|
- QML_REMOVED_IN_MINOR_VERSION
|
||||||
|
- QML_SINGLETON
|
||||||
|
- QML_UNAVAILABLE
|
||||||
|
- QML_UNCREATABLE
|
||||||
|
- QML_VALUE_TYPE
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
|
VerilogBreakBetweenInstancePorts: true
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- STRINGIZE
|
||||||
|
...
|
||||||
|
|
||||||
@ -25,27 +25,24 @@
|
|||||||
#include "chargingsessionsdbusinterfaceclient.h"
|
#include "chargingsessionsdbusinterfaceclient.h"
|
||||||
|
|
||||||
#include <QDBusArgument>
|
#include <QDBusArgument>
|
||||||
#include <QDBusInterface>
|
|
||||||
#include <QDBusConnectionInterface>
|
#include <QDBusConnectionInterface>
|
||||||
|
#include <QDBusError>
|
||||||
|
#include <QDBusInterface>
|
||||||
#include <QDBusPendingCall>
|
#include <QDBusPendingCall>
|
||||||
#include <QDBusPendingCallWatcher>
|
#include <QDBusPendingCallWatcher>
|
||||||
#include <QDBusPendingReply>
|
#include <QDBusPendingReply>
|
||||||
#include <QDBusReply>
|
#include <QDBusReply>
|
||||||
#include <QDBusError>
|
|
||||||
#include <QDBusServiceWatcher>
|
#include <QDBusServiceWatcher>
|
||||||
|
|
||||||
static const QString kDbusService = QStringLiteral("io.nymea.energy.chargingsessions");
|
static const QString kDbusService = QStringLiteral("io.nymea.energy.chargingsessions");
|
||||||
static const QString kDbusPath = QStringLiteral("/io/nymea/energy/chargingsessions");
|
static const QString kDbusPath = QStringLiteral("/io/nymea/energy/chargingsessions");
|
||||||
static const QString kDbusInterface = QStringLiteral("io.nymea.energy.chargingsessions");
|
static const QString kDbusInterface = QStringLiteral("io.nymea.energy.chargingsessions");
|
||||||
|
|
||||||
ChargingSessionsDBusInterfaceClient::ChargingSessionsDBusInterfaceClient(QObject *parent) :
|
ChargingSessionsDBusInterfaceClient::ChargingSessionsDBusInterfaceClient(QObject *parent)
|
||||||
QObject(parent),
|
: QObject(parent)
|
||||||
m_connection(QDBusConnection::systemBus())
|
, m_connection(QDBusConnection::systemBus())
|
||||||
{
|
{
|
||||||
m_serviceWatcher = new QDBusServiceWatcher(kDbusService,
|
m_serviceWatcher = new QDBusServiceWatcher(kDbusService, m_connection, QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this);
|
||||||
m_connection,
|
|
||||||
QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration,
|
|
||||||
this);
|
|
||||||
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &ChargingSessionsDBusInterfaceClient::onServiceRegistered);
|
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &ChargingSessionsDBusInterfaceClient::onServiceRegistered);
|
||||||
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &ChargingSessionsDBusInterfaceClient::onServiceUnregistered);
|
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &ChargingSessionsDBusInterfaceClient::onServiceUnregistered);
|
||||||
|
|
||||||
|
|||||||
@ -24,12 +24,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QList>
|
|
||||||
#include <QVariantMap>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QDBusServiceWatcher>
|
#include <QDBusServiceWatcher>
|
||||||
|
#include <QList>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
class QDBusInterface;
|
class QDBusInterface;
|
||||||
class QDBusPendingCallWatcher;
|
class QDBusPendingCallWatcher;
|
||||||
|
|||||||
@ -24,12 +24,12 @@
|
|||||||
|
|
||||||
#include "energymanagerdbusclient.h"
|
#include "energymanagerdbusclient.h"
|
||||||
|
|
||||||
|
#include <QDBusArgument>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusConnectionInterface>
|
#include <QDBusConnectionInterface>
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QDBusArgument>
|
|
||||||
#include <QDBusMetaType>
|
|
||||||
#include <QDBusMessage>
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusMetaType>
|
||||||
#include <QDBusPendingCall>
|
#include <QDBusPendingCall>
|
||||||
#include <QDBusPendingCallWatcher>
|
#include <QDBusPendingCallWatcher>
|
||||||
#include <QDBusReply>
|
#include <QDBusReply>
|
||||||
@ -39,19 +39,16 @@ static const QString kDbusService = QStringLiteral("io.nymea.energymanager");
|
|||||||
static const QString kDbusPath = QStringLiteral("/io/nymea/energymanager");
|
static const QString kDbusPath = QStringLiteral("/io/nymea/energymanager");
|
||||||
static const QString kDbusInterface = QStringLiteral("io.nymea.energymanager");
|
static const QString kDbusInterface = QStringLiteral("io.nymea.energymanager");
|
||||||
|
|
||||||
EnergyManagerDbusClient::EnergyManagerDbusClient(QObject *parent) :
|
EnergyManagerDbusClient::EnergyManagerDbusClient(QObject *parent)
|
||||||
QObject(parent),
|
: QObject(parent)
|
||||||
m_connection(QDBusConnection::systemBus())
|
, m_connection(QDBusConnection::systemBus())
|
||||||
{
|
{
|
||||||
if (!m_connection.isConnected()) {
|
if (!m_connection.isConnected()) {
|
||||||
emit errorOccurred(QStringLiteral("DBus system bus not connected"));
|
emit errorOccurred(QStringLiteral("DBus system bus not connected"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_serviceWatcher = new QDBusServiceWatcher(kDbusService,
|
m_serviceWatcher = new QDBusServiceWatcher(kDbusService, m_connection, QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this);
|
||||||
m_connection,
|
|
||||||
QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration,
|
|
||||||
this);
|
|
||||||
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &EnergyManagerDbusClient::onServiceRegistered);
|
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &EnergyManagerDbusClient::onServiceRegistered);
|
||||||
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &EnergyManagerDbusClient::onServiceUnregistered);
|
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &EnergyManagerDbusClient::onServiceUnregistered);
|
||||||
|
|
||||||
@ -61,9 +58,7 @@ EnergyManagerDbusClient::EnergyManagerDbusClient(QObject *parent) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnergyManagerDbusClient::~EnergyManagerDbusClient()
|
EnergyManagerDbusClient::~EnergyManagerDbusClient() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantList EnergyManagerDbusClient::chargingInfos() const
|
QVariantList EnergyManagerDbusClient::chargingInfos() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -25,9 +25,9 @@
|
|||||||
#ifndef ENERGYMANAGERDBUSCLIENT_H
|
#ifndef ENERGYMANAGERDBUSCLIENT_H
|
||||||
#define ENERGYMANAGERDBUSCLIENT_H
|
#define ENERGYMANAGERDBUSCLIENT_H
|
||||||
|
|
||||||
|
#include <QDBusConnection>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVariantList>
|
#include <QVariantList>
|
||||||
#include <QDBusConnection>
|
|
||||||
|
|
||||||
class QDBusInterface;
|
class QDBusInterface;
|
||||||
class QDBusPendingCallWatcher;
|
class QDBusPendingCallWatcher;
|
||||||
|
|||||||
@ -23,34 +23,34 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "evdashengine.h"
|
#include "evdashengine.h"
|
||||||
|
#include "chargingsessionsdbusinterfaceclient.h"
|
||||||
|
#include "energymanagerdbusclient.h"
|
||||||
#include "evdashsettings.h"
|
#include "evdashsettings.h"
|
||||||
#include "evdashwebserverresource.h"
|
#include "evdashwebserverresource.h"
|
||||||
#include "energymanagerdbusclient.h"
|
|
||||||
#include "chargingsessionsdbusinterfaceclient.h"
|
|
||||||
|
|
||||||
#include <integrations/thingmanager.h>
|
#include <integrations/thingmanager.h>
|
||||||
#include <logging/logengine.h>
|
#include <logging/logengine.h>
|
||||||
|
|
||||||
#include <QWebSocket>
|
|
||||||
#include <QWebSocketServer>
|
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
#include <QWebSocket>
|
||||||
#include <QWebSocketProtocol>
|
#include <QWebSocketProtocol>
|
||||||
|
#include <QWebSocketServer>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QJsonParseError>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonParseError>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcEvDashExperience)
|
Q_DECLARE_LOGGING_CATEGORY(dcEvDashExperience)
|
||||||
|
|
||||||
EvDashEngine::EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvDashWebServerResource *webServerResource, QObject *parent)
|
EvDashEngine::EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvDashWebServerResource *webServerResource, QObject *parent)
|
||||||
: QObject{parent},
|
: QObject{parent}
|
||||||
m_thingManager{thingManager},
|
, m_thingManager{thingManager}
|
||||||
m_logEngine{logEngine},
|
, m_logEngine{logEngine}
|
||||||
m_webServerResource{webServerResource}
|
, m_webServerResource{webServerResource}
|
||||||
{
|
{
|
||||||
Things configuredThings = m_thingManager->configuredThings();
|
Things configuredThings = m_thingManager->configuredThings();
|
||||||
foreach (Thing *thing, configuredThings) {
|
foreach (Thing *thing, configuredThings) {
|
||||||
@ -72,18 +72,16 @@ EvDashEngine::EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvD
|
|||||||
// Setup websocket server
|
// Setup websocket server
|
||||||
m_webSocketServer = new QWebSocketServer(QStringLiteral("EvDashEngine"), QWebSocketServer::NonSecureMode, this);
|
m_webSocketServer = new QWebSocketServer(QStringLiteral("EvDashEngine"), QWebSocketServer::NonSecureMode, this);
|
||||||
|
|
||||||
connect(m_webSocketServer, &QWebSocketServer::newConnection, this, [this](){
|
connect(m_webSocketServer, &QWebSocketServer::newConnection, this, [this]() {
|
||||||
QWebSocket *socket = m_webSocketServer->nextPendingConnection();
|
QWebSocket *socket = m_webSocketServer->nextPendingConnection();
|
||||||
if (!socket) {
|
if (!socket) {
|
||||||
qCWarning(dcEvDashExperience()) << "Interface: Received new connection but socket was null";
|
qCWarning(dcEvDashExperience()) << "Interface: Received new connection but socket was null";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(socket, &QWebSocket::textMessageReceived, this, [this, socket](const QString &message) {
|
connect(socket, &QWebSocket::textMessageReceived, this, [this, socket](const QString &message) { processTextMessage(socket, message); });
|
||||||
processTextMessage(socket, message);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(socket, &QWebSocket::disconnected, this, [this, socket](){
|
connect(socket, &QWebSocket::disconnected, this, [this, socket]() {
|
||||||
m_clients.removeAll(socket);
|
m_clients.removeAll(socket);
|
||||||
m_authenticatedClients.remove(socket);
|
m_authenticatedClients.remove(socket);
|
||||||
qCDebug(dcEvDashExperience()) << "WebSocket client disconnected" << socket->peerAddress().toString() << "Remaining clients:" << m_clients.count();
|
qCDebug(dcEvDashExperience()) << "WebSocket client disconnected" << socket->peerAddress().toString() << "Remaining clients:" << m_clients.count();
|
||||||
@ -107,23 +105,20 @@ EvDashEngine::EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvD
|
|||||||
|
|
||||||
// ChargingSessions client for fetching charging sessions
|
// ChargingSessions client for fetching charging sessions
|
||||||
m_chargingSessionsClient = new ChargingSessionsDBusInterfaceClient(this);
|
m_chargingSessionsClient = new ChargingSessionsDBusInterfaceClient(this);
|
||||||
connect(m_chargingSessionsClient, &ChargingSessionsDBusInterfaceClient::sessionsReceived,
|
connect(m_chargingSessionsClient, &ChargingSessionsDBusInterfaceClient::sessionsReceived, this, &EvDashEngine::onSessionsReceived);
|
||||||
this, &EvDashEngine::onSessionsReceived);
|
|
||||||
|
|
||||||
connect(m_chargingSessionsClient, &ChargingSessionsDBusInterfaceClient::errorOccurred,
|
|
||||||
this, &EvDashEngine::onSessionsError);
|
|
||||||
|
|
||||||
|
connect(m_chargingSessionsClient, &ChargingSessionsDBusInterfaceClient::errorOccurred, this, &EvDashEngine::onSessionsError);
|
||||||
|
|
||||||
// Energy manager client for associated cars and current mode
|
// Energy manager client for associated cars and current mode
|
||||||
m_energyManagerClient = new EnergyManagerDbusClient(this);
|
m_energyManagerClient = new EnergyManagerDbusClient(this);
|
||||||
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfosUpdated, this, [](const QVariantList &chargingInfos){
|
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfosUpdated, this, [](const QVariantList &chargingInfos) {
|
||||||
qCDebug(dcEvDashExperience()) << "ChargingInfos:";
|
qCDebug(dcEvDashExperience()) << "ChargingInfos:";
|
||||||
foreach (const QVariant &ciVariant, chargingInfos) {
|
foreach (const QVariant &ciVariant, chargingInfos) {
|
||||||
qCDebug(dcEvDashExperience()) << "-->" << ciVariant.toMap();
|
qCDebug(dcEvDashExperience()) << "-->" << ciVariant.toMap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfoAdded, this, [this](const QVariantMap &chargingInfo){
|
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfoAdded, this, [this](const QVariantMap &chargingInfo) {
|
||||||
qCDebug(dcEvDashExperience()) << "ChargingInfo added:" << chargingInfo;
|
qCDebug(dcEvDashExperience()) << "ChargingInfo added:" << chargingInfo;
|
||||||
Thing *charger = m_thingManager->findConfiguredThing(chargingInfo.value("evChargerId").toUuid());
|
Thing *charger = m_thingManager->findConfiguredThing(chargingInfo.value("evChargerId").toUuid());
|
||||||
if (charger) {
|
if (charger) {
|
||||||
@ -131,7 +126,7 @@ EvDashEngine::EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvD
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfoChanged, this, [this](const QVariantMap &chargingInfo){
|
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfoChanged, this, [this](const QVariantMap &chargingInfo) {
|
||||||
qCDebug(dcEvDashExperience()) << "ChargingInfo changed:" << chargingInfo;
|
qCDebug(dcEvDashExperience()) << "ChargingInfo changed:" << chargingInfo;
|
||||||
Thing *charger = m_thingManager->findConfiguredThing(chargingInfo.value("evChargerId").toUuid());
|
Thing *charger = m_thingManager->findConfiguredThing(chargingInfo.value("evChargerId").toUuid());
|
||||||
if (charger) {
|
if (charger) {
|
||||||
@ -139,11 +134,11 @@ EvDashEngine::EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvD
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfoRemoved, this, [](const QString &evChargerId){
|
connect(m_energyManagerClient, &EnergyManagerDbusClient::chargingInfoRemoved, this, [](const QString &evChargerId) {
|
||||||
qCDebug(dcEvDashExperience()) << "ChargingInfo removed:" << evChargerId;
|
qCDebug(dcEvDashExperience()) << "ChargingInfo removed:" << evChargerId;
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_energyManagerClient, &EnergyManagerDbusClient::errorOccurred, this, [](const QString &errorMessage){
|
connect(m_energyManagerClient, &EnergyManagerDbusClient::errorOccurred, this, [](const QString &errorMessage) {
|
||||||
qCWarning(dcEvDashExperience()) << "Energy manager DBus client error occurred:" << errorMessage;
|
qCWarning(dcEvDashExperience()) << "Energy manager DBus client error occurred:" << errorMessage;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -226,7 +221,6 @@ void EvDashEngine::onThingRemoved(const ThingId &thingId)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvDashEngine::onThingChanged(Thing *thing)
|
void EvDashEngine::onThingChanged(Thing *thing)
|
||||||
@ -242,28 +236,34 @@ void EvDashEngine::onThingChanged(Thing *thing)
|
|||||||
|
|
||||||
void EvDashEngine::monitorChargerThing(Thing *thing)
|
void EvDashEngine::monitorChargerThing(Thing *thing)
|
||||||
{
|
{
|
||||||
connect(thing, &Thing::stateValueChanged, this, [this, thing](const StateTypeId &stateTypeId, const QVariant &value, const QVariant &minValue, const QVariant &maxValue, const QVariantList &possibleValues){
|
connect(thing,
|
||||||
Q_UNUSED(stateTypeId)
|
&Thing::stateValueChanged,
|
||||||
Q_UNUSED(value)
|
this,
|
||||||
Q_UNUSED(minValue)
|
[this, thing](const StateTypeId &stateTypeId, const QVariant &value, const QVariant &minValue, const QVariant &maxValue, const QVariantList &possibleValues) {
|
||||||
Q_UNUSED(maxValue)
|
Q_UNUSED(stateTypeId)
|
||||||
Q_UNUSED(possibleValues)
|
Q_UNUSED(value)
|
||||||
|
Q_UNUSED(minValue)
|
||||||
|
Q_UNUSED(maxValue)
|
||||||
|
Q_UNUSED(possibleValues)
|
||||||
|
|
||||||
onThingChanged(thing);
|
onThingChanged(thing);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvDashEngine::monitorCarThing(Thing *thing)
|
void EvDashEngine::monitorCarThing(Thing *thing)
|
||||||
{
|
{
|
||||||
connect(thing, &Thing::stateValueChanged, this, [this, thing](const StateTypeId &stateTypeId, const QVariant &value, const QVariant &minValue, const QVariant &maxValue, const QVariantList &possibleValues){
|
connect(thing,
|
||||||
Q_UNUSED(stateTypeId)
|
&Thing::stateValueChanged,
|
||||||
Q_UNUSED(value)
|
this,
|
||||||
Q_UNUSED(minValue)
|
[this, thing](const StateTypeId &stateTypeId, const QVariant &value, const QVariant &minValue, const QVariant &maxValue, const QVariantList &possibleValues) {
|
||||||
Q_UNUSED(maxValue)
|
Q_UNUSED(stateTypeId)
|
||||||
Q_UNUSED(possibleValues)
|
Q_UNUSED(value)
|
||||||
|
Q_UNUSED(minValue)
|
||||||
|
Q_UNUSED(maxValue)
|
||||||
|
Q_UNUSED(possibleValues)
|
||||||
|
|
||||||
onThingChanged(thing);
|
onThingChanged(thing);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvDashEngine::verifyChargerStatusChanged(Thing *charger)
|
void EvDashEngine::verifyChargerStatusChanged(Thing *charger)
|
||||||
@ -272,7 +272,6 @@ void EvDashEngine::verifyChargerStatusChanged(Thing *charger)
|
|||||||
QString source = QString("state-%1-%2").arg(charger->id().toString(QUuid::WithBraces), stateName);
|
QString source = QString("state-%1-%2").arg(charger->id().toString(QUuid::WithBraces), stateName);
|
||||||
LogFetchJob *job = m_logEngine->fetchLogEntries({source}, {stateName}, {}, {}, {}, Types::SampleRateAny, Qt::DescendingOrder, 0, 1);
|
LogFetchJob *job = m_logEngine->fetchLogEntries({source}, {stateName}, {}, {}, {}, Types::SampleRateAny, Qt::DescendingOrder, 0, 1);
|
||||||
connect(job, &LogFetchJob::finished, charger, [this, charger, stateName](const LogEntries &entries) {
|
connect(job, &LogFetchJob::finished, charger, [this, charger, stateName](const LogEntries &entries) {
|
||||||
|
|
||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
qCDebug(dcEvDashExperience()) << "Last state change of" << charger->name() << stateName << "unknown";
|
qCDebug(dcEvDashExperience()) << "Last state change of" << charger->name() << stateName << "unknown";
|
||||||
// Forget any cached values, the database did not return any information...
|
// Forget any cached values, the database did not return any information...
|
||||||
@ -404,10 +403,7 @@ QJsonObject EvDashEngine::handleApiRequest(QWebSocket *socket, const QJsonObject
|
|||||||
|
|
||||||
m_authenticatedClients.insert(socket, token);
|
m_authenticatedClients.insert(socket, token);
|
||||||
|
|
||||||
QJsonObject responsePayload {
|
QJsonObject responsePayload{{QStringLiteral("authenticated"), true}, {QStringLiteral("timestamp"), QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs)}};
|
||||||
{QStringLiteral("authenticated"), true},
|
|
||||||
{QStringLiteral("timestamp"), QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs)}
|
|
||||||
};
|
|
||||||
return createSuccessResponse(requestId, responsePayload);
|
return createSuccessResponse(requestId, responsePayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +419,6 @@ QJsonObject EvDashEngine::handleApiRequest(QWebSocket *socket, const QJsonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action.compare(QStringLiteral("GetChargers"), Qt::CaseInsensitive) == 0) {
|
if (action.compare(QStringLiteral("GetChargers"), Qt::CaseInsensitive) == 0) {
|
||||||
|
|
||||||
QJsonObject payload;
|
QJsonObject payload;
|
||||||
QJsonArray chargerList;
|
QJsonArray chargerList;
|
||||||
foreach (Thing *thing, m_thingManager->configuredThings()) {
|
foreach (Thing *thing, m_thingManager->configuredThings()) {
|
||||||
@ -532,7 +527,6 @@ QJsonObject EvDashEngine::packCharger(Thing *charger) const
|
|||||||
foreach (const QVariant &chargingInfoVariant, m_energyManagerClient->chargingInfos()) {
|
foreach (const QVariant &chargingInfoVariant, m_energyManagerClient->chargingInfos()) {
|
||||||
QVariantMap chargingInfo = chargingInfoVariant.toMap();
|
QVariantMap chargingInfo = chargingInfoVariant.toMap();
|
||||||
if (chargingInfo.value("evChargerId").toUuid() == charger->id()) {
|
if (chargingInfo.value("evChargerId").toUuid() == charger->id()) {
|
||||||
|
|
||||||
// Set assigned car name
|
// Set assigned car name
|
||||||
if (chargingInfo.value("assignedCarId").toString().isEmpty()) {
|
if (chargingInfo.value("assignedCarId").toString().isEmpty()) {
|
||||||
chargerObject.insert("assignedCar", "");
|
chargerObject.insert("assignedCar", "");
|
||||||
|
|||||||
@ -25,9 +25,9 @@
|
|||||||
#ifndef EVDASHENGINE_H
|
#ifndef EVDASHENGINE_H
|
||||||
#define EVDASHENGINE_H
|
#define EVDASHENGINE_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QObject>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
@ -47,13 +47,7 @@ class EvDashEngine : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum EvDashError {
|
enum EvDashError { EvDashErrorNoError = 0, EvDashErrorBackendError, EvDashErrorDuplicateUser, EvDashErrorUserNotFound, EvDashErrorBadPassword };
|
||||||
EvDashErrorNoError = 0,
|
|
||||||
EvDashErrorBackendError,
|
|
||||||
EvDashErrorDuplicateUser,
|
|
||||||
EvDashErrorUserNotFound,
|
|
||||||
EvDashErrorBadPassword
|
|
||||||
};
|
|
||||||
Q_ENUM(EvDashError)
|
Q_ENUM(EvDashError)
|
||||||
|
|
||||||
explicit EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvDashWebServerResource *webServerResource, QObject *parent = nullptr);
|
explicit EvDashEngine(ThingManager *thingManager, LogEngine *logEngine, EvDashWebServerResource *webServerResource, QObject *parent = nullptr);
|
||||||
@ -118,7 +112,6 @@ private:
|
|||||||
QJsonObject packCar(Thing *car) const;
|
QJsonObject packCar(Thing *car) const;
|
||||||
void onSessionsReceived(const QList<QVariantMap> &sessions);
|
void onSessionsReceived(const QList<QVariantMap> &sessions);
|
||||||
void onSessionsError(const QString &errorMessage);
|
void onSessionsError(const QString &errorMessage);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EVDASHENGINE_H
|
#endif // EVDASHENGINE_H
|
||||||
|
|||||||
@ -30,42 +30,45 @@
|
|||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcEvDashExperience)
|
Q_DECLARE_LOGGING_CATEGORY(dcEvDashExperience)
|
||||||
|
|
||||||
EvDashJsonHandler::EvDashJsonHandler(EvDashEngine *engine, EvDashWebServerResource *resource, QObject *parent):
|
EvDashJsonHandler::EvDashJsonHandler(EvDashEngine *engine, EvDashWebServerResource *resource, QObject *parent)
|
||||||
JsonHandler{parent},
|
: JsonHandler{parent}
|
||||||
m_engine{engine},
|
, m_engine{engine}
|
||||||
m_resource{resource}
|
, m_resource{resource}
|
||||||
{
|
{
|
||||||
registerEnum<EvDashEngine::EvDashError>();
|
registerEnum<EvDashEngine::EvDashError>();
|
||||||
|
|
||||||
QString description;
|
QString description;
|
||||||
QVariantMap params, returns;
|
QVariantMap params, returns;
|
||||||
|
|
||||||
|
params.clear();
|
||||||
params.clear(); returns.clear();
|
returns.clear();
|
||||||
description = "Get the enabled status of EV Dash service.";
|
description = "Get the enabled status of EV Dash service.";
|
||||||
returns.insert("enabled", enumValueName(Bool));
|
returns.insert("enabled", enumValueName(Bool));
|
||||||
registerMethod("GetEnabled", description, params, returns);
|
registerMethod("GetEnabled", description, params, returns);
|
||||||
|
|
||||||
params.clear(); returns.clear();
|
params.clear();
|
||||||
|
returns.clear();
|
||||||
description = "Enable/Disable the EV Dash service.";
|
description = "Enable/Disable the EV Dash service.";
|
||||||
params.insert("enabled", enumValueName(Bool));
|
params.insert("enabled", enumValueName(Bool));
|
||||||
returns.insert("evDashError", enumRef<EvDashEngine::EvDashError>());
|
returns.insert("evDashError", enumRef<EvDashEngine::EvDashError>());
|
||||||
registerMethod("SetEnabled", description, params, returns);
|
registerMethod("SetEnabled", description, params, returns);
|
||||||
|
|
||||||
|
params.clear();
|
||||||
params.clear(); returns.clear();
|
returns.clear();
|
||||||
description = "Get the list of available users names.";
|
description = "Get the list of available users names.";
|
||||||
returns.insert("usernames", enumValueName(StringList));
|
returns.insert("usernames", enumValueName(StringList));
|
||||||
registerMethod("GetUsers", description, params, returns);
|
registerMethod("GetUsers", description, params, returns);
|
||||||
|
|
||||||
params.clear(); returns.clear();
|
params.clear();
|
||||||
|
returns.clear();
|
||||||
description = "Add a new user with the given username and password.";
|
description = "Add a new user with the given username and password.";
|
||||||
params.insert("username", enumValueName(String));
|
params.insert("username", enumValueName(String));
|
||||||
params.insert("password", enumValueName(String));
|
params.insert("password", enumValueName(String));
|
||||||
returns.insert("evDashError", enumRef<EvDashEngine::EvDashError>());
|
returns.insert("evDashError", enumRef<EvDashEngine::EvDashError>());
|
||||||
registerMethod("AddUser", description, params, returns);
|
registerMethod("AddUser", description, params, returns);
|
||||||
|
|
||||||
params.clear(); returns.clear();
|
params.clear();
|
||||||
|
returns.clear();
|
||||||
description = "Remove the user with the given username.";
|
description = "Remove the user with the given username.";
|
||||||
params.insert("username", enumValueName(String));
|
params.insert("username", enumValueName(String));
|
||||||
returns.insert("evDashError", enumRef<EvDashEngine::EvDashError>());
|
returns.insert("evDashError", enumRef<EvDashEngine::EvDashError>());
|
||||||
@ -77,27 +80,21 @@ EvDashJsonHandler::EvDashJsonHandler(EvDashEngine *engine, EvDashWebServerResour
|
|||||||
params.insert("enabled", enumValueName(Bool));
|
params.insert("enabled", enumValueName(Bool));
|
||||||
registerNotification("EnabledChanged", description, params);
|
registerNotification("EnabledChanged", description, params);
|
||||||
|
|
||||||
connect(m_engine, &EvDashEngine::enabledChanged, this, [this](bool enabled){
|
connect(m_engine, &EvDashEngine::enabledChanged, this, [this](bool enabled) { emit EnabledChanged({{"enabled", enabled}}); });
|
||||||
emit EnabledChanged({{"enabled", enabled}});
|
|
||||||
});
|
|
||||||
|
|
||||||
params.clear();
|
params.clear();
|
||||||
description = "Emitted whenever a new username has been added for the dashboard.";
|
description = "Emitted whenever a new username has been added for the dashboard.";
|
||||||
params.insert("username", enumValueName(String));
|
params.insert("username", enumValueName(String));
|
||||||
registerNotification("UserAdded", description, params);
|
registerNotification("UserAdded", description, params);
|
||||||
|
|
||||||
connect(m_resource, &EvDashWebServerResource::userAdded, this, [this](const QString &username){
|
connect(m_resource, &EvDashWebServerResource::userAdded, this, [this](const QString &username) { emit UserAdded({{"username", username}}); });
|
||||||
emit UserAdded({{"username", username}});
|
|
||||||
});
|
|
||||||
|
|
||||||
params.clear();
|
params.clear();
|
||||||
description = "Emitted whenever a username has been removed from the dashboard.";
|
description = "Emitted whenever a username has been removed from the dashboard.";
|
||||||
params.insert("username", enumValueName(String));
|
params.insert("username", enumValueName(String));
|
||||||
registerNotification("UserRemoved", description, params);
|
registerNotification("UserRemoved", description, params);
|
||||||
|
|
||||||
connect(m_resource, &EvDashWebServerResource::userRemoved, this, [this](const QString &username){
|
connect(m_resource, &EvDashWebServerResource::userRemoved, this, [this](const QString &username) { emit UserRemoved({{"username", username}}); });
|
||||||
emit UserRemoved({{"username", username}});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EvDashJsonHandler::name() const
|
QString EvDashJsonHandler::name() const
|
||||||
@ -157,6 +154,4 @@ JsonReply *EvDashJsonHandler::RemoveUser(const QVariantMap ¶ms)
|
|||||||
QVariantMap returns;
|
QVariantMap returns;
|
||||||
returns.insert("evDashError", enumValueName(error));
|
returns.insert("evDashError", enumValueName(error));
|
||||||
return createReply(returns);
|
return createReply(returns);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,6 @@ signals:
|
|||||||
private:
|
private:
|
||||||
EvDashEngine *m_engine = nullptr;
|
EvDashEngine *m_engine = nullptr;
|
||||||
EvDashWebServerResource *m_resource = nullptr;
|
EvDashWebServerResource *m_resource = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ENERGYJSONHANDLER_H
|
#endif // ENERGYJSONHANDLER_H
|
||||||
|
|||||||
@ -28,6 +28,4 @@
|
|||||||
|
|
||||||
EvDashSettings::EvDashSettings()
|
EvDashSettings::EvDashSettings()
|
||||||
: QSettings(NymeaSettings::settingsPath() + "/evdash.conf", QSettings::IniFormat)
|
: QSettings(NymeaSettings::settingsPath() + "/evdash.conf", QSettings::IniFormat)
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@ -32,7 +32,6 @@ class EvDashSettings : public QSettings
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit EvDashSettings();
|
explicit EvDashSettings();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EVDASHSETTINGS_H
|
#endif // EVDASHSETTINGS_H
|
||||||
|
|||||||
@ -25,13 +25,13 @@
|
|||||||
#include "evdashwebserverresource.h"
|
#include "evdashwebserverresource.h"
|
||||||
#include "evdashsettings.h"
|
#include "evdashsettings.h"
|
||||||
|
|
||||||
#include <QUuid>
|
#include <QCryptographicHash>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
#include <QJsonParseError>
|
#include <QJsonParseError>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QCryptographicHash>
|
#include <QUuid>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcEvDashExperience)
|
Q_DECLARE_LOGGING_CATEGORY(dcEvDashExperience)
|
||||||
@ -191,10 +191,7 @@ HttpReply *EvDashWebServerResource::handleLoginRequest(const HttpRequest &reques
|
|||||||
const QJsonDocument requestDoc = QJsonDocument::fromJson(request.payload(), &parseError);
|
const QJsonDocument requestDoc = QJsonDocument::fromJson(request.payload(), &parseError);
|
||||||
if (parseError.error != QJsonParseError::NoError || !requestDoc.isObject()) {
|
if (parseError.error != QJsonParseError::NoError || !requestDoc.isObject()) {
|
||||||
qCWarning(dcEvDashExperience()) << "Invalid login payload" << parseError.errorString();
|
qCWarning(dcEvDashExperience()) << "Invalid login payload" << parseError.errorString();
|
||||||
QJsonObject errorPayload {
|
QJsonObject errorPayload{{QStringLiteral("success"), false}, {QStringLiteral("error"), QStringLiteral("invalidRequest")}};
|
||||||
{QStringLiteral("success"), false},
|
|
||||||
{QStringLiteral("error"), QStringLiteral("invalidRequest")}
|
|
||||||
};
|
|
||||||
return HttpReply::createJsonReply(QJsonDocument(errorPayload), HttpReply::BadRequest);
|
return HttpReply::createJsonReply(QJsonDocument(errorPayload), HttpReply::BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,21 +200,14 @@ HttpReply *EvDashWebServerResource::handleLoginRequest(const HttpRequest &reques
|
|||||||
const QString password = requestObject.value(QStringLiteral("password")).toString();
|
const QString password = requestObject.value(QStringLiteral("password")).toString();
|
||||||
|
|
||||||
if (!verifyCredentials(username, password)) {
|
if (!verifyCredentials(username, password)) {
|
||||||
QJsonObject response {
|
QJsonObject response{{QStringLiteral("success"), false}, {QStringLiteral("error"), QStringLiteral("unauthorized")}};
|
||||||
{QStringLiteral("success"), false},
|
|
||||||
{QStringLiteral("error"), QStringLiteral("unauthorized")}
|
|
||||||
};
|
|
||||||
return HttpReply::createJsonReply(QJsonDocument(response), HttpReply::Unauthorized);
|
return HttpReply::createJsonReply(QJsonDocument(response), HttpReply::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString token = issueToken(username);
|
const QString token = issueToken(username);
|
||||||
const TokenInfo tokenInfo = m_activeTokens.value(token);
|
const TokenInfo tokenInfo = m_activeTokens.value(token);
|
||||||
|
|
||||||
QJsonObject payload {
|
QJsonObject payload{{QStringLiteral("success"), true}, {QStringLiteral("token"), token}, {QStringLiteral("expiresAt"), tokenInfo.expiresAt.toString(Qt::ISODateWithMs)}};
|
||||||
{QStringLiteral("success"), true},
|
|
||||||
{QStringLiteral("token"), token},
|
|
||||||
{QStringLiteral("expiresAt"), tokenInfo.expiresAt.toString(Qt::ISODateWithMs)}
|
|
||||||
};
|
|
||||||
|
|
||||||
return HttpReply::createJsonReply(QJsonDocument(payload));
|
return HttpReply::createJsonReply(QJsonDocument(payload));
|
||||||
}
|
}
|
||||||
@ -233,10 +223,7 @@ HttpReply *EvDashWebServerResource::handleRefreshRequest(const HttpRequest &requ
|
|||||||
QJsonParseError parseError;
|
QJsonParseError parseError;
|
||||||
const QJsonDocument requestDoc = QJsonDocument::fromJson(request.payload(), &parseError);
|
const QJsonDocument requestDoc = QJsonDocument::fromJson(request.payload(), &parseError);
|
||||||
if (parseError.error != QJsonParseError::NoError || !requestDoc.isObject()) {
|
if (parseError.error != QJsonParseError::NoError || !requestDoc.isObject()) {
|
||||||
QJsonObject errorPayload {
|
QJsonObject errorPayload{{QStringLiteral("success"), false}, {QStringLiteral("error"), QStringLiteral("invalidRequest")}};
|
||||||
{QStringLiteral("success"), false},
|
|
||||||
{QStringLiteral("error"), QStringLiteral("invalidRequest")}
|
|
||||||
};
|
|
||||||
return HttpReply::createJsonReply(QJsonDocument(errorPayload), HttpReply::BadRequest);
|
return HttpReply::createJsonReply(QJsonDocument(errorPayload), HttpReply::BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,10 +232,7 @@ HttpReply *EvDashWebServerResource::handleRefreshRequest(const HttpRequest &requ
|
|||||||
const QJsonObject requestObject = requestDoc.object();
|
const QJsonObject requestObject = requestDoc.object();
|
||||||
const QString token = requestObject.value(QStringLiteral("token")).toString();
|
const QString token = requestObject.value(QStringLiteral("token")).toString();
|
||||||
if (token.isEmpty() || !m_activeTokens.contains(token)) {
|
if (token.isEmpty() || !m_activeTokens.contains(token)) {
|
||||||
QJsonObject response {
|
QJsonObject response{{QStringLiteral("success"), false}, {QStringLiteral("error"), QStringLiteral("unauthorized")}};
|
||||||
{QStringLiteral("success"), false},
|
|
||||||
{QStringLiteral("error"), QStringLiteral("unauthorized")}
|
|
||||||
};
|
|
||||||
return HttpReply::createJsonReply(QJsonDocument(response), HttpReply::Unauthorized);
|
return HttpReply::createJsonReply(QJsonDocument(response), HttpReply::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,11 +240,7 @@ HttpReply *EvDashWebServerResource::handleRefreshRequest(const HttpRequest &requ
|
|||||||
info.expiresAt = QDateTime::currentDateTimeUtc().addSecs(s_tokenLifetimeSeconds);
|
info.expiresAt = QDateTime::currentDateTimeUtc().addSecs(s_tokenLifetimeSeconds);
|
||||||
m_activeTokens.insert(token, info);
|
m_activeTokens.insert(token, info);
|
||||||
|
|
||||||
QJsonObject payload {
|
QJsonObject payload{{QStringLiteral("success"), true}, {QStringLiteral("token"), token}, {QStringLiteral("expiresAt"), info.expiresAt.toString(Qt::ISODateWithMs)}};
|
||||||
{QStringLiteral("success"), true},
|
|
||||||
{QStringLiteral("token"), token},
|
|
||||||
{QStringLiteral("expiresAt"), info.expiresAt.toString(Qt::ISODateWithMs)}
|
|
||||||
};
|
|
||||||
|
|
||||||
return HttpReply::createJsonReply(QJsonDocument(payload));
|
return HttpReply::createJsonReply(QJsonDocument(payload));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,9 +25,9 @@
|
|||||||
#ifndef EVDASHWEBSERVERRESOURCE_H
|
#ifndef EVDASHWEBSERVERRESOURCE_H
|
||||||
#define EVDASHWEBSERVERRESOURCE_H
|
#define EVDASHWEBSERVERRESOURCE_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <webserver/webserverresource.h>
|
#include <webserver/webserverresource.h>
|
||||||
@ -57,12 +57,14 @@ signals:
|
|||||||
void userRemoved(const QString &username);
|
void userRemoved(const QString &username);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct TokenInfo {
|
struct TokenInfo
|
||||||
|
{
|
||||||
QString username;
|
QString username;
|
||||||
QDateTime expiresAt;
|
QDateTime expiresAt;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UserInfo {
|
struct UserInfo
|
||||||
|
{
|
||||||
QString username;
|
QString username;
|
||||||
QByteArray passwordHash;
|
QByteArray passwordHash;
|
||||||
QByteArray passwordSalt;
|
QByteArray passwordSalt;
|
||||||
@ -84,8 +86,6 @@ private:
|
|||||||
bool verifyStaticFile(const QString &fileName);
|
bool verifyStaticFile(const QString &fileName);
|
||||||
|
|
||||||
bool verifyCredentials(const QString &username, const QString &password) const;
|
bool verifyCredentials(const QString &username, const QString &password) const;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EVDASHWEBSERVERRESOURCE_H
|
#endif // EVDASHWEBSERVERRESOURCE_H
|
||||||
|
|||||||
@ -31,13 +31,9 @@
|
|||||||
#include <jsonrpc/jsonrpcserver.h>
|
#include <jsonrpc/jsonrpcserver.h>
|
||||||
#include <loggingcategories.h>
|
#include <loggingcategories.h>
|
||||||
|
|
||||||
|
|
||||||
NYMEA_LOGGING_CATEGORY(dcEvDashExperience, "EvDashExperience")
|
NYMEA_LOGGING_CATEGORY(dcEvDashExperience, "EvDashExperience")
|
||||||
|
|
||||||
ExperiencePluginEvDash::ExperiencePluginEvDash()
|
ExperiencePluginEvDash::ExperiencePluginEvDash() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExperiencePluginEvDash::init()
|
void ExperiencePluginEvDash::init()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,7 +34,7 @@ Q_DECLARE_LOGGING_CATEGORY(dcEvDashExperience)
|
|||||||
class EvDashEngine;
|
class EvDashEngine;
|
||||||
class EvDashWebServerResource;
|
class EvDashWebServerResource;
|
||||||
|
|
||||||
class ExperiencePluginEvDash: public ExperiencePlugin
|
class ExperiencePluginEvDash : public ExperiencePlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "io.nymea.ExperiencePlugin")
|
Q_PLUGIN_METADATA(IID "io.nymea.ExperiencePlugin")
|
||||||
@ -50,7 +50,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
EvDashEngine *m_engine = nullptr;
|
EvDashEngine *m_engine = nullptr;
|
||||||
EvDashWebServerResource *m_resource = nullptr;
|
EvDashWebServerResource *m_resource = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXPERIENCEPLUGINEVDASH_H
|
#endif // EXPERIENCEPLUGINEVDASH_H
|
||||||
|
|||||||
Reference in New Issue
Block a user