DetailedApplicationController.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Cedric Seehausen (usdnr at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <stdlib.h>
28
29#include <string>
30
31#include <QDesktopServices>
32#include <QMessageBox>
33#include <QUrl>
34
40
42
43
44using namespace ScenarioManager;
45using namespace Controller;
46using namespace Exec;
47using namespace Data_Structure;
48
50 QObject* parent) :
51 QObject(parent), executor(executor), showingStartable(false)
52{
53 QObject::connect(&propertyAdderView,
54 SIGNAL(create(std::string, std::string)),
55 this,
56 SLOT(setProperty(std::string, std::string)));
57}
58
62
63void
68
69void
71 ScenarioItem* item)
72{
73 if (application.get() == nullptr)
74 {
75 return;
76 }
77 showingStartable = true;
78 currentApplication = application;
79 currentScenario = ScenarioPtr();
80
81 // A lifecycle worker may be loading the same properties right now for a start. That is safe:
82 // Application guards the swap and the property maps, and load() parses outside the lock, so
83 // whichever finishes last simply wins.
84 executor->loadAndSetCachedProperties(
85 application, Parser::IceParser::getCacheDir(), false, false);
86 application->load();
87 view->setVisible(true);
88 view->showApplicationInstance(application, item);
89}
90
91void
94{
95 if (application.get() == nullptr)
96 {
97 return;
98 }
99 showingStartable = false;
100 currentApplication = ApplicationInstancePtr();
101 currentScenario = ScenarioPtr();
104 executor->loadAndSetCachedProperties(app, Parser::IceParser::getCacheDir());
105
106 view->setVisible(true);
107 view->showApplication(app);
108}
109
110void
112{
113 if (scenario.get() == nullptr)
114 {
115 return;
116 }
117 showingStartable = true;
118 currentApplication = ApplicationInstancePtr();
119 currentScenario = scenario;
120
121 scenario->reloadGlobalConf();
122 view->setVisible(true);
123 view->showScenario(scenario);
124}
125
126void
128{
129 if (package.get() == nullptr)
130 {
131 return;
132 }
133 showingStartable = false;
134 currentApplication = ApplicationInstancePtr();
135 currentScenario = ScenarioPtr();
136 view->showPackage(package);
137}
138
139void
141{
142 if (showingStartable)
143 {
144 std::string url = "file://";
145 if (currentApplication.get() != nullptr)
146 {
147 url.append(currentApplication->getConfigPath());
148 }
149 else if (currentScenario.get() != nullptr)
150 {
151 url.append(currentScenario->getGlobalConfigPath());
152 }
153 QDesktopServices::openUrl(QUrl(url.c_str()));
154 }
155}
156
157void
158DetailedApplicationController::setProperty(std::string name, std::string value)
159{
160 if (showingStartable)
161 {
162 if (currentApplication.get() != nullptr)
163 {
164 currentApplication->addProperty(name, value);
165 currentApplication->save();
166 showApplicationInstance(currentApplication, nullptr);
167 }
168 else if (currentScenario.get() != nullptr)
169 {
170 currentScenario->getGlobalConfig()->defineOptionalProperty<std::string>(
171 name, "::NOT_DEFINED::", "Custom Property");
172 currentScenario->getGlobalConfig()->getProperties()->setProperty(name, value);
173 currentScenario->save();
174 showScenario(currentScenario);
175 }
176 }
177}
178
179void
181{
182 if (showingStartable)
183 {
184 if (currentApplication.get() != nullptr)
185 {
186 executor->startApplication(currentApplication);
187 }
188 else if (currentScenario.get() != nullptr)
189 {
190 try
191 {
192 startScenario(currentScenario);
193 }
194 catch (IceGrid::ServerStartException& ex)
195 {
196 showWarningDialog("Ice had an launching error. Please make sure your remote launch "
197 "settings are correct");
198 }
199 }
200 }
201}
202
203void
204DetailedApplicationController::startScenario(ScenarioPtr scenario)
205{
206
207 StatusManager statusManager;
208 ScenarioListController::StartScenario(scenario, executor, iceAdmin);
209
210 // StatusManager statusManager;
211 // StopStrategyFactory stopStrategyFactory;
212
213 // if (scenario->getScenarioDeploymentType() == ScenarioDeploymentType::Local)
214 // {
215 // executor->setStarter(StarterFactory::getFactory()->getStarter(), scenario);
216 // executor->setStopStrategy(executor->getDefaultStopStrategy(), scenario);
217 // executor->startScenario(scenario);
218 // }
219 // else
220 // {
221 // executor->setStarter(StarterFactory::getFactory()->getIceStarter(iceAdmin), scenario);
222 // executor->setStopStrategy(stopStrategyFactory.getKillStrategy(StopperFactory::getFactory()->getIceStopper(iceAdmin)), scenario);
223 // if (executor->isScenarioDeployed(scenario))
224 // {
225 // try
226 // {
227 // executor->startScenario(scenario).get();
228 // }
229 // catch (IceGrid::ServerStartException& ex)
230 // {
231 // showWarningDialog("Ice had an launching error. Please make sure your remote launch settings are correct");
232 // }
233 // }
234 // else
235 // {
236 // try
237 // {
238 // executor->deployScenario(scenario).get();
239 // }
240 // catch (IceGrid::DeploymentException& ex)
241 // {
242 // showWarningDialog(QString::fromStdString(ex.reason));
243 // }
244 // }
245 // }
246}
247
248void
250{
251 if (showingStartable)
252 {
253 if (currentApplication.get() != nullptr)
254 {
255 executor->stopApplication(currentApplication);
256 }
257 else if (currentScenario.get() != nullptr)
258 {
259 executor->stopScenario(currentScenario);
260 }
261 }
262}
263
264void
266{
267 if (showingStartable)
268 {
269 if (currentApplication.get() != nullptr)
270 {
271 currentApplication->save();
272 executor->restartApplication(currentApplication);
273 }
274 else if (currentScenario.get() != nullptr)
275 {
276 currentScenario->save();
277 try
278 {
279 executor->restartScenario(currentScenario);
280 }
281 catch (IceGrid::ServerStartException& ex)
282 {
283 showWarningDialog("Ice had an launching error. Please make sure your remote launch "
284 "settings are correct");
285 }
286 }
287 }
288}
289
290void
294
295void
297{
298 propertyAdderView.exec();
299}
300
301void
302DetailedApplicationController::showWarningDialog(QString message)
303{
304 QMessageBox box;
305 box.setText(message);
306 box.exec();
307}
308
309void
311{
312 this->iceAdmin = iceAdmin;
313}
View that shows detailed information about a Scenario, Package or Application.
TreeItem representing data contained in a Scenario or an Application.
void showApplication(Data_Structure::ApplicationPtr application)
Shows an Application in the DetailedApplicationView.
void showPackage(Data_Structure::PackagePtr package)
Shows a Package in the DetailedApplicationView.
void deleteProperty(std::string name)
Deletes a property off the configuration file of the current ApplicationInstance.
void setDetailedApplicationView(DetailedApplicationView *ptr)
Sets the view this controller manages.
DetailedApplicationController(Exec::ExecutorPtr executor, QObject *parent=0)
Constructor that optionally sets the parent object.
void setIceAdmin(IceGrid::AdminPrx iceAdmin)
Set an IceAdmin for the controller.
void showScenario(Data_Structure::ScenarioPtr scenario)
Shows a Scenario in the DetailedApplicationView.
void save()
Saves the configuration of the current ApplicationInstance to the config file.
void showInStandardEditor()
Shows the configuration of the current ApplicationInstance in the standard editor.
void setProperty(std::string name, std::string value)
Sets a property of the current ApplicationInstance.
void showApplicationInstance(Data_Structure::ApplicationInstancePtr application, ScenarioItem *item)
Shows an ApplicationInstance in the DetailedApplicationView.
static bool StartScenario(ScenarioManager::Data_Structure::ScenarioPtr scenario, Exec::ExecutorPtr executor, IceGrid::AdminPrx iceAdmin)
Class containing data about an application Provides methods to get and set the date contained in the ...
Definition Application.h:49
static std::string getCacheDir()
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::shared_ptr< Application > ApplicationPtr
std::shared_ptr< Package > PackagePtr
Definition Package.h:122
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
std::shared_ptr< Executor > ExecutorPtr
Definition Executor.h:210