Ref T240, use ITimestampBased / ITimestampObjectList

* using the existing base classes (interfaces) gives you plenty of useful utility functions
* hint: we do not init with current timestamp as default as this is relatively slow
This commit is contained in:
Klaus Basan
2018-02-03 00:22:16 +01:00
parent 5b87b60682
commit 80f5d9b595
7 changed files with 33 additions and 28 deletions

View File

@@ -1053,6 +1053,7 @@ namespace BlackCore
{ {
if (!m_rawFsdMessagesEnabled) { return; } if (!m_rawFsdMessagesEnabled) { return; }
CRawFsdMessage rawFsdMessage(fsdMessage); CRawFsdMessage rawFsdMessage(fsdMessage);
rawFsdMessage.setCurrentUtcTime();
if (m_rawFsdMessageLogFile.isOpen()) if (m_rawFsdMessageLogFile.isOpen())
{ {
QTextStream stream(&m_rawFsdMessageLogFile); QTextStream stream(&m_rawFsdMessageLogFile);
@@ -1061,8 +1062,6 @@ namespace BlackCore
emit rawFsdMessageReceived(rawFsdMessage); emit rawFsdMessageReceived(rawFsdMessage);
} }
void CNetworkVatlib::fsdMessageSettingsChanged() void CNetworkVatlib::fsdMessageSettingsChanged()
{ {
if (!m_net) { return; } if (!m_net) { return; }

View File

@@ -213,9 +213,9 @@ namespace BlackGui
ui->cb_FileWritingMode->setCurrentIndex(static_cast<int>(mode)); ui->cb_FileWritingMode->setCurrentIndex(static_cast<int>(mode));
} }
QString CRawFsdMessagesComponent::rawFsdMessageToString(const BlackMisc::Network::CRawFsdMessage &rawFsdMessage) QString CRawFsdMessagesComponent::rawFsdMessageToString(const CRawFsdMessage &rawFsdMessage)
{ {
return QString("%1 %2").arg(rawFsdMessage.getReceptionTime().toString("HH:mm:ss"), rawFsdMessage.getRawMessage()); static const QString s("%1 %2");
} return s.arg(rawFsdMessage.getFormattedUtcTimestampHmsz(), rawFsdMessage.getRawMessage());
} }
} // namespace } // namespace

View File

@@ -31,7 +31,7 @@ namespace BlackMisc
{ {
Q_UNUSED(i18n); Q_UNUSED(i18n);
static const QString s("%1 %2"); static const QString s("%1 %2");
return s.arg(m_receptionTime.toString("dd.MM.yy HH:mm:ss"), m_rawMessage); return s.arg(this->getFormattedUtcTimestampHmsz(), m_rawMessage);
} }
bool CRawFsdMessage::isPacketType(const QString &type) const bool CRawFsdMessage::isPacketType(const QString &type) const
@@ -47,27 +47,30 @@ namespace BlackMisc
const QStringList &CRawFsdMessage::getAllPacketTypes() const QStringList &CRawFsdMessage::getAllPacketTypes()
{ {
static const QStringList allPacketTypes = { "@", "%", "#AA", "#DA", "#AP", "#DP", "#TM", "#WX", "#DL", "#TD", "#WD" static const QStringList allPacketTypes = { "@", "%", "#AA", "#DA", "#AP", "#DP", "#TM", "#WX", "#DL", "#TD", "#WD"
"#CD", "#PC", "#SB", "$FP", "$AM", "$PI", "$PO", "$HO", "$HA", "$AX", "$AR", "#CD", "#PC", "#SB", "$FP", "$AM", "$PI", "$PO", "$HO", "$HA", "$AX", "$AR",
"$CQ", "$CR", "$ER", "$!!" }; "$CQ", "$CR", "$ER", "$!!"
};
return allPacketTypes; return allPacketTypes;
} }
CVariant CRawFsdMessage::propertyByIndex(const CPropertyIndex &index) const CVariant CRawFsdMessage::propertyByIndex(const CPropertyIndex &index) const
{ {
if (index.isMyself()) { return CVariant::from(*this); } if (index.isMyself()) { return CVariant::from(*this); }
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexReceptionTime: return CVariant::fromValue(m_rawMessage); case IndexRawMessage: return CVariant::fromValue(m_rawMessage);
case IndexRawMessage: return CVariant::fromValue(m_receptionTime); default: return CValueObject::propertyByIndex(index);
default:
return CValueObject::propertyByIndex(index);
} }
} }
void CRawFsdMessage::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) void CRawFsdMessage::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{ {
if (index.isMyself()) { (*this) = variant.to<CRawFsdMessage>(); return; } if (index.isMyself()) { (*this) = variant.to<CRawFsdMessage>(); return; }
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {

View File

@@ -12,6 +12,7 @@
#ifndef BLACKMISC_NETWORK_RAWFSDMESSAGE_H #ifndef BLACKMISC_NETWORK_RAWFSDMESSAGE_H
#define BLACKMISC_NETWORK_RAWFSDMESSAGE_H #define BLACKMISC_NETWORK_RAWFSDMESSAGE_H
#include "blackmisc/timestampbased.h"
#include "blackmisc/valueobject.h" #include "blackmisc/valueobject.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
#include "blackmisc/metaclass.h" #include "blackmisc/metaclass.h"
@@ -27,14 +28,15 @@ namespace BlackMisc
namespace Network namespace Network
{ {
//! Value object for a raw FSD message //! Value object for a raw FSD message
class BLACKMISC_EXPORT CRawFsdMessage : public CValueObject<CRawFsdMessage> class BLACKMISC_EXPORT CRawFsdMessage :
public CValueObject<CRawFsdMessage>,
public ITimestampBased
{ {
public: public:
//! Properties by index //! Properties by index
enum ColumnIndex enum ColumnIndex
{ {
IndexReceptionTime = CPropertyIndex::GlobalIndexCRawFsdMessage, IndexRawMessage = CPropertyIndex::GlobalIndexCRawFsdMessage,
IndexRawMessage
}; };
//! Default constructor. //! Default constructor.
@@ -49,9 +51,6 @@ namespace BlackMisc
//! Set raw message //! Set raw message
void setRawMessage(const QString &rawMessage) { m_rawMessage = rawMessage; } void setRawMessage(const QString &rawMessage) { m_rawMessage = rawMessage; }
//! Get reception time
const QDateTime &getReceptionTime() const { return m_receptionTime; }
//! Returns true if the raw message is from the given PDU packet type //! Returns true if the raw message is from the given PDU packet type
bool isPacketType(const QString &type) const; bool isPacketType(const QString &type) const;
@@ -59,7 +58,7 @@ namespace BlackMisc
bool containsString(const QString &str) const; bool containsString(const QString &str) const;
//! Returns a list of all known packet types. //! Returns a list of all known packet types.
static const QStringList &getAllPacketTypes (); static const QStringList &getAllPacketTypes();
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex //! \copydoc BlackMisc::Mixin::Index::propertyByIndex
CVariant propertyByIndex(const CPropertyIndex &index) const; CVariant propertyByIndex(const CPropertyIndex &index) const;
@@ -72,12 +71,11 @@ namespace BlackMisc
private: private:
QString m_rawMessage; QString m_rawMessage;
QDateTime m_receptionTime = QDateTime::currentDateTime();
BLACK_METACLASS( BLACK_METACLASS(
CRawFsdMessage, CRawFsdMessage,
BLACK_METAMEMBER(rawMessage), BLACK_METAMEMBER(rawMessage),
BLACK_METAMEMBER(receptionTime) BLACK_METAMEMBER(timestampMSecsSinceEpoch)
); );
}; };
} // namespace } // namespace

View File

@@ -13,6 +13,7 @@
#define BLACKMISC_NETWORK_RAWFSDMESSAGELIST_H #define BLACKMISC_NETWORK_RAWFSDMESSAGELIST_H
#include "rawfsdmessage.h" #include "rawfsdmessage.h"
#include "blackmisc/timestampobjectlist.h"
#include "blackmisc/collection.h" #include "blackmisc/collection.h"
#include "blackmisc/sequence.h" #include "blackmisc/sequence.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
@@ -28,7 +29,8 @@ namespace BlackMisc
//! Value object encapsulating a list raw FSD messages. //! Value object encapsulating a list raw FSD messages.
class BLACKMISC_EXPORT CRawFsdMessageList : class BLACKMISC_EXPORT CRawFsdMessageList :
public CSequence<CRawFsdMessage>, public CSequence<CRawFsdMessage>,
public Mixin::MetaType<CRawFsdMessageList> public Mixin::MetaType<CRawFsdMessageList>,
public ITimestampObjectList<CRawFsdMessage, CRawFsdMessageList>
{ {
public: public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CRawFsdMessageList) BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CRawFsdMessageList)

View File

@@ -12,14 +12,12 @@
#include "blackmisc/aviation/liverylist.h" #include "blackmisc/aviation/liverylist.h"
#include "blackmisc/aviation/aircrafticaocodelist.h" #include "blackmisc/aviation/aircrafticaocodelist.h"
#include "blackmisc/aviation/airlineicaocodelist.h" #include "blackmisc/aviation/airlineicaocodelist.h"
#include "blackmisc/aviation/airport.h"
#include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/airportlist.h"
#include "blackmisc/db/dbinfolist.h" #include "blackmisc/db/dbinfolist.h"
#include "blackmisc/db/artifactlist.h" #include "blackmisc/db/artifactlist.h"
#include "blackmisc/db/distributionlist.h" #include "blackmisc/db/distributionlist.h"
#include "blackmisc/network/textmessage.h"
#include "blackmisc/network/textmessagelist.h" #include "blackmisc/network/textmessagelist.h"
#include "blackmisc/network/urllog.h" #include "blackmisc/network/rawfsdmessagelist.h"
#include "blackmisc/network/urlloglist.h" #include "blackmisc/network/urlloglist.h"
#include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/distributorlist.h"
#include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/aircraftmodellist.h"
@@ -348,6 +346,7 @@ namespace BlackMisc
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Db::CDistribution, BlackMisc::Db::CDistributionList>; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Db::CDistribution, BlackMisc::Db::CDistributionList>;
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CUrlLog, BlackMisc::Network::CUrlLogList>; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CUrlLog, BlackMisc::Network::CUrlLogList>;
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CRawFsdMessage, BlackMisc::Network::CRawFsdMessageList>;
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>;
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList>; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList>;
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CMatchingStatisticsEntry, BlackMisc::Simulation::CMatchingStatistics>; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CMatchingStatisticsEntry, BlackMisc::Simulation::CMatchingStatistics>;

View File

@@ -162,6 +162,8 @@ namespace BlackMisc
{ {
class CTextMessage; class CTextMessage;
class CTextMessageList; class CTextMessageList;
class CRawFsdMessage;
class CRawFsdMessageList;
class CUrlLog; class CUrlLog;
class CUrlLogList; class CUrlLogList;
} }
@@ -191,8 +193,6 @@ namespace BlackMisc
class CCountry; class CCountry;
class CCountryList; class CCountryList;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAirlineIcaoCode, BlackMisc::Aviation::CAirlineIcaoCodeList>;
@@ -203,10 +203,14 @@ namespace BlackMisc
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CRawFsdMessage, BlackMisc::Network::CRawFsdMessageList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CUrlLog, BlackMisc::Network::CUrlLogList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CUrlLog, BlackMisc::Network::CUrlLogList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CIdentifier, BlackMisc::CIdentifierList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CIdentifier, BlackMisc::CIdentifierList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CCountry, BlackMisc::CCountryList>; extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CCountry, BlackMisc::CCountryList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampWithOffsetObjectList<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampWithOffsetObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
//! \endcond //! \endcond
} //namespace } //namespace