CConsoleApplicationComp.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 // Qt includes
5 #include <QtCore/QCoreApplication>
6 #include <QtCore/QStringList>
7 
8 // ACF includes
9 #include <istd/TOptDelPtr.h>
10 #include <imod/TModelWrap.h>
11 #include <ilog/TLoggerCompWrap.h>
12 #include <iqt/CConsoleReader.h>
13 #include <ibase/IApplication.h>
14 #include <ibase/IApplicationInfo.h>
16 
17 
18 namespace ibase
19 {
20 
21 
26  public QObject,
28  virtual public ibase::IApplication
29 {
30  Q_OBJECT
31 
32 public:
34 
35  I_BEGIN_COMPONENT(CConsoleApplicationComp);
36  I_REGISTER_INTERFACE(ibase::IApplication);
37  I_REGISTER_SUBELEMENT(RuntimeStatus);
38  I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, ibase::IRuntimeStatusProvider, ExtractRuntimeStatus);
39  I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, imod::IModel, ExtractRuntimeStatus);
40  I_REGISTER_SUBELEMENT_INTERFACE(RuntimeStatus, istd::IChangeable, ExtractRuntimeStatus);
41  I_ASSIGN(m_applicationInfoCompPtr, "ApplicationInfo", "Info about the worker application", true, "ApplicationInfo");
42  I_ASSIGN_MULTI_0(m_componentsToInitializeCompPtr, "ComponentsToInitialize", "List of components to be initialized after creation of the application instance (QCoreApplication)", false);
43  I_END_COMPONENT;
44 
45  // reimplemented (ibase::IApplication)
46  virtual bool InitializeApplication(int argc, char** argv);
47  virtual int Execute(int argc, char** argv);
48  virtual QString GetHelpText() const;
49  virtual QStringList GetApplicationArguments() const;
50 
51 protected:
56  virtual void OnApplicationShutdown();
57 
58  // reimplemented (icomp::CComponentBase)
59  virtual void OnComponentDestroyed();
60 
61 private slots:
62  void OnKeyPressed(char ch);
63 
64 private:
65  class RuntimeStatus: public ibase::IRuntimeStatusProvider
66  {
67  public:
68  RuntimeStatus();
69 
70  void SetRuntimeStatus(IRuntimeStatusProvider::RuntimeStatus runtimeStatus);
71 
72  // reimplemented (ibase::IRuntimeStatusProvider)
73  virtual IRuntimeStatusProvider::RuntimeStatus GetRuntimeStatus() const;
74 
75  private:
77  };
78 
79  imod::TModelWrap<RuntimeStatus> m_runtimeStatus;
80 
81  // static template methods for sub element access
82  template <class InterfaceType>
83  static InterfaceType* ExtractRuntimeStatus(CConsoleApplicationComp& component)
84  {
85  return &component.m_runtimeStatus;
86  }
87 
88 private:
89  I_REF(ibase::IApplicationInfo, m_applicationInfoCompPtr);
90  I_MULTIREF(istd::IPolymorphic, m_componentsToInitializeCompPtr);
91 
92  QStringList m_applicationArguments;
93  istd::TOptDelPtr<QCoreApplication> m_applicationPtr;
94 
95  iqt::CConsoleReader m_consoleReader;
96 };
97 
98 
99 } // namespace ibase
100 
101 
virtual void OnComponentDestroyed()
virtual void OnApplicationShutdown()
Callback for the application's shutdown.
Provider of the run-time status.
Wrapper provider of log-functionality for component based implementations.
virtual QString GetHelpText() const
Get information about the possible command line arguments of this application.
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
Console (non-gui) application.
Base interface for all used interfaces and implementations.
Definition: IPolymorphic.h:17
This interface provides some information about the application.
virtual QStringList GetApplicationArguments() const
Get the command line arguments of this application.
virtual bool InitializeApplication(int argc, char **argv)
Initialize the application object.
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
ilog::CLoggerComponentBase BaseClass
User-input reader for command line console.
Interface for the main entry point of a component-based application.
Definition: IApplication.h:22
virtual int Execute(int argc, char **argv)
Start execution loop of the application.

© 2007-2017 Witold Gantzke and Kirill Lepskiy