From c36028ca9c8e8eccdc1fd6bcef0395a8aa999911 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 13 Mar 2016 19:37:26 +0000 Subject: [PATCH] refs #485, Restricted --- src/blackcore/application.cpp | 3 ++- src/blackcore/cookiemanager.cpp | 2 +- src/blackcore/cookiemanager.h | 9 ++++----- src/blackcore/webdataservices.cpp | 2 +- src/blackcore/webdataservices.h | 9 ++++----- src/blackgui/stylesheetutility.cpp | 3 +-- src/blackgui/stylesheetutility.h | 9 ++++----- src/blackmisc/restricted.h | 30 ++++++++++++++++++++++++++++++ 8 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 src/blackmisc/restricted.h diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index d7231bff3..083967149 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -42,6 +42,7 @@ BlackCore::CApplication *sApp = nullptr; // set by constructor namespace BlackCore { CApplication::CApplication(const QString &applicationName) : + m_cookieManager( {}, this), m_applicationName(applicationName), m_coreFacadeConfig(CCoreFacadeConfig::allEmpty()) { @@ -450,7 +451,7 @@ namespace BlackCore { CLogMessage(this).info("Will start web data services now"); this->m_webDataServices.reset( - new CWebDataServices(this->m_webReader, this->m_dbReaderHint) + new CWebDataServices(this->m_webReader, this->m_dbReaderHint, {}, this) ); } return true; diff --git a/src/blackcore/cookiemanager.cpp b/src/blackcore/cookiemanager.cpp index b02733a4d..98a2c8c7d 100644 --- a/src/blackcore/cookiemanager.cpp +++ b/src/blackcore/cookiemanager.cpp @@ -18,7 +18,7 @@ using namespace BlackMisc; namespace BlackCore { - CCookieManager::CCookieManager(QObject *parent) : QNetworkCookieJar(parent) + CCookieManager::CCookieManager(BlackMisc::Restricted, QObject *parent) : QNetworkCookieJar(parent) { // code } diff --git a/src/blackcore/cookiemanager.h b/src/blackcore/cookiemanager.h index bd1694749..82c2c7857 100644 --- a/src/blackcore/cookiemanager.h +++ b/src/blackcore/cookiemanager.h @@ -12,6 +12,7 @@ #ifndef BLACKCORE_COOKIEMANAGER_H #define BLACKCORE_COOKIEMANAGER_H +#include "blackmisc/restricted.h" #include "blackcore/blackcoreexport.h" #include #include @@ -30,9 +31,10 @@ namespace BlackCore { Q_OBJECT - friend class CApplication; - public: + //! Constructor, only allowed from BlackCore::CApplication + CCookieManager(BlackMisc::Restricted, QObject *parent = nullptr); + //! \copydoc QNetworkCookieJar::setCookiesFromUrl //! \threadsafe virtual bool setCookiesFromUrl(const QList &cookies, const QUrl &url) override; @@ -62,9 +64,6 @@ namespace BlackCore virtual bool updateCookie(const QNetworkCookie &cookie) override; private: - //! Constructor - CCookieManager(QObject *parent = nullptr); - mutable QReadWriteLock m_lock { QReadWriteLock::Recursive }; }; diff --git a/src/blackcore/webdataservices.cpp b/src/blackcore/webdataservices.cpp index 3506deabe..bf845c84b 100644 --- a/src/blackcore/webdataservices.cpp +++ b/src/blackcore/webdataservices.cpp @@ -37,7 +37,7 @@ using namespace BlackMisc::Weather; namespace BlackCore { - CWebDataServices::CWebDataServices(CWebReaderFlags::WebReader readerFlags, CWebReaderFlags::DbReaderHint hint, QObject *parent) : + CWebDataServices::CWebDataServices(CWebReaderFlags::WebReader readerFlags, CWebReaderFlags::DbReaderHint hint, BlackMisc::Restricted, QObject *parent) : QObject(parent), m_readerFlags(readerFlags), m_dbHint(hint) { if (!sApp) { return; } // shutting down diff --git a/src/blackcore/webdataservices.h b/src/blackcore/webdataservices.h index 0e8e0f362..5afe04f98 100644 --- a/src/blackcore/webdataservices.h +++ b/src/blackcore/webdataservices.h @@ -28,6 +28,7 @@ #include "blackmisc/logcategorylist.h" #include "blackmisc/countrylist.h" #include "blackmisc/project.h" +#include "blackmisc/restricted.h" #include namespace BlackCore @@ -48,12 +49,14 @@ namespace BlackCore public QObject { Q_OBJECT - friend class CApplication; public: //! Log categories static const BlackMisc::CLogCategoryList &getLogCategories(); + //! Constructor, only allowed from BlackCore::CApplication + CWebDataServices(CWebReaderFlags::WebReader readerFlags, CWebReaderFlags:: DbReaderHint hint, BlackMisc::Restricted, QObject *parent = nullptr); + //! Shutdown void gracefulShutdown(); @@ -261,10 +264,6 @@ namespace BlackCore //! First read (allows to immediately read in background) void readInBackground(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllEntities, int delayMs = 0); - protected: - //! Constructor - CWebDataServices(CWebReaderFlags::WebReader readerFlags, CWebReaderFlags:: DbReaderHint hint, QObject *parent = nullptr); - private slots: //! ATC bookings received void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations); diff --git a/src/blackgui/stylesheetutility.cpp b/src/blackgui/stylesheetutility.cpp index 4df8493b8..fea24eeac 100644 --- a/src/blackgui/stylesheetutility.cpp +++ b/src/blackgui/stylesheetutility.cpp @@ -19,8 +19,7 @@ namespace BlackGui { - - CStyleSheetUtility::CStyleSheetUtility(QObject *parent) : QObject(parent) + CStyleSheetUtility::CStyleSheetUtility(BlackMisc::Restricted, QObject *parent) : QObject(parent) { this->read(); } diff --git a/src/blackgui/stylesheetutility.h b/src/blackgui/stylesheetutility.h index 32973177d..0706c360f 100644 --- a/src/blackgui/stylesheetutility.h +++ b/src/blackgui/stylesheetutility.h @@ -13,6 +13,7 @@ #define BLACKGUI_STYLESHEETUTILITY_H #include "blackgui/blackguiexport.h" +#include "blackmisc/restricted.h" #include #include #include @@ -29,9 +30,11 @@ namespace BlackGui class BLACKGUI_EXPORT CStyleSheetUtility : public QObject { Q_OBJECT - friend class CGuiApplication; public: + //! Constructor + explicit CStyleSheetUtility(BlackMisc::Restricted, QObject *parent = nullptr); + //! Style for given file name QString style(const QString &fileName) const; @@ -137,10 +140,6 @@ namespace BlackGui private: QMap m_styleSheets; //!< filename, stylesheet QScopedPointer m_iniFile; - - //! Constructor - explicit CStyleSheetUtility(QObject *parent = nullptr); }; - } #endif // guard diff --git a/src/blackmisc/restricted.h b/src/blackmisc/restricted.h new file mode 100644 index 000000000..d9fa769e4 --- /dev/null +++ b/src/blackmisc/restricted.h @@ -0,0 +1,30 @@ +/* Copyright (C) 2016 + * 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_RESTRICTED_H +#define BLACKMISC_RESTRICTED_H + +namespace BlackMisc +{ + /*! + * Restricted is just an empty class, that can only be constructed by the class T. + */ + template class Restricted + { + private: + friend T; + + //! Constructor is only available to the template parameter T. + Restricted() {} + }; +} + +#endif // guard