VPTissue Reference Manual
CoupledCliController.h
Go to the documentation of this file.
1 #ifndef COUPLED_CLI_CONTROLLER_H_
2 #define COUPLED_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 "CliSimulationTask.h"
23 
24 #include "../../cpp_sim/util/clock_man/Timeable.h"
25 #include "adapt2rfp/adapt2rfp.h"
26 #include "session/ISession.h"
27 #include <QObject>
28 #include <chrono>
29 #include <memory>
30 #include <string>
31 
32 namespace SimPT_Shell {
33 
34 namespace Session {
35  class SimSessionCoupled;
36 }
37 
38 namespace Ws {
39  class CliWorkspace;
40 }
41 
46 {
47  Q_OBJECT
48 public:
52  virtual ~CoupledCliController();
53 
60  static std::shared_ptr<CoupledCliController> Create(const std::string& workspace, bool quiet);
61 
66  int Execute(CliSimulationTask task);
67 
72  Timings GetTimings() const;
73 
77  void Terminate();
78 
79 signals:
83  void TerminationRequested();
84 
85 private:
91  CoupledCliController(std::shared_ptr<Ws::CliWorkspace> workspace_model, bool quiet);
92 
96  bool IsQuiet() const;
97 
103  std::shared_ptr<Session::SimSessionCoupled> OpenProject(const std::string& project_name, const std::string& file_name);
104 
109  int SimulatorRun(CliSimulationTask task);
110 
114  void SigIntHandler(int sig);
115 
119 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
120  void SigQtHandler(QtMsgType type, const QMessageLogContext&, const QString&);
121 #else
122  void SigQtHandler(QtMsgType type, const char* msg);
123 #endif
124 
128  static void UserError(const std::string& msg);
129 
133  static void UserMessage(const std::string& msg);
134 
135 private:
136  typedef SimShell::Session::ISession::InfoMessageReason InfoMessageReason; // Because of Qt wanting to match parameter types of signals and slots by string comparison
137 
138 private slots:
142  void SimulationInfo(const std::string &message, const InfoMessageReason &reason);
143 
147  void SimulationError(const std::string &error);
148 
149 private:
151  typedef void (SigIntHandlerType)(int);
152 
154  typedef UA_CoMP_Adapt2rfp::Adaptor<SigIntHandlerType> SigIntAdaptorType;
155 
157 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
158  typedef void (SigQtHandlerType)(QtMsgType, const QMessageLogContext&, const QString&);
159 #else
160  typedef void (SigQtHandlerType)(QtMsgType, const char*);
161 #endif
162 
164  typedef UA_CoMP_Adapt2rfp::Adaptor<SigQtHandlerType> SigQtAdaptorType;
165 
166 private:
168  std::shared_ptr<Ws::CliWorkspace> m_workspace_model;
169 
171  bool m_quiet;
172 
174  SigIntAdaptorType m_sig_int_adaptor;
175 
177  SigQtAdaptorType m_sig_qt_adaptor;
178 
180  Timings m_timings;
181 };
182 
183 } // namespace
184 
185 #endif // end_of_include_guard
static std::shared_ptr< CoupledCliController > Create(const std::string &workspace, bool quiet)
Create controller.
Interface/Implementation for CliTask.
void Terminate()
Request termination of the simulation.
Namespace for SimPT shell package.
Definition: Client.cpp:50
InfoMessageReason
Enumeration for the reason of an emitted InfoMessage from the project.
Definition: ISession.h:126
int Execute(CliSimulationTask task)
Execute the task defined via prior SetTask call.
void TerminationRequested()
Private signal, to be used for signaling that the simulation should stop.
Interface for ISession.
Timings GetTimings() const
Execution timings in duration units specified in Timeable base class.
Cli Workspace for the command-line simulator.
Definition: CliWorkspace.h:30
Collection of instances associated with an opened/running coupled project.
virtual ~CoupledCliController()
Virtual destructor.
see the online Qt documentation
A CliTask represents an invocation of the program from the command line.
Command line interface application controller.
Utility class to for timing.
Definition: Timeable.h:38