mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 10:45:37 +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:
@@ -17,6 +17,8 @@
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/pq/time.h"
|
||||
#include "blackmisc/network/serverlist.h"
|
||||
#include "blackmisc/directoryutils.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -164,11 +166,94 @@ namespace BlackCore
|
||||
return reader;
|
||||
}
|
||||
};
|
||||
|
||||
//! FSD Message settings
|
||||
class BLACKCORE_EXPORT CRawFsdMessageSettings : public BlackMisc::CValueObject<BlackCore::Vatsim::CRawFsdMessageSettings>
|
||||
{
|
||||
public:
|
||||
//! File writing mode
|
||||
enum FileWriteMode
|
||||
{
|
||||
Truncate,
|
||||
Append,
|
||||
Timestamped
|
||||
};
|
||||
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexWriteEnabled = BlackMisc::CPropertyIndex::GlobalIndexRawFsdMessageSettings,
|
||||
IndexFileDir,
|
||||
IndexFileWriteMode
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CRawFsdMessageSettings();
|
||||
|
||||
//! Simplified constructor
|
||||
CRawFsdMessageSettings(bool enabled, const QString &fileDir);
|
||||
|
||||
//! Is file writing enabled?
|
||||
bool isFileWritingEnabled() const { return m_fileWritingEnabled; }
|
||||
|
||||
//! Get file directory
|
||||
QString getFileDir() const { return m_FileDir; }
|
||||
|
||||
//! Get file write mode
|
||||
FileWriteMode getFileWriteMode () const { return m_fileWriteMode; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
bool m_fileWritingEnabled = false;
|
||||
QString m_FileDir;
|
||||
FileWriteMode m_fileWriteMode = Truncate;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CRawFsdMessageSettings,
|
||||
BLACK_METAMEMBER(fileWritingEnabled),
|
||||
BLACK_METAMEMBER(FileDir),
|
||||
BLACK_METAMEMBER(fileWriteMode)
|
||||
);
|
||||
};
|
||||
|
||||
//! Raw FSD message settings
|
||||
struct TRawFsdMessageSetting : public BlackMisc::TSettingTrait<CRawFsdMessageSettings>
|
||||
{
|
||||
//! \copydoc BlackCore::TSettingTrait::key
|
||||
static const char *key() { return "network/rawfsdmessagelog"; }
|
||||
|
||||
//! \copydoc BlackCore::TSettingTrait::humanReadable
|
||||
static const QString &humanReadable() { static const QString name("FSD message Logging"); return name; }
|
||||
|
||||
//! \copydoc BlackCore::TSettingTrait::isValid
|
||||
static bool isValid(const CRawFsdMessageSettings &setting)
|
||||
{
|
||||
if (setting.isFileWritingEnabled()) { return !setting.getFileDir().isEmpty(); }
|
||||
return true;
|
||||
}
|
||||
|
||||
//! \copydoc BlackCore::TSettingTrait::defaultValue
|
||||
static const CRawFsdMessageSettings &defaultValue()
|
||||
{
|
||||
static const CRawFsdMessageSettings setting { false, BlackMisc::CDirectoryUtils::logDirectory() };
|
||||
return setting;
|
||||
}
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::Vatsim::CReaderSettings)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackCore::Vatsim::CReaderSettings>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackCore::Vatsim::CReaderSettings>)
|
||||
Q_DECLARE_METATYPE(BlackCore::Vatsim::CRawFsdMessageSettings)
|
||||
Q_DECLARE_METATYPE(BlackCore::Vatsim::CRawFsdMessageSettings::FileWriteMode)
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user