Split out detection system from ResourceManager into DetectionManager

* Split detection system out into its own class, DetectionManager
    * Clean up ResourceManger's many callbacks into just two, one for detection and one general purpose
This commit is contained in:
Adam Honse
2026-01-08 23:35:50 -06:00
parent 0a232bfe1e
commit da750672e8
221 changed files with 3149 additions and 2776 deletions

View File

@@ -51,43 +51,50 @@ static int detection_pass;
static unsigned int lastpercent = 101;
/*---------------------------------------------------------*\
| ServiceStartupProgress |
| ServiceResourceManagerCallback |
| |
| Report detection progress when running as a service |
\*---------------------------------------------------------*/
static void ServiceStartupProgress(void*)
static void ServiceResourceManagerCallback(void *, unsigned int update_reason)
{
unsigned int percent = ResourceManager::get()->GetDetectionPercent();
unsigned int estimate;
percent = std::clamp(percent, 0u, 100u);
if(lastpercent > percent)
switch(update_reason)
{
detection_pass += 1;
}
case RESOURCEMANAGER_UPDATE_REASON_DETECTION_PROGRESS_CHANGED:
{
unsigned int percent = ResourceManager::get()->GetDetectionPercent();
unsigned int estimate;
lastpercent = percent;
percent = std::clamp(percent, 0u, 100u);
switch(detection_pass)
{
case 0:
percent = 0;
break;
case 1:
percent = percent * 4 / 5;
break;
case 2:
percent = percent / 5 + 80;
break;
default:
percent = 100;
if(lastpercent > percent)
{
detection_pass += 1;
}
lastpercent = percent;
switch(detection_pass)
{
case 0:
percent = 0;
break;
case 1:
percent = percent * 4 / 5;
break;
case 2:
percent = percent / 5 + 80;
break;
default:
percent = 100;
break;
}
estimate = (100 - percent) / 5 + 10;
ReportServiceStatus(SERVICE_START_PENDING, NO_ERROR, estimate * 1000);
}
break;
}
estimate = (100 - percent) / 5 + 10;
ReportServiceStatus(SERVICE_START_PENDING, NO_ERROR, estimate * 1000);
}
/*---------------------------------------------------------*\
@@ -588,7 +595,7 @@ static int common_main(int argc, char* argv[])
\*-----------------------------------------------------*/
if(started_as_service)
{
ResourceManager::get()->RegisterDetectionProgressCallback(ServiceStartupProgress, NULL);
ResourceManager::get()->RegisterResourceManagerCallback(ServiceResourceManagerCallback, NULL);
}
/*-----------------------------------------------------*\
@@ -604,7 +611,7 @@ static int common_main(int argc, char* argv[])
\*-----------------------------------------------------*/
if(started_as_service)
{
ResourceManager::get()->UnregisterDetectionProgressCallback(ServiceStartupProgress, NULL);
ResourceManager::get()->UnregisterResourceManagerCallback(ServiceResourceManagerCallback, NULL);
}
/*-----------------------------------------------------*\
@@ -624,11 +631,6 @@ static int common_main(int argc, char* argv[])
}
}
/*-----------------------------------------------------*\
| Perform ResourceManager cleanup before exiting |
\*-----------------------------------------------------*/
ResourceManager::get()->Cleanup();
LOG_TRACE("OpenRGB finishing with exit code %d", exitval);
return exitval;