mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Add methods to receive and write raw FSD messages
This commit adds methods to register for live FSD message reception. The amount of traffic can be quite high, therefore no normal signal is used - which would be available via DBus. Instead one has to connect manually by passing a functor. This guarantees that we communicate only in-process. If someone tries to connect on the proxy side, the connection will fail. This needs to be handled properly in client code. This commit also adds a method to write the FSD message to a selected file. Maniphest Tasks: T222
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/weather/metar.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
//! \addtogroup dbus
|
||||
//! @{
|
||||
|
||||
@@ -302,6 +304,13 @@ namespace BlackCore
|
||||
//! Request parts for callsign (from another client)
|
||||
virtual void testRequestAircraftConfig(const BlackMisc::Aviation::CCallsign &callsign) = 0;
|
||||
|
||||
public:
|
||||
//! Raw FSD message receiver functor
|
||||
using RawFsdMessageReceivedSlot = std::function<void(const BlackMisc::Network::CRawFsdMessage &)>;
|
||||
|
||||
//! Connect to receive raw fsd messages
|
||||
virtual QMetaObject::Connection connectRawFsdMessageSignal(QObject *receiver, RawFsdMessageReceivedSlot rawFsdMessageReceivedSlot) = 0;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IContextNetwork(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {}
|
||||
|
||||
@@ -385,6 +385,16 @@ namespace BlackCore
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
Q_UNUSED(enabled);
|
||||
}
|
||||
|
||||
public:
|
||||
//! \copydoc IContextNetwork::connectRawFsdMessageSignal
|
||||
virtual QMetaObject::Connection connectRawFsdMessageSignal(QObject *receiver, RawFsdMessageReceivedSlot rawFsdMessageReceivedSlot) override
|
||||
{
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
Q_UNUSED(receiver);
|
||||
Q_UNUSED(rawFsdMessageReceivedSlot);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -751,5 +751,16 @@ namespace BlackCore
|
||||
rooms.push_back(s2.getVoiceRoom());
|
||||
return rooms;
|
||||
}
|
||||
|
||||
QMetaObject::Connection CContextNetwork::connectRawFsdMessageSignal(QObject *receiver, RawFsdMessageReceivedSlot rawFsdMessageReceivedSlot)
|
||||
{
|
||||
Q_ASSERT_X(receiver, Q_FUNC_INFO, "Missing receiver");
|
||||
|
||||
// bind does not allow to define connection type, so we use receiver as workaround
|
||||
const QMetaObject::Connection uc; // unconnected
|
||||
const QMetaObject::Connection c = rawFsdMessageReceivedSlot ? connect(m_network, &INetwork::rawFsdMessageReceived, receiver, rawFsdMessageReceivedSlot) : uc;
|
||||
Q_ASSERT_X(c || !rawFsdMessageReceivedSlot, Q_FUNC_INFO, "connect failed");
|
||||
return c;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -191,6 +191,10 @@ namespace BlackCore
|
||||
//! Gracefully shut down, e.g. for thread safety
|
||||
void gracefulShutdown();
|
||||
|
||||
public:
|
||||
//! \copydoc IContextNetwork::connectRawFsdMessageSignal
|
||||
virtual QMetaObject::Connection connectRawFsdMessageSignal(QObject *receiver, RawFsdMessageReceivedSlot rawFsdMessageReceivedSlot) override;
|
||||
|
||||
protected:
|
||||
//! Constructor, with link to runtime
|
||||
CContextNetwork(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);
|
||||
|
||||
@@ -93,6 +93,7 @@ namespace BlackCore
|
||||
s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
|
||||
"removedAircraft", this, SIGNAL(removedAircraft(BlackMisc::Aviation::CCallsign)));
|
||||
Q_ASSERT(s);
|
||||
|
||||
Q_UNUSED(s);
|
||||
this->relayBaseClassSignals(serviceName, connection, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName());
|
||||
}
|
||||
@@ -331,5 +332,12 @@ namespace BlackCore
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Weather::CMetar>(QLatin1String("getMetarForAirport"), airportIcaoCode);
|
||||
}
|
||||
|
||||
QMetaObject::Connection CContextNetworkProxy::connectRawFsdMessageSignal(QObject *receiver, RawFsdMessageReceivedSlot rawFsdMessageReceivedSlot)
|
||||
{
|
||||
Q_UNUSED(receiver);
|
||||
Q_UNUSED(rawFsdMessageReceivedSlot);
|
||||
return {};
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -124,6 +124,10 @@ namespace BlackCore
|
||||
virtual void testRequestAircraftConfig(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
//! @}
|
||||
|
||||
public:
|
||||
//! \copydoc IContextNetwork::connectRawFsdMessageSignal
|
||||
virtual QMetaObject::Connection connectRawFsdMessageSignal(QObject *receiver, RawFsdMessageReceivedSlot rawFsdMessageReceivedSlot) override;
|
||||
|
||||
private:
|
||||
BlackMisc::CGenericDBusInterface *m_dBusInterface; /*!< DBus interface */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user