diff --git a/src/blackgui/runtimebasedcomponent.cpp b/src/blackgui/runtimebasedcomponent.cpp new file mode 100644 index 000000000..ab3b5d69a --- /dev/null +++ b/src/blackgui/runtimebasedcomponent.cpp @@ -0,0 +1,70 @@ +#include "runtimebasedcomponent.h" + +namespace BlackGui +{ + const BlackCore::IContextApplication *CRuntimeBasedComponent::getIContextApplication() const + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextApplication(); + } + + BlackCore::IContextApplication *CRuntimeBasedComponent::getIContextApplication() + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextApplication(); + } + + BlackCore::IContextAudio *CRuntimeBasedComponent::getIContextAudio() + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextAudio(); + } + + const BlackCore::IContextAudio *CRuntimeBasedComponent::getIContextAudio() const + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextAudio(); + } + + void CRuntimeBasedComponent::createRuntime(const BlackCore::CRuntimeConfig &config, QObject *parent) + { + this->m_runtime = new BlackCore::CRuntime(config, parent); + this->m_runtimeOwner = true; + } + + BlackCore::IContextNetwork *CRuntimeBasedComponent::getIContextNetwork() + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextNetwork(); + } + + const BlackCore::IContextNetwork *CRuntimeBasedComponent::getIContextNetwork() const + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextNetwork(); + } + + BlackCore::IContextSettings *CRuntimeBasedComponent::getIContextSettings() + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextSettings(); + } + + const BlackCore::IContextSettings *CRuntimeBasedComponent::getIContextSettings() const + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextSettings(); + } + + const BlackCore::IContextSimulator *CRuntimeBasedComponent::getIContextSimulator() const + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextSimulator(); + } + + BlackCore::IContextSimulator *CRuntimeBasedComponent::getIContextSimulator() + { + if (!this->m_runtime) return nullptr; + return this->m_runtime->getIContextSimulator(); + } +} diff --git a/src/blackgui/runtimebasedcomponent.h b/src/blackgui/runtimebasedcomponent.h new file mode 100644 index 000000000..d54ec4ace --- /dev/null +++ b/src/blackgui/runtimebasedcomponent.h @@ -0,0 +1,78 @@ +#ifndef BLACKGUI_RUNTIMEBASEDCOMPONENT_H +#define BLACKGUI_RUNTIMEBASEDCOMPONENT_H + +#include "blackcore/context_runtime.h" +#include "blackcore/context_all_interfaces.h" + +namespace BlackGui +{ + /*! + * \brief Component, which provides reference to runtime object + * \details Access to runtime allows to encapsualate many aspects of data access and makes + * the component widely independent from a central data provideer + * \sa BlackCore::CRuntime + */ + class CRuntimeBasedComponent + { + public: + //! Set runtime, usually set by runtime owner (must only be one, usually main window) + void setRuntime(BlackCore::CRuntime *runtime, bool runtimeOwner = false) { this->m_runtime = runtime; this->m_runtimeOwner = runtimeOwner; } + + protected: + //! Constructor + //! \remarks usually runtime will be provide later, not at initialization time + CRuntimeBasedComponent(BlackCore::CRuntime *runtime = nullptr, bool runtimeOwner = false) : + m_runtime(runtime), m_runtimeOwner(runtimeOwner) + {} + + //! Runtime const + const BlackCore::CRuntime *getRuntime() const { return this->m_runtime;} + + //! Runtime non const + BlackCore::CRuntime *getRuntime() { return this->m_runtime;} + + //! Create a runtime (becomes owner). Only create one runtime. + void createRuntime(const BlackCore::CRuntimeConfig &config, QObject *parent); + + //! Context for network + BlackCore::IContextNetwork *getIContextNetwork(); + + //! Context for network + const BlackCore::IContextNetwork *getIContextNetwork() const; + + //! Context for audio + BlackCore::IContextAudio *getIContextAudio(); + + //! Context for audio + const BlackCore::IContextAudio *getIContextAudio() const; + + //! Context for settings + BlackCore::IContextSettings *getIContextSettings(); + + //! Context for settings + const BlackCore::IContextSettings *getIContextSettings() const; + + //! Context for application + const BlackCore::IContextApplication *getIContextApplication() const; + + //! Context for application + BlackCore::IContextApplication *getIContextApplication(); + + //! Context for simulator + const BlackCore::IContextSimulator *getIContextSimulator() const; + + //! Context for simulator + BlackCore::IContextSimulator *getIContextSimulator(); + + //! Owner? + bool isRuntimeOwner() const { return this->m_runtimeOwner; } + + private: + BlackCore::CRuntime *m_runtime; + bool m_runtimeOwner; + + }; + +} // namespace + +#endif // guard