DDS  ver. 1.6
KeyValueManager.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef __DDS__KeyValueManager__
6 #define __DDS__KeyValueManager__
7 
8 // DDS
9 #include "DeleteKeyCmd.h"
10 #include "Topology.h"
11 #include "UpdateKeyCmd.h"
12 // STD
13 #include <map>
14 #include <mutex>
15 
16 namespace dds
17 {
18  namespace commander_cmd
19  {
25 
32  {
33  typedef std::shared_ptr<SKeyValueRecord> ptr_t;
34  typedef std::weak_ptr<SKeyValueRecord> wptr_t;
35  // task ID --> STaskKeyValue
36  typedef std::multimap<uint64_t, SKeyValueRecord::ptr_t> taskMap_t;
37  // key --> STaskKeyValue
38  // typedef std::map<std::string, SKeyValueRecord::ptr_t> keyMap_t;
39 
42 
44  void deleteKeyValue();
45  std::string getKeyValueString() const;
46 
47  friend std::ostream& operator<<(std::ostream& _stream, const SKeyValueRecord& _value);
48 
49  private:
50  mutable std::mutex m_mutex;
51  protocol_api::SUpdateKeyCmd m_keyValue;
52  bool m_deleted;
53  };
54 
55  inline std::ostream& operator<<(std::ostream& _stream, const SKeyValueRecord& _value)
56  {
57  std::lock_guard<std::mutex> lock(_value.m_mutex);
58 
59  return _stream << "SKeyValueRecord cmd: " << _value.m_keyValue << " deleted: " << _value.m_deleted;
60  }
61 
65  {
66  typedef std::shared_ptr<SPropertyRecord> ptr_t;
67  typedef std::weak_ptr<SPropertyRecord> wptr_t;
68  // property --> SPropertyRecord
69  typedef std::map<std::string, SPropertyRecord::ptr_t> propertyMap_t;
70 
72  ~SPropertyRecord();
73 
74  void addKeyValueRecord(uint64_t _taskID, SKeyValueRecord::ptr_t _keyValueRecord);
75 
77 
78  std::string getKeyValueString() const;
79 
80  friend std::ostream& operator<<(std::ostream& _stream, const SPropertyRecord& _value);
81 
82  private:
84  };
85 
86  inline std::ostream& operator<<(std::ostream& _stream, const SPropertyRecord& _value)
87  {
88  _stream << "SPropertyRecord\n";
89  for (const auto& v : _value.m_taskMap)
90  {
91  _stream << " " << v.first << " --> " << *(v.second) << "\n";
92  }
93  return _stream;
94  }
95 
106  {
107  public:
109  ~CKeyValueManager();
110 
111  void initWithTopology(const topology_api::CTopology& _topology);
112  void updateWithTopology(const topology_api::CTopology& _topology,
113  const topology_api::CTopology::HashSet_t& _removedTasks,
114  const topology_api::CTopology::HashSet_t& _addedTasks);
116  void deleteKeyValue(uint64_t _taskID);
117 
118  std::string getKeyValueString(const std::string _propertyID) const;
119  std::string getPropertyString() const;
120 
121  friend std::ostream& operator<<(std::ostream& _stream, const CKeyValueManager& _value);
122 
123  private:
124  void initWithTopologyImpl(const topology_api::CTopology& _topology,
125  const topology_api::CTopology::HashSet_t* _addedTasks);
126 
127  SPropertyRecord::propertyMap_t m_propertyMap;
128  // The map is used to query specific records by task ID, for example, to fetch or delete all records for a
129  // specific task ID.
130  SKeyValueRecord::taskMap_t m_taskMap;
131  };
132 
133  inline std::ostream& operator<<(std::ostream& _stream, const CKeyValueManager& _value)
134  {
135  _stream << "CKeyValueManager\n";
136  _stream << "[Property map]\n";
137  for (const auto& v : _value.m_propertyMap)
138  {
139  _stream << " " << v.first << " --> " << *(v.second) << "\n";
140  }
141  _stream << "[Task map]\n";
142  for (const auto& v : _value.m_taskMap)
143  {
144  _stream << " " << v.first << " --> " << *(v.second) << "\n";
145  }
146 
147  return _stream;
148  }
149  }
150 }
151 
152 #endif /* defined(__DDS__KeyValueManager__) */
std::multimap< uint64_t, SKeyValueRecord::ptr_t > taskMap_t
Definition: KeyValueManager.h:36
Definition: UpdateKeyCmd.h:14
bool updateKeyValue(const protocol_api::SUpdateKeyCmd &_cmd, protocol_api::SUpdateKeyCmd &_serverCmd)
Definition: KeyValueManager.cpp:31
TODO: Key-Value has to provide a possibility to properly react on the errors. If Key-Value was not sa...
Definition: KeyValueManager.h:31
friend std::ostream & operator<<(std::ostream &_stream, const SKeyValueRecord &_value)
Definition: KeyValueManager.h:55
std::map< std::string, SPropertyRecord::ptr_t > propertyMap_t
Definition: KeyValueManager.h:69
std::set< uint64_t > HashSet_t
Definition: Topology.h:63
std::string getKeyValueString() const
Definition: KeyValueManager.cpp:54
Definition: dds-agent/src/AgentConnectionManager.h:16
Definition: Topology.h:42
Key-value manager for the DDS commander.
Definition: KeyValueManager.h:105
void deleteKeyValue()
Definition: KeyValueManager.cpp:47
~SKeyValueRecord()
Definition: KeyValueManager.cpp:27
SKeyValueRecord()
Definition: KeyValueManager.cpp:20
std::weak_ptr< SPropertyRecord > wptr_t
Definition: KeyValueManager.h:67
Container for the key-value records with the same property ID.
Definition: KeyValueManager.h:64
std::shared_ptr< SPropertyRecord > ptr_t
Definition: KeyValueManager.h:66
std::weak_ptr< SKeyValueRecord > wptr_t
Definition: KeyValueManager.h:34
std::shared_ptr< SKeyValueRecord > ptr_t
Definition: KeyValueManager.h:33