ddt  0.1
ddtMemoryManager.hpp
Go to the documentation of this file.
1 // @copyright
2 // (c) Copyright ESO 2020
3 // All Rights Reserved
4 // ESO (eso.org) is an Intergovernmental Organization, and therefore special
5 // legal conditions apply.
6 //
7 // @file ddtMemoryManager.hpp
8 // @brief Manager for shared memories.
9 //
10 // This class manages the handling of shared memories.
11 //
12 // @author Matthias Grimm, CGI
13 // @since 2020/01/16
14 //
15 
16 #ifndef DDTMEMORYMANAGER_HPP_
17 #define DDTMEMORYMANAGER_HPP_
18 
19 #include <boost/circular_buffer.hpp>
20 #include <boost/interprocess/containers/string.hpp>
21 #include <boost/interprocess/managed_shared_memory.hpp>
22 #include <boost/tokenizer.hpp>
23 #include <csignal>
24 #include <fstream>
25 #include <iostream>
26 
27 #include "ddt/ddtErrorCodes.hpp"
28 #include "ddt/ddtLogger.hpp"
30 
31 namespace ip = boost::interprocess;
32 
33 namespace ddt {
34 
39 struct Shm {
40  ip::managed_shared_memory *managed_shm;
44 };
45 
50  public:
57  DdtMemoryManager(DdtLogger *logger, const std::string broker_port);
58 
62  virtual ~DdtMemoryManager();
63 
74  int32_t CreateSharedMemory(const std::string data_stream_identifier,
75  const int32_t max_data_sample_size,
76  const int32_t number_of_samples);
77 
84  bool DeleteSharedMemory(const std::string data_stream_identifier);
85 
92  bool CheckIfShmExists(const std::string data_stream_identifier);
93 
99  int32_t get_max_data_sample_size(const std::string data_stream_identifier);
100 
106  int32_t get_number_of_samples(const std::string data_stream_identifier);
107 
114  const std::string data_stream_identifier);
115 
122  const std::string get_shm_id(const std::string data_stream_identifier);
123 
129  int32_t GetMaxPossibleBufferSize(const int32_t max_data_sample_size);
130 
131  protected:
138  bool CheckSpaceAvailability(const int32_t max_data_sample_size,
139  const int buffer_size);
140 
141  private:
148  void Init(DdtLogger *ddt_logger, const std::string broker_port);
149 
154  const uint64_t GetAvailableSpace();
155 
160  std::map<std::string, Shm> shm_map;
161  std::mutex shm_mutex;
162 
163  const std::string shm_file_path = "/tmp/";
164  std::string shm_file;
165  std::string port;
166 
167  DdtLogger *logger;
168 
169  const std::string SHM_PATH = "/dev/shm";
170  const int ADDITIONAL_SPACE = 1500;
171  const int AVAILABLE_POSITION = 3;
172  const int BYTES_PER_KBYTE = 1024;
173  static const int CHAR_LEN = 128;
174 };
175 
176 } // namespace ddt
177 
178 #endif /* DDTMEMORYMANAGER_HPP_ */
ddt::DdtMemoryManager::get_number_of_samples
int32_t get_number_of_samples(const std::string data_stream_identifier)
Definition: ddtMemoryManager.cpp:279
ddtErrorCodes.hpp
ddt::DdtMemoryManager::CheckSpaceAvailability
bool CheckSpaceAvailability(const int32_t max_data_sample_size, const int buffer_size)
Definition: ddtMemoryManager.cpp:342
ddt::DdtLogger
Definition: ddtLogger.hpp:71
ddt::DdtMemoryAccessor
Definition: ddtMemoryAccessor.hpp:258
ddt
Definition: ddtClient.hpp:36
ddt::DdtMemoryManager::GetMaxPossibleBufferSize
int32_t GetMaxPossibleBufferSize(const int32_t max_data_sample_size)
Definition: ddtMemoryManager.cpp:331
ddt::DdtMemoryManager
Definition: ddtMemoryManager.hpp:49
ddt::DdtMemoryManager::CheckIfShmExists
bool CheckIfShmExists(const std::string data_stream_identifier)
Definition: ddtMemoryManager.cpp:79
ddt::DdtMemoryManager::get_max_data_sample_size
int32_t get_max_data_sample_size(const std::string data_stream_identifier)
Definition: ddtMemoryManager.cpp:267
ddt::DdtMemoryManager::get_memory_accessor
DdtMemoryAccessor * get_memory_accessor(const std::string data_stream_identifier)
Definition: ddtMemoryManager.cpp:291
ddt::Shm::managed_shm
ip::managed_shared_memory * managed_shm
Definition: ddtMemoryManager.hpp:40
ddt::DdtMemoryManager::DeleteSharedMemory
bool DeleteSharedMemory(const std::string data_stream_identifier)
Definition: ddtMemoryManager.cpp:232
ddt::Shm
Definition: ddtMemoryManager.hpp:39
ddt::Shm::number_of_samples
int number_of_samples
Definition: ddtMemoryManager.hpp:42
ddt::DdtMemoryManager::get_shm_id
const std::string get_shm_id(const std::string data_stream_identifier)
Definition: ddtMemoryManager.cpp:73
ddt::DdtMemoryManager::CreateSharedMemory
int32_t CreateSharedMemory(const std::string data_stream_identifier, const int32_t max_data_sample_size, const int32_t number_of_samples)
Definition: ddtMemoryManager.cpp:91
ddt::Shm::max_data_sample_size
int max_data_sample_size
Definition: ddtMemoryManager.hpp:41
ddt::Shm::memory_accessor
DdtMemoryAccessor * memory_accessor
Definition: ddtMemoryManager.hpp:43
ddt::DdtMemoryManager::DdtMemoryManager
DdtMemoryManager(DdtLogger *logger, const std::string broker_port)
Definition: ddtMemoryManager.cpp:20
ddt::DdtMemoryManager::~DdtMemoryManager
virtual ~DdtMemoryManager()
ddtLogger.hpp
ddtMemoryAccessor.hpp