DDS  ver. 2.0
Topology.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 
6 #ifndef __DDS__Topology__
7 #define __DDS__Topology__
8 
9 // DDS Topo
10 #include "Task.h"
11 #include "TaskCollection.h"
12 #include "TaskGroup.h"
13 #include "TopoElement.h"
14 #include "TopoIndex.h"
15 // STD
16 #include <map>
17 #include <ostream>
18 #include <set>
19 #include <string>
20 // BOOST
21 #include <boost/iterator/filter_iterator.hpp>
22 
23 namespace dds
24 {
25  namespace topology_api
26  {
27  struct STaskInfo
28  {
30  : m_task(nullptr)
31  , m_taskIndex(0)
32  , m_collectionIndex(std::numeric_limits<uint32_t>::max())
33  , m_taskPath()
34  {
35  }
37  size_t m_taskIndex;
39  std::string m_taskPath;
40  };
41 
42  class CTopology
43  {
44  public:
47  typedef std::map<uint64_t, STaskInfo> HashToTaskInfoMap_t;
48  typedef std::function<bool(std::pair<uint64_t, const STaskInfo&>)> TaskInfoCondition_t;
49  typedef boost::filter_iterator<TaskInfoCondition_t, HashToTaskInfoMap_t::const_iterator> TaskInfoIterator_t;
50  typedef std::pair<TaskInfoIterator_t, TaskInfoIterator_t> TaskInfoIteratorPair_t;
51 
52  typedef std::map<uint64_t, TaskCollectionPtr_t> HashToTaskCollectionMap_t;
53  typedef std::function<bool(std::pair<uint64_t, TaskCollectionPtr_t>)> TaskCollectionCondition_t;
54  typedef boost::filter_iterator<TaskCollectionCondition_t, HashToTaskCollectionMap_t::const_iterator>
56  typedef std::pair<TaskCollectionIterator_t, TaskCollectionIterator_t> TaskCollectionIteratorPair_t;
57 
58  typedef std::map<std::string, TaskPtr_t> HashPathToTaskMap_t;
59  typedef std::map<std::string, TaskCollectionPtr_t> HashPathToTaskCollectionMap_t;
60  typedef std::map<CTopoIndex, TopoElementPtr_t, CompareTopoIndexLess> TopoIndexToTopoElementMap_t;
61  typedef std::map<uint64_t, std::vector<uint64_t>> CollectionHashToTaskHashesMap_t;
62 
63  typedef std::set<uint64_t> HashSet_t;
64 
66  CTopology();
67 
69  virtual ~CTopology();
70 
73  void init(const std::string& _fileName, bool _initForTest = false);
74 
81  void getDifference(const CTopology& _topology,
82  HashSet_t& _removedTasks,
83  HashSet_t& _removedCollections,
84  HashSet_t& _addedTasks,
85  HashSet_t& _addedCollections);
86 
87  void setXMLValidationDisabled(bool _val);
88 
90  TaskGroupPtr_t getMainGroup() const;
91  TopoElementPtr_t getTopoElementByTopoIndex(const CTopoIndex& _index) const;
92  TaskPtr_t getTaskByHash(uint64_t _hash) const;
93  const STaskInfo& getTaskInfoByHash(uint64_t _hash) const;
94  TaskCollectionPtr_t getTaskCollectionByHash(uint64_t _hash) const;
95  const std::vector<uint64_t>& getTaskHashesByTaskCollectionHash(uint64_t _hash) const;
96  TaskPtr_t getTaskByHashPath(const std::string& _hashPath) const;
97 
99  const TopoIndexToTopoElementMap_t& getTopoIndexToTopoElementMap() const;
100  const HashToTaskInfoMap_t& getHashToTaskInfoMap() const;
101  const HashToTaskCollectionMap_t& getHashToTaskCollectionMap() const;
102  const HashPathToTaskMap_t& getHashPathToTaskMap() const;
103  const HashPathToTaskCollectionMap_t& getHashPathToTaskCollectionMap() const;
104 
106  TaskInfoIteratorPair_t getTaskInfoIterator(TaskInfoCondition_t _condition = nullptr) const;
107  TaskCollectionIteratorPair_t getTaskCollectionIterator(
108  TaskCollectionCondition_t _condition = nullptr) const;
109  TaskInfoIteratorPair_t getTaskInfoIteratorForPropertyId(const std::string& _propertyId) const;
110 
111  std::string stringOfTasks(const HashSet_t& _ids) const;
112  std::string stringOfCollections(const HashSet_t& _ids) const;
113 
116  virtual std::string toString() const;
117 
121  friend std::ostream& operator<<(std::ostream& _strm, const CTopology& _topology);
122 
123  private:
124  void FillTopoIndexToTopoElementMap(const TopoElementPtr_t& _element);
125  void FillHashToTopoElementMap(const TopoElementPtr_t& _element, bool _fillHashPathMaps = false);
126 
127  uint64_t getNextHashForTask(uint64_t _crc) const;
128  uint64_t getNextHashForTaskCollection(uint64_t _crc) const;
129 
130  TaskGroupPtr_t m_main;
131 
132  TopoIndexToTopoElementMap_t m_topoIndexToTopoElementMap;
133 
134  HashToTaskCollectionMap_t m_hashToTaskCollectionMap;
135  HashToTaskInfoMap_t m_hashToTaskInfoMap;
136  std::map<std::string, size_t> m_counterMap;
137  std::string m_currentTaskCollectionHashPath;
138  uint64_t m_currentTaskCollectionCrc;
139 
140  CollectionHashToTaskHashesMap_t m_collectionHashToTaskHashesMap;
141 
142  // FIXME: Hash path maps has to be removed due to performance reasons.
143  // In any case we do not need them.
144  // For the moment we store them only for tests.
145  HashPathToTaskMap_t m_hashPathToTaskMap;
146  HashPathToTaskCollectionMap_t m_hashPathToTaskCollectionMap;
147 
148  bool m_bXMLValidationDisabled;
149  };
150  }
151 }
152 #endif /* defined(__DDS__Topology__) */
std::string m_taskPath
Definition: Topology.h:39
size_t m_collectionIndex
Definition: Topology.h:38
Definition: TopoIndex.h:16
std::map< uint64_t, STaskInfo > HashToTaskInfoMap_t
Note that hash is of type uint_64. Hash is calculated using CRC64 algorithm.
Definition: Topology.h:47
boost::filter_iterator< TaskCollectionCondition_t, HashToTaskCollectionMap_t::const_iterator > TaskCollectionIterator_t
Definition: Topology.h:55
size_t m_taskIndex
Definition: Topology.h:37
std::pair< TaskCollectionIterator_t, TaskCollectionIterator_t > TaskCollectionIteratorPair_t
Definition: Topology.h:56
std::function< bool(std::pair< uint64_t, const STaskInfo & >)> TaskInfoCondition_t
Definition: Topology.h:48
std::shared_ptr< CTaskCollection > TaskCollectionPtr_t
Definition: TaskCollection.h:47
std::map< CTopoIndex, TopoElementPtr_t, CompareTopoIndexLess > TopoIndexToTopoElementMap_t
Definition: Topology.h:60
Definition: Topology.h:27
std::set< uint64_t > HashSet_t
Definition: Topology.h:63
std::map< uint64_t, TaskCollectionPtr_t > HashToTaskCollectionMap_t
Definition: Topology.h:52
Definition: dds-agent/src/AgentConnectionManager.h:18
std::map< uint64_t, std::vector< uint64_t > > CollectionHashToTaskHashesMap_t
Definition: Topology.h:61
std::function< bool(std::pair< uint64_t, TaskCollectionPtr_t >)> TaskCollectionCondition_t
Definition: Topology.h:53
Definition: Topology.h:42
boost::filter_iterator< TaskInfoCondition_t, HashToTaskInfoMap_t::const_iterator > TaskInfoIterator_t
Definition: Topology.h:49
std::pair< TaskInfoIterator_t, TaskInfoIterator_t > TaskInfoIteratorPair_t
Definition: Topology.h:50
std::shared_ptr< CTask > TaskPtr_t
Definition: dds-topology-lib/src/Task.h:93
std::map< std::string, TaskPtr_t > HashPathToTaskMap_t
Definition: Topology.h:58
TaskPtr_t m_task
Definition: Topology.h:36
std::ostream & operator<<(std::ostream &_out, EAgentCmdType &_agentCmd)
Definition: dds-agent-cmd/src/Options.h:45
std::map< std::string, TaskCollectionPtr_t > HashPathToTaskCollectionMap_t
Definition: Topology.h:59
STaskInfo()
Definition: Topology.h:29
std::shared_ptr< CTaskGroup > TaskGroupPtr_t
Definition: TaskGroup.h:55
std::shared_ptr< CTopoElement > TopoElementPtr_t
Definition: TopoElement.h:42