FastLED 3.10.9
Loading...
Searching...
No Matches

◆ setExclusiveDriverByName()

bool fl::ChannelManager::setExclusiveDriverByName ( const char * name)

Enable only one driver exclusively (disables all others) — by-name escape hatch.

Parameters
nameDriver name to enable exclusively (case-sensitive, e.g., "MOCK_SPI")
Returns
true if driver was found and set as exclusive, false if name not found

Test / mock helper: works with drivers that have ALREADY been registered via addDriver() (typically ChannelEngineMock instances under unit tests), or for drivers whose names are NOT in the fl::Bus enum (custom third-party drivers, RPC-resolved names). Does NOT link or register new drivers.

For built-in drivers, prefer either:

  • setExclusiveDriver(fl::Bus) (typed runtime form), or
  • setExclusiveDriver<fl::Bus B>() (compile-time form that links the driver TU via ODR-use).
    Note
    Atomically disables all drivers, then enables the specified one
    Changes take effect immediately on next enqueue()
    If name is not found, all drivers remain disabled (defensive behavior)
    Use nullptr or empty string to disable all drivers (returns false)
    Warning
    This will disable ALL other registered drivers, including future additions

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

283 {
284 // Handle null or empty name: disable everything.
285 if (!name || !name[0]) {
286 FL_ERROR("ChannelManager::setExclusiveDriverByName() - Null or empty driver name provided");
287 mExclusiveDriver.clear();
288 for (auto& entry : mDrivers) {
289 entry.enabled = false;
290 }
291 return false;
292 }
293
294 // Store exclusive driver name for forward compatibility.
295 // When non-empty, addDriver() will auto-disable non-matching drivers.
296 mExclusiveDriver = name;
297
298 // Single-pass: enable only drivers matching the given name.
299 bool found = false;
300 for (auto& entry : mDrivers) {
301 entry.enabled = (entry.name == name);
302 found = found || entry.enabled;
303 }
304
305 if (!found) {
306 FL_ERROR("ChannelManager::setExclusiveDriverByName() - Driver '" << name << "' not found in registry");
307 }
308 return found;
309}
fl::vector< EngineEntry > mDrivers
Shared drivers sorted by priority descending (higher values first)
Definition manager.h:327
fl::string mExclusiveDriver
Exclusive driver name (empty if no exclusive mode)
Definition manager.h:336
#define FL_ERROR(...)
Definition log.h:373

References FL_ERROR, fl::FL_NO_EXCEPT, mDrivers, and mExclusiveDriver.

Referenced by setExclusiveDriver().

+ Here is the caller graph for this function: