swift
Loading...
Searching...
No Matches
rawfsdmessage.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QtGlobal>
7
10#include "misc/stringutils.h"
11
12using namespace swift::misc;
13
14SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::network, CRawFsdMessage)
15
16namespace swift::misc::network
17{
18 CRawFsdMessage::CRawFsdMessage(const QString &rawMessage) : m_rawMessage(rawMessage) {}
19
21 {
22 Q_UNUSED(i18n)
23 return QStringLiteral("%1 %2").arg(this->getFormattedUtcTimestampHmsz(), m_rawMessage);
24 }
25
26 bool CRawFsdMessage::isPacketType(const QString &type) const
27 {
28 return m_rawMessage.startsWith("FSD Sent=>" + type) || m_rawMessage.startsWith("FSD Recv=>" + type);
29 }
30
31 bool CRawFsdMessage::containsString(const QString &str) const { return m_rawMessage.contains(str); }
32
34 {
35 static const QStringList allPacketTypes = { "@",
36 "%",
37 "#AA",
38 "#DA",
39 "#AP",
40 "#DP",
41 "#TM",
42 "#WX",
43 "#DL",
44 "#TD",
45 "#WD"
46 "#CD",
47 "#PC",
48 "#SB",
49 "$FP",
50 "$AM",
51 "$PI",
52 "$PO",
53 "$HO",
54 "$HA",
55 "$AX",
56 "$AR",
57 "$CQ",
58 "$CR",
59 "$ER",
60 "$!!" };
61 return allPacketTypes;
62 }
63
65 {
66 if (index.isMyself())
67 {
68 return QVariant::fromValue(*this);
69 }
71 {
73 }
74
75 const auto i = index.frontCasted<ColumnIndex>();
76 switch (i)
77 {
78 case IndexRawMessage: return QVariant::fromValue(m_rawMessage);
79 default: return CValueObject::propertyByIndex(index);
80 }
81 }
82
84 {
85 if (index.isMyself())
86 {
87 (*this) = variant.value<CRawFsdMessage>();
88 return;
89 }
91 {
93 return;
94 }
95
96 const auto i = index.frontCasted<ColumnIndex>();
97 switch (i)
98 {
99 case IndexRawMessage: this->setRawMessage(variant.value<QString>()); break;
100 default: CValueObject::setPropertyByIndex(index, variant); break;
101 }
102 }
103} // namespace swift::misc::network
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
QString getFormattedUtcTimestampHmsz() const
As hh:mm:ss.zzz.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition mixinindex.h:167
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition mixinindex.h:180
void setRawMessage(const QString &rawMessage)
Set raw message.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool containsString(const QString &str) const
Does the raw message contain str?
CRawFsdMessage()=default
Default constructor.
QString convertToQString(bool i18n=false) const
Cast as QString.
bool isPacketType(const QString &type) const
Returns true if the raw message is from the given PDU packet type.
static const QStringList & getAllPacketTypes()
Returns a list of all known packet types.
Free functions in swift::misc.
QString arg(Args &&... args) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QVariant fromValue(T &&value)
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67