mirror of https://github.com/rusefi/rusefi.git
registerCanListener should be idempotent
This commit is contained in:
parent
26452365c8
commit
4f39b22be6
|
@ -36,6 +36,10 @@ public:
|
||||||
return m_next;
|
return m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasNext() const {
|
||||||
|
return m_next;
|
||||||
|
}
|
||||||
|
|
||||||
// Return true if the provided frame should be accepted for processing by the listener.
|
// Return true if the provided frame should be accepted for processing by the listener.
|
||||||
// Override if you need more complex logic than comparing to a single ID.
|
// Override if you need more complex logic than comparing to a single ID.
|
||||||
virtual bool acceptFrame(const CANRxFrame& frame) const {
|
virtual bool acceptFrame(const CANRxFrame& frame) const {
|
||||||
|
|
|
@ -55,7 +55,23 @@ static void printPacket(const size_t busIndex, const CANRxFrame &rx) {
|
||||||
|
|
||||||
volatile float canMap = 0;
|
volatile float canMap = 0;
|
||||||
|
|
||||||
CanListener *canListeners_head = nullptr;
|
struct CanListenerTailSentinel : public CanListener {
|
||||||
|
CanListenerTailSentinel()
|
||||||
|
: CanListener(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool acceptFrame(const CANRxFrame&) const override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void decodeFrame(const CANRxFrame&, efitick_t) override {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static CanListenerTailSentinel tailSentinel;
|
||||||
|
CanListener *canListeners_head = &tailSentinel;
|
||||||
|
|
||||||
void serviceCanSubscribers(const CANRxFrame &frame, efitick_t nowNt) {
|
void serviceCanSubscribers(const CANRxFrame &frame, efitick_t nowNt) {
|
||||||
CanListener *current = canListeners_head;
|
CanListener *current = canListeners_head;
|
||||||
|
@ -71,8 +87,11 @@ void serviceCanSubscribers(const CANRxFrame &frame, efitick_t nowNt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerCanListener(CanListener& listener) {
|
void registerCanListener(CanListener& listener) {
|
||||||
listener.setNext(canListeners_head);
|
// If the listener already has a next, it's already registered
|
||||||
canListeners_head = &listener;
|
if (!listener.hasNext()) {
|
||||||
|
listener.setNext(canListeners_head);
|
||||||
|
canListeners_head = &listener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerCanSensor(CanSensorBase& sensor) {
|
void registerCanSensor(CanSensorBase& sensor) {
|
||||||
|
|
Loading…
Reference in New Issue