mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 09:44:12 +01:00
Fix linting issues
This commit is contained in:
parent
4be588c749
commit
0a4aad9eb0
3 changed files with 18 additions and 5 deletions
12
esphome/core/event_emitter.cpp
Normal file
12
esphome/core/event_emitter.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include "event_emitter.h"
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
|
||||||
|
static const char *const TAG = "event_emitter";
|
||||||
|
|
||||||
|
void RaiseEventEmitterFullError(EventEmitterListenerID id) {
|
||||||
|
ESP_LOGE(TAG, "EventEmitter has reached the maximum number of listeners for event");
|
||||||
|
ESP_LOGW(TAG, "Removing listener with ID %d to make space for new listener", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace esphome
|
|
@ -2,12 +2,14 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
|
||||||
using EventEmitterListenerID = uint32_t;
|
using EventEmitterListenerID = uint32_t;
|
||||||
|
void RaiseEventEmitterFullError(EventEmitterListenerID id);
|
||||||
|
|
||||||
// EventEmitter class that can emit events with a specific name (it is highly recommended to use an enum class for this) and a list of arguments.
|
// EventEmitter class that can emit events with a specific name (it is highly recommended to use an enum class for this) and a list of arguments.
|
||||||
// Supports multiple listeners for each event.
|
// Supports multiple listeners for each event.
|
||||||
|
@ -38,8 +40,7 @@ template <typename EvtType, typename... Args> class EventEmitter {
|
||||||
// Check if the map is full
|
// Check if the map is full
|
||||||
if (listeners_[event].size() == std::numeric_limits<EventEmitterListenerID>::max()) {
|
if (listeners_[event].size() == std::numeric_limits<EventEmitterListenerID>::max()) {
|
||||||
// Raise an error if the map is full
|
// Raise an error if the map is full
|
||||||
ESP_LOGE("event_emitter", "EventEmitter has reached the maximum number of listeners for event %d", event);
|
RaiseEventEmitterFullError(0);
|
||||||
ESP_LOGW("event_emitter", "Removing listener with ID %d for event %d", 0, event);
|
|
||||||
off(event, 0);
|
off(event, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue