mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-01-31 10:21:10 -05:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user