lintel 0.2.0
Loading...
Searching...
No Matches
SharedMemoryPropertyRepository.h
Go to the documentation of this file.
1#ifndef LINTEL_SHAREDMEMORYPROPERTYREPOSITORY_H
2#define LINTEL_SHAREDMEMORYPROPERTYREPOSITORY_H
3
4#include <boost/interprocess/sync/named_upgradable_mutex.hpp>
5
9
10namespace lintel {
35
38{
39private:
40 // constexpr char* instead of std::string: static initialization can then not
41 // throw (clang-tidy cert-err58-cpp).
42 static struct Shapes
43 {
44 static constexpr const char *PROCESS_NAME = "process_name";
45 static constexpr const char *CLASS_NAME = "class_name";
46 static constexpr const char *INSTANCE_NAME = "instance_name";
47 static constexpr const char *NAME = "name";
48 static constexpr const char *VALUE = "value";
49 static constexpr const char *TYPE = "type";
50 } m_shape;
51
52 const PropertyDataDto &m_dto;
53
54public:
56
57 void serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const override
58 {
59 writer->StartObject();
60 writer->String(m_shape.PROCESS_NAME);
61 writer->String(m_dto.m_processName.c_str());
62 writer->String(m_shape.CLASS_NAME);
63 writer->String(m_dto.m_className.c_str());
64 writer->String(m_shape.INSTANCE_NAME);
65 writer->String(m_dto.m_instanceName.c_str());
66 writer->String(m_shape.NAME);
67 writer->String(m_dto.m_name.c_str());
68 writer->String(m_shape.VALUE);
69 writer->String(m_dto.m_value.c_str());
70 writer->String(m_shape.TYPE);
71 writer->String(m_dto.m_type.c_str());
72 writer->EndObject();
73 }
74
75 bool deserialize(const rapidjson::Value &obj) override
76 {
77 bool success = true;
78 if (!obj.IsObject()) { return false; }
79 if (!obj.HasMember(m_shape.PROCESS_NAME)) {
80 success = false;
81 LOG_ERROR("{} not defined in json serialization", m_shape.PROCESS_NAME);
82 }
83 if (!obj.HasMember(m_shape.CLASS_NAME)) {
84 success = false;
85 LOG_ERROR("{} not defined in json serialization", m_shape.CLASS_NAME);
86 }
87 if (!obj.HasMember(m_shape.INSTANCE_NAME)) {
88 success = false;
89 LOG_ERROR("{} not defined in json serialization", m_shape.INSTANCE_NAME);
90 }
91 if (!obj.HasMember(m_shape.NAME)) {
92 success = false;
93 LOG_ERROR("{} not defined in json serialization", m_shape.NAME);
94 }
95 if (!obj.HasMember(m_shape.VALUE)) {
96 success = false;
97 LOG_ERROR("{} not defined in json serialization", m_shape.VALUE);
98 }
99 if (!obj.HasMember(m_shape.TYPE)) {
100 success = false;
101 LOG_ERROR("{} not defined in json serialization", m_shape.TYPE);
102 }
103 return success;
104 }
105};
106
109 : public SharedMemoryMapRepository<shm::String, PropertyDataDto, shm::String, PropertyDataDao>
110 , public PropertyRepository
111{
112private:
113 static constexpr int32_t m_version = 0;
114 std::shared_ptr<ProcessName> m_processName;
116 mutable boost::interprocess::named_upgradable_mutex m_upgradableMutex;
117 static constexpr std::string_view UUID = "B3F746E1-D4F0-49DB-A0F7-51F72436263A";
118
119protected:
120 void onAcquireReadLock() const override { m_upgradableMutex.lock_sharable(); }
121
122 void onReleaseReadLock() const override { m_upgradableMutex.unlock_sharable(); }
123
124public:
125 SharedMemoryPropertyRepository(const std::shared_ptr<SharedMemoryService> &sharedMemoryService,
126 const std::shared_ptr<SharedMemorySegmentManager> &sharedMemorySegmentManager,
127 const std::shared_ptr<Configuration> &configuration,
128 std::shared_ptr<ProcessName> processName);
129
131
132 void save(const std::vector<std::shared_ptr<PropertyBase>> &properties) override;
133
134 void save(std::shared_ptr<PropertyBase> property) override;
135
136 std::vector<std::shared_ptr<PropertyBase>> awake() override;
137
138 std::vector<std::shared_ptr<PropertyBase>> allOf(const std::string &processName,
139 const std::string &className,
140 const std::string &instanceName,
141 const std::string &name) override;
142
144
145 void deleteOf(const std::vector<std::shared_ptr<PropertyBase>> &properties) override;
146};
147
148}// namespace lintel
149#endif// LINTEL_SHAREDMEMORYPROPERTYREPOSITORY_H
#define LOG_ERROR(message,...)
Definition LoggerService.h:130
Definition DataStorage.h:13
Definition JsonSerializable.h:17
Definition SharedMemoryPropertyRepository.h:38
void serialize(rapidjson::Writer< rapidjson::StringBuffer > *writer) const override
Definition SharedMemoryPropertyRepository.h:57
PropertyDataDao(const PropertyDataDto &dto)
Definition SharedMemoryPropertyRepository.h:55
bool deserialize(const rapidjson::Value &obj) override
Definition SharedMemoryPropertyRepository.h:75
@ SHM_REPOSITORY
Definition PropertyRepositoryType.h:19
Definition PropertyRepository.h:18
Definition SharedMemoryRepository.h:249
Definition SharedMemoryPropertyRepository.h:111
void onMigrate(int32_t currentActiveVersion) override
void save(std::shared_ptr< PropertyBase > property) override
DataStorage getDataStorage() override
std::vector< std::shared_ptr< PropertyBase > > awake() override
SharedMemoryPropertyRepository(const std::shared_ptr< SharedMemoryService > &sharedMemoryService, const std::shared_ptr< SharedMemorySegmentManager > &sharedMemorySegmentManager, const std::shared_ptr< Configuration > &configuration, std::shared_ptr< ProcessName > processName)
void deleteOf(const std::vector< std::shared_ptr< PropertyBase > > &properties) override
std::vector< std::shared_ptr< PropertyBase > > allOf(const std::string &processName, const std::string &className, const std::string &instanceName, const std::string &name) override
void onAcquireReadLock() const override
Definition SharedMemoryPropertyRepository.h:120
void onReleaseReadLock() const override
Definition SharedMemoryPropertyRepository.h:122
void save(const std::vector< std::shared_ptr< PropertyBase > > &properties) override
Definition UUID.h:9
boost::container::basic_string< char, std::char_traits< char >, SegmentAllocator< char > > String
Definition ShmConstructors.h:57
Definition BaseFeature.h:6
constexpr std::string_view type_name()
Definition TypeName.h:9
Definition SharedMemoryPropertyRepository.h:13
shm::String m_value
Definition SharedMemoryPropertyRepository.h:18
shm::String m_processName
Definition SharedMemoryPropertyRepository.h:14
bool operator!=(const PropertyDataDto &rhs) const
bool operator==(const PropertyDataDto &rhs) const
bool operator>(const PropertyDataDto &rhs) const
bool operator<(const PropertyDataDto &rhs) const
shm::String m_type
Definition SharedMemoryPropertyRepository.h:19
shm::String m_className
Definition SharedMemoryPropertyRepository.h:15
bool operator>=(const PropertyDataDto &rhs) const
shm::String m_name
Definition SharedMemoryPropertyRepository.h:17
static int32_t getSize()
Definition SharedMemoryPropertyRepository.h:21
bool operator<=(const PropertyDataDto &rhs) const
shm::String m_instanceName
Definition SharedMemoryPropertyRepository.h:16