mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
refs #199, removed context_application_base (moved to IContext application)
* as discussed under 4, and in the meeting https://dev.vatsim-germany.org/boards/22/topics/1671?r=1676#message-1676
This commit is contained in:
@@ -1,43 +1,43 @@
|
||||
#include "blackcore/context_application_base.h"
|
||||
#include "blackcore/context_application.h"
|
||||
#include "blackcore/context_application_event.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
QList<CContextApplicationBase *> CContextApplicationBase::s_contexts;
|
||||
QtMessageHandler CContextApplicationBase::s_oldHandler = nullptr;
|
||||
QList<IContextApplication *> IContextApplication::s_contexts;
|
||||
QtMessageHandler IContextApplication::s_oldHandler = nullptr;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CContextApplicationBase::CContextApplicationBase(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
||||
IContextApplication(mode, runtime), m_outputRedirectionLevel(IContextApplication::RedirectNone), m_redirectedOutputRedirectionLevel(IContextApplication::RedirectNone)
|
||||
IContextApplication::IContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
||||
CContext(mode, runtime), m_outputRedirectionLevel(IContextApplication::RedirectNone), m_redirectedOutputRedirectionLevel(IContextApplication::RedirectNone)
|
||||
{
|
||||
if (CContextApplicationBase::s_contexts.isEmpty())
|
||||
CContextApplicationBase::s_oldHandler = qInstallMessageHandler(CContextApplicationBase::messageHandlerDispatch);
|
||||
CContextApplicationBase::s_contexts.append(this);
|
||||
if (IContextApplication::s_contexts.isEmpty())
|
||||
IContextApplication::s_oldHandler = qInstallMessageHandler(IContextApplication::messageHandlerDispatch);
|
||||
IContextApplication::s_contexts.append(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Output data from redirect signal
|
||||
*/
|
||||
void CContextApplicationBase::setStreamingForRedirectedOutputLevel(RedirectionLevel redirectionLevel)
|
||||
void IContextApplication::setStreamingForRedirectedOutputLevel(RedirectionLevel redirectionLevel)
|
||||
{
|
||||
disconnect(this, &IContextApplication::redirectedOutput, this, &CContextApplicationBase::streamRedirectedOutput);
|
||||
disconnect(this, &IContextApplication::redirectedOutput, this, &IContextApplication::streamRedirectedOutput);
|
||||
if (redirectionLevel != RedirectNone)
|
||||
connect(this, &IContextApplication::redirectedOutput, this, &CContextApplicationBase::streamRedirectedOutput);
|
||||
connect(this, &IContextApplication::redirectedOutput, this, &IContextApplication::streamRedirectedOutput);
|
||||
this->m_redirectedOutputRedirectionLevel = redirectionLevel;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process event in object's thread, used to emit signal from other thread
|
||||
*/
|
||||
bool CContextApplicationBase::event(QEvent *event)
|
||||
bool IContextApplication::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == CApplicationEvent::eventType())
|
||||
{
|
||||
@@ -45,13 +45,13 @@ namespace BlackCore
|
||||
emit this->redirectedOutput(e->m_message, this->getUniqueId());
|
||||
return true;
|
||||
}
|
||||
return IContextApplication::event(event);
|
||||
return CContext::event(event);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset output redirection
|
||||
*/
|
||||
void CContextApplicationBase::resetOutputRedirection()
|
||||
void IContextApplication::resetOutputRedirection()
|
||||
{
|
||||
qInstallMessageHandler(0);
|
||||
}
|
||||
@@ -59,12 +59,12 @@ namespace BlackCore
|
||||
/*
|
||||
* Dispatch message
|
||||
*/
|
||||
void CContextApplicationBase::messageHandlerDispatch(QtMsgType type, const QMessageLogContext &messageContext, const QString &message)
|
||||
void IContextApplication::messageHandlerDispatch(QtMsgType type, const QMessageLogContext &messageContext, const QString &message)
|
||||
{
|
||||
if (CContextApplicationBase::s_oldHandler) CContextApplicationBase::s_oldHandler(type, messageContext, message);
|
||||
if (CContextApplicationBase::s_contexts.isEmpty()) return;
|
||||
CContextApplicationBase *ctx;
|
||||
foreach(ctx, CContextApplicationBase::s_contexts)
|
||||
if (IContextApplication::s_oldHandler) IContextApplication::s_oldHandler(type, messageContext, message);
|
||||
if (IContextApplication::s_contexts.isEmpty()) return;
|
||||
IContextApplication *ctx;
|
||||
foreach(ctx, IContextApplication::s_contexts)
|
||||
{
|
||||
ctx->messageHandler(type, messageContext, message);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace BlackCore
|
||||
/*
|
||||
* Handle message
|
||||
*/
|
||||
void CContextApplicationBase::messageHandler(QtMsgType type, const QMessageLogContext &messageContext, const QString &message)
|
||||
void IContextApplication::messageHandler(QtMsgType type, const QMessageLogContext &messageContext, const QString &message)
|
||||
{
|
||||
Q_UNUSED(messageContext);
|
||||
if (this->m_outputRedirectionLevel == RedirectNone) return;
|
||||
@@ -119,7 +119,7 @@ namespace BlackCore
|
||||
/*
|
||||
* Redirected output
|
||||
*/
|
||||
void CContextApplicationBase::streamRedirectedOutput(const CStatusMessage &message, qint64 contextId)
|
||||
void IContextApplication::streamRedirectedOutput(const CStatusMessage &message, qint64 contextId)
|
||||
{
|
||||
if (this->getUniqueId() == contextId) return; // avoid infinite output
|
||||
if (this->m_redirectedOutputRedirectionLevel == RedirectNone) return;
|
||||
@@ -25,7 +25,7 @@ namespace BlackCore
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}
|
||||
IContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
||||
|
||||
public:
|
||||
|
||||
@@ -70,16 +70,22 @@ namespace BlackCore
|
||||
virtual ~IContextApplication() {}
|
||||
|
||||
//! Output redirection (redirect my output)
|
||||
virtual RedirectionLevel getOutputRedirectionLevel() const = 0;
|
||||
RedirectionLevel getOutputRedirectionLevel() const { return this->m_outputRedirectionLevel; }
|
||||
|
||||
//! Output redirection (redirect my output)
|
||||
virtual void setOutputRedirectionLevel(RedirectionLevel level) = 0;
|
||||
void setOutputRedirectionLevel(RedirectionLevel redirectionLevel) { this->m_outputRedirectionLevel = redirectionLevel; }
|
||||
|
||||
//! Redirected output generated by others
|
||||
virtual RedirectionLevel getStreamingForRedirectedOutputLevel() const = 0;
|
||||
RedirectionLevel getStreamingForRedirectedOutputLevel() const { return this->m_redirectedOutputRedirectionLevel; }
|
||||
|
||||
//! Redirected output generated by others
|
||||
virtual void setStreamingForRedirectedOutputLevel(RedirectionLevel level) = 0;
|
||||
void setStreamingForRedirectedOutputLevel(RedirectionLevel redirectionLevel) ;
|
||||
|
||||
//! Process event, cross thread messages
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
//! Reset output redirection
|
||||
static void resetOutputRedirection();
|
||||
|
||||
signals:
|
||||
//! \brief Status message
|
||||
@@ -112,15 +118,35 @@ namespace BlackCore
|
||||
//! A component has changed its state
|
||||
virtual void notifyAboutComponentChange(uint component, uint action) = 0;
|
||||
|
||||
//! Remote enable version of writing a text file
|
||||
//! Remote enabled version of writing a text file
|
||||
virtual bool writeToFile(const QString &fileName, const QString &content) = 0;
|
||||
|
||||
//! Remote enable version of reading a text file
|
||||
//! Remote enabled version of reading a text file
|
||||
virtual QString readFromFile(const QString &fileName) = 0;
|
||||
|
||||
//! Remote enable version of deleting a file
|
||||
//! Remote enabled version of deleting a file
|
||||
virtual bool removeFile(const QString &fileName) = 0;
|
||||
|
||||
private:
|
||||
//! All contexts, used with messageHandler
|
||||
static QList<IContextApplication *> s_contexts;
|
||||
|
||||
//! Previous message handler
|
||||
static QtMessageHandler s_oldHandler;
|
||||
|
||||
//! Message handler, handles one individual context
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext &messageContext, const QString &messsage);
|
||||
|
||||
//! Handle output dispatch, handles all contexts
|
||||
static void messageHandlerDispatch(QtMsgType type, const QMessageLogContext &messageContext, const QString &message);
|
||||
|
||||
RedirectionLevel m_outputRedirectionLevel; //!< enable / disable my output
|
||||
RedirectionLevel m_redirectedOutputRedirectionLevel; //!< enable / disable others output
|
||||
|
||||
private slots:
|
||||
//! Re-stream the redirected output
|
||||
void streamRedirectedOutput(const BlackMisc::CStatusMessage &message, qint64 contextId);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
#ifndef BLACKCORE_CONTEXT_APPLICATION_BASE_H
|
||||
#define BLACKCORE_CONTEXT_APPLICATION_BASE_H
|
||||
|
||||
#include "blackcore/context_application.h"
|
||||
#include <QEvent>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
/*!
|
||||
* \brief Class, implementing streaming handling for application context
|
||||
*/
|
||||
class CContextApplicationBase : public IContextApplication
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Destructor
|
||||
virtual ~CContextApplicationBase() {}
|
||||
|
||||
//! \copydoc IContextApplication::getOutputRedirectionLevel
|
||||
virtual RedirectionLevel getOutputRedirectionLevel() const override { return this->m_outputRedirectionLevel; }
|
||||
|
||||
//! \copydoc IContextApplication::setOutputRedirectionLevel
|
||||
virtual void setOutputRedirectionLevel(RedirectionLevel redirectionLevel) override { this->m_outputRedirectionLevel = redirectionLevel; }
|
||||
|
||||
//! \copydoc IContextApplication::getStreamingForRedirectedOutputLevel
|
||||
virtual RedirectionLevel getStreamingForRedirectedOutputLevel() const override { return this->m_redirectedOutputRedirectionLevel; }
|
||||
|
||||
//! \copydoc IContextApplication::setStreamingForRedirectedOutputLevel
|
||||
virtual void setStreamingForRedirectedOutputLevel(RedirectionLevel redirectionLevel) override;
|
||||
|
||||
//! Process event, cross thread messages
|
||||
virtual bool event(QEvent *event) override;
|
||||
|
||||
//! Reset output redirection
|
||||
static void resetOutputRedirection();
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CContextApplicationBase(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
||||
|
||||
private:
|
||||
//! All contexts, used with messageHandler
|
||||
static QList<CContextApplicationBase *> s_contexts;
|
||||
|
||||
//! Previous message handler
|
||||
static QtMessageHandler s_oldHandler;
|
||||
|
||||
//! Message handler, handles one individual context
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext &messageContext, const QString &messsage);
|
||||
|
||||
//! Handle output dispatch, handles all contexts
|
||||
static void messageHandlerDispatch(QtMsgType type, const QMessageLogContext &messageContext, const QString &message);
|
||||
|
||||
RedirectionLevel m_outputRedirectionLevel; //!< enable / disable my output
|
||||
RedirectionLevel m_redirectedOutputRedirectionLevel; //!< enable / disable others output
|
||||
|
||||
private slots:
|
||||
//! Re-stream the redirected output
|
||||
void streamRedirectedOutput(const BlackMisc::CStatusMessage &message, qint64 contextId);
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Event to allow cross thread output redirection
|
||||
*/
|
||||
class CApplicationEvent : public QEvent
|
||||
{
|
||||
friend class CContextApplicationBase;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CApplicationEvent(const BlackMisc::CStatusMessage &msg, qint64 contextId) :
|
||||
QEvent(eventType()), m_message(msg), m_contextId(contextId) {}
|
||||
//! Destructor
|
||||
virtual ~CApplicationEvent() {}
|
||||
//! Event type
|
||||
static const QEvent::Type &eventType()
|
||||
{
|
||||
const static QEvent::Type t = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return t;
|
||||
}
|
||||
|
||||
private:
|
||||
BlackMisc::CStatusMessage m_message;
|
||||
qint64 m_contextId;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
36
src/blackcore/context_application_event.h
Normal file
36
src/blackcore/context_application_event.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef BLACKCORE_CONTEXT_APPLICATION_EVENT_H
|
||||
#define BLACKCORE_CONTEXT_APPLICATION_EVENT_H
|
||||
|
||||
#include "blackcore/context_application.h"
|
||||
#include <QEvent>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
/*!
|
||||
* \brief Event to allow cross thread output redirection
|
||||
*/
|
||||
class CApplicationEvent : public QEvent
|
||||
{
|
||||
friend class IContextApplication;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CApplicationEvent(const BlackMisc::CStatusMessage &msg, qint64 contextId) :
|
||||
QEvent(eventType()), m_message(msg), m_contextId(contextId) {}
|
||||
//! Destructor
|
||||
virtual ~CApplicationEvent() {}
|
||||
//! Event type
|
||||
static const QEvent::Type &eventType()
|
||||
{
|
||||
const static QEvent::Type t = static_cast<QEvent::Type>(QEvent::registerEventType());
|
||||
return t;
|
||||
}
|
||||
|
||||
private:
|
||||
BlackMisc::CStatusMessage m_message;
|
||||
qint64 m_contextId;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
@@ -17,7 +17,7 @@ namespace BlackCore
|
||||
* Init this context
|
||||
*/
|
||||
CContextApplication::CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
||||
CContextApplicationBase(mode, runtime)
|
||||
IContextApplication(mode, runtime)
|
||||
{}
|
||||
|
||||
/*
|
||||
@@ -90,6 +90,9 @@ namespace BlackCore
|
||||
return content;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove file
|
||||
*/
|
||||
bool CContextApplication::removeFile(const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty()) return false;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifndef BLACKCORE_CONTEXTAPPLICATION_IMPL_H
|
||||
#define BLACKCORE_CONTEXTAPPLICATION_IMPL_H
|
||||
|
||||
#include "context_application_base.h"
|
||||
#include "context_application.h"
|
||||
#include "context_runtime.h"
|
||||
#include "dbus_server.h"
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace BlackCore
|
||||
/*!
|
||||
* \brief Application context
|
||||
*/
|
||||
class CContextApplication : public CContextApplicationBase
|
||||
class CContextApplication : public IContextApplication
|
||||
{
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
|
||||
Q_OBJECT
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace BlackCore
|
||||
/*
|
||||
* Constructor for DBus
|
||||
*/
|
||||
CContextApplicationProxy::CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContextApplicationBase(mode, runtime), m_dBusInterface(nullptr)
|
||||
CContextApplicationProxy::CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr)
|
||||
{
|
||||
this->m_dBusInterface = new BlackMisc::CGenericDBusInterface(serviceName , IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), connection, this);
|
||||
this->relaySignals(serviceName, connection);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifndef BLACKCORE_CONTEXTAPPLICATION_PROXY_H
|
||||
#define BLACKCORE_CONTEXTAPPLICATION_PROXY_H
|
||||
|
||||
#include "context_application_base.h"
|
||||
#include "context_application.h"
|
||||
#include "blackmisc/genericdbusinterface.h"
|
||||
|
||||
namespace BlackCore
|
||||
@@ -15,7 +15,7 @@ namespace BlackCore
|
||||
/*!
|
||||
* \brief Application context proxy
|
||||
*/
|
||||
class CContextApplicationProxy : public CContextApplicationBase
|
||||
class CContextApplicationProxy : public IContextApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class CRuntime;
|
||||
@@ -48,7 +48,7 @@ namespace BlackCore
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CContextApplicationProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContextApplicationBase(mode, runtime), m_dBusInterface(nullptr) {}
|
||||
CContextApplicationProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr) {}
|
||||
|
||||
//! DBus version constructor
|
||||
CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
||||
|
||||
@@ -380,7 +380,7 @@ namespace BlackCore
|
||||
disconnect(this->getIContextApplication());
|
||||
this->getIContextApplication()->setOutputRedirectionLevel(IContextApplication::RedirectNone);
|
||||
this->getIContextApplication()->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectNone);
|
||||
CContextApplicationBase::resetOutputRedirection();
|
||||
IContextApplication::resetOutputRedirection();
|
||||
this->getIContextApplication()->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user