Skip to content

Commit 9b511cf

Browse files
committed
allow several rounds of executing instructions to e.g. support load within load
1 parent c68b281 commit 9b511cf

1 file changed

Lines changed: 58 additions & 53 deletions

File tree

src/lib/ebus/message.cpp

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,67 +2490,72 @@ result_t MessageMap::resolveCondition(void (*readMessageFunc)(Message* message),
24902490

24912491
result_t MessageMap::executeInstructions(void (*readMessageFunc)(Message* message), ostringstream* log) {
24922492
result_t overallResult = RESULT_OK;
2493-
vector<string> remove;
2494-
for (auto& it : m_instructions) {
2495-
auto instructions = it.second;
2496-
bool removeSingletons = false;
2497-
vector<Instruction*> remain;
2498-
for (const auto instruction : instructions) {
2499-
if (!m_addAll && removeSingletons && instruction->isSingleton()) {
2500-
delete instruction;
2501-
continue;
2502-
}
2503-
Condition* condition = instruction->getCondition();
2504-
bool execute = m_addAll || condition == nullptr;
2505-
if (!execute) {
2506-
string errorDescription;
2507-
result_t result = resolveCondition(instruction->isSingleton()?readMessageFunc:nullptr, condition,
2508-
&errorDescription);
2509-
if (result != RESULT_OK) {
2510-
overallResult = result;
2511-
*log << "error resolving condition for \"";
2512-
instruction->getDestination(log);
2513-
*log << "\": " << getResultCode(result);
2514-
if (!errorDescription.empty()) {
2515-
*log << " " << errorDescription;
2516-
}
2517-
} else if (condition->isTrue()) {
2518-
execute = true;
2493+
size_t maxRounds = 3, cntBefore, cntAfter;
2494+
do {
2495+
cntBefore = cntAfter = m_instructions.size();
2496+
vector<string> remove;
2497+
for (auto& it : m_instructions) {
2498+
auto instructions = it.second;
2499+
bool removeSingletons = false;
2500+
vector<Instruction*> remain;
2501+
for (const auto instruction : instructions) {
2502+
if (!m_addAll && removeSingletons && instruction->isSingleton()) {
2503+
delete instruction;
2504+
continue;
25192505
}
2520-
}
2521-
if (execute) {
2522-
if (!m_addAll && instruction->isSingleton()) {
2523-
removeSingletons = true;
2506+
Condition* condition = instruction->getCondition();
2507+
bool execute = m_addAll || condition == nullptr;
2508+
if (!execute) {
2509+
string errorDescription;
2510+
result_t result = resolveCondition(instruction->isSingleton()?readMessageFunc:nullptr, condition,
2511+
&errorDescription);
2512+
if (result != RESULT_OK) {
2513+
overallResult = result;
2514+
*log << "error resolving condition for \"";
2515+
instruction->getDestination(log);
2516+
*log << "\": " << getResultCode(result);
2517+
if (!errorDescription.empty()) {
2518+
*log << " " << errorDescription;
2519+
}
2520+
} else if (condition->isTrue()) {
2521+
execute = true;
2522+
}
25242523
}
2525-
result_t result = instruction->execute(this, log);
2526-
if (result != RESULT_OK) {
2527-
overallResult = result;
2524+
if (execute) {
2525+
if (!m_addAll && instruction->isSingleton()) {
2526+
removeSingletons = true;
2527+
}
2528+
result_t result = instruction->execute(this, log);
2529+
if (result != RESULT_OK) {
2530+
overallResult = result;
2531+
}
2532+
delete instruction;
2533+
} else {
2534+
remain.push_back(instruction);
25282535
}
2529-
delete instruction;
2530-
} else {
2531-
remain.push_back(instruction);
25322536
}
2533-
}
2534-
if (removeSingletons && !remain.empty()) {
2535-
instructions = remain;
2536-
remain.clear();
2537-
for (const auto instruction : instructions) {
2538-
if (!instruction->isSingleton()) {
2539-
remain.push_back(instruction);
2540-
continue;
2537+
if (removeSingletons && !remain.empty()) {
2538+
instructions = remain;
2539+
remain.clear();
2540+
for (const auto instruction : instructions) {
2541+
if (!instruction->isSingleton()) {
2542+
remain.push_back(instruction);
2543+
continue;
2544+
}
2545+
delete instruction;
25412546
}
2542-
delete instruction;
2547+
}
2548+
if (remain.empty()) {
2549+
remove.push_back(it.first);
2550+
} else {
2551+
it.second = remain;
25432552
}
25442553
}
2545-
if (remain.empty()) {
2546-
remove.push_back(it.first);
2547-
} else {
2548-
it.second = remain;
2554+
cntAfter = m_instructions.size();
2555+
for (const auto& it : remove) {
2556+
m_instructions.erase(it);
25492557
}
2550-
}
2551-
for (const auto& it : remove) {
2552-
m_instructions.erase(it);
2553-
}
2558+
} while (overallResult == RESULT_OK && cntAfter>cntBefore && --maxRounds>0);
25542559
return overallResult;
25552560
}
25562561

0 commit comments

Comments
 (0)