ACF $AcfVersion:0$
CConsoleApplicationComp.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QCoreApplication>
7#include <QtCore/QStringList>
8
9// ACF includes
10#include <istd/TOptDelPtr.h>
11#include <imod/TModelWrap.h>
13#include <iqt/CConsoleReader.h>
14#include <ibase/IApplication.h>
17
18
19namespace ibase
20{
21
22
27 public QObject,
29 virtual public ibase::IApplication
30{
31 Q_OBJECT
32
33public:
35
36 I_BEGIN_COMPONENT(CConsoleApplicationComp);
37 I_REGISTER_INTERFACE(ibase::IApplication);
38 I_REGISTER_SUBELEMENT(RuntimeStatus);
39 I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, ibase::IRuntimeStatusProvider, ExtractRuntimeStatus);
40 I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, imod::IModel, ExtractRuntimeStatus);
41 I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, istd::IChangeable, ExtractRuntimeStatus);
42 I_ASSIGN(m_applicationInfoCompPtr, "ApplicationInfo", "Info about the worker application", true, "ApplicationInfo");
43 I_ASSIGN_MULTI_0(m_componentsToInitializeCompPtr, "ComponentsToInitialize", "List of components to be initialized after creation of the application instance (QCoreApplication)", false);
44 I_END_COMPONENT;
45
46 // reimplemented (ibase::IApplication)
47 virtual bool InitializeApplication(int argc, char** argv) override;
48 virtual int Execute(int argc, char** argv) override;
49 virtual QString GetHelpText() const override;
50 virtual QStringList GetApplicationArguments() const override;
51
52protected:
57 virtual void OnApplicationShutdown();
58
59 // reimplemented (icomp::CComponentBase)
60 virtual void OnComponentDestroyed() override;
61
62Q_SIGNALS:
64
65private Q_SLOTS:
66 void OnKeyPressed(char ch);
67 void OnEventLoopStarted();
68
69private:
70 class RuntimeStatus: public ibase::IRuntimeStatusProvider
71 {
72 public:
73 RuntimeStatus();
74
75 void SetRuntimeStatus(IRuntimeStatusProvider::RuntimeStatus runtimeStatus);
76
77 // reimplemented (ibase::IRuntimeStatusProvider)
78 virtual IRuntimeStatusProvider::RuntimeStatus GetRuntimeStatus() const override;
79
80 private:
82 };
83
84 imod::TModelWrap<RuntimeStatus> m_runtimeStatus;
85
86 // static template methods for sub element access
87 template <class InterfaceType>
88 static InterfaceType* ExtractRuntimeStatus(CConsoleApplicationComp& component)
89 {
90 return &component.m_runtimeStatus;
91 }
92
93private:
94 I_REF(ibase::IApplicationInfo, m_applicationInfoCompPtr);
95 I_MULTIREF(istd::IPolymorphic, m_componentsToInitializeCompPtr);
96
97 QStringList m_applicationArguments;
99
100 iqt::CConsoleReader m_consoleReader;
101};
102
103
104} // namespace ibase
105
106
Console (non-gui) application.
virtual QString GetHelpText() const override
Get information about the possible command line arguments of this application.
virtual QStringList GetApplicationArguments() const override
Get the command line arguments of this application.
virtual int Execute(int argc, char **argv) override
Start execution loop of the application.
virtual bool InitializeApplication(int argc, char **argv) override
Initialize the application object.
virtual void OnComponentDestroyed() override
Called when component is destroyed.
ilog::CLoggerComponentBase BaseClass
virtual void OnApplicationShutdown()
Callback for the application's shutdown.
Interface for the main entry point of a component-based application.
This interface provides some information about the application.
Provider of the run-time status.
Template wrapper adding comprehensive logging functionality to components.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
This model wrapper provides a simple connection between a concrete istd::IChangeable implementation a...
Definition TModelWrap.h:24
User-input reader for command line console.
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
Base interface for all used interfaces and implementations.
Pointer wrapper providing activatable deleting pointed object during destruction.
Definition TOptDelPtr.h:21
This namespace contains basic implementations of standard primitives on the component level.