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  };
42 
44  CServer() = default;
45 
47  CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user,
48  const CFsdSetup &fsdSetup, const CEcosystem &ecosytem, bool isAcceptingConnections = true);
49 
51  CServer(const QString &address, int port, const CUser &user);
52 
54  CServer(const CEcosystem &ecosystem);
55 
57  const QString &getAddress() const { return m_address; }
58 
60  void setAddress(const QString &address);
61 
63  const CUser &getUser() const { return m_user; }
64 
66  void setUser(const CUser &user) { m_user = user; }
67 
69  const QString &getName() const { return m_name; }
70 
72  bool hasName() const { return !m_name.isEmpty(); }
73 
75  void setName(const QString &name);
76 
78  bool matchesName(const QString &name) const;
79 
81  bool matchesAddressPort(const CServer &server) const;
82 
84  bool matchesAddress(const QString &address) const;
85 
87  const QString &getDescription() const { return m_description; }
88 
90  void setDescription(const QString &description);
91 
93  int getPort() const { return m_port; }
94 
96  void setPort(int port) { m_port = port; }
97 
99  const CEcosystem &getEcosystem() const { return m_ecosystem; }
100 
102  void setEcosystem(const CEcosystem &ecosystem);
103 
105  bool isAcceptingConnections() const { return m_isAcceptingConnections; }
106 
108  void setIsAcceptingConnections(bool value) { m_isAcceptingConnections = value; }
109 
111  bool isValidForLogin() const;
112 
114  bool hasAddressAndPort() const;
115 
117  const CFsdSetup &getFsdSetup() const { return m_fsdSetup; }
118 
120  void setFsdSetup(const CFsdSetup &setup) { m_fsdSetup = setup; }
121 
123  void addSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
124  {
125  m_fsdSetup.addSendReceiveDetails(sendReceive);
126  }
127 
129  void removeSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
130  {
131  m_fsdSetup.removeSendReceiveDetails(sendReceive);
132  }
133 
135  QDateTime getConnectedSince() const { return this->getUtcTimestamp(); }
136 
138  void setConnectedSinceNow() { this->setCurrentUtcTime(); }
139 
141  void markAsDisconnected() { this->setTimestampToNull(); }
142 
144  bool isConnected() const;
145 
147  bool isNull() const;
148 
150  CStatusMessageList validate() const;
151 
153  QString getServerSessionId(bool onlyConnected) const;
154 
156  QVariant propertyByIndex(CPropertyIndexRef index) const;
157 
159  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
160 
162  int comparePropertyByIndex(CPropertyIndexRef index, const CServer &compareValue) const;
163 
165  QString convertToQString(bool i18n = false) const;
166 
168  static const CServer &fscFsdServer();
169 
171  static const CServer &esTowerView();
172 
173  private:
174  QString m_name;
175  QString m_description;
176  QString m_address;
177  int m_port = -1;
178  CUser m_user;
179  CEcosystem m_ecosystem;
180  bool m_isAcceptingConnections = true;
181  CFsdSetup m_fsdSetup;
182 
184  CServer,
185  SWIFT_METAMEMBER(name),
186  SWIFT_METAMEMBER(description),
187  SWIFT_METAMEMBER(address),
188  SWIFT_METAMEMBER(port),
189  SWIFT_METAMEMBER(user),
190  SWIFT_METAMEMBER(fsdSetup),
191  SWIFT_METAMEMBER(ecosystem),
192  SWIFT_METAMEMBER(isAcceptingConnections),
193  SWIFT_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForJson | DisabledForComparison));
194  };
195 } // namespace swift::misc::network
196 
197 Q_DECLARE_METATYPE(swift::misc::network::CServer)
198 
199 #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 FSD server.
Definition: server.h:28
void markAsDisconnected()
Mark as diconnected.
Definition: server.h:141
QDateTime getConnectedSince() const
Connected since.
Definition: server.h:135
const QString & getDescription() const
Get description.
Definition: server.h:87
bool hasName() const
Has name?
Definition: server.h:72
void addSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
Add send / receive details.
Definition: server.h:123
int getPort() const
Get port.
Definition: server.h:93
CServer()=default
Default constructor.
const QString & getName() const
Get name.
Definition: server.h:69
const CFsdSetup & getFsdSetup() const
Get FSD setup.
Definition: server.h:117
void setIsAcceptingConnections(bool value)
Set whether server is accepting connections (allows to disable server temporarily or generally)
Definition: server.h:108
void setUser(const CUser &user)
Set user.
Definition: server.h:66
const QString & getAddress() const
Get address.
Definition: server.h:57
void setPort(int port)
Set port.
Definition: server.h:96
const CEcosystem & getEcosystem() const
Get the ecosystem.
Definition: server.h:99
void removeSendReceiveDetails(CFsdSetup::SendReceiveDetails sendReceive)
Remove send / receive details.
Definition: server.h:129
bool isAcceptingConnections() const
Server is accepting connections (allows to disable server temporarily or generally)
Definition: server.h:105
const CUser & getUser() const
Get user.
Definition: server.h:63
void setConnectedSinceNow()
Mark as connected since now.
Definition: server.h:138
void setFsdSetup(const CFsdSetup &setup)
Set FSD setup.
Definition: server.h:120
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:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:52
@ DisabledForComparison
Element will be ignored by compare() and comparison operators.
Definition: metaclass.h:200
@ DisabledForJson
Element will be ignored during JSON serialization.
Definition: metaclass.h:204
#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