mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-07-29 14:36:06 -04:00
Maintain a list of created virtual controllers in the OpenRGBPluginAPI object and only allow registering virtual controllers that exist in this list
This commit is contained in:
@@ -41,6 +41,12 @@ RGBControllerInterface* OpenRGBPluginAPI::CreateVirtualRGBController(RGBControll
|
||||
{
|
||||
RGBController_Virtual* rgb_controller = new RGBController_Virtual(setup);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the new controller to the list of created |
|
||||
| controllers |
|
||||
\*-----------------------------------------------------*/
|
||||
created_controllers.push_back((RGBController*)rgb_controller);
|
||||
|
||||
return(rgb_controller);
|
||||
}
|
||||
|
||||
@@ -63,6 +69,27 @@ void OpenRGBPluginAPI::RegisterVirtualRGBController(RGBControllerInterface* rgb_
|
||||
{
|
||||
LOG_INFO("[PluginManager] Registering RGB controller %s", rgb_controller->GetName().c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Ensure the pointer given is a pointer to a valid |
|
||||
| virtual controller |
|
||||
\*-----------------------------------------------------*/
|
||||
bool found = false;
|
||||
|
||||
for(std::size_t controller_idx = 0; controller_idx < created_controllers.size(); controller_idx++)
|
||||
{
|
||||
if(created_controllers[controller_idx] == rgb_controller)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
LOG_ERROR("[PluginManager] Attempted to register an RGBController that was not created by this plugin API instance.");
|
||||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mark this controller as locally owned |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -131,6 +158,12 @@ void OpenRGBPluginAPI::UpdateVirtualRGBController(RGBControllerInterface* rgb_co
|
||||
|
||||
void OpenRGBPluginAPI::DeleteVirtualRGBController(RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove the controller from the list of created |
|
||||
| controllers |
|
||||
\*-----------------------------------------------------*/
|
||||
created_controllers.erase(std::remove(created_controllers.begin(), created_controllers.end(), (RGBController*)rgb_controller), created_controllers.end());
|
||||
|
||||
delete (RGBController*)rgb_controller;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
/*-----------------------------------------------------*\
|
||||
| RGBControllers registered by plugin |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<RGBController*> created_controllers;
|
||||
std::vector<RGBController*> rgb_controllers;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user