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 
85 
87 {
88  std::string cachePath = ArmarXDataPath::GetCachePath();
89  cachePath.append("/pids/");
90 
91  std::filesystem::remove_all(std::filesystem::path(cachePath));
92 }
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: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:83
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:86
ArmarXDataPath.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28