1 | // |
---|
2 | // You received this file as part of Finroc |
---|
3 | // A framework for intelligent robot control |
---|
4 | // |
---|
5 | // Copyright (C) Finroc GbR (finroc.org) |
---|
6 | // |
---|
7 | // This program is free software; you can redistribute it and/or modify |
---|
8 | // it under the terms of the GNU General Public License as published by |
---|
9 | // the Free Software Foundation; either version 2 of the License, or |
---|
10 | // (at your option) any later version. |
---|
11 | // |
---|
12 | // This program is distributed in the hope that it will be useful, |
---|
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | // GNU General Public License for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License along |
---|
18 | // with this program; if not, write to the Free Software Foundation, Inc., |
---|
19 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
---|
20 | // |
---|
21 | //---------------------------------------------------------------------- |
---|
22 | /*!\file core/port/tEdgeAggregator.h |
---|
23 | * |
---|
24 | * \author Max Reichardt |
---|
25 | * |
---|
26 | * \date 2012-10-28 |
---|
27 | * |
---|
28 | * \brief Contains tEdgeAggregator |
---|
29 | * |
---|
30 | * \b tEdgeAggregator |
---|
31 | * |
---|
32 | * Framework element that aggregates edges to determine data dependencies |
---|
33 | * between higher level entities (and to collect usage data). |
---|
34 | * Module and group interfaces, for instance, typically do this. |
---|
35 | * |
---|
36 | * This information is valuable for efficient scheduling. |
---|
37 | */ |
---|
38 | //---------------------------------------------------------------------- |
---|
39 | #ifndef __core__port__tEdgeAggregator_h__ |
---|
40 | #define __core__port__tEdgeAggregator_h__ |
---|
41 | |
---|
42 | //---------------------------------------------------------------------- |
---|
43 | // External includes (system with <>, local with "") |
---|
44 | //---------------------------------------------------------------------- |
---|
45 | #include "rrlib/rtti/rtti.h" |
---|
46 | |
---|
47 | //---------------------------------------------------------------------- |
---|
48 | // Internal includes with "" |
---|
49 | //---------------------------------------------------------------------- |
---|
50 | #include "core/tFrameworkElement.h" |
---|
51 | |
---|
52 | //---------------------------------------------------------------------- |
---|
53 | // Namespace declaration |
---|
54 | //---------------------------------------------------------------------- |
---|
55 | namespace finroc |
---|
56 | { |
---|
57 | namespace core |
---|
58 | { |
---|
59 | |
---|
60 | //---------------------------------------------------------------------- |
---|
61 | // Forward declarations / typedefs / enums |
---|
62 | //---------------------------------------------------------------------- |
---|
63 | struct tAggregatedEdge; |
---|
64 | |
---|
65 | //---------------------------------------------------------------------- |
---|
66 | // Class declaration |
---|
67 | //---------------------------------------------------------------------- |
---|
68 | //! Edge aggregating framework element |
---|
69 | /*! |
---|
70 | * Framework element that aggregates edges to determine data dependencies |
---|
71 | * between higher level entities (and to collect usage data). |
---|
72 | * Module and group interfaces, for instance, typically do this. |
---|
73 | * |
---|
74 | * This information is valuable for efficient scheduling. |
---|
75 | */ |
---|
76 | class tEdgeAggregator : public tFrameworkElement |
---|
77 | { |
---|
78 | typedef rrlib::concurrent_containers::tSet < tAggregatedEdge*, rrlib::concurrent_containers::tAllowDuplicates::NO, rrlib::thread::tNoMutex, |
---|
79 | rrlib::concurrent_containers::set::storage::ArrayChunkBased<5, 15, definitions::cSINGLE_THREADED >> tConnectionSet; |
---|
80 | typedef tConnectionSet::tConstIterator tConnectionIterator; |
---|
81 | |
---|
82 | //---------------------------------------------------------------------- |
---|
83 | // Public methods and typedefs |
---|
84 | //---------------------------------------------------------------------- |
---|
85 | public: |
---|
86 | |
---|
87 | /*! see FrameworkElement for parameter description */ |
---|
88 | explicit tEdgeAggregator(tFrameworkElement* parent = NULL, const tString& name = "", tFlags flags = tFlags()); |
---|
89 | |
---|
90 | /*! |
---|
91 | * (Should be called by abstract port only - with runtime registry locked) |
---|
92 | * Notify parent aggregators that edge has been added |
---|
93 | * |
---|
94 | * \param source Source port |
---|
95 | * \param target Target port |
---|
96 | */ |
---|
97 | static void EdgeAdded(tAbstractPort& source, tAbstractPort& target); |
---|
98 | |
---|
99 | /*! |
---|
100 | * (Should be called by abstract port only - with runtime registry locked) |
---|
101 | * Notify parent aggregators that edge has been removed |
---|
102 | * |
---|
103 | * \param source Source port |
---|
104 | * \param target Target port |
---|
105 | */ |
---|
106 | static void EdgeRemoved(tAbstractPort& source, tAbstractPort& target); |
---|
107 | |
---|
108 | /*! |
---|
109 | * \param dest Destination aggregating element |
---|
110 | * \return Edge that connects these elements - or NULL if such an edge does not yet exists |
---|
111 | */ |
---|
112 | tAggregatedEdge* FindAggregatedEdge(tEdgeAggregator& dest); |
---|
113 | |
---|
114 | /*! |
---|
115 | * \param source Port |
---|
116 | * \return EdgeAggregator parent - or null if there's none |
---|
117 | */ |
---|
118 | static tEdgeAggregator* GetAggregator(const tAbstractPort& source); |
---|
119 | |
---|
120 | /*! |
---|
121 | * \return An iterator to iterate over all edge aggregators that this edge aggregators has incoming connections from. |
---|
122 | */ |
---|
123 | tConnectionIterator IncomingConnectionsBegin() const |
---|
124 | { |
---|
125 | return incoming_edges.Begin(); |
---|
126 | } |
---|
127 | |
---|
128 | /*! |
---|
129 | * \return An iterator to iterate over all ports that this port has incoming connections from pointing to the past-the-end element. |
---|
130 | */ |
---|
131 | tConnectionIterator IncomingConnectionsEnd() const |
---|
132 | { |
---|
133 | return incoming_edges.End(); |
---|
134 | } |
---|
135 | |
---|
136 | /*! |
---|
137 | * \return True, if the provided type is a data flow type |
---|
138 | */ |
---|
139 | inline static bool IsDataFlowType(const rrlib::rtti::tType& type) |
---|
140 | { |
---|
141 | return type.GetTypeClassification() != rrlib::rtti::tTypeClassification::RPC_TYPE && type.GetTypeClassification() != rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE; |
---|
142 | } |
---|
143 | |
---|
144 | /*! |
---|
145 | * \return An iterator to iterate over all edge aggregators that this edge aggregators has outgoing connections to. |
---|
146 | */ |
---|
147 | tConnectionIterator OutgoingConnectionsBegin() const |
---|
148 | { |
---|
149 | return emerging_edges.Begin(); |
---|
150 | } |
---|
151 | |
---|
152 | /*! |
---|
153 | * \return An iterator to iterate over all ports that this port has outgoing connections to pointing to the past-the-end element. |
---|
154 | */ |
---|
155 | tConnectionIterator OutgoingConnectionsEnd() const |
---|
156 | { |
---|
157 | return emerging_edges.End(); |
---|
158 | } |
---|
159 | |
---|
160 | /*! |
---|
161 | * Update Edge Statistics: Called every time when data has been published |
---|
162 | * |
---|
163 | * \param source Source port |
---|
164 | * \param target Destination port |
---|
165 | * \param estimated_data_size Data Size of data |
---|
166 | */ |
---|
167 | static void UpdateEdgeStatistics(tAbstractPort& source, tAbstractPort& target, size_t estimated_data_size); |
---|
168 | |
---|
169 | //---------------------------------------------------------------------- |
---|
170 | // Private fields and methods |
---|
171 | //---------------------------------------------------------------------- |
---|
172 | private: |
---|
173 | |
---|
174 | /*! Set of emerging aggregated edges */ |
---|
175 | tConnectionSet emerging_edges; |
---|
176 | |
---|
177 | /*! Set of incoming aggregated edges */ |
---|
178 | tConnectionSet incoming_edges; |
---|
179 | |
---|
180 | /*! |
---|
181 | * Called when edge has been added that is relevant for this element |
---|
182 | * |
---|
183 | * \param dest Destination aggregating element |
---|
184 | * \param data_flow_type Was a data flow edge added? |
---|
185 | */ |
---|
186 | void EdgeAdded(tEdgeAggregator& dest, bool data_flow_type); |
---|
187 | |
---|
188 | /*! |
---|
189 | * Called when edge has been added that is relevant for this element |
---|
190 | * |
---|
191 | * \param dest Destination aggregating element |
---|
192 | * \param data_flow_type Was a data flow edge added? |
---|
193 | */ |
---|
194 | void EdgeRemoved(tEdgeAggregator& dest, bool data_flow_type); |
---|
195 | |
---|
196 | }; |
---|
197 | |
---|
198 | //---------------------------------------------------------------------- |
---|
199 | // End of namespace declaration |
---|
200 | //---------------------------------------------------------------------- |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | #endif |
---|