StatusManager.cpp
Go to the documentation of this file.
1 #include "StatusManager.h"
2 
6 
7 #include <filesystem>
8 
9 #include <fstream>
10 
11 using namespace ScenarioManager;
12 using namespace Exec;
13 using namespace armarx;
14 
16 {
17 }
18 
19 
21 {
22  std::string cachePath = ArmarXDataPath::GetCachePath();
23  if (cachePath.empty())
24  {
25  return -1;
26  }
27 
28  cachePath.append("/pids/");
29  auto dir = remove_trailing_separator(cachePath);
30 
31  if (!std::filesystem::exists(dir) && !std::filesystem::create_directories(dir))
32  {
33  ARMARX_WARNING_S << "Unable to create Cache directory for the ScenarioManager plugin at " << cachePath;
34  }
35 
36 
37  std::string filename = cachePath
38  + app->getPackageName() + "."
39  + app->getScenario()->getName() + "."
40  + app->getName() + (app->getInstanceName().empty() ? "" : ".")
41  + app->getInstanceName() + ".pids";
42 
43  if (!std::filesystem::exists(filename))
44  {
45  return -1;
46  }
47 
48  std::ifstream input(filename);
49 
50  int pid;
51  input >> pid;
52 
53  return pid;
54 }
55 
57 {
58  std::string cachePath = ArmarXDataPath::GetCachePath();
59  cachePath.append("/pids/");
60  auto dir = remove_trailing_separator(cachePath);
61 
62  if (!std::filesystem::exists(dir) && !std::filesystem::create_directories(dir))
63  {
64  ARMARX_WARNING_S << "Unable to create Cache directory for the ScenarioManager plugin at " << cachePath;
65  }
66 
67  std::string filename = cachePath
68  + app->getPackageName() + "."
69  + app->getScenario()->getName() + "."
70  + app->getName() + (app->getInstanceName().empty() ? "" : ".")
71  + app->getInstanceName() + ".pids";
72 
73  if (app->getPid() == -1)
74  {
75  std::filesystem::remove(std::filesystem::path(filename));
76  return;
77  }
78 
79  std::ofstream output(filename);
80 
81  output << app->getPid();
82  output.close();
83 }
84 
86 {
87  std::string cachePath = ArmarXDataPath::GetCachePath();
88  cachePath.append("/iceDeployment/");
89 
90  std::string filename = cachePath
91  + scenario->getPackage()->getName() + "."
92  + scenario->getName() + ".ice";
93 
94  return std::filesystem::exists(filename);
95 }
96 
98 {
99  if (state)
100  {
101  std::string cachePath = ArmarXDataPath::GetCachePath();
102  cachePath.append("/iceDeployment/");
103  std::filesystem::path dir(cachePath);
104 
105  if (!std::filesystem::exists(dir) && !std::filesystem::create_directories(dir))
106  {
107  ARMARX_WARNING_S << "Unable to create Cache directory for the ScenarioManager plugin at " << cachePath;
108  }
109 
110  std::string filename = cachePath
111  + scenario->getPackage()->getName() + "."
112  + scenario->getName() + ".ice";
113 
114  if (!std::filesystem::exists(filename))
115  {
116  std::ofstream output(filename);
117  output << "";
118  output.close();
119  }
120  }
121  else
122  {
123  std::string cachePath = ArmarXDataPath::GetCachePath();
124  cachePath.append("/iceDeployment/");
125 
126  std::string filename = cachePath
127  + scenario->getPackage()->getName() + "."
128  + scenario->getName() + ".ice";
129 
130  if (std::filesystem::exists(filename))
131  {
132  if (!std::filesystem::remove(filename))
133  {
134  ARMARX_WARNING_S << "Unable to remove the ice deployment file " << filename;
135  }
136  }
137  }
138 }
139 
140 
142 {
143  std::string cachePath = ArmarXDataPath::GetCachePath();
144  cachePath.append("/pids/");
145 
146  std::filesystem::remove_all(std::filesystem::path(cachePath));
147 }
ScenarioManager::Data_Structure::ApplicationInstancePtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
Definition: ApplicationInstance.h:33
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
ScenarioManager::StatusManager::loadPid
int loadPid(Data_Structure::ApplicationInstancePtr app)
Definition: StatusManager.cpp:20
ScenarioManager::StatusManager::savePid
void savePid(Data_Structure::ApplicationInstancePtr app)
Definition: StatusManager.cpp:56
armarx::remove_trailing_separator
fs::path remove_trailing_separator(fs::path p)
Definition: filesystem.h:32
filesystem.h
StatusManager.h
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
ScenarioManager::StatusManager::StatusManager
StatusManager()
Definition: StatusManager.cpp:15
filename
std::string filename
Definition: VisualizationRobot.cpp:84
ScenarioManager::StatusManager::isIceScenario
bool isIceScenario(Data_Structure::ScenarioPtr scenario)
Definition: StatusManager.cpp:85
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
ScenarioManager
Definition: Application.cpp:166
Logging.h
ScenarioManager::StatusManager::clearCache
static void clearCache()
Definition: StatusManager.cpp:141
ScenarioManager::StatusManager::setIceScenario
void setIceScenario(Data_Structure::ScenarioPtr scenario, bool state)
Definition: StatusManager.cpp:97
ArmarXDataPath.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28