refs #199, removed reEmitSignal for time being.

* Discussion: https://dev.vatsim-germany.org/issues/199#note-11
* Turned widgetGuiStarted / Terminated in more generic method
This commit is contained in:
Klaus Basan
2014-04-10 18:07:18 +02:00
parent 429f79f841
commit 4776b1e650
10 changed files with 44 additions and 64 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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