swift
ecosystemprovider.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QReadLocker>
7 
8 namespace swift::misc::network
9 {
11  {
12  QReadLocker l(&m_lockSystem);
13  return m_currentEcoSystem;
14  }
15 
17  {
18  QReadLocker l(&m_lockSystem);
19  return m_lastEcoSystem;
20  }
21 
23  {
24  return this->getCurrentEcosystem() == system;
25  }
26 
28 
30  {
31  return this->getLastEcosystem() == system;
32  }
33 
35  {
36  if (this->isCurrentEcosystem(ecosystem)) { return false; }
37  QReadLocker l(&m_lockSystem);
38  m_currentEcoSystem = ecosystem;
39  return true;
40  }
41 
43  {
44  if (this->isLastEcosystem(ecosystem)) { return false; }
45  QReadLocker l(&m_lockSystem);
46  m_lastEcoSystem = ecosystem;
47  return true;
48  }
49 
50  // pin vtable to this file
51  void CEcosystemAware::anchor() {}
52 
54  {
55  if (!this->hasProvider()) { return CEcosystem::unspecified(); }
56  return this->provider()->getCurrentEcosystem();
57  }
58 
60  {
61  if (!this->hasProvider()) { return CEcosystem::unspecified(); }
62  return this->provider()->getLastEcosystem();
63  }
64 
66  {
67  if (!this->hasProvider()) { return this->getCurrentEcosystem() == system; }
68  return this->provider()->isCurrentEcosystem(system);
69  }
70 
72 
74  {
75  if (!this->hasProvider()) { return false; }
76  if (this->isCurrentEcosystemVATSIM()) { return false; }
78  {
79  return false;
80  } // our test server is supposed to be I VATSIM system
81  return !this->getCurrentEcosystem().isUnspecified(); // other know system which is specified
82  }
83 
84  bool CEcosystemAware::isLastEcosystem(const CEcosystem &system) const
85  {
86  if (!this->hasProvider()) { return this->getLastEcosystem() == system; }
87  return this->provider()->isLastEcosystem(system);
88  }
89 
91  {
92  IEcosystemProvider *p = qobject_cast<IEcosystemProvider *>(object);
93  return p;
94  }
95 } // namespace swift::misc::network
IEcosystemProvider * provider()
Provider.
Definition: provider.h:72
static IEcosystemProvider * providerIfPossible(QObject *object)
Cast as provider if possible.
bool isCurrentEcosystemVATSIM() const
Current ecosystem VATSIM?
bool isCurrentEcosystem(const CEcosystem &system) const
Current ecosystem?
CEcosystem getCurrentEcosystem() const
Current ecosystem.
bool isNotVATSIMEcosystem() const
Connected with other system than VATSIM?
bool isLastEcosystem(const CEcosystem &system) const
Last known ecosystem?
CEcosystem getLastEcosystem() const
Last known ecosystem.
Ecosystem of server belonging together.
Definition: ecosystem.h:21
bool isUnspecified() const
Unknown system?
Definition: ecosystem.h:51
static const CEcosystem & vatsim()
VATSIM eco system.
Definition: ecosystem.cpp:26
static const CEcosystem & swiftTest()
swift test eco system
Definition: ecosystem.cpp:38
static const CEcosystem & unspecified()
Unspecified.
Definition: ecosystem.cpp:20
Direct threadsafe in memory access to current ecosystem.
bool setCurrentEcosystem(const CEcosystem &ecosystem)
Set the current system.
bool setLastEcosystem(const CEcosystem &ecosystem)
Set the last known system.
bool isCurrentEcosystemVATSIM() const
Current ecosystem VATSIM?
CEcosystem getCurrentEcosystem() const
Current ecosystem.
CEcosystem getLastEcosystem() const
Last known ecosystem.
bool isLastEcosystem(const CEcosystem &system) const
Last known ecosystem?
bool isCurrentEcosystem(const CEcosystem &system) const
Current ecosystem?