mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 18:25:42 +08:00
committed by
Roland Winklmeier
parent
5498b449ac
commit
de75c5c35a
@@ -50,6 +50,9 @@ namespace BlackCore
|
|||||||
//! \brief Connect to simulator
|
//! \brief Connect to simulator
|
||||||
virtual bool connectTo() = 0;
|
virtual bool connectTo() = 0;
|
||||||
|
|
||||||
|
//! Connect asynchron to simulator
|
||||||
|
virtual void asyncConnectTo() = 0;
|
||||||
|
|
||||||
//! \brief Disconnect from simulator
|
//! \brief Disconnect from simulator
|
||||||
virtual bool disconnectFrom() = 0;
|
virtual bool disconnectFrom() = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
include (../../../../config.pri)
|
include (../../../../config.pri)
|
||||||
include (../../../../build.pri)
|
include (../../../../build.pri)
|
||||||
|
|
||||||
QT += core dbus gui network
|
QT += core dbus gui network concurrent
|
||||||
|
|
||||||
TARGET = simulator_fsx
|
TARGET = simulator_fsx
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "blacksim/fsx/fsxsimulatorsetup.h"
|
#include "blacksim/fsx/fsxsimulatorsetup.h"
|
||||||
#include "blacksim/simulatorinfo.h"
|
#include "blacksim/simulatorinfo.h"
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QtConcurrent>
|
||||||
|
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
@@ -73,6 +74,21 @@ namespace BlackSimPlugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSimulatorFsx::asyncConnectTo()
|
||||||
|
{
|
||||||
|
connect(&m_watcherConnect, SIGNAL(finished()), this, SLOT(connectToFinished()));
|
||||||
|
|
||||||
|
auto asyncConnectFunc = [&]() -> bool
|
||||||
|
{
|
||||||
|
if (FAILED(SimConnect_Open(&m_hSimConnect, "BlackBox", nullptr, 0, 0, 0))) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
QFuture<bool> result = QtConcurrent::run( asyncConnectFunc );
|
||||||
|
|
||||||
|
m_watcherConnect.setFuture(result);
|
||||||
|
}
|
||||||
|
|
||||||
bool CSimulatorFsx::disconnectFrom()
|
bool CSimulatorFsx::disconnectFrom()
|
||||||
{
|
{
|
||||||
if (!m_isConnected)
|
if (!m_isConnected)
|
||||||
@@ -327,6 +343,22 @@ namespace BlackSimPlugin
|
|||||||
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSimulatorFsx::connectToFinished()
|
||||||
|
{
|
||||||
|
if( m_watcherConnect.result() )
|
||||||
|
{
|
||||||
|
initSystemEvents();
|
||||||
|
initDataDefinitions();
|
||||||
|
m_simconnectTimerId = startTimer(50);
|
||||||
|
m_isConnected = true;
|
||||||
|
|
||||||
|
emit statusChanged(Connected);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
emit statusChanged(ConnectionFailed);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT CSimulatorFsx::initSystemEvents()
|
HRESULT CSimulatorFsx::initSystemEvents()
|
||||||
{
|
{
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
@@ -82,6 +83,9 @@ namespace BlackSimPlugin
|
|||||||
//! \copydoc ISimulator::connectTo()
|
//! \copydoc ISimulator::connectTo()
|
||||||
virtual bool connectTo() override;
|
virtual bool connectTo() override;
|
||||||
|
|
||||||
|
//! \copydoc ISimulator::asyncConnectTo()
|
||||||
|
virtual void asyncConnectTo() override;
|
||||||
|
|
||||||
//! \copydoc ISimulator::disconnectFrom()
|
//! \copydoc ISimulator::disconnectFrom()
|
||||||
virtual bool disconnectFrom() override;
|
virtual bool disconnectFrom() override;
|
||||||
|
|
||||||
@@ -134,6 +138,9 @@ namespace BlackSimPlugin
|
|||||||
//! \brief Dispatch SimConnect messages
|
//! \brief Dispatch SimConnect messages
|
||||||
void dispatch();
|
void dispatch();
|
||||||
|
|
||||||
|
//! \brief Called when asynchronous connection to Simconnect has finished
|
||||||
|
void connectToFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct SimConnectObject
|
struct SimConnectObject
|
||||||
@@ -167,6 +174,8 @@ namespace BlackSimPlugin
|
|||||||
QHash<BlackMisc::Aviation::CCallsign, SimConnectObject> m_simConnectObjects;
|
QHash<BlackMisc::Aviation::CCallsign, SimConnectObject> m_simConnectObjects;
|
||||||
|
|
||||||
int m_simconnectTimerId;
|
int m_simconnectTimerId;
|
||||||
|
|
||||||
|
QFutureWatcher<bool> m_watcherConnect;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user