DiskStorageMixin.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
4 #include <map>
5 #include <string>
6 
7 #include <SimoxUtility/json.h>
8 
10 
12 
13 #include "util/filesystem.h"
14 
16 {
17  using Path = std::filesystem::path;
18 
20  {
21  public:
22  DiskMemoryItemMixin() = default;
23  DiskMemoryItemMixin(const Path& memoryParentPath,
24  const std::string& exportName,
25  const armem::MemoryID& id);
26  virtual ~DiskMemoryItemMixin() = default;
27 
28  Path getMemoryBasePath() const;
29  Path getFullPath() const;
30 
31  // Filesystem interaction
32  bool memoryBasePathExists() const;
33  bool fullPathExists() const;
34  bool fileExists(const std::string& filename) const;
35 
36  void ensureMemoryBasePathExists(bool createIfNotExistent = false) const;
37  void ensureFullPathExists(bool createIfNotExistent = false) const;
38  void ensureFileExists(const std::string& filename, bool createIfNotExistent = false) const;
39 
40  void writeDataToFile(const std::string& filename,
41  const std::vector<unsigned char>& data) const;
42 
43  std::vector<unsigned char> readDataFromFile(const std::string& filename) const;
44  std::vector<Path> getAllDirectories() const;
45  std::vector<Path> getAllFiles() const;
46 
47  void createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix);
48 
49 
50  protected:
51  // setter
52  void setMixinMemoryID(const MemoryID& n);
53  void setMixinExportName(const std::string& n);
54 
55  // configuration
56  void configureMixin(const nlohmann::json& json);
57 
58  //construct correct memory base path
59  Path addDateToMemoryBasePath(const std::filesystem::path& n) const;
60 
61  public:
62  static const int DEPTH_TO_DATA_FILES =
63  7; // from memory folder = 1 (cseg) + 1 (pseg) + 1 (ent) + 3 (snap) + 1 (inst)
64 
65  protected:
66  static const constexpr char* TYPE_FILENAME = "type.aron";
67  static const constexpr char* DATA_FILENAME = "data.aron";
68  static const constexpr char* METADATA_FILENAME = "metadata.aron";
69 
70  static const constexpr char* MEMORY_EXPORT_SUFFIX = "_";
71 
72  private:
73  std::filesystem::path memoryBasePath;
74  std::string memoryBasePathString;
75  std::string exportName;
76  armem::MemoryID _id;
77  };
78 } // namespace armarx::armem::server::ltm::detail::mixin
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::DATA_FILENAME
static const constexpr char * DATA_FILENAME
Definition: DiskStorageMixin.h:67
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::addDateToMemoryBasePath
Path addDateToMemoryBasePath(const std::filesystem::path &n) const
Definition: DiskStorageMixin.cpp:28
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::ensureMemoryBasePathExists
void ensureMemoryBasePathExists(bool createIfNotExistent=false) const
Definition: DiskStorageMixin.cpp:124
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::getMemoryBasePath
Path getMemoryBasePath() const
Definition: DiskStorageMixin.cpp:71
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::ensureFileExists
void ensureFileExists(const std::string &filename, bool createIfNotExistent=false) const
Definition: DiskStorageMixin.cpp:137
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::createPropertyDefinitions
void createPropertyDefinitions(PropertyDefinitionsPtr &defs, const std::string &prefix)
Definition: DiskStorageMixin.cpp:173
PeriodicTask.h
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::getAllFiles
std::vector< Path > getAllFiles() const
Definition: DiskStorageMixin.cpp:167
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::METADATA_FILENAME
static const constexpr char * METADATA_FILENAME
Definition: DiskStorageMixin.h:68
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::setMixinMemoryID
void setMixinMemoryID(const MemoryID &n)
Definition: DiskStorageMixin.cpp:54
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::DEPTH_TO_DATA_FILES
static const int DEPTH_TO_DATA_FILES
Definition: DiskStorageMixin.h:62
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::~DiskMemoryItemMixin
virtual ~DiskMemoryItemMixin()=default
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::getAllDirectories
std::vector< Path > getAllDirectories() const
Definition: DiskStorageMixin.cpp:160
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::fileExists
bool fileExists(const std::string &filename) const
Definition: DiskStorageMixin.cpp:117
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::readDataFromFile
std::vector< unsigned char > readDataFromFile(const std::string &filename) const
Definition: DiskStorageMixin.cpp:153
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::TYPE_FILENAME
static const constexpr char * TYPE_FILENAME
Definition: DiskStorageMixin.h:66
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::setMixinExportName
void setMixinExportName(const std::string &n)
Definition: DiskStorageMixin.cpp:47
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::DiskMemoryItemMixin
DiskMemoryItemMixin()=default
filename
std::string filename
Definition: VisualizationRobot.cpp:83
memory_definitions.h
armarx::armem::server::ltm::detail::mixin
Definition: BufferedMemoryMixin.cpp:3
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::fullPathExists
bool fullPathExists() const
Definition: DiskStorageMixin.cpp:110
filesystem.h
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::MEMORY_EXPORT_SUFFIX
static const constexpr char * MEMORY_EXPORT_SUFFIX
Definition: DiskStorageMixin.h:70
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::configureMixin
void configureMixin(const nlohmann::json &json)
Definition: DiskStorageMixin.cpp:62
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin
Definition: DiskStorageMixin.h:19
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::getFullPath
Path getFullPath() const
Definition: DiskStorageMixin.cpp:87
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::writeDataToFile
void writeDataToFile(const std::string &filename, const std::vector< unsigned char > &data) const
Definition: DiskStorageMixin.cpp:145
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::ensureFullPathExists
void ensureFullPathExists(bool createIfNotExistent=false) const
Definition: DiskStorageMixin.cpp:130
armarx::armem::server::ltm::detail::mixin::DiskMemoryItemMixin::memoryBasePathExists
bool memoryBasePathExists() const
Definition: DiskStorageMixin.cpp:104