mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
Checks to avoid issues during the XPlane startup.
Those here are precautionary.
This commit is contained in:
@@ -24,9 +24,9 @@ static XSwiftBus::CPlugin *g_plugin = nullptr;
|
|||||||
|
|
||||||
PLUGIN_API int XPluginStart(char *o_name, char *o_sig, char *o_desc)
|
PLUGIN_API int XPluginStart(char *o_name, char *o_sig, char *o_desc)
|
||||||
{
|
{
|
||||||
#if APL
|
#ifdef APL
|
||||||
// https://developer.x-plane.com/2014/12/mac-plugin-developers-you-should-be-using-native-paths/
|
// https://developer.x-plane.com/2014/12/mac-plugin-developers-you-should-be-using-native-paths/
|
||||||
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS",1);
|
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
INFO_LOG("XSwiftBus plugin starting");
|
INFO_LOG("XSwiftBus plugin starting");
|
||||||
@@ -58,6 +58,12 @@ PLUGIN_API void XPluginReceiveMessage(XPLMPluginID from, long msg, void *param)
|
|||||||
{
|
{
|
||||||
if (from == XPLM_PLUGIN_XPLANE)
|
if (from == XPLM_PLUGIN_XPLANE)
|
||||||
{
|
{
|
||||||
|
if (!g_plugin || !g_plugin->isRunning())
|
||||||
|
{
|
||||||
|
WARNING_LOG("Received message, but plugin NOT running");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (msg)
|
switch (msg)
|
||||||
{
|
{
|
||||||
case XPLM_MSG_PLANE_LOADED:
|
case XPLM_MSG_PLANE_LOADED:
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace XSwiftBus
|
|||||||
void CPlugin::readConfig()
|
void CPlugin::readConfig()
|
||||||
{
|
{
|
||||||
initXPlanePath();
|
initXPlanePath();
|
||||||
auto configFilePath = g_xplanePath + "Resources" + g_sep + "plugins" + g_sep + "xswiftbus" + g_sep + "xswiftbus.conf";
|
const std::string configFilePath = g_xplanePath + "Resources" + g_sep + "plugins" + g_sep + "xswiftbus" + g_sep + "xswiftbus.conf";
|
||||||
m_pluginConfig.setFilePath(configFilePath);
|
m_pluginConfig.setFilePath(configFilePath);
|
||||||
m_pluginConfig.parse();
|
m_pluginConfig.parse();
|
||||||
m_pluginConfig.print();
|
m_pluginConfig.print();
|
||||||
@@ -175,10 +175,11 @@ namespace XSwiftBus
|
|||||||
float CPlugin::startServerDeferred(float, float, int, void *refcon)
|
float CPlugin::startServerDeferred(float, float, int, void *refcon)
|
||||||
{
|
{
|
||||||
auto *plugin = static_cast<CPlugin *>(refcon);
|
auto *plugin = static_cast<CPlugin *>(refcon);
|
||||||
if (! plugin->m_isRunning)
|
if (!plugin->m_isRunning)
|
||||||
{
|
{
|
||||||
plugin->startServer();
|
plugin->startServer();
|
||||||
plugin->m_isRunning = true;
|
plugin->m_isRunning = true;
|
||||||
|
INFO_LOG("XSwiftBus plugin started (deferred)");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ namespace XSwiftBus
|
|||||||
//! Called by XPluginReceiveMessage when the aircraft is positioned at an airport
|
//! Called by XPluginReceiveMessage when the aircraft is positioned at an airport
|
||||||
void onAircraftRepositioned();
|
void onAircraftRepositioned();
|
||||||
|
|
||||||
|
//! Is running
|
||||||
|
bool isRunning() const { return m_isRunning; }
|
||||||
|
|
||||||
|
//! Should stop
|
||||||
|
bool shouldStop() const { return m_shouldStop; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CConfig m_pluginConfig;
|
CConfig m_pluginConfig;
|
||||||
CDBusDispatcher m_dbusDispatcher;
|
CDBusDispatcher m_dbusDispatcher;
|
||||||
@@ -78,7 +84,7 @@ namespace XSwiftBus
|
|||||||
decltype(m_atisEnabled.get()) m_atisSaved = 0;
|
decltype(m_atisEnabled.get()) m_atisSaved = 0;
|
||||||
|
|
||||||
std::thread m_dbusThread;
|
std::thread m_dbusThread;
|
||||||
bool m_isRunning = false;
|
bool m_isRunning = false;
|
||||||
bool m_shouldStop = false;
|
bool m_shouldStop = false;
|
||||||
|
|
||||||
void readConfig();
|
void readConfig();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <XPLM/XPLMPlanes.h>
|
#include <XPLM/XPLMPlanes.h>
|
||||||
#include <XPLM/XPLMUtilities.h>
|
#include <XPLM/XPLMUtilities.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
// clazy:excludeall=reserve-candidates
|
// clazy:excludeall=reserve-candidates
|
||||||
@@ -33,7 +34,12 @@ namespace XSwiftBus
|
|||||||
char filename[256];
|
char filename[256];
|
||||||
char path[512];
|
char path[512];
|
||||||
XPLMGetNthAircraftModel(XPLM_USER_AIRCRAFT, filename, path);
|
XPLMGetNthAircraftModel(XPLM_USER_AIRCRAFT, filename, path);
|
||||||
AcfProperties acfProperties = extractAcfProperties(path);
|
if (std::strlen(filename) < 1 || std::strlen(path) < 1)
|
||||||
|
{
|
||||||
|
WARNING_LOG("Aircraft changed, but NO path or file name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const AcfProperties acfProperties = extractAcfProperties(path);
|
||||||
emitAircraftModelChanged(path, filename, getAircraftLivery(), getAircraftIcaoCode(), acfProperties.modelString, acfProperties.modelName, getAircraftDescription());
|
emitAircraftModelChanged(path, filename, getAircraftLivery(), getAircraftIcaoCode(), acfProperties.modelString, acfProperties.modelName, getAircraftDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user