From 5718abe03c98654109f2a4a8263820a127da3d53 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 23 Sep 2015 15:09:39 +0200 Subject: [PATCH] refs #452, DB flags describing what entities to read --- .../blackmiscfreefunctions_nwmeta.cpp | 11 ++- src/blackmisc/network/dbflags.cpp | 67 +++++++++++++++++ src/blackmisc/network/dbflags.h | 72 +++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 src/blackmisc/network/dbflags.cpp create mode 100644 src/blackmisc/network/dbflags.h diff --git a/src/blackmisc/blackmiscfreefunctions_nwmeta.cpp b/src/blackmisc/blackmiscfreefunctions_nwmeta.cpp index 4a8bbf899..f4a2352b6 100644 --- a/src/blackmisc/blackmiscfreefunctions_nwmeta.cpp +++ b/src/blackmisc/blackmiscfreefunctions_nwmeta.cpp @@ -8,7 +8,8 @@ */ #include "blackmiscfreefunctions.h" -#include "network/network.h" +#include "blackmisc/network/network.h" +#include "blackmisc/network/dbflags.h" /* * Metadata for Network @@ -27,4 +28,12 @@ void BlackMisc::Network::registerMetadata() CClient::registerMetadata(); CClientList::registerMetadata(); CVoiceCapabilities::registerMetadata(); + + int id = qRegisterMetaType(); + Q_ASSERT_X(id >= 1024, Q_FUNC_INFO, "wrong id for metatype"); + id = qRegisterMetaType(); + Q_ASSERT_X(id >= 1024, Q_FUNC_INFO, "wrong id for metatype"); + id = qRegisterMetaType(); + Q_ASSERT_X(id >= 1024, Q_FUNC_INFO, "wrong id for metatype"); + Q_UNUSED(id); } diff --git a/src/blackmisc/network/dbflags.cpp b/src/blackmisc/network/dbflags.cpp new file mode 100644 index 000000000..d19cc1cfa --- /dev/null +++ b/src/blackmisc/network/dbflags.cpp @@ -0,0 +1,67 @@ +/* Copyright (C) 2015 + * 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 and at http://www.swift-project.org/license.html. 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. + */ + +#include "blackmisc/network/dbflags.h" +#include + +namespace BlackMisc +{ + namespace Network + { + QString CDbFlags::flagToString(CDbFlags::EntityFlags flag) + { + switch (flag) + { + case NoEntity: return "no data"; + case VatsimBookings: return "VATSIM bookings"; + case VatsimDataFile: return "VATSIM data file"; + case AircraftIcaoEntity: return "Aircraft ICAO"; + case AirlineIcaoEntity: return "Airline ICAO"; + case CountryEntity: return "Country"; + case DistributorEntity: return "Distributor"; + case LiveryEntity: return "Livery"; + case ModelEntity: return "Model"; + case AllIcaoEntities: return "All ICAO"; + case AllIcaoAndCountries: return "All ICAO + country"; + case AllEntities: return "All"; + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "wrong flags"); + return "wrong flags"; + } + } + + QString CDbFlags::flagToString(Entity flag) + { + QStringList list; + if (flag.testFlag(NoEntity)) list << "no data"; + if (flag.testFlag(VatsimBookings)) list << "VATSIM bookings"; + if (flag.testFlag(VatsimDataFile)) list << "VATSIM data file"; + if (flag.testFlag(AircraftIcaoEntity)) list << "Aircraft ICAO"; + if (flag.testFlag(AirlineIcaoEntity)) list << "Airline ICAO"; + if (flag.testFlag(CountryEntity)) list << "Country"; + if (flag.testFlag(DistributorEntity)) list << "Distributor"; + if (flag.testFlag(LiveryEntity)) list << "Livery"; + if (flag.testFlag(ModelEntity)) list << "Model"; + return list.join(','); + } + + QString CDbFlags::flagToString(CDbFlags::ReadState flag) + { + switch (flag) + { + case ReadFinished: return "finished"; + case ReadFailed: return "failed"; + case StartRead: return "read started"; + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "wrong flags"); + return "wrong flags"; + } + } + } // namespace +} // namespace diff --git a/src/blackmisc/network/dbflags.h b/src/blackmisc/network/dbflags.h new file mode 100644 index 000000000..67293234d --- /dev/null +++ b/src/blackmisc/network/dbflags.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2015 + * 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 and at http://www.swift-project.org/license.html. 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_NETWORK_ENTITREADERFLAGS_H +#define BLACKMISC_NETWORK_ENTITREADERFLAGS_H + +#include "blackmisc/blackmiscexport.h" +#include + +namespace BlackMisc +{ + namespace Network + { + /*! + * What and state of reading from DB + */ + class BLACKMISC_EXPORT CDbFlags + { + public: + //! Which data to read, requires corresponding readers + enum EntityFlags + { + NoEntity = 0, ///< no data at all + VatsimBookings = 1 << 0, ///< bookings + VatsimDataFile = 1 << 1, ///< the VATSIM data file + AircraftIcaoEntity = 1 << 2, ///< ICAO codes for aircraft + AirlineIcaoEntity = 1 << 3, ///< ICAO codes for airlines + CountryEntity = 1 << 4, ///< Country codes + DistributorEntity = 1 << 5, ///< distributors + LiveryEntity = 1 << 6, ///< liveries + ModelEntity = 1 << 7, ///< models + AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, ///< all ICAO codes + AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, ///< all ICAO codes and countries + DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, ///< Combinded + AllEntities = 0xFFFF ///< everything + }; + Q_DECLARE_FLAGS(Entity, EntityFlags) + + //! State of operation + enum ReadState + { + StartRead, ///< reading has been started + ReadFinished, ///< reading done + ReadFailed ///< reading failed + }; + + //! Convert to string + static QString flagToString(EntityFlags flag); + + //! Convert to string + static QString flagToString(BlackMisc::Network::CDbFlags::Entity flag); + + //! Convert to string + static QString flagToString(ReadState flag); + }; + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Network::CDbFlags::EntityFlags) +Q_DECLARE_METATYPE(BlackMisc::Network::CDbFlags::Entity) +Q_DECLARE_METATYPE(BlackMisc::Network::CDbFlags::ReadState) +Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Network::CDbFlags::Entity) + +#endif // guard