[XSwiftBus] Add hasMultiplayerPlanesAquired() DBus API

This function will return whether X-Plane multiplayer planes have been acquired by XSwiftBus or if not, who else acquired them.
This commit is contained in:
Roland Rossgotterer
2018-11-24 19:00:49 +01:00
committed by Klaus Basan
parent 55c2e2e559
commit 49bd38d722
5 changed files with 83 additions and 12 deletions

View File

@@ -41,6 +41,20 @@ namespace BlackSimPlugin
}
}
MultiplayerAcquireInfo CXSwiftBusTrafficProxy::acquireMultiplayerPlanes()
{
QDBusPendingReply<bool, QString> reply = m_dbusInterface->asyncCall(QLatin1String("acquireMultiplayerPlanes"));
reply.waitForFinished();
if (reply.isError())
{
BlackMisc::CLogMessage(this).debug("CXSwiftBusTrafficProxy::acquireMultiplayerPlanes returned: %1") << reply.error().message();
}
MultiplayerAcquireInfo info;
info.hasAcquired = reply.argumentAt<0>();
info.owner = reply.argumentAt<1>();
return info;
}
bool CXSwiftBusTrafficProxy::initialize()
{
return m_dbusInterface->callDBusRet<bool>(QLatin1String("initialize"));

View File

@@ -99,6 +99,13 @@ namespace BlackSimPlugin
QList<bool> idents; //!< List of active idents
};
//! Multiplayer Acquire Info
struct MultiplayerAcquireInfo
{
bool hasAcquired; //!< Has XSwiftBus acquired multiplayer planes?
QString owner; //!< Name of the plugin having multiplayer planes acquired
};
/*!
* Proxy object connected to a real XSwiftBus::CTraffic object via DBus
*/
@@ -145,6 +152,9 @@ namespace BlackSimPlugin
void remoteAircraftAddingFailed(const QString &callsign);
public slots:
//! \copydoc XSwiftBus::CTraffic::acquireMultiplayerPlanes
MultiplayerAcquireInfo acquireMultiplayerPlanes();
//! \copydoc XSwiftBus::CTraffic::initialize
bool initialize();

View File

@@ -1,5 +1,9 @@
R"(<node>
<interface name="org.swift_project.xswiftbus.traffic">
<method name="acquireMultiplayerPlanes">
<arg name="acquired" type="b" direction="out"/>
<arg name="owner" type="s" direction="out"/>
</method>
<method name="initialize">
<arg type="b" direction="out"/>
</method>

View File

@@ -19,6 +19,8 @@
#include "XPLMGraphics.h"
#include <XPLM/XPLMProcessing.h>
#include <XPLM/XPLMUtilities.h>
#include <XPLM/XPLMPlanes.h>
#include <XPLM/XPLMPlugin.h>
#include <cassert>
#include <cstring>
#include <cmath>
@@ -83,25 +85,50 @@ namespace XSwiftBus
{
if (! s_legacyDataOK) { return false; }
auto err = XPMPMultiplayerInit(preferences, preferences);
if (*err) { cleanup(); return false; }
m_initialized = true;
if (! m_initialized)
{
auto err = XPMPMultiplayerInit(preferences, preferences);
if (*err) { cleanup(); }
else { m_initialized = true; }
}
err = XPMPMultiplayerEnable();
if (*err) { cleanup(); return false; }
m_enabled = true;
return m_initialized;
}
XPMPLoadPlanesIfNecessary();
return true;
bool CTraffic::acquireMultiplayerPlanes(std::string *owner)
{
if (! m_enabledMultiplayer)
{
auto err = XPMPMultiplayerEnable();
if (*err)
{
cleanup();
}
else
{
m_enabledMultiplayer = true;
XPMPLoadPlanesIfNecessary();
}
}
int totalAircraft;
int activeAircraft;
XPLMPluginID controller;
XPLMCountAircraft(&totalAircraft, &activeAircraft, &controller);
char pluginName[256];
XPLMGetPluginInfo(controller, pluginName, nullptr, nullptr, nullptr);
*owner = std::string(pluginName);
return m_enabledMultiplayer;
}
void CTraffic::cleanup()
{
removeAllPlanes();
if (m_enabled)
if (m_enabledMultiplayer)
{
m_enabled = false;
m_enabledMultiplayer = false;
XPMPMultiplayerDisable();
}
@@ -474,7 +501,20 @@ namespace XSwiftBus
}
else if (message.getInterfaceName() == XSWIFTBUS_TRAFFIC_INTERFACENAME)
{
if (message.getMethodName() == "initialize")
if (message.getMethodName() == "acquireMultiplayerPlanes")
{
queueDBusCall([ = ]()
{
std::string owner;
bool acquired = acquireMultiplayerPlanes(&owner);
CDBusMessage reply = CDBusMessage::createReply(sender, serial);
reply.beginArgumentWrite();
reply.appendArgument(acquired);
reply.appendArgument(owner);
sendDBusMessage(reply);
});
}
else if (message.getMethodName() == "initialize")
{
sendDBusReply(sender, serial, initialize());
}

View File

@@ -65,6 +65,9 @@ namespace XSwiftBus
//! Initialize the multiplayer planes rendering and return true if successful
bool initialize();
//! Returns whether multiplayer planes have been acquired. If not, owner will be set to the plugin that acquired it.
bool acquireMultiplayerPlanes(std::string *owner = nullptr);
//! Reverse the actions of initialize().
void cleanup();
@@ -132,7 +135,7 @@ namespace XSwiftBus
private:
bool m_initialized = false;
bool m_enabled = false;
bool m_enabledMultiplayer = false;
CTerrainProbe m_terrainProbe;
void emitSimFrame();