From 4776b1e65047f71c674872e39e97714e35a23ae1 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 10 Apr 2014 18:07:18 +0200 Subject: [PATCH] refs #199, removed reEmitSignal for time being. * Discussion: https://dev.vatsim-germany.org/issues/199#note-11 * Turned widgetGuiStarted / Terminated in more generic method --- samples/blackgui/mainwindow.cpp | 3 +- samples/blackgui/mainwindow_init.cpp | 4 +-- src/blackcore/context.cpp | 20 ------------- src/blackcore/context.h | 4 --- src/blackcore/context_application.h | 31 ++++++++++++++------- src/blackcore/context_application_impl.cpp | 6 ++-- src/blackcore/context_application_impl.h | 4 +-- src/blackcore/context_application_proxy.cpp | 25 +++++++---------- src/blackcore/context_application_proxy.h | 4 +-- src/blackcore/context_runtime.cpp | 7 ++--- 10 files changed, 44 insertions(+), 64 deletions(-) diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 8d4ffae97..eb6371d0b 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -67,7 +67,8 @@ void MainWindow::gracefulShutdown() { if (!this->m_init) return; this->m_init = false; - if (this->m_rt->getIContextApplication()) emit this->m_rt->getIContextApplication()->widgetGuiTerminating(); + if (this->m_rt->getIContextApplication()) + emit this->m_rt->getIContextApplication()->notifyAboutComponentChange(IContextApplication::ComponentGui, IContextApplication::ActionStops); // close info window if (this->m_infoWindow) diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 8c8b4733c..8e62a791e 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -220,7 +220,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode) connect = this->connect(this->m_rt->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &MainWindow::audioTestUpdate); Q_ASSERT(connect); Q_UNUSED(connect); // suppress GCC warning in release build - + // start timers, update timers will be started when network is connected this->m_timerContextWatchdog->start(2 * 1000); @@ -241,7 +241,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode) this->initContextMenus(); // starting - emit this->m_rt->getIContextApplication()->widgetGuiStarting(); + emit this->m_rt->getIContextApplication()->notifyAboutComponentChange(IContextApplication::ComponentGui, IContextApplication::ActionStarts); // do this as last statement, so it can be used as flag // whether init has been completed diff --git a/src/blackcore/context.cpp b/src/blackcore/context.cpp index fa32f5edd..f02a85549 100644 --- a/src/blackcore/context.cpp +++ b/src/blackcore/context.cpp @@ -49,26 +49,6 @@ namespace BlackCore return this->getRuntime()->getIContextSimulator(); } - void CContext::reEmitSignalFromProxy(const QString &signalName) - { - if (signalName.isEmpty()) return; - if (this->usingLocalObjects()) - { - // resent in implementation - QString sn = signalName; - if (!sn.endsWith("()")) sn.append("()"); - const QMetaObject *metaObject = this->metaObject(); - int signalId = metaObject->indexOfSignal(sn.toUtf8().constData()); - Q_ASSERT(signalId >= 0); - void *a[] = { 0 }; - QMetaObject::activate(this, signalId, a); - } - else - { - Q_ASSERT_X(false, "signalFromProxy", "Proxy needs to override method"); - } - } - const IContextSimulator *CContext::getIContextSimulator() const { return this->getRuntime()->getIContextSimulator(); diff --git a/src/blackcore/context.h b/src/blackcore/context.h index 48f69e29f..986404bad 100644 --- a/src/blackcore/context.h +++ b/src/blackcore/context.h @@ -83,10 +83,6 @@ namespace BlackCore QObject(parent), m_mode(mode), m_contextId(QDateTime::currentMSecsSinceEpoch()) {} - //! Re-emit signal locally - //! \details proxy uses slot to send signal, and on implementation side this re-emitted as signal - void reEmitSignalFromProxy(const QString &signalName); - CRuntimeConfig::ContextMode m_mode; //!< How context is used qint64 m_contextId; //!< unique identifer, avoid redirection rountrips }; diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index 3e19efa77..d46841bb4 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -30,7 +30,7 @@ namespace BlackCore public: //! What output to redirect - enum RedirectionLevel + enum RedirectionLevel : uint { RedirectNone, RedirectAllOutput, @@ -38,6 +38,20 @@ namespace BlackCore RedirectError }; + //! Components + enum Component : uint + { + ComponentGui, + ComponentCore + }; + + //! What a component does + enum Actions : uint + { + ActionStarts, + ActionStops + }; + //! Service name static const QString &InterfaceName() { @@ -81,25 +95,22 @@ namespace BlackCore //! never output redirected stream messages from the same context again void redirectedOutput(const BlackMisc::CStatusMessage &message, qint64 contextId); - //! Widget GUI is about to start - void widgetGuiStarting(); - - //! Widget GUI is about to terminate - void widgetGuiTerminating(); + //! A component changes + void componentChanged(uint component, uint action); public slots: //! \brief Ping a token, used to check if application is alive virtual qint64 ping(qint64 token) const = 0; - //! \copydoc CContext::reEmitSignalFromProxy - virtual void signalFromProxy(const QString &signalName) = 0; - - //! \brief Status message + //! Status message virtual void sendStatusMessage(const BlackMisc::CStatusMessage &message) = 0; //! Send status messages virtual void sendStatusMessages(const BlackMisc::CStatusMessageList &messages) = 0; + + //! A component has changed its state + virtual void notifyAboutComponentChange(uint component, uint action) = 0; }; } diff --git a/src/blackcore/context_application_impl.cpp b/src/blackcore/context_application_impl.cpp index b838e775c..63c6cee40 100644 --- a/src/blackcore/context_application_impl.cpp +++ b/src/blackcore/context_application_impl.cpp @@ -44,11 +44,11 @@ namespace BlackCore } /* - * Re-emit signal + * Component has changed */ - void CContextApplication::signalFromProxy(const QString &signalName) + void CContextApplication::notifyAboutComponentChange(uint component, uint action) { - CContext::reEmitSignalFromProxy(signalName); + this->componentChanged(component, action); } } // namespace diff --git a/src/blackcore/context_application_impl.h b/src/blackcore/context_application_impl.h index d7b6ee583..dc44cfba4 100644 --- a/src/blackcore/context_application_impl.h +++ b/src/blackcore/context_application_impl.h @@ -33,8 +33,8 @@ namespace BlackCore //! Send status messages virtual void sendStatusMessages(const BlackMisc::CStatusMessageList &messages) override; - //! \copydoc CContext::reEmitSignalFromProxy - virtual void signalFromProxy(const QString &signalName) override; + //! \copydoc IContextApplication::notifyAboutComponentChange + virtual void notifyAboutComponentChange(uint component, uint action) override; protected: //! Constructor diff --git a/src/blackcore/context_application_proxy.cpp b/src/blackcore/context_application_proxy.cpp index cb23c24ef..8538fe0c0 100644 --- a/src/blackcore/context_application_proxy.cpp +++ b/src/blackcore/context_application_proxy.cpp @@ -33,13 +33,8 @@ namespace BlackCore "statusMessages", this, SIGNAL(statusMessages(BlackMisc::CStatusMessageList))); connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), "redirectedOutput", this, SIGNAL(redirectedOutput(BlackMisc::CStatusMessage, qint64))); - - // 1. No need to connect widgetGuiTerminating, only orginates from Proxy side / or is local - // 2. No need to connect widgetGuiStarting - - // signals originating from proxy side - connect(this, &CContextApplicationProxy::widgetGuiStarting, [this] { this->signalFromProxy("widgetGuiStarting");}); - connect(this, &CContextApplicationProxy::widgetGuiTerminating, [this] { this->signalFromProxy("widgetGuiTerminating");}); + connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "componentChanged", this, SIGNAL(componentChanged(uint, uint))); } /* @@ -51,14 +46,6 @@ namespace BlackCore return t; } - /* - * Signal from proxy - */ - void CContextApplicationProxy::signalFromProxy(const QString &signalName) - { - this->m_dBusInterface->callDBus(QLatin1Literal("signalFromProxy"), signalName); - } - /* * Status messages */ @@ -75,4 +62,12 @@ namespace BlackCore this->m_dBusInterface->callDBus(QLatin1Literal("sendStatusMessages"), messages); } + /* + * Component has changed + */ + void CContextApplicationProxy::notifyAboutComponentChange(uint component, uint action) + { + this->m_dBusInterface->callDBus(QLatin1Literal("notifyAboutComponentChange"), component, action); + } + } // namespace diff --git a/src/blackcore/context_application_proxy.h b/src/blackcore/context_application_proxy.h index cdf91264e..8ccb8eb9d 100644 --- a/src/blackcore/context_application_proxy.h +++ b/src/blackcore/context_application_proxy.h @@ -34,8 +34,8 @@ namespace BlackCore //! Send status messages virtual void sendStatusMessages(const BlackMisc::CStatusMessageList &messages) override; - //! \copydoc CContext::reEmitSignalFromProxy - void signalFromProxy(const QString &signalName) override; + //! \copydoc IContextApplication::notifyAboutComponentChange + virtual void notifyAboutComponentChange(uint component, uint action) override; protected: //! Constructor diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index edf465f0e..4692c3321 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -72,11 +72,8 @@ namespace BlackCore if (enabled) { QMetaObject::Connection con; - con = QObject::connect(this->getIContextApplication(), &IContextApplication::widgetGuiStarting, - [this]() { QStringList l; l << "widgetGuiStarting"; this->logSignal(this->getIContextApplication(), l);}); - this->m_logSignalConnections.insert("application", con); - con = QObject::connect(this->getIContextApplication(), &IContextApplication::widgetGuiTerminating, - [this]() { QStringList l; l << "widgetGuiTerminating"; this->logSignal(this->getIContextApplication(), l);}); + con = QObject::connect(this->getIContextApplication(), &IContextApplication::componentChanged, + [this](uint component, uint action) { QStringList l; l << "componentChanged" << QString::number(component) << QString::number(action); this->logSignal(this->getIContextApplication(), l);}); this->m_logSignalConnections.insert("application", con); con = QObject::connect(this->getIContextApplication(), &IContextApplication::statusMessage, [this](const BlackMisc::CStatusMessage & msg) { QStringList l; l << "statusMessage" << msg.toQString() ; this->logSignal(this->getIContextApplication(), l);});