Wait on asynchronous device detection before performing CLI operations that require device list
This commit is contained in:
parent
9c4e73bbed
commit
634ec9f488
2 changed files with 26 additions and 4 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
std::unique_ptr<ResourceManager> ResourceManager::instance;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
ResourceManager *ResourceManager::get()
|
||||
{
|
||||
|
|
@ -22,15 +23,17 @@ ResourceManager::ResourceManager()
|
|||
|
||||
ResourceManager::~ResourceManager()
|
||||
{
|
||||
for(i2c_smbus_interface* bus : busses)
|
||||
{
|
||||
delete bus;
|
||||
}
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
for(RGBController* rgb_controller : rgb_controllers)
|
||||
{
|
||||
delete rgb_controller;
|
||||
}
|
||||
|
||||
for(i2c_smbus_interface* bus : busses)
|
||||
{
|
||||
//delete bus;
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::RegisterI2CBus(i2c_smbus_interface *bus)
|
||||
|
|
@ -108,6 +111,12 @@ void ResourceManager::DetectDevices()
|
|||
| Start the device detection thread |
|
||||
\*-------------------------------------------------*/
|
||||
DetectDevicesThread = new std::thread(&ResourceManager::DetectDevicesThreadFunction, this);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Release the current thread to allow detection |
|
||||
| thread to start |
|
||||
\*-------------------------------------------------*/
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
|
||||
void ResourceManager::DetectDevicesThreadFunction()
|
||||
|
|
|
|||
13
cli.cpp
13
cli.cpp
|
|
@ -5,6 +5,7 @@
|
|||
#include <iostream>
|
||||
#include "OpenRGB.h"
|
||||
#include "ProfileManager.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "RGBController.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include "NetworkClient.h"
|
||||
|
|
@ -398,6 +399,8 @@ void OptionVersion()
|
|||
|
||||
void OptionListDevices(std::vector<RGBController *> &rgb_controllers)
|
||||
{
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
for(std::size_t controller_idx = 0; controller_idx < rgb_controllers.size(); controller_idx++)
|
||||
{
|
||||
RGBController *controller = rgb_controllers[controller_idx];
|
||||
|
|
@ -499,6 +502,8 @@ void OptionListDevices(std::vector<RGBController *> &rgb_controllers)
|
|||
|
||||
bool OptionDevice(int *current_device, std::string argument, Options *options, std::vector<RGBController *> &rgb_controllers)
|
||||
{
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
try
|
||||
{
|
||||
*current_device = std::stoi(argument);
|
||||
|
|
@ -529,6 +534,8 @@ bool OptionDevice(int *current_device, std::string argument, Options *options, s
|
|||
|
||||
bool OptionZone(int *current_device, int *current_zone, std::string argument, Options *options, std::vector<RGBController *> &rgb_controllers)
|
||||
{
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
try
|
||||
{
|
||||
*current_zone = std::stoi(argument);
|
||||
|
|
@ -584,6 +591,8 @@ bool OptionSize(int *current_device, int *current_zone, std::string argument, Op
|
|||
{
|
||||
const unsigned int new_size = std::stoi(argument);
|
||||
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Fail out if device, zone, or size are out of range |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
@ -617,6 +626,8 @@ bool OptionSize(int *current_device, int *current_zone, std::string argument, Op
|
|||
|
||||
bool OptionProfile(std::string argument, std::vector<RGBController *> &rgb_controllers)
|
||||
{
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Attempt to load profile |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
@ -1068,6 +1079,8 @@ unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> &rgb_
|
|||
break;
|
||||
}
|
||||
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| If the options has one or more specific devices, loop |
|
||||
| through all of the specific devices and apply settings. |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue