swift
messagebase.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_CORE_FSD_MESSAGEBASE_H
7 #define SWIFT_CORE_FSD_MESSAGEBASE_H
8 
9 #include <QDebug>
10 #include <QString>
11 #include <QStringBuilder>
12 #include <QStringList>
13 
14 #include "core/swiftcoreexport.h"
15 
18 enum class MessageType
19 {
20  Unknown,
21  AddAtc,
22  AddPilot,
23  AtcDataUpdate,
24  AuthChallenge,
25  AuthResponse,
26  ClientIdentification,
27  ClientQuery,
28  ClientResponse,
29  DeleteATC,
30  DeletePilot,
31  EuroscopeSimData, // Euroscope only
32  FlightPlan,
33  ProController,
34  FsdIdentification,
35  KillRequest,
36  PilotDataUpdate,
37  VisualPilotDataUpdate,
38  VisualPilotDataPeriodic,
39  VisualPilotDataStopped,
40  VisualPilotDataToggle,
41  Ping,
42  Pong,
43  ServerError,
44  ServerHeartbeat,
45  TextMessage,
46  PilotClientCom,
47  Rehost,
48  Mute,
49 };
50 
51 namespace swift::core::fsd
52 {
55  {
56  public:
58  MessageBase() = default;
59 
61  MessageBase(const QString &sender);
62 
64  MessageBase(const QString &sender, const QString &receiver);
65 
67  void setCallsign(const QString &sender) { m_sender = sender; }
68 
70  QString sender() const { return m_sender; }
71 
73  void setReceiver(const QString &receiver) { m_receiver = receiver; }
74 
76  QString receiver() const { return m_receiver; }
77 
79  bool isValid() const { return m_isValid; }
80 
82  void setValid(bool isValid) { m_isValid = isValid; }
83 
84  protected:
87 
88  bool m_isValid = true;
89  };
90 
92  template <class T>
93  QString messageToFSDString(const T &message)
94  {
95  if (!message.isValid()) return {};
96  return message.pdu() % message.toTokens().join(':') % QStringLiteral("\r\n");
97  }
98 } // namespace swift::core::fsd
99 
100 #endif // SWIFT_CORE_FSD_MESSAGEBASE_H
FSD message base class.
Definition: messagebase.h:55
void setCallsign(const QString &sender)
Set callsign.
Definition: messagebase.h:67
QString sender() const
get message sender
Definition: messagebase.h:70
bool isValid() const
Is message valid?
Definition: messagebase.h:79
QString m_receiver
message receiver
Definition: messagebase.h:86
MessageBase()=default
Default Constructor.
void setReceiver(const QString &receiver)
Set message receiver.
Definition: messagebase.h:73
void setValid(bool isValid)
set message valid
Definition: messagebase.h:82
QString m_sender
message sender
Definition: messagebase.h:85
QString receiver() const
Get message receiver.
Definition: messagebase.h:76
MessageType
Message type.
Definition: messagebase.h:19
QString messageToFSDString(const T &message)
String which will be send.
Definition: messagebase.h:93
#define SWIFT_CORE_EXPORT
Export a class or function from the library.