scenarioitem.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 
25 
26 #include "scenarioitem.h"
27 
30 
31 using namespace armarx;
32 using namespace ScenarioManager;
33 using namespace Data_Structure;
34 
35 ScenarioItem::ScenarioItem(QList<QVariant> rootData)
36 {
37  m_itemData = rootData.toVector();
38 }
39 
41 {
42  this->scenario = scenario;
43 
44  update();
45 }
46 
48 {
49  this->application = application;
50  setEnabled(application->getEnabled());
51 
52  update();
53 }
54 
55 ScenarioItem::ScenarioItem(std::string name, std::vector<ApplicationInstancePtr> applications)
56  : applications(new std::vector<ApplicationInstancePtr>(applications))
57 {
58  this->packageName = name;
59 
60  for (const auto& appl : applications)
61  {
62  ScenarioItem* currentItem = new ScenarioItem(appl);
63  currentItem->setEnabled(appl->getEnabled());
64 
65  this->appendChild(currentItem);
66  }
67 
68  update();
69 }
70 
72 {
73  if (m_itemData.size() < 5)
74  {
75  m_itemData.resize(5);
76  m_itemData[1] = "Start";
77  m_itemData[2] = "Stop";
78  m_itemData[3] = "Restart";
79  }
80  if (scenario.get() != nullptr)
81  {
82  m_itemData[0] = scenario->getName().c_str();
83  m_itemData[4] = QString::fromStdString(scenario->getStatus());
84  }
85  else if (!packageName.empty())
86  {
87  m_itemData[0] = QString::fromStdString(packageName);
88 
89  std::string status = ApplicationStatus::Unknown;
90  for (int i = 0; i < childCount(); i++)
91  {
93  auto item = dynamic_cast<ScenarioItem*>(child(i));
95  item->update();
96  if (!child(i)->isEnabled())
97  {
98  continue;
99  }
100  auto childState = child(i)->data(4).toString().toStdString();
101  if (status == ApplicationStatus::Unknown && childState == ApplicationStatus::Running)
102  {
104  }
105  else if (status == ApplicationStatus::Unknown && childState == ApplicationStatus::Stopped)
106  {
107  status = ApplicationStatus::Stopped;
108  }
109  else if (status == ApplicationStatus::Unknown && childState == ApplicationStatus::Inactive)
110  {
111  status = ApplicationStatus::Inactive;
112  }
113  else if (status != ApplicationStatus::Unknown && childState == ApplicationStatus::Missing)
114  {
115  // Dont change scenario/package state if an app is missing
116  }
117  else if ((status == ApplicationStatus::Running && childState == ApplicationStatus::Stopped)
118  || (status == ApplicationStatus::Stopped && childState == ApplicationStatus::Running)
119  || (status == ApplicationStatus::Running && childState == ApplicationStatus::Inactive)
120  || (status == ApplicationStatus::Stopped && childState == ApplicationStatus::Inactive)
121  || (status == ApplicationStatus::Inactive && childState == ApplicationStatus::Running)
122  || (status == ApplicationStatus::Inactive && childState == ApplicationStatus::Stopped))
123  {
124  status = ApplicationStatus::Mixed;
125  break;
126  }
127  else if (childState == ApplicationStatus::Waiting)
128  {
129  status = ApplicationStatus::Waiting;
130  break;
131  }
132  }
133 
134  m_itemData[4] = QString::fromStdString(status);
135  }
136  else
137  {
138  if (application->getInstanceName().empty())
139  {
140  m_itemData [0] = application->getName().c_str();
141  }
142  else
143  {
144  m_itemData[0] = (application->getInstanceName() + "." + application->getName()).c_str();
145  }
146 
147  std::string status = application->getStatus();
148  if (!application->getFound())
149  {
150  // Status is shown as "Missing", no need for a warning, info is enough.
151  ARMARX_INFO << "Application '" + application->getExecutableAbsPath() + "' not found!";
152 
153  m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Missing));
154  }
156  {
157  m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Running));
158  }
159  else if (status == ApplicationStatus::Stopped)
160  {
161  m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Stopped));
162  }
163  else if (status == ApplicationStatus::Inactive)
164  {
165  m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Inactive));
166  }
167  else if (status == ApplicationStatus::Waiting)
168  {
169  m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Waiting));
170  }
171  else
172  {
173  m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Unknown));
174  }
175 
176  setEnabled(application->getEnabled());
177  }
178 }
179 
181 {
182  return packageName;
183 }
184 
186 {
187  return scenario;
188 }
189 
191 {
192  return application;
193 }
194 
196 {
197  return applications;
198 }
ScenarioItem
TreeItem representing data contained in a Scenario or an Application.
Definition: scenarioitem.h:38
ScenarioItem::ScenarioItem
ScenarioItem(QList< QVariant > rootData)
Constructor that sets the data contained in this item.
Definition: scenarioitem.cpp:35
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
ScenarioItem::getPackageName
std::string getPackageName()
Definition: scenarioitem.cpp:180
TreeItem::m_itemData
QVector< QVariant > m_itemData
Definition: treeitem.h:74
ScenarioManager::Data_Structure::ApplicationInstanceVectorPtr
std::shared_ptr< std::vector< ApplicationInstancePtr > > ApplicationInstanceVectorPtr
Definition: ApplicationInstance.h:35
TreeItem::data
virtual QVariant data(int column) const
Definition: treeitem.cpp:64
KITProsthesis::ProsthesisState::Running
@ Running
Definition: KITProstheticHandInterface.ice:43
scenarioitem.h
TreeItem::appendChild
void appendChild(TreeItem *child)
Definition: treeitem.cpp:43
ScenarioItem::getApplicationInstances
ScenarioManager::Data_Structure::ApplicationInstanceVectorPtr getApplicationInstances()
Definition: scenarioitem.cpp:195
ApplicationInstancePtr
std::shared_ptr< ScenarioManager::Data_Structure::ApplicationInstance > ApplicationInstancePtr
Definition: StopStrategy.h:7
TreeItem::childCount
int childCount() const
Definition: treeitem.cpp:54
TreeItem::child
TreeItem * child(int row)
Definition: treeitem.cpp:49
armarx::status
status
Definition: FiniteStateMachine.h:259
TreeItem::isEnabled
bool isEnabled()
Definition: treeitem.cpp:89
ScenarioItem::update
void update()
Clears the item_data and parses the Scenario or Application for new data.
Definition: scenarioitem.cpp:71
TreeItem::setEnabled
void setEnabled(bool enabled)
Definition: treeitem.cpp:84
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
ExpressionException.h
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
ScenarioManager
Definition: Application.cpp:166
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
std
Definition: Application.h:66
Logging.h
ScenarioItem::getScenario
ScenarioManager::Data_Structure::ScenarioPtr getScenario()
If this item represents a Scenario, it is returned.
Definition: scenarioitem.cpp:185
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ScenarioItem::getApplicationInstance
ScenarioManager::Data_Structure::ApplicationInstancePtr getApplicationInstance()
If this item represents an Application, it is returned.
Definition: scenarioitem.cpp:190