12#ifndef __MODULEORDER_HPP__
13#define __MODULEORDER_HPP__
15#include "mainModule.hpp"
24static bitmapVal_t errC = 0;
25static const Module_t *errorVec[maxModules] = {0};
31 bitmapVal_t dependencies = 0U;
32 bitmapVal_t *depList[maxModules] = {0};
33 Node(
const Module_t *module, bitmapVal_t nID) :
module{module}, nID{nID} {
37bool finder(
Node *n, std::map<bitmapVal_t, Node *> &nodesR, std::list<Node *> &error,
bool &done) {
38 if (nodesR[n->nID]->marked) {
42 nodesR[n->nID]->marked =
true;
44 for (bitmapVal_t *v : n->depList) {
47 auto node = nodesR.find(*v);
48 if (node != nodesR.end()) {
49 if (finder(node->second, nodesR, error, done)) {
50 if (!done && error.front()->nID != n->nID)
61bool Manager_t::orderModules() {
63 std::list<Node *> nodes;
65 bitmapVal_t
final = 0;
66 bitmapVal_t mapped = 0;
71 Log.
d(ID,
"Mapping module nodes");
74 for (
size_t i = 0; i < s_id; i++) {
78 bitmapVal_t dC = allModules[i]->count;
81 Log.
d(ID,
"Root node", node->nID);
84 newModules[c++] = node->module;
87 Log.
d(ID,
"Dependent node", node->nID);
88 const Module_t *
const *dependents = allModules[i]->dependents;
89 for (
size_t j = 0; j < allModules[i]->count; j++) {
91 Log.
d(ID,
" ├─ Dependency", dep->id);
92 node->dependencies |= dep->id;
95 Log.
d(ID,
" └ Final dependencies", node->dependencies);
96 nodes.push_back(node);
103 Log.
d(ID,
"Tracing graph");
105 while (mapped !=
final) {
106 bitmapVal_t _mapped = mapped;
108 typename std::list<Node *>::iterator iter;
110 for (iter = nodes.begin(); iter != nodes.end();) {
112 if ((mapped & node->dependencies) && !(~mapped & node->dependencies)) {
113 _mapped |= node->nID;
114 newModules[c++] = node->module;
116 iter = nodes.erase(iter);
124 Log.
f(ID,
"Circular dependency detected");
126 std::list<Node *> error;
128 std::map<bitmapVal_t, Node *> nodesR;
129 for (
Node *node : nodes) {
130 nodesR[node->nID] = node;
135 for (
Node *node : nodes) {
136 if (finder(node, nodesR, error, done))
139 for (
auto &n : nodesR) {
140 n.second->marked =
false;
144 for (
Node *node : error) {
145 errorVec[errC++] = node->module;
147#if CONF_LOGGING_ASCII_DEBUG
148 for (bitmapVal_t i = 0; i < errC - 1; i++) {
149 Serial.print(errorVec[i]->
id);
150 Serial.print(
" <---> ");
152 Serial.println(errorVec[errC - 1]->
id);
154 for (bitmapVal_t i = 0; i < errC - 1; i++) {
155 Log.
e(ID,
"Depends on vv", errorVec[i]->
id);
157 Log.
e(ID,
"Circles back to start ^^", errorVec[errC - 1]->
id);
167 for (
Node *node : nodes) {
171 Log.
d(ID,
"Modules ordered", c);
173 std::copy(newModules, newModules + s_id, allModules);
Logging::Log_t Log
The global logging object.
Module_t should be used for major components of a framework, it is used to isolate,...
void d(LOG_TAG TAG, LOG_MSG message)
Log a string using a debug tag.
void e(LOG_TAG TAG, LOG_MSG message)
Log a string using an error tag.
void f(LOG_TAG TAG, LOG_MSG message)
Log a string using a fatal tag.