22 #include "../../cpp_simptshell/cli/CliSimulationTask.h"
24 #include "workspace/Workspace.h"
27 #include <boost/property_tree/ptree.hpp>
28 #include <boost/property_tree/xml_parser.hpp>
34 #include <QSystemSemaphore>
41 const QString C_SEMKEY =
"__NODE_SIM_SEMAPHORE__";
42 const std::string C_WORKSPACE_PATH =
"parex_result_";
52 void remDir(QString dir)
55 auto files = d.entryInfoList(QDir::NoDotAndDotDot
56 | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files);
57 for (
auto file : files){
59 remDir(file.absoluteFilePath());
60 }
else if (file.isFile()){
61 QFile::remove(file.absoluteFilePath());
68 shared_ptr<Ws::CliWorkspace> SetupWorkspace(
const SimTask& task,
const std::string& project_name,
69 const std::string& workspace_path,
const std::string& file)
73 QString path = QString::fromStdString(workspace_path);
74 if (!dir.exists(path)) {
79 shared_ptr<Ws::CliWorkspace> w;
81 w = make_shared<Ws::CliWorkspace>(workspace_path);
83 Ws::CliWorkspace::Init(workspace_path);
84 w = make_shared<Ws::CliWorkspace>(workspace_path);
88 Ws::CliWorkspace::ProjectIterator p;
90 p = w->New(
"project", project_name);
92 cerr << e.
what() << endl;
97 write_xml(workspace_path +
"/" + project_name +
"/" + file, task.ToPtree());
101 cerr << e.
what() << endl;
109 : m_controller(nullptr), m_stopped(false)
119 QSystemSemaphore m(C_SEMKEY, 1);
121 std::cerr <<
"SEMAPHORE ERROR: " << QSystemSemaphore::SystemSemaphoreError() << std::endl;
123 std::string temp = C_WORKSPACE_PATH + name;
124 remDir(QDir(temp.c_str()).absolutePath());
131 std::cout <<
"Starting Task.." << std::endl;
133 const unsigned int num_steps = 0;
134 const bool num_steps_set =
false;
135 std::string workspace_path = C_WORKSPACE_PATH + task.
GetExploration();
136 std::stringstream ss;
137 ss <<
"Simulation" << task.
GetId();
138 std::string project_name = ss.str();
139 const std::string sim_file =
"SimLeaf.xml";
140 const bool file_set =
true;
142 SimResult::ResultType success = SimResult::ResultType::Failure;
145 QSystemSemaphore m(C_SEMKEY, 1);
147 std::cerr <<
"SEMAPHORE ERROR: " << QSystemSemaphore::SystemSemaphoreError() << std::endl;
149 auto workspace = SetupWorkspace(task, project_name, workspace_path, sim_file);
153 std::cerr <<
"ERROR: Unable to setup workspace. Aborting simulation" << std::endl;
162 int result = m_controller->Execute(ctask);
164 success = SimResult::ResultType::Success;
167 catch (std::exception &e) {
168 std::cerr <<
"Error while simulating: " << e.what() << std::endl;
171 std::cerr <<
"Problem" << std::endl;
174 std::cerr <<
"Error set-up Controller" << std::endl;
178 success = SimResult::ResultType::Stopped;
179 std::string s = workspace_path +
"/" + project_name;
180 QString d = s.c_str();
181 remDir(QDir(d).absolutePath());
186 m_controller =
nullptr;
193 m_controller->Terminate();
Interface for CliController.
Namespace for miscellaneous utilities.
A container class for the final result of a simulation.
virtual const char * what() const noexcept
Return error message.
Namespace for SimPT shell package.
void StopTask()
Stop the current task.
void TaskSolved(const SimResult &)
Emitted when task is solved. If it was unsuccssful or interrupted a flag is set in SimResult...
static std::shared_ptr< CliController > Create(const std::string &workspace, bool quiet)
Create controller.
virtual ~Simulator()
Destructor.
Interface for the Simulator.
Extremely simple Exception root class.
void Delete(const std::string &name)
Delete a folder on the disk.
virtual void SolveTask(const SimTask &task)
Do the real task of solving a SimTask and saving the results as requested by that task...
Namespace for SimPT parameter explorer package.
std::string GetExploration() const
Get the name of the exploration.
Header file for Exception class.
Contains all information needed for a transmitable simulation task.
int GetId() const
Get the id of the task in the exploration.
A CliTask represents an invocation of the program from the command line.