refs #485, Restricted<T>

This commit is contained in:
Klaus Basan
2016-03-13 19:37:26 +00:00
committed by Mathew Sutcliffe
parent 18a907086d
commit c36028ca9c
8 changed files with 47 additions and 20 deletions

View File

@@ -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;

View File

@@ -18,7 +18,7 @@ using namespace BlackMisc;
namespace BlackCore
{
CCookieManager::CCookieManager(QObject *parent) : QNetworkCookieJar(parent)
CCookieManager::CCookieManager(BlackMisc::Restricted<CApplication>, QObject *parent) : QNetworkCookieJar(parent)
{
// code
}

View File

@@ -12,6 +12,7 @@
#ifndef BLACKCORE_COOKIEMANAGER_H
#define BLACKCORE_COOKIEMANAGER_H
#include "blackmisc/restricted.h"
#include "blackcore/blackcoreexport.h"
#include <QNetworkCookieJar>
#include <QNetworkCookie>
@@ -30,9 +31,10 @@ namespace BlackCore
{
Q_OBJECT
friend class CApplication;
public:
//! Constructor, only allowed from BlackCore::CApplication
CCookieManager(BlackMisc::Restricted<CApplication>, QObject *parent = nullptr);
//! \copydoc QNetworkCookieJar::setCookiesFromUrl
//! \threadsafe
virtual bool setCookiesFromUrl(const QList<QNetworkCookie> &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 };
};

View File

@@ -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<CApplication>, QObject *parent) :
QObject(parent), m_readerFlags(readerFlags), m_dbHint(hint)
{
if (!sApp) { return; } // shutting down

View File

@@ -28,6 +28,7 @@
#include "blackmisc/logcategorylist.h"
#include "blackmisc/countrylist.h"
#include "blackmisc/project.h"
#include "blackmisc/restricted.h"
#include <QObject>
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<CApplication>, 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);

View File

@@ -19,8 +19,7 @@
namespace BlackGui
{
CStyleSheetUtility::CStyleSheetUtility(QObject *parent) : QObject(parent)
CStyleSheetUtility::CStyleSheetUtility(BlackMisc::Restricted<CGuiApplication>, QObject *parent) : QObject(parent)
{
this->read();
}

View File

@@ -13,6 +13,7 @@
#define BLACKGUI_STYLESHEETUTILITY_H
#include "blackgui/blackguiexport.h"
#include "blackmisc/restricted.h"
#include <QMap>
#include <QObject>
#include <QFont>
@@ -29,9 +30,11 @@ namespace BlackGui
class BLACKGUI_EXPORT CStyleSheetUtility : public QObject
{
Q_OBJECT
friend class CGuiApplication;
public:
//! Constructor
explicit CStyleSheetUtility(BlackMisc::Restricted<CGuiApplication>, QObject *parent = nullptr);
//! Style for given file name
QString style(const QString &fileName) const;
@@ -137,10 +140,6 @@ namespace BlackGui
private:
QMap<QString, QString> m_styleSheets; //!< filename, stylesheet
QScopedPointer<QSettings> m_iniFile;
//! Constructor
explicit CStyleSheetUtility(QObject *parent = nullptr);
};
}
#endif // guard

View File

@@ -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<T> is just an empty class, that can only be constructed by the class T.
*/
template <typename T> class Restricted
{
private:
friend T;
//! Constructor is only available to the template parameter T.
Restricted() {}
};
}
#endif // guard