mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
Refactoring code of FG plugin
This commit is contained in:
committed by
Mat Sutcliffe
parent
9363bf3b1f
commit
1b273a36dc
@@ -0,0 +1,84 @@
|
||||
/* Copyright (C) 2018
|
||||
* 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. 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
|
||||
|
||||
#include "fgswiftbusconfigwriter.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace Flightgear
|
||||
{
|
||||
CFGSwiftBusConfigWriter::CFGSwiftBusConfigWriter(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
void CFGSwiftBusConfigWriter::setDBusAddress(const QString &dBusAddress)
|
||||
{
|
||||
if (CDBusServer::isSessionOrSystemAddress(dBusAddress)) { m_dbusMode = "session"; }
|
||||
else { m_dbusMode = "p2p"; }
|
||||
|
||||
if (m_dbusMode == "p2p")
|
||||
{
|
||||
CDBusServer::dBusAddressToHostAndPort(dBusAddress, m_dbusAddress, m_dbusPort);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CFGSwiftBusConfigWriter::updateInAllXPlaneVersions()
|
||||
{
|
||||
updateInXPlane9();
|
||||
updateInXPlane10();
|
||||
updateInXPlane11();
|
||||
}
|
||||
|
||||
void CFGSwiftBusConfigWriter::updateInXPlane9()
|
||||
{
|
||||
//QString path = CXPlaneUtil::xswiftbusPluginDir(CXPlaneUtil::xplane9Dir());
|
||||
//if (!path.isEmpty()) { writeTo(path); }
|
||||
}
|
||||
|
||||
void CFGSwiftBusConfigWriter::updateInXPlane10()
|
||||
{
|
||||
//QString path = CXPlaneUtil::xswiftbusPluginDir(CXPlaneUtil::xplane10Dir());
|
||||
//if (!path.isEmpty()) { writeTo(path); }
|
||||
}
|
||||
|
||||
void CFGSwiftBusConfigWriter::updateInXPlane11()
|
||||
{
|
||||
//QString path = CXPlaneUtil::xswiftbusPluginDir(CXPlaneUtil::xplane11Dir());
|
||||
//if (!path.isEmpty()) { writeTo(path); }
|
||||
}
|
||||
|
||||
void CFGSwiftBusConfigWriter::writeTo(const QString &filePath)
|
||||
{
|
||||
QString configFilePath = filePath + "/xswiftbus.conf";
|
||||
QFile configFile(configFilePath);
|
||||
configFile.remove();
|
||||
if (configFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QTextStream ts(&configFile);
|
||||
ts << "# DBus Mode - Options: p2p, session" << endl;
|
||||
ts << "dbusMode = " << m_dbusMode << endl;
|
||||
ts << endl;
|
||||
ts << "# DBus server address - relevant for P2P mode only" << endl;
|
||||
ts << "dbusAddress = " << m_dbusAddress << endl;
|
||||
ts << endl;
|
||||
ts << "# DBus server port - relevant for P2P mode only" << endl;
|
||||
ts << "dbusPort = " << m_dbusPort << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
src/blackmisc/simulation/flightgear/fgswiftbusconfigwriter.h
Normal file
60
src/blackmisc/simulation/flightgear/fgswiftbusconfigwriter.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* Copyright (C) 2018
|
||||
* 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. 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_SIMULATION_FLIGHTGEAR_FGSWIFTBUSCONFIGWRITER_H
|
||||
#define BLACKMISC_SIMULATION_FLIGHTGEAR_FGSWIFTBUSCONFIGWRITER_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace Flightgear
|
||||
{
|
||||
//! FGSwiftBus configuration file writer
|
||||
class BLACKMISC_EXPORT CFGSwiftBusConfigWriter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Default constructor.
|
||||
CFGSwiftBusConfigWriter(QObject *parent = nullptr);
|
||||
|
||||
//! Set new DBus address
|
||||
void setDBusAddress(const QString &dBusAddress);
|
||||
|
||||
//! Update fgswiftbus.conf in all known X-Plane versions (XP9 - XP11 are supported)
|
||||
void updateInAllXPlaneVersions();
|
||||
|
||||
//! Update xswiftbus.conf in X-Plane 9
|
||||
void updateInXPlane9();
|
||||
|
||||
//! Update xswiftbus.conf in X-Plane 10
|
||||
void updateInXPlane10();
|
||||
|
||||
//! Update xswiftbus.conf in X-Plane 11
|
||||
void updateInXPlane11();
|
||||
|
||||
//! Write new xswiftbus.conf to filePath. Existing files are removed.
|
||||
void writeTo(const QString &filePath);
|
||||
|
||||
private:
|
||||
QString m_dbusMode = "p2p";
|
||||
QString m_dbusAddress = "127.0.0.1";
|
||||
QString m_dbusPort = "45001";
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_XSWIFTBUSSETTINGS_H
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_XSWIFTBUSSETTINGS_H
|
||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_FGSWIFTBUSSETTINGS_H
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_FGSWIFTBUSSETTINGS_H
|
||||
|
||||
#include <QString>
|
||||
#include "blackmisc/settingscache.h"
|
||||
@@ -23,15 +23,15 @@ namespace BlackMisc
|
||||
namespace Settings
|
||||
{
|
||||
/*!
|
||||
* Setting for XSwiftBus.
|
||||
* Setting for FGSwiftBus.
|
||||
*/
|
||||
struct TXSwiftBusServer : public BlackMisc::TSettingTrait<QString>
|
||||
struct TFGSwiftBusServer : public BlackMisc::TSettingTrait<QString>
|
||||
{
|
||||
//! \copydoc BlackMisc::TSettingTrait::key
|
||||
static const char *key() { return "xswiftbus/server"; }
|
||||
static const char *key() { return "fgswiftbus/server"; }
|
||||
|
||||
//! \copydoc BlackCore::TSettingTrait::humanReadable
|
||||
static const QString &humanReadable() { static const QString name("XSwiftBus"); return name; }
|
||||
static const QString &humanReadable() { static const QString name("FGSiftBus"); return name; }
|
||||
|
||||
//! \copydoc BlackMisc::TSettingTrait::defaultValue
|
||||
static QString defaultValue() { return "tcp:host=127.0.0.1,port=45003"; }
|
||||
|
||||
Reference in New Issue
Block a user