mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 17:55:34 +08:00
Ref T89, provider for ecosystem info
Also Ref T259, Ref T243
This commit is contained in:
@@ -22,6 +22,12 @@ namespace BlackMisc
|
|||||||
return this->getSystemString();
|
return this->getSystemString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CEcosystem &CEcosystem::unspecified()
|
||||||
|
{
|
||||||
|
static const CEcosystem e(Unspecified);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
const CEcosystem &CEcosystem::vatsim()
|
const CEcosystem &CEcosystem::vatsim()
|
||||||
{
|
{
|
||||||
static const CEcosystem e(VATSIM);
|
static const CEcosystem e(VATSIM);
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
|
//! Unspecified
|
||||||
|
static const CEcosystem &unspecified();
|
||||||
|
|
||||||
//! VATSIM eco system
|
//! VATSIM eco system
|
||||||
static const CEcosystem &vatsim();
|
static const CEcosystem &vatsim();
|
||||||
|
|
||||||
|
|||||||
79
src/blackmisc/network/ecosystemprovider.cpp
Normal file
79
src/blackmisc/network/ecosystemprovider.cpp
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/* Copyright (C) 2018
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ecosystemprovider.h"
|
||||||
|
#include <QReadLocker>
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
CEcosystem IEcosystemProvider::getCurrentEcosystem() const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockSystem);
|
||||||
|
return m_currentEcoSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
CEcosystem IEcosystemProvider::getLastEcosystem() const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockSystem);
|
||||||
|
return m_lastEcoSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IEcosystemProvider::isCurrentEcosystem(const CEcosystem &system) const
|
||||||
|
{
|
||||||
|
return this->getCurrentEcosystem() == system;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IEcosystemProvider::isLastEcosystem(const CEcosystem &system) const
|
||||||
|
{
|
||||||
|
return this->getLastEcosystem() == system;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IEcosystemProvider::setCurrentEcosystem(const CEcosystem &ecosystem)
|
||||||
|
{
|
||||||
|
if (this->isCurrentEcosystem(ecosystem)) { return false; }
|
||||||
|
QReadLocker l(&m_lockSystem);
|
||||||
|
m_currentEcoSystem = ecosystem;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IEcosystemProvider::setLastEcosystem(const CEcosystem &ecosystem)
|
||||||
|
{
|
||||||
|
if (this->isLastEcosystem(ecosystem)) { return false; }
|
||||||
|
QReadLocker l(&m_lockSystem);
|
||||||
|
m_lastEcoSystem = ecosystem;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CEcosystem CEcosystemAware::getCurrentEcosystem() const
|
||||||
|
{
|
||||||
|
if (!this->hasProvider()) { return CEcosystem::unspecified(); }
|
||||||
|
return this->provider()->getCurrentEcosystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
CEcosystem CEcosystemAware::getLastEcosystem() const
|
||||||
|
{
|
||||||
|
if (!this->hasProvider()) { return CEcosystem::unspecified(); }
|
||||||
|
return this->provider()->getLastEcosystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CEcosystemAware::isCurrentEcosystem(const CEcosystem &system) const
|
||||||
|
{
|
||||||
|
if (!this->hasProvider()) { return this->getCurrentEcosystem() == system; }
|
||||||
|
return this->provider()->isCurrentEcosystem(system);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CEcosystemAware::isLastEcosystem(const CEcosystem &system) const
|
||||||
|
{
|
||||||
|
if (!this->hasProvider()) { return this->getLastEcosystem() == system; }
|
||||||
|
return this->provider()->isLastEcosystem(system);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
87
src/blackmisc/network/ecosystemprovider.h
Normal file
87
src/blackmisc/network/ecosystemprovider.h
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/* Copyright (C) 2018
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#ifndef BLACKMISC_NETWORK_ECOSYSTEMPROVIDER_H
|
||||||
|
#define BLACKMISC_NETWORK_ECOSYSTEMPROVIDER_H
|
||||||
|
|
||||||
|
#include "ecosystem.h"
|
||||||
|
#include "blackmisc/provider.h"
|
||||||
|
#include <QReadWriteLock>
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
//! Direct threadsafe in memory access to current ecosystem
|
||||||
|
class BLACKMISC_EXPORT IEcosystemProvider : public IProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Current ecosystem
|
||||||
|
//! \remark CEcosystem::Unspecified if not connected with any network
|
||||||
|
//! \threadsafe
|
||||||
|
CEcosystem getCurrentEcosystem() const;
|
||||||
|
|
||||||
|
//! Last known ecosystem
|
||||||
|
//! \threadsafe
|
||||||
|
CEcosystem getLastEcosystem() const;
|
||||||
|
|
||||||
|
//! Current ecosystem?
|
||||||
|
//! \threadsafe
|
||||||
|
bool isCurrentEcosystem(const CEcosystem &system) const;
|
||||||
|
|
||||||
|
//! Last known ecosystem?
|
||||||
|
//! \threadsafe
|
||||||
|
bool isLastEcosystem(const CEcosystem &system) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! Set the current system
|
||||||
|
//! \threadsafe
|
||||||
|
bool setCurrentEcosystem(const CEcosystem &ecosystem);
|
||||||
|
|
||||||
|
//! Set the last known system
|
||||||
|
//! \threadsafe
|
||||||
|
bool setLastEcosystem(const CEcosystem &ecosystem);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CEcosystem m_currentEcoSystem;
|
||||||
|
CEcosystem m_lastEcoSystem;
|
||||||
|
mutable QReadWriteLock m_lockSystem; //!< lock
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Delegating class which can be directly used to access an \sa IEcosystemProvider instance
|
||||||
|
class BLACKMISC_EXPORT CEcosystemAware : public IProviderAware<IEcosystemProvider>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Set the provider
|
||||||
|
void setEcosystemProvider(IEcosystemProvider *provider) { this->setProvider(provider); }
|
||||||
|
|
||||||
|
//! \copydoc IEcosystemProvider::getCurrentEcosystem
|
||||||
|
CEcosystem getCurrentEcosystem() const;
|
||||||
|
|
||||||
|
//! \copydoc IEcosystemProvider::getLastEcosystem
|
||||||
|
CEcosystem getLastEcosystem() const;
|
||||||
|
|
||||||
|
//! \copydoc IEcosystemProvider::isCurrentEcosystem
|
||||||
|
bool isCurrentEcosystem(const CEcosystem &system) const;
|
||||||
|
|
||||||
|
//! \copydoc IEcosystemProvider::isLastEcosystem
|
||||||
|
bool isLastEcosystem(const CEcosystem &system) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! Constructor
|
||||||
|
CEcosystemAware(IEcosystemProvider *EcosystemProvider) : IProviderAware(EcosystemProvider) { Q_ASSERT(EcosystemProvider); }
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Q_DECLARE_INTERFACE(BlackMisc::Network::IEcosystemProvider, "BlackMisc::Network::IEcosystemProvider")
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
Reference in New Issue
Block a user