CLI: return a device list again, and print the version

This commit is contained in:
Alessandro Di Ronza
2026-07-27 22:27:54 +00:00
committed by Adam Honse
parent da77b63bea
commit 069eeccb60
2 changed files with 42 additions and 1 deletions

View File

@@ -31,6 +31,11 @@ using namespace std::chrono_literals;
\*---------------------------------------------------------*/
const char* DETECTIONMANAGER = "DetectionManager";
/*---------------------------------------------------------*\
| Upper bound for WaitForDetection(), in milliseconds |
\*---------------------------------------------------------*/
#define DETECTION_WAIT_TIMEOUT_MS 60000
/*---------------------------------------------------------*\
| Warning Dialog Strings |
\*---------------------------------------------------------*/
@@ -502,6 +507,16 @@ void DetectionManager::BeginDetection()
\*-----------------------------------------------------*/
if(detection_ready)
{
/*-------------------------------------------------*\
| Flag detection as in progress here rather than in |
| the background thread. WaitForDetection() must |
| not be able to return between this call and the |
| thread actually starting, or a caller that only |
| wants the finished device list, such as the CLI, |
| gets an empty one. |
\*-------------------------------------------------*/
detection_in_progress = true;
RunInBackgroundThread(std::bind(&DetectionManager::BackgroundDetectDevices, this));
}
}
@@ -518,6 +533,32 @@ std::string DetectionManager::GetDetectionString()
void DetectionManager::WaitForDetection()
{
/*-----------------------------------------------------*\
| Taking the mutex is not enough on its own: detection |
| runs in a background thread and there is a window |
| between BeginDetection() and that thread taking the |
| mutex where it would be free. Wait for the in |
| progress flag to clear first, then take the mutex to |
| make sure the detection thread is done. |
\*-----------------------------------------------------*/
/*-----------------------------------------------------*\
| Bounded, so that a detection that never starts cannot |
| hang the caller forever: waiting too long is a bug, |
| but blocking startup indefinitely would be worse |
\*-----------------------------------------------------*/
unsigned int waited_ms = 0;
while(detection_in_progress.load() && waited_ms < DETECTION_WAIT_TIMEOUT_MS)
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
waited_ms += 10;
}
if(detection_in_progress.load())
{
LOG_WARNING("[%s] Gave up waiting for detection after %u ms", DETECTIONMANAGER, waited_ms);
}
DetectDevicesMutex.lock();
DetectDevicesMutex.unlock();
}

View File

@@ -487,7 +487,7 @@ void OptionListDevices(std::vector<RGBController *>& rgb_controllers)
\*---------------------------------------------------------*/
if(!controller->GetVersion().empty())
{
std::cout << " Version: " << controller->GetLocation() << std::endl;
std::cout << " Version: " << controller->GetVersion() << std::endl;
}
/*---------------------------------------------------------*\