From 6abd13d13dbd4b7b0181da63044db7b61bc84bdb Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 28 Sep 2018 04:58:16 +0200 Subject: [PATCH] Ref T376, integrated voice setup into server and adjusted FSD setup to support compare --- src/blackmisc/network/fsdsetup.cpp | 38 +++++++++++++++---------- src/blackmisc/network/fsdsetup.h | 10 ++++--- src/blackmisc/network/server.cpp | 32 ++++++++++++--------- src/blackmisc/network/server.h | 45 +++++++++++++++++++----------- 4 files changed, 76 insertions(+), 49 deletions(-) diff --git a/src/blackmisc/network/fsdsetup.cpp b/src/blackmisc/network/fsdsetup.cpp index e49e8dd32..c30236c12 100644 --- a/src/blackmisc/network/fsdsetup.cpp +++ b/src/blackmisc/network/fsdsetup.cpp @@ -8,12 +8,13 @@ */ #include "blackmisc/network/fsdsetup.h" -#include "blackmisc/logcategory.h" #include "blackmisc/logcategorylist.h" #include "blackmisc/propertyindex.h" #include "blackmisc/statusmessage.h" #include "blackmisc/stringutils.h" #include "blackmisc/variant.h" +#include "blackmisc/verify.h" +#include "blackmisc/comparefunctions.h" #include #include @@ -84,34 +85,41 @@ namespace BlackMisc CVariant CFsdSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexTextCodec: - return CVariant::fromValue(this->m_textCodec); - case IndexSendReceiveDetails: - return CVariant::fromValue(this->m_sendReceive); - default: - return CValueObject::propertyByIndex(index); + case IndexTextCodec: return CVariant::fromValue(m_textCodec); + case IndexSendReceiveDetails: return CVariant::fromValue(m_sendReceive); + default: return CValueObject::propertyByIndex(index); } } void CFsdSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexTextCodec: - this->setTextCodec(variant.value()); - break; - case IndexSendReceiveDetails: - this->setSendReceiveDetails(variant.value()); - break; + case IndexTextCodec: this->setTextCodec(variant.value()); break; + case IndexSendReceiveDetails: this->setSendReceiveDetails(variant.value()); break; default: CValueObject::setPropertyByIndex(index, variant); break; } } + + int CFsdSetup::comparePropertyByIndex(const CPropertyIndex &index, const CFsdSetup &compareValue) const + { + if (index.isMyself()) { return this->convertToQString(true).compare(compareValue.convertToQString()); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexTextCodec: return this->getTextCodec().compare(compareValue.getTextCodec()); + case IndexSendReceiveDetails: return Compare::compare(m_sendReceive, compareValue.m_sendReceive); + default: break; + } + BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable("No comparison for index " + index.toQString())); + return 0; + } } // namespace } // namespace diff --git a/src/blackmisc/network/fsdsetup.h b/src/blackmisc/network/fsdsetup.h index 28cb648ea..3ee894ffc 100644 --- a/src/blackmisc/network/fsdsetup.h +++ b/src/blackmisc/network/fsdsetup.h @@ -12,12 +12,11 @@ #ifndef BLACKMISC_NETWORK_FSDSETUP_H #define BLACKMISC_NETWORK_FSDSETUP_H -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/metaclass.h" #include "blackmisc/statusmessagelist.h" -#include "blackmisc/propertyindex.h" #include "blackmisc/valueobject.h" -#include "blackmisc/variant.h" +#include "blackmisc/metaclass.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/blackmiscexport.h" #include #include @@ -106,6 +105,9 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + int comparePropertyByIndex(const CPropertyIndex &index, const CFsdSetup &compareValue) const; + //! \copydoc BlackMisc::Mixin::String::toQString() QString convertToQString(bool i18n = false) const; diff --git a/src/blackmisc/network/server.cpp b/src/blackmisc/network/server.cpp index ae352c776..af62f23f6 100644 --- a/src/blackmisc/network/server.cpp +++ b/src/blackmisc/network/server.cpp @@ -20,6 +20,8 @@ #include #include +using namespace BlackMisc::Audio; + namespace BlackMisc { namespace Network @@ -30,12 +32,12 @@ namespace BlackMisc return all; } - CServer::CServer( - const QString &name, const QString &description, const QString &address, int port, const CUser &user, - const CFsdSetup &setup, const CEcosystem &ecosytem, ServerType serverType, bool isAcceptingConnections) + CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, + const CFsdSetup &fsdSetup, const CVoiceSetup &voiceSetup, const CEcosystem &ecosytem, ServerType serverType, bool isAcceptingConnections) : m_name(decode(name)), m_description(decode(description)), m_address(decode(address)), m_port(port), m_user(user), - m_fsdSetup(setup), m_ecosystem(ecosytem), - m_serverType(serverType), m_isAcceptingConnections(isAcceptingConnections) + m_ecosystem(ecosytem), + m_serverType(serverType), m_isAcceptingConnections(isAcceptingConnections), + m_fsdSetup(fsdSetup), m_voiceSetup(voiceSetup) {} CServer::CServer( @@ -65,21 +67,21 @@ namespace BlackMisc const CServer &CServer::swiftFsdTestServer(bool withPw) { // CUser("guest", "Guest Client project", "", "guest") - // use CObfuscation::endocde to get the strings + // PW!!!!! => use CObfuscation::endocde to get the strings static const CServer dvp("Testserver", "Client project testserver", "fsd.swift-project.org", 6809, CUser("OBF:AwJ6BweZqpmtmORL", "OBF:AwI/594lQTJGZnmSwB0=", "", "OBF:AwKi3JkHNAczBno="), - CFsdSetup(), CEcosystem(CEcosystem::swiftTest()), CServer::FSDServerVatsim); - static const CServer dvnp("Testserver", "Client project testserver", "fsd.swift-project.org", 6809, - CUser("OBF:AwJ6BweZqpmtmORL", "OBF:AwI/594lQTJGZnmSwB0=", "", ""), - CFsdSetup(), CEcosystem(CEcosystem::swiftTest()), CServer::FSDServerVatsim); - return withPw ? dvp : dvnp; + CFsdSetup(), CVoiceSetup(), CEcosystem(CEcosystem::swiftTest()), CServer::FSDServerVatsim); + static const CServer dvnWithPw("Testserver", "Client project testserver", "fsd.swift-project.org", 6809, + CUser("OBF:AwJ6BweZqpmtmORL", "OBF:AwI/594lQTJGZnmSwB0=", "", ""), + CFsdSetup(), CVoiceSetup(), CEcosystem(CEcosystem::swiftTest()), CServer::FSDServerVatsim); + return withPw ? dvp : dvnWithPw; } const CServer &CServer::fscServer() { static const CServer fsc("FSC", "FSC e.V.", "OBF:AwJIKfgkQDJEIRnno29DJlB+UK0=", 6809, CUser(), - CFsdSetup(), CEcosystem(CEcosystem::privateFsd()), CServer::FSDServer); + CFsdSetup(), CVoiceSetup(), CEcosystem(CEcosystem::privateFsd()), CServer::FSDServer); return fsc; } @@ -166,6 +168,7 @@ namespace BlackMisc if (this->getPort() < 1 || this->getPort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, "Wrong port")); } msgs.push_back(this->getUser().validate()); msgs.push_back(this->getFsdSetup().validate()); + msgs.push_back(this->getVoiceSetup().validate()); msgs.addCategories(cats); msgs.sortBySeverity(); return msgs; @@ -192,6 +195,7 @@ namespace BlackMisc case IndexPort: return CVariant::fromValue(m_port); case IndexUser: return m_user.propertyByIndex(index.copyFrontRemoved()); case IndexFsdSetup: return m_fsdSetup.propertyByIndex(index.copyFrontRemoved()); + case IndexVoiceSetup: return m_voiceSetup.propertyByIndex(index.copyFrontRemoved()); case IndexEcosystem: return m_ecosystem.propertyByIndex(index.copyFrontRemoved()); case IndexIsAcceptingConnections: return CVariant::fromValue(m_isAcceptingConnections); case IndexServerType: return CVariant::fromValue(m_serverType); @@ -214,6 +218,7 @@ namespace BlackMisc case IndexName: this->setName(variant.value()); break; case IndexUser: m_user.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexFsdSetup: m_fsdSetup.setPropertyByIndex(index.copyFrontRemoved(), variant); break; + case IndexVoiceSetup: m_voiceSetup.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexEcosystem: m_ecosystem.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexIsAcceptingConnections: this->setIsAcceptingConnections(variant.value()); break; case IndexServerType: this->setServerType(static_cast(variant.toInt())); break; @@ -230,7 +235,8 @@ namespace BlackMisc { case IndexAddress: return this->getAddress().compare(compareValue.getAddress(), Qt::CaseInsensitive); case IndexDescription: return this->getDescription().compare(compareValue.getDescription(), Qt::CaseInsensitive); - case IndexFsdSetup: return this->getFsdSetup().toQString().compare(compareValue.getFsdSetup().toQString()); + case IndexFsdSetup: return m_fsdSetup.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getFsdSetup()); + case IndexVoiceSetup: return m_voiceSetup.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getVoiceSetup()); case IndexName: return this->getName().compare(compareValue.getName(), Qt::CaseInsensitive); case IndexIsAcceptingConnections: return Compare::compare(this->isAcceptingConnections(), compareValue.isAcceptingConnections()); case IndexPort: return Compare::compare(this->getPort(), compareValue.getPort()); diff --git a/src/blackmisc/network/server.h b/src/blackmisc/network/server.h index 1f94ee2ae..836b4c2bc 100644 --- a/src/blackmisc/network/server.h +++ b/src/blackmisc/network/server.h @@ -12,9 +12,10 @@ #ifndef BLACKMISC_NETWORK_SERVER_H #define BLACKMISC_NETWORK_SERVER_H -#include "blackmisc/network/user.h" -#include "blackmisc/network/fsdsetup.h" -#include "blackmisc/network/ecosystem.h" +#include "user.h" +#include "fsdsetup.h" +#include "ecosystem.h" +#include "blackmisc/audio/voicesetup.h" #include "blackmisc/obfuscation.h" #include "blackmisc/blackmiscexport.h" #include "blackmisc/metaclass.h" @@ -47,6 +48,7 @@ namespace BlackMisc IndexPort, IndexUser, IndexFsdSetup, + IndexVoiceSetup, IndexEcosystem, IndexIsAcceptingConnections, IndexServerType, @@ -76,7 +78,8 @@ namespace BlackMisc //! Constructor. CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, - const CFsdSetup &setup, const CEcosystem &ecosytem, ServerType serverType, + const CFsdSetup &fsdSetup, const Audio::CVoiceSetup &voiceSetup, + const CEcosystem &ecosytem, ServerType serverType, bool isAcceptingConnections = true); //! Constructor (minimal for testing) @@ -148,21 +151,27 @@ namespace BlackMisc //! Address and port? bool hasAddressAndPort() const; - //! Get setup + //! Get FSD setup const CFsdSetup &getFsdSetup() const { return m_fsdSetup; } + //! Set FSD setup + void setFsdSetup(const CFsdSetup &setup) { m_fsdSetup = setup; } + //! A FSD server? bool isFsdServer() const; - //! Set setup - void setFsdSetup(const CFsdSetup &setup) { m_fsdSetup = setup; } - //! Set server type bool setServerType(ServerType serverType); //! Get server type ServerType getServerType() const { return static_cast(m_serverType); } + //! Get voice setup + const Audio::CVoiceSetup &getVoiceSetup() const { return m_voiceSetup; } + + //! Set voice setup + void setVoiceSetup(const Audio::CVoiceSetup &setup) { m_voiceSetup = setup; } + //! Unspecified? bool hasUnspecifiedServerType() const; @@ -209,15 +218,16 @@ namespace BlackMisc static const CServer &fscServer(); private: - QString m_name; - QString m_description; - QString m_address; - int m_port = -1; - CUser m_user; - CFsdSetup m_fsdSetup; - CEcosystem m_ecosystem; - int m_serverType = static_cast(Unspecified); - bool m_isAcceptingConnections = true; //!< disable server for connections + QString m_name; + QString m_description; + QString m_address; + int m_port = -1; + CUser m_user; + CEcosystem m_ecosystem; + int m_serverType = static_cast(Unspecified); + bool m_isAcceptingConnections = true; //!< disable server for connections + CFsdSetup m_fsdSetup; + Audio::CVoiceSetup m_voiceSetup; BLACK_METACLASS( CServer, @@ -227,6 +237,7 @@ namespace BlackMisc BLACK_METAMEMBER(port), BLACK_METAMEMBER(user), BLACK_METAMEMBER(fsdSetup), + BLACK_METAMEMBER(voiceSetup), BLACK_METAMEMBER(ecosystem), BLACK_METAMEMBER(serverType), BLACK_METAMEMBER(isAcceptingConnections),