mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
refs #369, direct access to own aircraft (in memory)
* provider interface * implementations
This commit is contained in:
91
src/blackmisc/simulation/simdirectaccessownaircraft.cpp
Normal file
91
src/blackmisc/simulation/simdirectaccessownaircraft.cpp
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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 "simdirectaccessownaircraft.h"
|
||||||
|
#include "blackmisc/avaircraft.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Simulation
|
||||||
|
{
|
||||||
|
|
||||||
|
const CSimulatedAircraft &COwnAircraftProviderSupportReadOnly::ownAircraft() const
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(this->m_ownAircraftProvider, "ownAircraft", "No object available");
|
||||||
|
return this->m_ownAircraftProvider->ownAircraft();
|
||||||
|
}
|
||||||
|
|
||||||
|
const CSimulatedAircraft &COwnAircraftProviderSupport::ownAircraft() const
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(this->m_ownAircraftProvider, "ownAircraft", "No object available");
|
||||||
|
return this->m_ownAircraftProvider->ownAircraft();
|
||||||
|
}
|
||||||
|
|
||||||
|
CSimulatedAircraft &COwnAircraftProviderSupport::ownAircraft()
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(this->m_ownAircraftProvider, "ownAircraft", "No object available");
|
||||||
|
return this->m_ownAircraftProvider->ownAircraft();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COwnAircraftProviderSupport::providerUpdateCockpit(const CComSystem &com1, const CComSystem &com2, const CTransponder &transponder, const QString &originator)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(this->m_ownAircraftProvider, "providerUpdateCockpit", "No object available");
|
||||||
|
return this->m_ownAircraftProvider->updateCockpit(com1, com2, transponder, originator);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COwnAircraftProviderSupport::providerUpdateActiveComFrequency(const CFrequency &frequency, int comUnit, const QString &originator)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(this->m_ownAircraftProvider, "providerUpdateActiveComFrequency", "No object available");
|
||||||
|
return this->m_ownAircraftProvider->updateActiveComFrequency(frequency, comUnit, originator);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COwnAircraftProviderSupport::providerUpdateSelcal(const CSelcal &selcal, const QString &originator)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(this->m_ownAircraftProvider, "providerUpdateSelcal", "No object available");
|
||||||
|
return this->m_ownAircraftProvider->updateSelcal(selcal, originator);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COwnAircraftProviderDummy::updateCockpit(const Aviation::CComSystem &com1, const Aviation::CComSystem &com2, const Aviation::CTransponder &transponder, const QString &originator)
|
||||||
|
{
|
||||||
|
ownAircraft().setCom1System(com1);
|
||||||
|
ownAircraft().setCom2System(com2);
|
||||||
|
ownAircraft().setTransponder(transponder);
|
||||||
|
Q_UNUSED(originator);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COwnAircraftProviderDummy::updateActiveComFrequency(const PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator)
|
||||||
|
{
|
||||||
|
if (!CComSystem::isValidComFrequency(frequency)) { return false; }
|
||||||
|
CComSystem::ComUnit comUnitEnum = static_cast<CComSystem::ComUnit>(comUnit);
|
||||||
|
CComSystem com = ownAircraft().getComSystem(comUnitEnum);
|
||||||
|
com.setFrequencyActive(frequency);
|
||||||
|
ownAircraft().setComSystem(com, comUnitEnum);
|
||||||
|
Q_UNUSED(originator);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COwnAircraftProviderDummy::updateSelcal(const CSelcal &selcal, const QString &originator)
|
||||||
|
{
|
||||||
|
ownAircraft().setSelcal(selcal);
|
||||||
|
Q_UNUSED(originator);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
COwnAircraftProviderDummy *COwnAircraftProviderDummy::instance()
|
||||||
|
{
|
||||||
|
static COwnAircraftProviderDummy *dummy = new COwnAircraftProviderDummy();
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
125
src/blackmisc/simulation/simdirectaccessownaircraft.h
Normal file
125
src/blackmisc/simulation/simdirectaccessownaircraft.h
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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_SIMDIRECTACCESSOWNAIRCRAFT_H
|
||||||
|
#define BLACKMISC_SIMDIRECTACCESSOWNAIRCRAFT_H
|
||||||
|
|
||||||
|
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
namespace Simulation
|
||||||
|
{
|
||||||
|
//! Direct in memory access to own aircraft
|
||||||
|
class IOwnAircraftProviderReadOnly
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Own aircraft
|
||||||
|
virtual const CSimulatedAircraft &ownAircraft() const = 0;
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
virtual ~IOwnAircraftProviderReadOnly() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Direct in memory access to own aircraft
|
||||||
|
class IOwnAircraftProvider : public IOwnAircraftProviderReadOnly
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Own aircraft
|
||||||
|
virtual CSimulatedAircraft &ownAircraft() = 0;
|
||||||
|
|
||||||
|
// cockpit related updates, which can come from multiple sources
|
||||||
|
// and are subject of roundtrips
|
||||||
|
|
||||||
|
//! Update cockpit, but send signals when applicable
|
||||||
|
virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) = 0;
|
||||||
|
|
||||||
|
//! Update cockpit, but send signals when applicable
|
||||||
|
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator) = 0;
|
||||||
|
|
||||||
|
//! Update cockpit, but send signals when applicable
|
||||||
|
virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const QString &originator) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
//! For testing
|
||||||
|
class COwnAircraftProviderDummy : public QObject, public IOwnAircraftProvider
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
COwnAircraftProviderDummy() = default;
|
||||||
|
|
||||||
|
//! Singleton
|
||||||
|
static COwnAircraftProviderDummy *instance();
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProviderReadOnly::ownAircraft
|
||||||
|
virtual const CSimulatedAircraft &ownAircraft() const { return this->m_ownAircraft; }
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProvider::ownAircraft
|
||||||
|
virtual CSimulatedAircraft &ownAircraft() { return this->m_ownAircraft; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
//! \copydoc IOwnAircraftProvider::updateCockpit
|
||||||
|
virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override;
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProvider::updateComFrequency
|
||||||
|
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator) override;
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProvider::updateSelcal
|
||||||
|
virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const QString &originator) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft;
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Class which can be directly used providing access to such an interface
|
||||||
|
class COwnAircraftProviderSupportReadOnly
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! \copydoc IOwnAircraftProviderReadOnly::ownAircraft
|
||||||
|
virtual const CSimulatedAircraft &ownAircraft() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! Constructor
|
||||||
|
COwnAircraftProviderSupportReadOnly(const IOwnAircraftProviderReadOnly *ownAircraftProvider) : m_ownAircraftProvider(ownAircraftProvider) {}
|
||||||
|
const IOwnAircraftProviderReadOnly *m_ownAircraftProvider = nullptr; //!< access to object
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Delegating class which can be directly used providing access to such an interface
|
||||||
|
class COwnAircraftProviderSupport
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! \copydoc IOwnAircraftProviderReadOnly::ownAircraft
|
||||||
|
virtual const CSimulatedAircraft &ownAircraft() const;
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProvider::ownAircraft
|
||||||
|
virtual CSimulatedAircraft &ownAircraft();
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProvider::updateCockpit
|
||||||
|
virtual bool providerUpdateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator);
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProvider::updateComFrequency
|
||||||
|
virtual bool providerUpdateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator);
|
||||||
|
|
||||||
|
//! \copydoc IOwnAircraftProvider::updateSelcal
|
||||||
|
virtual bool providerUpdateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const QString &originator);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! Constructor
|
||||||
|
COwnAircraftProviderSupport(IOwnAircraftProvider *ownAircraftProvider) : m_ownAircraftProvider(ownAircraftProvider) { Q_ASSERT(ownAircraftProvider); }
|
||||||
|
IOwnAircraftProvider *m_ownAircraftProvider = nullptr; //!< access to object
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
Reference in New Issue
Block a user