DEV: contains() data path added to sequencer (as else) and to cli_device

This commit is contained in:
2021-10-25 15:58:47 +03:00
parent 887bbf391e
commit fce49ee963
2 changed files with 105 additions and 70 deletions
+40 -9
View File
@@ -115,8 +115,9 @@ class sequencer {
EXPECT, //!< Expects data from implementation via get()
OR_EXPECT, //!< Expects data from implementation via get() in conjunction with previous EXPECT
DETECT, //!< Detects data into rx buffer without receiving them via contents()
OR_DETECT //!< Detects data into rx buffer without receiving them via contents() in conjunction with
OR_DETECT, //!< Detects data into rx buffer without receiving them via contents() in conjunction with
//!< previous DETECT
OTHERWISE //!< An "else" path if the EXPECT[, OR_EXPECT[, OR_EXPECT ... ]] block timesout.
//! \note
//! The \c DETECT extra incoming channel serve the purpose of sneak into receive
@@ -346,6 +347,7 @@ class sequencer {
case control_t::OR_EXPECT: skip_while = control_t::OR_EXPECT; break;
case control_t::DETECT:
case control_t::OR_DETECT: skip_while = control_t::OR_DETECT; break;
case control_t::OTHERWISE: skip_while = control_t::OTHERWISE; break;
}
s = step;
while (script[++s].control == skip_while)
@@ -357,6 +359,17 @@ class sequencer {
}
}
template <size_t Steps>
size_t expect_end (const script_t<Steps>& script, size_t step) {
while ((++step < Steps) && (script[step].control == control_t::OR_EXPECT)) ;
return step;
}
template <size_t Steps>
size_t detect_end (const script_t<Steps>& script, size_t step) {
while ((++step < Steps) && (script[step].control == control_t::OR_DETECT)) ;
return step;
}
//! @}
@@ -452,34 +465,52 @@ class sequencer {
case control_t::OR_EXPECT:
resp_size = get_(buffer);
if (resp_size) {
size_t s = step ; do{
for (size_t s = step ; s < expect_end(script, step) ; ++s) {
if (script[s].match != nullptr && script[s].match({buffer, resp_size}, script[s].token)) {
handle_ (script[s].handler, {buffer, resp_size});
std::tie(step, status) = action_ (script, s);
break;
}
} while ((++s < Steps) && (script[s].control == control_t::OR_EXPECT));
}
}
if (record.timeout && (clock_() - mark) >= record.timeout) {
size_t s = expect_end(script, step);
if ((s < Steps) && (script[s].control == control_t::OTHERWISE)) {
handle_ (script[s].handler, {buffer, resp_size});
std::tie(step, status) = action_ (script, s);
} else {
return exit_error.value;
}
}
if (record.timeout && (clock_() - mark) >= record.timeout)
return exit_error.value;
break;
case control_t::DETECT:
case control_t::OR_DETECT:
resp_size = contents_(buffer);
if (resp_size) {
size_t s = step ; do {
for (size_t s = step ; s < detect_end(script, step) ; ++s) {
if (script[s].match != nullptr && script[s].match({buffer, resp_size}, script[s].token)) {
handle_ (script[s].handler, {buffer, resp_size});
std::tie(step, status) = action_ (script, s);
break;
}
} while ((++s < Steps) && (script[s].control == control_t::OR_DETECT));
}
}
if (record.timeout && (clock_() - mark) >= record.timeout) {
size_t s = detect_end(script, step);
if ((s < Steps) && (script[s].control == control_t::OTHERWISE)) {
handle_ (script[s].handler, {buffer, resp_size});
std::tie(step, status) = action_ (script, s);
} else {
return exit_error.value;
}
}
if (record.timeout && (clock_() - mark) >= record.timeout)
return exit_error.value;
break;
case control_t::OTHERWISE:
handle_ (script[step].handler, {buffer, resp_size});
std::tie(step, status) = action_ (script, step);
break;
} // switch (record.control)
} while ( status == seq_status_t::CONTINUE);