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();
}
}
}

View file

@ -3,6 +3,7 @@
#include <memory>
#include <vector>
#include <functional>
#include <thread>
#include "i2c_smbus.h"
#include "RGBController.h"
@ -10,6 +11,8 @@
typedef std::function<void(std::vector<RGBController*>&)> DeviceDetectorFunction;
typedef std::function<void(std::vector<i2c_smbus_interface*>&, std::vector<RGBController*>&)> I2CDeviceDetectorFunction;
typedef void (*ResourceManagerCallback)(void *);
class ResourceManager
{
public:
@ -27,8 +30,14 @@ public:
void RegisterDeviceDetector (DeviceDetectorFunction detector);
void RegisterI2CDeviceDetector (I2CDeviceDetectorFunction detector);
void RegisterDeviceListChangeCallback(ResourceManagerCallback new_callback, void * new_callback_arg);
void DeviceListChanged();
void DetectDevices();
void DetectDevicesThreadFunction();
private:
static std::unique_ptr<ResourceManager> instance;
@ -36,4 +45,10 @@ private:
std::vector<RGBController*> rgb_controllers;
std::vector<DeviceDetectorFunction> device_detectors;
std::vector<I2CDeviceDetectorFunction> i2c_device_detectors;
std::thread * DetectDevicesThread;
std::mutex DeviceListChangeMutex;
std::vector<ResourceManagerCallback> DeviceListChangeCallbacks;
std::vector<void *> DeviceListChangeCallbackArgs;
};

View file

@ -32,7 +32,7 @@ DMIInfo::DMIInfo()
// Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS"
// These devices may be browsed under Device Manager -> System Devices
std::vector<QueryObj> q_res_BaseBoard;
hres = wmi.query("SELECT * FROM Win32_BaseBoard", q_res_BaseBoard);
//hres = wmi.query("SELECT * FROM Win32_BaseBoard", q_res_BaseBoard);
if (hres)
{

View file

@ -3,6 +3,7 @@
#include "OpenRGBDeviceInfoPage.h"
#include "OpenRGBServerInfoPage.h"
#include "OpenRGBProfileSaveDialog.h"
#include "ResourceManager.h"
#include <QLabel>
#include <QTabBar>
#include <QMessageBox>
@ -53,6 +54,13 @@ static QString GetIconString(device_type type)
}
}
static void UpdateInfoCallback(void * this_ptr)
{
OpenRGBDialog2 * this_obj = (OpenRGBDialog2 *)this_ptr;
QMetaObject::invokeMethod(this_obj, "on_ClientListUpdated", Qt::QueuedConnection);
}
OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager* manager, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), profile_manager(manager), ui(new OpenRGBDialog2Ui)
{
ui->setupUi(this);
@ -70,6 +78,8 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
SMBusToolsPage = NULL;
SoftInfoPage = NULL;
ResourceManager::get()->RegisterDeviceListChangeCallback(UpdateInfoCallback, this);
/*-----------------------------------------------------*\
| Set up tray icon menu |
\*-----------------------------------------------------*/

View file

@ -39,8 +39,8 @@ Wmi::Wmi() : pLoc(nullptr), pSvc(nullptr)
Wmi::~Wmi()
{
pSvc->Release();
pLoc->Release();
//pSvc->Release();
//pLoc->Release();
CoUninitialize();
}