mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-17 14:07:34 +08:00
DataValidatorGroup: add add_new_validator() to dynamically add new validators
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
|
||||
#include "data_validator_group.h"
|
||||
#include <ecl/ecl.h>
|
||||
#include <cassert>
|
||||
|
||||
DataValidatorGroup::DataValidatorGroup(unsigned siblings) :
|
||||
_first(nullptr),
|
||||
@@ -49,6 +50,7 @@ DataValidatorGroup::DataValidatorGroup(unsigned siblings) :
|
||||
_first_failover_time(0),
|
||||
_toggle_count(0)
|
||||
{
|
||||
assert(siblings > 0);
|
||||
DataValidator *next = _first;
|
||||
|
||||
for (unsigned i = 0; i < siblings; i++) {
|
||||
@@ -56,6 +58,7 @@ DataValidatorGroup::DataValidatorGroup(unsigned siblings) :
|
||||
}
|
||||
|
||||
_first = next;
|
||||
_timeout_interval_us = _first->get_timeout();
|
||||
}
|
||||
|
||||
DataValidatorGroup::~DataValidatorGroup()
|
||||
@@ -67,6 +70,15 @@ DataValidatorGroup::~DataValidatorGroup()
|
||||
}
|
||||
}
|
||||
|
||||
DataValidator *DataValidatorGroup::add_new_validator()
|
||||
{
|
||||
DataValidator *validator = new DataValidator(_first);
|
||||
if (!validator) {
|
||||
return nullptr;
|
||||
}
|
||||
_first = validator;
|
||||
_first->set_timeout(_timeout_interval_us);
|
||||
return _first;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -78,6 +90,7 @@ DataValidatorGroup::set_timeout(uint32_t timeout_interval_us)
|
||||
next->set_timeout(timeout_interval_us);
|
||||
next = next->sibling();
|
||||
}
|
||||
_timeout_interval_us = timeout_interval_us;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -48,6 +48,12 @@ public:
|
||||
DataValidatorGroup(unsigned siblings);
|
||||
virtual ~DataValidatorGroup();
|
||||
|
||||
/**
|
||||
* Create a new Validator (with index equal to the number of currently existing validators)
|
||||
* @return the newly created DataValidator or nullptr on error
|
||||
*/
|
||||
DataValidator *add_new_validator();
|
||||
|
||||
/**
|
||||
* Put an item into the validator group.
|
||||
*
|
||||
@@ -117,6 +123,7 @@ public:
|
||||
|
||||
private:
|
||||
DataValidator *_first; /**< sibling in the group */
|
||||
uint32_t _timeout_interval_us; /**< currently set timeout */
|
||||
int _curr_best; /**< currently best index */
|
||||
int _prev_best; /**< the previous best index */
|
||||
uint64_t _first_failover_time; /**< timestamp where the first failover occured or zero if none occured */
|
||||
|
||||
Reference in New Issue
Block a user