swift
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 
9 #include "misc/statusmessage.h"
10 #include "misc/stringutils.h"
11 
12 using namespace swift::misc;
13 
14 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::network, CRawFsdMessage)
15 
16 namespace swift::misc::network
17 {
18  CRawFsdMessage::CRawFsdMessage(const QString &rawMessage) : m_rawMessage(rawMessage) {}
19 
20  QString CRawFsdMessage::convertToQString(bool i18n) const
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 
33  const QStringList &CRawFsdMessage::getAllPacketTypes()
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()) { return QVariant::fromValue(*this); }
68 
69  const ColumnIndex i = index.frontCasted<ColumnIndex>();
70  switch (i)
71  {
72  case IndexRawMessage: return QVariant::fromValue(m_rawMessage);
73  default: return CValueObject::propertyByIndex(index);
74  }
75  }
76 
77  void CRawFsdMessage::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
78  {
79  if (index.isMyself())
80  {
81  (*this) = variant.value<CRawFsdMessage>();
82  return;
83  }
85  {
87  return;
88  }
89 
90  const ColumnIndex i = index.frontCasted<ColumnIndex>();
91  switch (i)
92  {
93  case IndexRawMessage: this->setRawMessage(variant.value<QString>()); break;
94  default: CValueObject::setPropertyByIndex(index, variant); break;
95  }
96  }
97 } // 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.
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
Value object for a raw FSD message.
Definition: rawfsdmessage.h:25
void setRawMessage(const QString &rawMessage)
Set raw message.
Definition: rawfsdmessage.h:43
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.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67