mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 10:45:37 +08:00
refs #485, Restricted<T>
This commit is contained in:
committed by
Mathew Sutcliffe
parent
18a907086d
commit
c36028ca9c
@@ -42,6 +42,7 @@ BlackCore::CApplication *sApp = nullptr; // set by constructor
|
|||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
CApplication::CApplication(const QString &applicationName) :
|
CApplication::CApplication(const QString &applicationName) :
|
||||||
|
m_cookieManager( {}, this),
|
||||||
m_applicationName(applicationName),
|
m_applicationName(applicationName),
|
||||||
m_coreFacadeConfig(CCoreFacadeConfig::allEmpty())
|
m_coreFacadeConfig(CCoreFacadeConfig::allEmpty())
|
||||||
{
|
{
|
||||||
@@ -450,7 +451,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
CLogMessage(this).info("Will start web data services now");
|
CLogMessage(this).info("Will start web data services now");
|
||||||
this->m_webDataServices.reset(
|
this->m_webDataServices.reset(
|
||||||
new CWebDataServices(this->m_webReader, this->m_dbReaderHint)
|
new CWebDataServices(this->m_webReader, this->m_dbReaderHint, {}, this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using namespace BlackMisc;
|
|||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
CCookieManager::CCookieManager(QObject *parent) : QNetworkCookieJar(parent)
|
CCookieManager::CCookieManager(BlackMisc::Restricted<CApplication>, QObject *parent) : QNetworkCookieJar(parent)
|
||||||
{
|
{
|
||||||
// code
|
// code
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#ifndef BLACKCORE_COOKIEMANAGER_H
|
#ifndef BLACKCORE_COOKIEMANAGER_H
|
||||||
#define BLACKCORE_COOKIEMANAGER_H
|
#define BLACKCORE_COOKIEMANAGER_H
|
||||||
|
|
||||||
|
#include "blackmisc/restricted.h"
|
||||||
#include "blackcore/blackcoreexport.h"
|
#include "blackcore/blackcoreexport.h"
|
||||||
#include <QNetworkCookieJar>
|
#include <QNetworkCookieJar>
|
||||||
#include <QNetworkCookie>
|
#include <QNetworkCookie>
|
||||||
@@ -30,9 +31,10 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class CApplication;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
//! Constructor, only allowed from BlackCore::CApplication
|
||||||
|
CCookieManager(BlackMisc::Restricted<CApplication>, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! \copydoc QNetworkCookieJar::setCookiesFromUrl
|
//! \copydoc QNetworkCookieJar::setCookiesFromUrl
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
virtual bool setCookiesFromUrl(const QList<QNetworkCookie> &cookies, const QUrl &url) override;
|
virtual bool setCookiesFromUrl(const QList<QNetworkCookie> &cookies, const QUrl &url) override;
|
||||||
@@ -62,9 +64,6 @@ namespace BlackCore
|
|||||||
virtual bool updateCookie(const QNetworkCookie &cookie) override;
|
virtual bool updateCookie(const QNetworkCookie &cookie) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Constructor
|
|
||||||
CCookieManager(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
mutable QReadWriteLock m_lock { QReadWriteLock::Recursive };
|
mutable QReadWriteLock m_lock { QReadWriteLock::Recursive };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ using namespace BlackMisc::Weather;
|
|||||||
|
|
||||||
namespace BlackCore
|
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)
|
QObject(parent), m_readerFlags(readerFlags), m_dbHint(hint)
|
||||||
{
|
{
|
||||||
if (!sApp) { return; } // shutting down
|
if (!sApp) { return; } // shutting down
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "blackmisc/logcategorylist.h"
|
#include "blackmisc/logcategorylist.h"
|
||||||
#include "blackmisc/countrylist.h"
|
#include "blackmisc/countrylist.h"
|
||||||
#include "blackmisc/project.h"
|
#include "blackmisc/project.h"
|
||||||
|
#include "blackmisc/restricted.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
@@ -48,12 +49,14 @@ namespace BlackCore
|
|||||||
public QObject
|
public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CApplication;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Log categories
|
//! Log categories
|
||||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
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
|
//! Shutdown
|
||||||
void gracefulShutdown();
|
void gracefulShutdown();
|
||||||
|
|
||||||
@@ -261,10 +264,6 @@ namespace BlackCore
|
|||||||
//! First read (allows to immediately read in background)
|
//! First read (allows to immediately read in background)
|
||||||
void readInBackground(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllEntities, int delayMs = 0);
|
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:
|
private slots:
|
||||||
//! ATC bookings received
|
//! ATC bookings received
|
||||||
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
|
CStyleSheetUtility::CStyleSheetUtility(BlackMisc::Restricted<CGuiApplication>, QObject *parent) : QObject(parent)
|
||||||
CStyleSheetUtility::CStyleSheetUtility(QObject *parent) : QObject(parent)
|
|
||||||
{
|
{
|
||||||
this->read();
|
this->read();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#define BLACKGUI_STYLESHEETUTILITY_H
|
#define BLACKGUI_STYLESHEETUTILITY_H
|
||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
|
#include "blackmisc/restricted.h"
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
@@ -29,9 +30,11 @@ namespace BlackGui
|
|||||||
class BLACKGUI_EXPORT CStyleSheetUtility : public QObject
|
class BLACKGUI_EXPORT CStyleSheetUtility : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CGuiApplication;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
//! Constructor
|
||||||
|
explicit CStyleSheetUtility(BlackMisc::Restricted<CGuiApplication>, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! Style for given file name
|
//! Style for given file name
|
||||||
QString style(const QString &fileName) const;
|
QString style(const QString &fileName) const;
|
||||||
|
|
||||||
@@ -137,10 +140,6 @@ namespace BlackGui
|
|||||||
private:
|
private:
|
||||||
QMap<QString, QString> m_styleSheets; //!< filename, stylesheet
|
QMap<QString, QString> m_styleSheets; //!< filename, stylesheet
|
||||||
QScopedPointer<QSettings> m_iniFile;
|
QScopedPointer<QSettings> m_iniFile;
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
explicit CStyleSheetUtility(QObject *parent = nullptr);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
30
src/blackmisc/restricted.h
Normal file
30
src/blackmisc/restricted.h
Normal 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
|
||||||
Reference in New Issue
Block a user