VPTissue Reference Manual
CliController.h
Go to the documentation of this file.
1 #ifndef CLI_CONTROLLER_H_
2 #define CLI_CONTROLLER_H_
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "cli/CliConverterTask.h"
23 #include "CliSimulationTask.h"
24 #include "adapt2rfp/adapt2rfp.h"
25 #include "session/SimSession.h"
27 #include "workspace/CliWorkspace.h"
28 
29 #include <QMessageBox>
30 #include <QObject>
31 #include <string>
32 
33 namespace SimPT_Shell {
34 
39 {
40  Q_OBJECT
41 public:
45  virtual ~CliController();
46 
52  static std::shared_ptr<CliController> Create(const std::string& workspace, bool quiet);
53 
59  static std::shared_ptr<CliController> Create(std::shared_ptr<Ws::CliWorkspace> workspace, bool quiet);
60 
65  int Execute(CliConverterTask task);
66 
71  int Execute(CliSimulationTask task);
72 
77  Timings GetTimings() const;
78 
82  void Terminate();
83 
84 signals:
88  void TerminationRequested();
89 
90 private:
96  CliController(std::shared_ptr<Ws::CliWorkspace> workspace_model, bool quiet);
97 
101  bool IsQuiet() const;
102 
107  int SimulatorRun(CliSimulationTask task);
108 
112  void SigIntHandler(int sig);
113 
117 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
118  void SigQtHandler(QtMsgType type, const QMessageLogContext&, const QString&);
119 #else
120  void SigQtHandler(QtMsgType type, const char* msg);
121 #endif
122 
126  static void UserError(const std::string& msg);
127 
131  static void UserMessage(const std::string& msg);
132 
133 private:
134  // Because of Qt wanting to match parameter types of signals and slots by string comparison
136 
137 private slots:
139  void SimulationInfo(const std::string& message, const InfoMessageReason& reason);
140 
142  void SimulationError(const std::string& error);
143 
144 private:
146  //typedef void (SigIntHandlerType)(int);
147  using SigIntHandlerType = void (int);
148 
150  using SigIntAdaptorType = UA_CoMP_Adapt2rfp::Adaptor<SigIntHandlerType>;
151 
153 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
154  using SigQtHandlerType = void (QtMsgType, const QMessageLogContext&, const QString&);
155 #else
156  using SigQtHandlerType = void (QtMsgType, const char*);
157 #endif
158 
160  using SigQtAdaptorType = UA_CoMP_Adapt2rfp::Adaptor<SigQtHandlerType>;
161 
162 private:
164  std::shared_ptr<Ws::CliWorkspace> m_workspace_model;
165 
167  bool m_quiet;
168 
170  SigIntAdaptorType m_sig_int_adaptor;
171 
173  SigQtAdaptorType m_sig_qt_adaptor;
174 
176  Timings m_timings;
177 };
178 
179 } // namespace
180 
181 #endif // end_of_include_guard
A CliConverterTask represents an invocation of the converter from the command line.
Interface/Implementation for CliTask.
virtual ~CliController()
Virtual destructor.
Namespace for SimPT shell package.
Definition: Client.cpp:50
static std::shared_ptr< CliController > Create(const std::string &workspace, bool quiet)
Create controller.
InfoMessageReason
Enumeration for the reason of an emitted InfoMessage from the project.
Definition: ISession.h:126
Command line interface application controller.
Definition: CliController.h:38
Interface for workspace.
Interfaces for simulator session.
Timings GetTimings() const
Execution timings in duration units specified in Timeable base class.
int Execute(CliConverterTask task)
Execute converter task.
Interface for Timeable.
void Terminate()
Request termination of the simulation.
Interface/Implementation for CliConverterTask.
see the online Qt documentation
A CliTask represents an invocation of the program from the command line.
void TerminationRequested()
Private signal, to be used for signaling that the simulation should stop.
Utility class to for timing.
Definition: Timeable.h:38