diff --git a/src/blackcore/context_application_base.cpp b/src/blackcore/context_application.cpp similarity index 67% rename from src/blackcore/context_application_base.cpp rename to src/blackcore/context_application.cpp index 910049771..06661c019 100644 --- a/src/blackcore/context_application_base.cpp +++ b/src/blackcore/context_application.cpp @@ -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 #include - using namespace BlackMisc; namespace BlackCore { - QList CContextApplicationBase::s_contexts; - QtMessageHandler CContextApplicationBase::s_oldHandler = nullptr; + QList 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; diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index 05081f773..f043d72a6 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -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 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); + }; } diff --git a/src/blackcore/context_application_base.h b/src/blackcore/context_application_base.h deleted file mode 100644 index f1f8e4983..000000000 --- a/src/blackcore/context_application_base.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef BLACKCORE_CONTEXT_APPLICATION_BASE_H -#define BLACKCORE_CONTEXT_APPLICATION_BASE_H - -#include "blackcore/context_application.h" -#include - -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 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::registerEventType()); - return t; - } - - private: - BlackMisc::CStatusMessage m_message; - qint64 m_contextId; - }; - -} // namespace - -#endif // guard diff --git a/src/blackcore/context_application_event.h b/src/blackcore/context_application_event.h new file mode 100644 index 000000000..9cb7d6c72 --- /dev/null +++ b/src/blackcore/context_application_event.h @@ -0,0 +1,36 @@ +#ifndef BLACKCORE_CONTEXT_APPLICATION_EVENT_H +#define BLACKCORE_CONTEXT_APPLICATION_EVENT_H + +#include "blackcore/context_application.h" +#include + +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::registerEventType()); + return t; + } + + private: + BlackMisc::CStatusMessage m_message; + qint64 m_contextId; + }; + +} // namespace + +#endif // guard diff --git a/src/blackcore/context_application_impl.cpp b/src/blackcore/context_application_impl.cpp index bb5ac0ccf..1a632126a 100644 --- a/src/blackcore/context_application_impl.cpp +++ b/src/blackcore/context_application_impl.cpp @@ -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; diff --git a/src/blackcore/context_application_impl.h b/src/blackcore/context_application_impl.h index d94e9e743..a8a078dc9 100644 --- a/src/blackcore/context_application_impl.h +++ b/src/blackcore/context_application_impl.h @@ -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 diff --git a/src/blackcore/context_application_proxy.cpp b/src/blackcore/context_application_proxy.cpp index 1ff07a83d..7de3aedd9 100644 --- a/src/blackcore/context_application_proxy.cpp +++ b/src/blackcore/context_application_proxy.cpp @@ -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); diff --git a/src/blackcore/context_application_proxy.h b/src/blackcore/context_application_proxy.h index 3a138982f..318aa623a 100644 --- a/src/blackcore/context_application_proxy.h +++ b/src/blackcore/context_application_proxy.h @@ -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); diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index ad2b241d4..ee7f8750e 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -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(); }