FastLED 3.10.10
Loading...
Searching...
No Matches

◆ addDriverSlow()

FL_NO_INLINE FL_COLD bool fl::ChannelManager::addDriverSlow ( int priority,
const fl::shared_ptr< IChannelDriver > & driver,
const fl::string * engineName,
AddDriverSlowReason reason )
private

Handle validation failures and the uncommon replacement flow outside the normal driver-registration path.

Definition at line 96 of file manager.cpp.hpp.

100 {
101 if (reason == AddDriverSlowReason::NULL_DRIVER) {
102 FL_WARN("ChannelManager::addDriver() - Null driver provided");
103 return false;
104 }
105 if (reason == AddDriverSlowReason::EMPTY_NAME) {
106 FL_WARN("ChannelManager::addDriver() - Engine has empty name (driver->getName() returned empty string)");
107 return false;
108 }
109
110 for (const auto& entry : mDrivers) {
111 if (entry.name == *engineName) {
112 // True-duplicate fast path: same shared_ptr at same priority is
113 // a no-op (legacy clockless controllers may pre-bind the same
114 // driver singleton from many template instantiations). Skip the
115 // replace flow entirely so we don't waitForReady() or emit a
116 // spurious "Replacing" warning.
117 if (entry.driver == driver && entry.priority == priority) {
118 FL_DBG("ChannelManager::addDriver() - '" << engineName->c_str() << "' already registered at priority " << priority << " (idempotent no-op)");
119 return false;
120 }
121 FL_WARN("ChannelManager::addDriver() - Replacing existing driver '" << engineName->c_str() << "'");
122
123 FL_DBG("ChannelManager: Waiting for all drivers to become READY before replacement");
124 waitForReady();
125
126 // Re-scan after waiting: task pumping in waitForReady() can run
127 // callbacks, so do not retain an index or iterator across it.
128 for (size_t i = 0; i < mDrivers.size(); ++i) {
129 if (mDrivers[i].name != *engineName) {
130 continue;
131 }
132 FL_DBG("ChannelManager: Removing old driver '" << engineName->c_str() << "' (shared_ptr may delete)");
133 if (mDrivers[i].driver) {
134 mDrivers[i].driver->setPollNeededCallback(IChannelDriver::PollNeededCallback());
135 }
136 mDrivers.erase(mDrivers.begin() + i);
137 break;
138 }
139 return true;
140 }
141 }
142 return true;
143}
fl::vector< EngineEntry > mDrivers
Shared drivers sorted by priority descending (higher values first)
Definition manager.h:330
bool waitForReady(u32 timeoutMs=1000) FL_NO_EXCEPT
Wait for all drivers to become READY.
const char * c_str() const FL_NO_EXCEPT
#define FL_WARN(...)
Definition log.h:437
#define FL_DBG
Definition log.h:553

References EMPTY_NAME, FL_COLD, FL_DBG, fl::FL_NO_EXCEPT, FL_NO_INLINE, FL_WARN, mDrivers, NULL_DRIVER, and waitForReady().

Referenced by addDriver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: