Initial prototype of asynchronous detection. DMI information broken

This commit is contained in:
Adam Honse 2020-08-06 08:43:42 -05:00
parent 5270b46e31
commit 7898e9b95d
5 changed files with 87 additions and 4 deletions

View file

@ -40,6 +40,7 @@ std::vector<i2c_smbus_interface*> & ResourceManager::GetI2CBusses()
void ResourceManager::RegisterRGBController(RGBController *rgb_controller)
{
rgb_controllers.push_back(rgb_controller);
DeviceListChanged();
}
std::vector<RGBController*> & ResourceManager::GetRGBControllers()
@ -57,15 +58,72 @@ void ResourceManager::RegisterDeviceDetector(DeviceDetectorFunction detector)
device_detectors.push_back(detector);
}
void ResourceManager::RegisterDeviceListChangeCallback(ResourceManagerCallback new_callback, void * new_callback_arg)
{
DeviceListChangeCallbacks.push_back(new_callback);
DeviceListChangeCallbackArgs.push_back(new_callback_arg);
}
void ResourceManager::DeviceListChanged()
{
DeviceListChangeMutex.lock();
/*-------------------------------------------------*\
| Client info has changed, call the callbacks |
\*-------------------------------------------------*/
for(unsigned int callback_idx = 0; callback_idx < DeviceListChangeCallbacks.size(); callback_idx++)
{
DeviceListChangeCallbacks[callback_idx](DeviceListChangeCallbackArgs[callback_idx]);
}
DeviceListChangeMutex.unlock();
}
void ResourceManager::DetectDevices()
{
/*-------------------------------------------------*\
| Start the device detection thread |
\*-------------------------------------------------*/
DetectDevicesThread = new std::thread(&ResourceManager::DetectDevicesThreadFunction, this);
}
void ResourceManager::DetectDevicesThreadFunction()
{
unsigned int prev_count = 0;
/*-------------------------------------------------*\
| Detect i2c devices |
\*-------------------------------------------------*/
for(int i2c_detector_idx = 0; i2c_detector_idx < i2c_device_detectors.size(); i2c_detector_idx++)
{
i2c_device_detectors[i2c_detector_idx](busses, rgb_controllers);
/*-------------------------------------------------*\
| If the device list size has changed, call the |
| device list changed callbacks |
\*-------------------------------------------------*/
if(rgb_controllers.size() != prev_count)
{
DeviceListChanged();
}
prev_count = rgb_controllers.size();
}
/*-------------------------------------------------*\
| Detect other devices |
\*-------------------------------------------------*/
for(int detector_idx = 0; detector_idx < device_detectors.size(); detector_idx++)
{
device_detectors[detector_idx](rgb_controllers);
/*-------------------------------------------------*\
| If the device list size has changed, call the |
| device list changed callbacks |
\*-------------------------------------------------*/
if(rgb_controllers.size() != prev_count)
{
DeviceListChanged();
}
prev_count = rgb_controllers.size();
}
}
}