@@ -138,10 +138,8 @@ class UcConnectionGenerator(
138
138
} else {
139
139
UcChannelQueue (portVarRef, emptyList())
140
140
}
141
-
142
141
}
143
142
144
-
145
143
companion object {
146
144
private val Connection .delayString
147
145
get(): String = this .delay.orNever().toCCode()
@@ -151,6 +149,11 @@ class UcConnectionGenerator(
151
149
/* * A global list of FederatedConnectionBundles. It is computed once and reused when code-generating */
152
150
private var allFederatedConnectionBundles: List <UcFederatedConnectionBundle > = emptyList()
153
151
152
+ /* *
153
+ * This function takes a list of grouped connections and creates the necessary FederatedConnectionBundles.
154
+ * The bundles are written to the global variable allFederatedConnectionBundles and shared accross federates.
155
+ * Thus, this function should only be called once during code-gen.
156
+ */
154
157
private fun createFederatedConnectionBundles (groupedConnections : List <UcGroupedConnection >) {
155
158
val groupedSet = HashSet (groupedConnections)
156
159
val bundles = mutableListOf<UcFederatedConnectionBundle >()
@@ -181,14 +184,15 @@ class UcConnectionGenerator(
181
184
}
182
185
183
186
init {
187
+ // Only pass through all federates and add NetworkInterface objects to them once.
184
188
if (isFederated && ! federateInterfacesInitialized) {
185
189
for (fed in allFederates) {
186
190
UcNetworkInterfaceFactory .createInterfaces(fed).forEach { fed.addInterface(it) }
187
191
}
188
192
federateInterfacesInitialized = true
189
193
}
190
194
191
- // Only parse out federated connection bundles once for the very first federate
195
+ // Parse out all GroupedConnections. Note that this is repeated for each federate.
192
196
val channels = mutableListOf<UcConnectionChannel >()
193
197
reactor.allConnections.forEach { channels.addAll(parseConnectionChannels(it, allFederates)) }
194
198
val grouped = groupConnections(channels)
@@ -212,10 +216,11 @@ class UcConnectionGenerator(
212
216
.filter { it.channels.fold(true ) { acc, c -> acc && (c.src.federate == currentFederate) } }
213
217
)
214
218
} else {
219
+ // In the non-federated case, all grouped connections are handled togehter.
215
220
nonFederatedConnections.addAll(grouped)
216
221
}
217
222
218
- // Assign a unique ID to each connection to avoid possible naming conflicts.
223
+ // Assign a unique ID to each connection to avoid possible naming conflicts in the generated code .
219
224
val allGroupedConnections =
220
225
federatedConnectionBundles.map { it.groupedConnections }.flatten().plus(nonFederatedConnections)
221
226
allGroupedConnections.forEachIndexed { idx, el ->
0 commit comments