StatusManager.cpp
Go to the documentation of this file.
1 #include "StatusManager.h"
2 
3 #include <filesystem>
4 #include <fstream>
5 
9 
10 using namespace ScenarioManager;
11 using namespace Exec;
12 using namespace armarx;
13 
15 {
16 }
17 
18 int
20 {
21  std::string cachePath = ArmarXDataPath::GetCachePath();
22  if (cachePath.empty())
23  {
24  return -1;
25  }
26 
27  cachePath.append("/pids/");
28  auto dir = remove_trailing_separator(cachePath);
29 
30  if (!std::filesystem::exists(dir) && !std::filesystem::create_directories(dir))
31  {
32  ARMARX_WARNING_S << "Unable to create Cache directory for the ScenarioManager plugin at "
33  << cachePath;
34  }
35 
36 
37  std::string filename = cachePath + app->getPackageName() + "." + app->getScenario()->getName() +
38  "." + app->getName() + (app->getInstanceName().empty() ? "" : ".") +
39  app->getInstanceName() + ".pids";
40 
41  if (!std::filesystem::exists(filename))
42  {
43  return -1;
44  }
45 
46  std::ifstream input(filename);
47 
48  int pid;
49  input >> pid;
50 
51  return pid;
52 }
53 
54 void
56 {
57  std::string cachePath = ArmarXDataPath::GetCachePath();
58  cachePath.append("/pids/");
59  auto dir = remove_trailing_separator(cachePath);
60 
61  if (!std::filesystem::exists(dir) && !std::filesystem::create_directories(dir))
62  {
63  ARMARX_WARNING_S << "Unable to create Cache directory for the ScenarioManager plugin at "
64  << cachePath;
65  }
66 
67  std::string filename = cachePath + app->getPackageName() + "." + app->getScenario()->getName() +
68  "." + app->getName() + (app->getInstanceName().empty() ? "" : ".") +
69  app->getInstanceName() + ".pids";
70 
71  if (app->getPid() == -1)
72  {
73  std::filesystem::remove(std::filesystem::path(filename));
74  return;
75  }
76 
77  std::ofstream output(filename);
78 
79  output << app->getPid();
80  output.close();
81 }
82 
83 void
85 {
86  std::string cachePath = ArmarXDataPath::GetCachePath();
87  cachePath.append("/pids/");
88 
89  std::filesystem::remove_all(std::filesystem::path(cachePath));
90 }
ScenarioManager::Data_Structure::ApplicationInstancePtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
Definition: ApplicationInstance.h:33
ScenarioManager::StatusManager::loadPid
int loadPid(Data_Structure::ApplicationInstancePtr app)
Definition: StatusManager.cpp:19
ScenarioManager::StatusManager::savePid
void savePid(Data_Structure::ApplicationInstancePtr app)
Definition: StatusManager.cpp:55
armarx::remove_trailing_separator
fs::path remove_trailing_separator(fs::path p)
Definition: filesystem.h:34
filesystem.h
StatusManager.h
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
ScenarioManager::StatusManager::StatusManager
StatusManager()
Definition: StatusManager.cpp:14
filename
std::string filename
Definition: VisualizationRobot.cpp:86
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:213
ScenarioManager
Definition: Application.cpp:180
Logging.h
ScenarioManager::StatusManager::clearCache
static void clearCache()
Definition: StatusManager.cpp:84
ArmarXDataPath.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27