swift
server.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_NETWORK_SERVER_H
7 #define SWIFT_MISC_NETWORK_SERVER_H
8 
9 #include <QMetaType>
10 #include <QString>
11 
12 #include "misc/metaclass.h"
13 #include "misc/network/ecosystem.h"
14 #include "misc/network/fsdsetup.h"
15 #include "misc/network/user.h"
16 #include "misc/propertyindexref.h"
17 #include "misc/statusmessagelist.h"
18 #include "misc/swiftmiscexport.h"
19 #include "misc/timestampbased.h"
20 #include "misc/valueobject.h"
21 
22 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::network, CServer)
23 
24 namespace swift::misc::network
25 {
27  class SWIFT_MISC_EXPORT CServer : public CValueObject<CServer>, public ITimestampBased
28  {
29  public:
32  {
33  IndexName = CPropertyIndexRef::GlobalIndexCServer,
34  IndexDescription,
35  IndexAddress,
36  IndexPort,
37  IndexUser,
38  IndexFsdSetup,
39  IndexEcosystem,
40  IndexIsAcceptingConnections,
41  IndexServerType,
42  IndexServerTypeAsString
43  };
44 
47  {
48  Unspecified,
49  FSDServerVatsim,
50  FSDServer,
51  VoiceServerVatsim,
52  VoiceServer,
53  WebService,
54  };
55 
57  static const QList<int> &allServerTypes();
58 
60  static const QString &serverTypeToString(ServerType server);
61 
63  CServer() {}
64 
66  CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user,
67  const CFsdSetup &fsdSetup, const CEcosystem &ecosytem, ServerType serverType,
68  bool isAcceptingConnections = true);
69 
71  CServer(const QString &address, int port, const CUser &user);
72 
74  CServer(const CEcosystem &ecosystem);
75 
77  CServer(ServerType serverType);
78 
80  const QString &getAddress() const { return m_address; }
81 
83  void setAddress(const QString &address);
84 
86  const CUser &getUser() const { return m_user; }
87 
89  void setUser(const CUser &user) { m_user = user; }
90 
92  const QString &getName() const { return m_name; }
93 
95  bool hasName() const { return !m_name.isEmpty(); }
96 
98  void setName(const QString &name);
99 
101  bool matchesName(const QString &name) const;
102 
104  bool matchesAddressPort(const CServer &server) const;
105 
107  bool matchesAddress(const QString &address) const;
108 
110  const QString &getDescription() const { return m_description; }
111 
113  void setDescription(const QString &description);
114 
116  int getPort() const { return m_port; }
117 
119  void setPort(int port) { m_port = port; }
120 
122  const CEcosystem &getEcosystem() const { return m_ecosystem; }
123 
125  bool setEcosystem(const CEcosystem &ecosystem);
126 
128  bool isAcceptingConnections() const { return m_isAcceptingConnections; }
129 
131  void setIsAcceptingConnections(bool value) { m_isAcceptingConnections = value; }
132 
134  bool isValidForLogin() const;
135 
137  bool hasAddressAndPort() const;
138 
140  const CFsdSetup &getFsdSetup() const { return m_fsdSetup; }
141 
143  void setFsdSetup(const CFsdSetup &setup) { m_fsdSetup = setup; }
144 
146  void addSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
147  {
148  m_fsdSetup.addSendReceiveDetails(sendReceive);
149  }
150 
152  void removeSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
153  {
154  m_fsdSetup.removeSendReceiveDetails(sendReceive);
155  }
156 
158  bool isFsdServer() const;
159 
161  bool setServerType(ServerType serverType);
162 
164  ServerType getServerType() const { return static_cast<ServerType>(m_serverType); }
165 
167  bool hasUnspecifiedServerType() const;
168 
170  const QString &getServerTypeAsString() const;
171 
173  QDateTime getConnectedSince() const { return this->getUtcTimestamp(); }
174 
176  void setConnectedSinceNow() { this->setCurrentUtcTime(); }
177 
179  void markAsDisconnected() { this->setTimestampToNull(); }
180 
182  bool isConnected() const;
183 
185  bool isNull() const;
186 
188  CStatusMessageList validate() const;
189 
191  QString getServerSessionId(bool onlyConnected) const;
192 
194  QVariant propertyByIndex(CPropertyIndexRef index) const;
195 
197  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
198 
200  int comparePropertyByIndex(CPropertyIndexRef index, const CServer &compareValue) const;
201 
203  QString convertToQString(bool i18n = false) const;
204 
206  static const CServer &fscFsdServer();
207 
209  static const CServer &esTowerView();
210 
211  private:
212  QString m_name;
213  QString m_description;
214  QString m_address;
215  int m_port = -1;
216  CUser m_user;
217  CEcosystem m_ecosystem;
218  int m_serverType = static_cast<int>(Unspecified);
219  bool m_isAcceptingConnections = true;
220  CFsdSetup m_fsdSetup;
221 
223  CServer,
224  SWIFT_METAMEMBER(name),
225  SWIFT_METAMEMBER(description),
226  SWIFT_METAMEMBER(address),
227  SWIFT_METAMEMBER(port),
228  SWIFT_METAMEMBER(user),
229  SWIFT_METAMEMBER(fsdSetup),
230  SWIFT_METAMEMBER(ecosystem),
231  SWIFT_METAMEMBER(serverType),
232  SWIFT_METAMEMBER(isAcceptingConnections),
233  SWIFT_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForJson | DisabledForComparison));
234  };
235 } // namespace swift::misc::network
236 
237 Q_DECLARE_METATYPE(swift::misc::network::CServer)
239 
240 #endif // SWIFT_MISC_NETWORK_SERVER_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Status messages, e.g. from Core -> GUI.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Entity with timestamp.
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
Ecosystem of server belonging together.
Definition: ecosystem.h:21
Value object for a FSD setup.
Definition: fsdsetup.h:24
Value object encapsulating information of a server.
Definition: server.h:28
void markAsDisconnected()
Mark as diconnected.
Definition: server.h:179
QDateTime getConnectedSince() const
Connected since.
Definition: server.h:173
const QString & getDescription() const
Get description.
Definition: server.h:110
bool hasName() const
Has name?
Definition: server.h:95
void addSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
Add send / receive details.
Definition: server.h:146
int getPort() const
Get port.
Definition: server.h:116
const QString & getName() const
Get name.
Definition: server.h:92
const CFsdSetup & getFsdSetup() const
Get FSD setup.
Definition: server.h:140
void setIsAcceptingConnections(bool value)
Set whether server is accepting connections (allows to disable server temporarily or generally)
Definition: server.h:131
void setUser(const CUser &user)
Set user.
Definition: server.h:89
const QString & getAddress() const
Get address.
Definition: server.h:80
void setPort(int port)
Set port.
Definition: server.h:119
const CEcosystem & getEcosystem() const
Get the ecosystem.
Definition: server.h:122
void removeSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
Remove send / receive details.
Definition: server.h:152
CServer()
Default constructor.
Definition: server.h:63
bool isAcceptingConnections() const
Server is accepting connections (allows to disable server temporarily or generally)
Definition: server.h:128
const CUser & getUser() const
Get user.
Definition: server.h:86
void setConnectedSinceNow()
Mark as connected since now.
Definition: server.h:176
ServerType getServerType() const
Get server type.
Definition: server.h:164
void setFsdSetup(const CFsdSetup &setup)
Set FSD setup.
Definition: server.h:143
Value object encapsulating information of a user.
Definition: user.h:28
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
@ DisabledForComparison
Element will be ignored by compare() and comparison operators.
Definition: metaclass.h:202
@ DisabledForJson
Element will be ignored during JSON serialization.
Definition: metaclass.h:206
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65