refs #199, cleaned up contexts a bit after rebasing to current master

* friend CRuntime on top
* fixed some public constructors (made protected)
* Also made registerWithDBus protected
* Fixed some copy/paste issues in getIContextXXX
* Reordered private/public sections
This commit is contained in:
Klaus Basan
2014-04-01 22:16:26 +02:00
parent 6e3b081fd2
commit 679b34c7f4
16 changed files with 123 additions and 125 deletions

View File

@@ -24,8 +24,6 @@ namespace BlackCore
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
protected:
friend class CRuntime;
//! Constructor
IContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}

View File

@@ -21,14 +21,11 @@ namespace BlackCore
{
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
Q_OBJECT
friend class CRuntime;
public:
protected:
//! Constructor
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr);
//! Destructor
virtual ~CContextApplication() {}
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
//! Register myself in DBus
CContextApplication *registerWithDBus(CDBusServer *server)
@@ -37,11 +34,13 @@ namespace BlackCore
return this;
}
public slots:
public:
//! Destructor
virtual ~CContextApplication() {}
public slots:
//! \copydoc IContextApplication::ping()
virtual qint64 ping(qint64 token) const override;
};
}

View File

@@ -18,18 +18,15 @@ namespace BlackCore
class CContextApplicationProxy : public IContextApplication
{
Q_OBJECT
friend class CRuntime;
public:
//! Destructor
virtual ~CContextApplicationProxy() {}
private:
friend class CRuntime;
BlackMisc::CGenericDBusInterface *m_dBusInterface;
//! Relay connection signals to local signals
//! No idea why this has to be wired and is not done automatically
void relaySignals(const QString &serviceName, QDBusConnection &connection);
public slots:
//! \copydoc IContextApplication::ping()
virtual qint64 ping(qint64 token) const override;
protected:
//! Constructor
@@ -38,11 +35,12 @@ namespace BlackCore
//! DBus version constructor
CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime);
public slots:
//! \copydoc IContextApplication::ping()
virtual qint64 ping(qint64 token) const override;
private:
BlackMisc::CGenericDBusInterface *m_dBusInterface;
//! Relay connection signals to local signals
//! No idea why this has to be wired and is not done automatically
void relaySignals(const QString &serviceName, QDBusConnection &connection);
};
}

View File

@@ -20,20 +20,13 @@ namespace BlackCore
{
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
Q_OBJECT
friend class CRuntime;
public:
//! \brief Destructor
virtual ~CContextAudio();
//! \brief Register myself in DBus
CContextAudio *registerWithDBus(CDBusServer *server)
{
Q_ASSERT(server);
server->addObject(IContextAudio::ObjectPath(), this);
return this;
}
public slots:
//! \copydoc IContextAudio::setOwnAircraft()
virtual void setOwnAircraft(const BlackMisc::Aviation::CAircraft &ownAircraft) override;
@@ -105,8 +98,15 @@ namespace BlackCore
//! \brief Constructor
CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
//! \brief Register myself in DBus
CContextAudio *registerWithDBus(CDBusServer *server)
{
Q_ASSERT(server);
server->addObject(IContextAudio::ObjectPath(), this);
return this;
}
private slots:
friend class CRuntime;
void settingsChanged(uint typeValue);
private:

View File

@@ -22,6 +22,7 @@ namespace BlackCore
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
friend class CRuntime;
public:
@@ -29,7 +30,6 @@ namespace BlackCore
virtual ~CContextAudioProxy() {}
private:
friend class CRuntime;
BlackMisc::CGenericDBusInterface *m_dBusInterface;
//! Relay connection signals to local signals

View File

@@ -45,9 +45,6 @@ namespace BlackCore
//! Destructor
virtual ~IContextNetwork() {}
//! \brief Using local objects?
virtual bool usingLocalObjects() const = 0;
signals:
//! Send status message
@@ -170,12 +167,8 @@ namespace BlackCore
virtual void requestAtisUpdates() = 0;
protected:
friend class CRuntime;
//! Constructor
IContextNetwork(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr) : CContext(mode, runtime) {}
IContextNetwork(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}
};
}

View File

@@ -28,34 +28,12 @@ namespace BlackCore
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME)
friend class CRuntime;
public:
//! Destructor
virtual ~CContextNetwork();
//! Register myself in DBus
CContextNetwork *registerWithDBus(CDBusServer *server)
{
Q_ASSERT(server);
server->addObject(IContextNetwork::ObjectPath(), this);
return this;
}
//! Runtime
CRuntime *getRuntime()
{
return static_cast<CRuntime *>(this->parent());
}
//! \brief Const runtime
const CRuntime *getRuntime() const
{
return static_cast<CRuntime *>(this->parent());
}
//! \copydoc IContextNetwork::usingLocalObjects()
virtual bool usingLocalObjects() const override { return true; }
public slots: // IContextNetwork overrides
//! \copydoc IContextNetwork::readAtcBookingsFromSource()
@@ -134,8 +112,15 @@ namespace BlackCore
//! Constructor, with link to runtime
CContextNetwork(CRuntimeConfig::ContextMode, CRuntime *runtime);
//! Register myself in DBus
CContextNetwork *registerWithDBus(CDBusServer *server)
{
Q_ASSERT(server);
server->addObject(IContextNetwork::ObjectPath(), this);
return this;
}
private:
friend class CRuntime;
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
BlackMisc::Aviation::CAircraftList m_aircraftsInRange;

View File

@@ -24,17 +24,14 @@ namespace BlackCore
class CContextNetworkProxy : public IContextNetwork
{
Q_OBJECT
friend class CRuntime;
public:
//! Destructor
virtual ~CContextNetworkProxy() {}
//! \copydoc IContextNetwork::usingLocalObjects()
virtual bool usingLocalObjects() const override { return false; }
private:
friend class CRuntime;
BlackMisc::CGenericDBusInterface *m_dBusInterface; /*!< DBus interface */
//! \brief Relay connection signals to local signals.

View File

@@ -157,6 +157,15 @@ namespace BlackCore
connect(this->m_contextSettings, &IContextSettings::changedSettings,
this->getCContextAudio(), &CContextAudio::settingsChanged);
}
if (this->m_contextSimulator && this->m_contextSimulator->usingLocalObjects() && this->m_contextNetwork)
{
if (this->getCContextSimulator()->m_simulator)
{
connect(this->m_contextNetwork, SIGNAL(aircraftSituationUpdate(BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftSituation)),
this->getCContextSimulator()->m_simulator, SLOT(addAircraftSituation(BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftSituation)));
}
}
}
void CRuntime::initDBusConnection()
@@ -167,25 +176,25 @@ namespace BlackCore
IContextNetwork *CRuntime::getIContextNetwork()
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing network context");
Q_ASSERT_X(this->m_contextNetwork, "CCoreRuntime", "Requested missing network context");
return this->m_contextNetwork;
}
const IContextNetwork *CRuntime::getIContextNetwork() const
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing network context");
Q_ASSERT_X(this->m_contextNetwork, "CCoreRuntime", "Requested missing network context");
return this->m_contextNetwork;
}
IContextAudio *CRuntime::getIContextAudio()
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing audio context");
Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context");
return this->m_contextAudio;
}
const IContextAudio *CRuntime::getIContextAudio() const
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing audio context");
Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context");
return this->m_contextAudio;
}
@@ -203,35 +212,56 @@ namespace BlackCore
const IContextApplication *CRuntime::getIContextApplication() const
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing application context");
Q_ASSERT_X(this->m_contextApplication, "CCoreRuntime", "Requested missing application context");
return this->m_contextApplication;
}
IContextApplication *CRuntime::getIContextApplication()
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing application context");
Q_ASSERT_X(this->m_contextApplication, "CCoreRuntime", "Requested missing application context");
return this->m_contextApplication;
}
const IContextSimulator *CRuntime::getIContextSimulator() const
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing simulator context");
Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context");
return this->m_contextSimulator;
}
IContextSimulator *CRuntime::getIContextSimulator()
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing simulator context");
Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context");
return this->m_contextSimulator;
}
CContextAudio *CRuntime::getCContextAudio()
{
Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing audio context");
Q_ASSERT_X(this->m_contextSimulator->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object");
Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context");
Q_ASSERT_X(this->m_contextAudio->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object");
return static_cast<CContextAudio *>(this->m_contextAudio);
}
CContextAudio *CRuntime::getCContextAudio() const
{
Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context");
Q_ASSERT_X(this->m_contextAudio->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object");
return static_cast<CContextAudio *>(this->m_contextAudio);
}
CContextSimulator *CRuntime::getCContextSimulator()
{
Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context");
Q_ASSERT_X(this->m_contextSimulator->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object");
return static_cast<CContextSimulator *>(this->m_contextSimulator);
}
CContextSimulator *CRuntime::getCContextSimulator() const
{
Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context");
Q_ASSERT_X(this->m_contextSimulator->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object");
return static_cast<CContextSimulator *>(this->m_contextSimulator);
}
const CRuntimeConfig &CRuntimeConfig::forCore()
{
static CRuntimeConfig cfg = CRuntimeConfig(CRuntimeConfig(CRuntimeConfig::LocalInDbusServer));

View File

@@ -26,29 +26,6 @@ namespace BlackCore
{
Q_OBJECT
private:
bool m_init; /*!< flag */
CDBusServer *m_dbusServer;
bool m_initDBusConnection;
QDBusConnection m_dbusConnection;
IContextNetwork *m_contextNetwork;
IContextAudio *m_contextAudio;
IContextSettings *m_contextSettings;
IContextApplication *m_contextApplication;
IContextSimulator *m_contextSimulator;
//! Init
void init(const CRuntimeConfig &config);
//! initialization of DBus connection (where applicable)
void initDBusConnection();
//! initialization of DBus connection (where applicable)
void initDBusServer(const QString &dBusAddress);
//! post init tasks, mainly connecting context signal slots
void initPostSetup();
public:
//! Constructor
CRuntime(const CRuntimeConfig &config, QObject *parent = nullptr);
@@ -93,8 +70,34 @@ namespace BlackCore
IContextSimulator *getIContextSimulator();
private:
bool m_init; /*!< flag */
CDBusServer *m_dbusServer;
bool m_initDBusConnection;
QDBusConnection m_dbusConnection;
IContextNetwork *m_contextNetwork;
IContextAudio *m_contextAudio;
IContextSettings *m_contextSettings;
IContextApplication *m_contextApplication;
IContextSimulator *m_contextSimulator;
//! Init
void init(const CRuntimeConfig &config);
//! initialization of DBus connection (where applicable)
void initDBusConnection();
//! initialization of DBus connection (where applicable)
void initDBusServer(const QString &dBusAddress);
//! post init tasks, mainly connecting context signal slots
void initPostSetup();
CContextAudio *getCContextAudio();
CContextAudio *getCContextAudio() const;
CContextSimulator *getCContextSimulator();
CContextSimulator *getCContextSimulator() const;
};
}
#endif // guard

View File

@@ -22,7 +22,6 @@
namespace BlackCore
{
/*!
* Context settings interface
*/

View File

@@ -24,15 +24,12 @@ namespace BlackCore
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME)
friend class CRuntime;
protected:
//! \brief Constructor
CContextSettings(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr);
public:
//! Destructor
virtual ~CContextSettings() {}
//! \brief Register myself in DBus
CContextSettings *registerWithDBus(CDBusServer *server)
{
@@ -40,6 +37,10 @@ namespace BlackCore
return this;
}
public:
//! Destructor
virtual ~CContextSettings() {}
//! \brief settings file
const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); }
@@ -74,7 +75,6 @@ namespace BlackCore
virtual QString getSettingsAsJsonString() const override;
private:
friend class CRuntime;
BlackMisc::Settings::CSettingsNetwork m_settingsNetwork;
BlackMisc::Hardware::CKeyboardKeyList m_hotkeys;
QJsonDocument toJsonDocument() const;

View File

@@ -25,14 +25,13 @@ namespace BlackCore
class CContextSettingsProxy : public IContextSettings
{
Q_OBJECT
friend class CRuntime;
public:
//! \brief Destructor
virtual ~CContextSettingsProxy() {}
private:
friend class CRuntime;
BlackMisc::CGenericDBusInterface *m_dBusInterface;
//! Relay connection signals to local signals
@@ -47,7 +46,6 @@ namespace BlackCore
CContextSettingsProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextSettings(mode, runtime), m_dBusInterface(nullptr) {}
public slots:
//! \copydoc IContextSettings::getNetworkSettings()
virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const override;

View File

@@ -24,7 +24,6 @@ namespace BlackCore
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
public:
//! \brief Service name
static const QString &InterfaceName()
{
@@ -55,8 +54,6 @@ namespace BlackCore
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const = 0;
protected:
friend class CRuntime;
//! \brief Constructor
IContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}
};

View File

@@ -22,14 +22,23 @@ namespace BlackCore
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
friend class CRuntime;
public:
//! \brief Constructor
CContextSimulator(CRuntimeConfig::ContextMode, CRuntime *runtime);
//! \brief Destructor
virtual ~CContextSimulator();
public slots:
//! \copydoc IContextSimulator::isConnected()
virtual bool isConnected() const override;
//! \copydoc IContextSimulator::getOwnAircraft()
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override;
protected:
//! \brief Constructor
CContextSimulator(CRuntimeConfig::ContextMode, CRuntime *runtime);
//! Register myself in DBus
CContextSimulator *registerWithDBus(CDBusServer *server)
{
@@ -38,13 +47,6 @@ namespace BlackCore
return this;
}
public slots:
//! \copydoc IContextSimulator::isConnected()
virtual bool isConnected() const override;
//! \copydoc IContextSimulator::getOwnAircraft()
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override;
private slots:
//! \copydoc IContextSimulator::updateOwnAircraft()
virtual void updateOwnAircraft();
@@ -62,9 +64,7 @@ namespace BlackCore
BlackMisc::Aviation::CAircraft m_ownAircraft;
BlackCore::ISimulator *m_simulator;
QTimer *m_updateTimer;
BlackCore::IContextNetwork *m_contextNetwork;
QDir m_pluginsDir;
IContextNetwork *getNetworkContext();
};
} // namespace BlackCore

View File

@@ -15,12 +15,13 @@ namespace BlackCore
class CContextSimulatorProxy : public IContextSimulator
{
Q_OBJECT
friend class CRuntime;
public:
//! Destructor
~CContextSimulatorProxy() {}
private:
friend class CRuntime;
BlackMisc::CGenericDBusInterface *m_dBusInterface;
//! Relay connection signals to local signals