FastLED 3.10.6
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 89 of file manager.cpp.hpp.

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

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: