Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4de85363a | ||
|
|
5fc61d9e88 | ||
|
|
7ce0b51116 | ||
|
|
71386d9e5f | ||
|
|
a52766df76 | ||
|
|
3ae14c9d70 | ||
|
|
41994f4291 | ||
|
|
1ca10a5622 | ||
|
|
12a61009a7 | ||
|
|
d4effd7c13 | ||
|
|
bf6795a282 | ||
|
|
b65c1b376b | ||
|
|
aadc90cace | ||
|
|
ea4029caad | ||
|
|
c61a0d9c5a | ||
|
|
a32a766fbb | ||
|
|
4b359766eb | ||
|
|
833778f2a3 | ||
|
|
4fe6e45b9f | ||
|
|
c0d64bc790 | ||
|
|
9924e573f1 | ||
|
|
ca23ae4452 | ||
|
|
fb16226bc0 | ||
|
|
763eb3e87c |
+1
-1
@@ -36,7 +36,7 @@ ASRockASRRGBSMBusController::~ASRockASRRGBSMBusController()
|
||||
|
||||
std::string ASRockASRRGBSMBusController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ ASRockPolychromeV1SMBusController::~ASRockPolychromeV1SMBusController()
|
||||
|
||||
std::string ASRockPolychromeV1SMBusController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ ASRockPolychromeV2SMBusController::~ASRockPolychromeV2SMBusController()
|
||||
|
||||
std::string ASRockPolychromeV2SMBusController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -91,9 +91,9 @@ DetectedControllers DetectASRockSMBusControllers(std::vector<i2c_smbus_interface
|
||||
|
||||
for(unsigned int bus = 0; bus < buses.size(); bus++)
|
||||
{
|
||||
IF_MOBO_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_MOBO_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
if(buses[bus]->pci_subsystem_vendor == ASROCK_SUB_VEN)
|
||||
if(buses[bus]->info.pci_subsystem_vendor == ASROCK_SUB_VEN)
|
||||
{
|
||||
LOG_DEBUG(SMBUS_CHECK_DEVICE_MESSAGE_EN, ASROCK_DETECTOR_NAME, bus, VENDOR_NAME, SMBUS_ADDRESS);
|
||||
// Check for Polychrome controller at 0x6A
|
||||
|
||||
@@ -32,7 +32,7 @@ std::string AuraGPUController::GetDeviceName()
|
||||
|
||||
std::string AuraGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
@@ -79,7 +79,7 @@ void AuraGPUController::AuraGPURegisterWrite(unsigned char reg, unsigned char va
|
||||
|
||||
bool AuraGPUController::SaveOnlyApplies()
|
||||
{
|
||||
switch (bus->pci_subsystem_device)
|
||||
switch (bus->info.pci_subsystem_device)
|
||||
{
|
||||
case ASUS_VEGA64_STRIX:
|
||||
return false;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
bool TestForAsusAuraGPUController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
if(bus->pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
if(bus->info.pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ ColorfulGPUController::~ColorfulGPUController()
|
||||
|
||||
std::string ColorfulGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
@@ -45,7 +45,7 @@ void ColorfulGPUController::SetDirect(RGBColor color)
|
||||
uint8_t g = RGBGetGValue(color);
|
||||
uint8_t b = RGBGetBValue(color);
|
||||
|
||||
if(this->bus->pci_subsystem_device == COLORFUL_IGAME_RTX_4070_VULCAN_OCV)
|
||||
if(this->bus->info.pci_subsystem_device == COLORFUL_IGAME_RTX_4070_VULCAN_OCV)
|
||||
{
|
||||
uint8_t data_pkt[COLORFUL_PACKET_LENGTH_V2] = { 0xAA, 0xEF, 0x01, 0x04, 0x88, 0x26 };
|
||||
for(int i=6; i < COLORFUL_PACKET_LENGTH_V2 -2; i = i + 3)
|
||||
|
||||
@@ -24,7 +24,7 @@ ColorfulTuringGPUController::~ColorfulTuringGPUController()
|
||||
|
||||
std::string ColorfulTuringGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -17,7 +17,7 @@ DetectedControllers DetectColorfulTuringGPUControllers(i2c_smbus_interface* bus,
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
ColorfulTuringGPUController* controller = new ColorfulTuringGPUController(bus, i2c_addr, name);
|
||||
RGBController_ColorfulTuringGPU* rgb_controller = new RGBController_ColorfulTuringGPU(controller);
|
||||
|
||||
@@ -52,7 +52,7 @@ unsigned char CorsairDRAMController::GetProtocolVersion()
|
||||
|
||||
std::string CorsairDRAMController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
@@ -366,7 +366,7 @@ void CorsairDRAMController::ReadDeviceInfo()
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Device Information Data |
|
||||
\*-----------------------------------------------------*/
|
||||
if(LogManager::get()->getLoglevel() >= LL_TRACE)
|
||||
if(LogManager::get()->GetLogLevel() >= LL_TRACE)
|
||||
{
|
||||
char device_info_buf[256];
|
||||
unsigned int pos;
|
||||
|
||||
@@ -59,7 +59,7 @@ DetectedControllers DetectCorsairDRAMControllers(std::vector<i2c_smbus_interface
|
||||
|
||||
for(unsigned int bus = 0; bus < buses.size(); bus++)
|
||||
{
|
||||
IF_DRAM_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_DRAM_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
LOG_DEBUG("[%s] Testing bus %d", CORSAIR_DRAM_NAME, bus);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ std::string CorsairVengeanceController::GetDeviceName()
|
||||
|
||||
std::string CorsairVengeanceController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -35,7 +35,7 @@ std::string CrucialController::GetDeviceVersion()
|
||||
|
||||
std::string CrucialController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -145,7 +145,7 @@ DetectedControllers DetectCrucialControllers(std::vector<i2c_smbus_interface*> &
|
||||
{
|
||||
int address_list_idx = -1;
|
||||
|
||||
IF_DRAM_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_DRAM_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
for(unsigned int slot = 0; slot < 4; slot++)
|
||||
{
|
||||
@@ -182,7 +182,7 @@ DetectedControllers DetectCrucialControllers(std::vector<i2c_smbus_interface*> &
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
|
||||
LOG_DEBUG("[%s] In bus: %02X:%02X looking for devices at [%s]", CRUCIAL_CONTROLLER_NAME, buses[bus]->pci_vendor, buses[bus]->pci_device, TESTING_ADDRESSES);
|
||||
LOG_DEBUG("[%s] In bus: %02X:%02X looking for devices at [%s]", CRUCIAL_CONTROLLER_NAME, buses[bus]->info.pci_vendor, buses[bus]->info.pci_device, TESTING_ADDRESSES);
|
||||
|
||||
// Add Crucial controllers
|
||||
for(unsigned int address_list_idx = 0; address_list_idx < CRUCIAL_ADDRESS_COUNT; address_list_idx++)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "DetectionManager.h"
|
||||
#include "LogManager.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "KeyboardLayoutManager.h"
|
||||
#include "JsonUtils.h"
|
||||
#include "RGBController_Debug.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@@ -51,100 +52,6 @@ RGBController_Debug::RGBController_Debug(bool custom, json settings)
|
||||
custom_controller = custom;
|
||||
debug_settings = settings;
|
||||
|
||||
if(custom_controller)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Set the name |
|
||||
\*-------------------------------------------------*/
|
||||
name = debug_settings["DeviceName"];
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Find the device type |
|
||||
\*-------------------------------------------------*/
|
||||
if (debug_settings["DeviceType"] == "motherboard") type = DEVICE_TYPE_MOTHERBOARD;
|
||||
else if (debug_settings["DeviceType"] == "dram") type = DEVICE_TYPE_DRAM;
|
||||
else if (debug_settings["DeviceType"] == "gpu") type = DEVICE_TYPE_GPU;
|
||||
else if (debug_settings["DeviceType"] == "cooler") type = DEVICE_TYPE_COOLER;
|
||||
else if (debug_settings["DeviceType"] == "led_strip") type = DEVICE_TYPE_LEDSTRIP;
|
||||
else if (debug_settings["DeviceType"] == "keyboard") type = DEVICE_TYPE_KEYBOARD;
|
||||
else if (debug_settings["DeviceType"] == "mouse") type = DEVICE_TYPE_MOUSE;
|
||||
else if (debug_settings["DeviceType"] == "mousemat") type = DEVICE_TYPE_MOUSEMAT;
|
||||
else if (debug_settings["DeviceType"] == "headset") type = DEVICE_TYPE_HEADSET;
|
||||
else if (debug_settings["DeviceType"] == "headset_stand") type = DEVICE_TYPE_HEADSET_STAND;
|
||||
else if (debug_settings["DeviceType"] == "gamepad") type = DEVICE_TYPE_GAMEPAD;
|
||||
else if (debug_settings["DeviceType"] == "light") type = DEVICE_TYPE_LIGHT;
|
||||
else if (debug_settings["DeviceType"] == "speaker") type = DEVICE_TYPE_SPEAKER;
|
||||
else if (debug_settings["DeviceType"] == "unknown") type = DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set description, location, version, and serial |
|
||||
\*-------------------------------------------------*/
|
||||
description = debug_settings["DeviceDescription"];
|
||||
location = debug_settings["DeviceLocation"];
|
||||
version = debug_settings["DeviceVersion"];
|
||||
serial = debug_settings["DeviceSerial"];
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name_setting = "";
|
||||
std::string type_setting = "keyboard";
|
||||
|
||||
if(debug_settings.contains("name"))
|
||||
{
|
||||
name_setting = debug_settings["name"];
|
||||
}
|
||||
|
||||
if(debug_settings.contains("type"))
|
||||
{
|
||||
type_setting = debug_settings["type"];
|
||||
}
|
||||
|
||||
if(type_setting == "motherboard")
|
||||
{
|
||||
name = "Debug Motherboard";
|
||||
type = DEVICE_TYPE_MOTHERBOARD;
|
||||
}
|
||||
else if(type_setting == "dram")
|
||||
{
|
||||
name = "Debug DRAM";
|
||||
type = DEVICE_TYPE_DRAM;
|
||||
}
|
||||
else if(type_setting == "gpu")
|
||||
{
|
||||
name = "Debug GPU";
|
||||
type = DEVICE_TYPE_GPU;
|
||||
}
|
||||
else if(type_setting == "keyboard")
|
||||
{
|
||||
name = "Debug Keyboard";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
}
|
||||
else if(type_setting == "mouse")
|
||||
{
|
||||
name = "Debug Mouse";
|
||||
type = DEVICE_TYPE_MOUSE;
|
||||
}
|
||||
else if(type_setting == "argb")
|
||||
{
|
||||
name = "Debug ARGB Controller";
|
||||
type = DEVICE_TYPE_LEDSTRIP;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Fill in debug controller information |
|
||||
\*---------------------------------------------------------*/
|
||||
description = name + " Device";
|
||||
vendor = name + " Vendor String";
|
||||
location = name + " Location String";
|
||||
version = name + " Version String";
|
||||
serial = name + " Serial String";
|
||||
|
||||
if(name_setting != "")
|
||||
{
|
||||
name = name_setting;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the mode |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -157,6 +64,7 @@ RGBController_Debug::RGBController_Debug(bool custom, json settings)
|
||||
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupDevice();
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
@@ -165,6 +73,137 @@ RGBController_Debug::~RGBController_Debug()
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void RGBController_Debug::SetupDevice()
|
||||
{
|
||||
if(custom_controller)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Set the name, description, location, version, and |
|
||||
| serial |
|
||||
\*-------------------------------------------------*/
|
||||
name = JsonUtils::JsonGetString(debug_settings, "DeviceName", "Custom Device");
|
||||
description = JsonUtils::JsonGetString(debug_settings, "DeviceDescription");
|
||||
location = JsonUtils::JsonGetString(debug_settings, "DeviceLocation");
|
||||
version = JsonUtils::JsonGetString(debug_settings, "DeviceVersion");
|
||||
serial = JsonUtils::JsonGetString(debug_settings, "DeviceSerial");
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Find the device type |
|
||||
\*-------------------------------------------------*/
|
||||
std::string device_type = JsonUtils::JsonGetString(debug_settings, "DeviceType", "keyboard");
|
||||
|
||||
if( device_type == "motherboard") type = DEVICE_TYPE_MOTHERBOARD;
|
||||
else if(device_type == "dram") type = DEVICE_TYPE_DRAM;
|
||||
else if(device_type == "gpu") type = DEVICE_TYPE_GPU;
|
||||
else if(device_type == "cooler") type = DEVICE_TYPE_COOLER;
|
||||
else if(device_type == "led_strip") type = DEVICE_TYPE_LEDSTRIP;
|
||||
else if(device_type == "keyboard") type = DEVICE_TYPE_KEYBOARD;
|
||||
else if(device_type == "mouse") type = DEVICE_TYPE_MOUSE;
|
||||
else if(device_type == "mousemat") type = DEVICE_TYPE_MOUSEMAT;
|
||||
else if(device_type == "headset") type = DEVICE_TYPE_HEADSET;
|
||||
else if(device_type == "headset_stand") type = DEVICE_TYPE_HEADSET_STAND;
|
||||
else if(device_type == "gamepad") type = DEVICE_TYPE_GAMEPAD;
|
||||
else if(device_type == "light") type = DEVICE_TYPE_LIGHT;
|
||||
else if(device_type == "speaker") type = DEVICE_TYPE_SPEAKER;
|
||||
else if(device_type == "unknown") type = DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name_value;
|
||||
std::string name_setting = JsonUtils::JsonGetString(debug_settings, "name");
|
||||
std::string type_setting = JsonUtils::JsonGetString(debug_settings, "type", "keyboard");
|
||||
|
||||
if(type_setting == "motherboard")
|
||||
{
|
||||
name_value = "Debug Motherboard";
|
||||
type = DEVICE_TYPE_MOTHERBOARD;
|
||||
}
|
||||
else if(type_setting == "dram")
|
||||
{
|
||||
name_value = "Debug DRAM";
|
||||
type = DEVICE_TYPE_DRAM;
|
||||
}
|
||||
else if(type_setting == "gpu")
|
||||
{
|
||||
name_value = "Debug GPU";
|
||||
type = DEVICE_TYPE_GPU;
|
||||
}
|
||||
else if(type_setting == "keyboard")
|
||||
{
|
||||
name_value = "Debug Keyboard";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
}
|
||||
else if(type_setting == "mouse")
|
||||
{
|
||||
name_value = "Debug Mouse";
|
||||
type = DEVICE_TYPE_MOUSE;
|
||||
}
|
||||
else if(type_setting == "argb")
|
||||
{
|
||||
name_value = "Debug ARGB Controller";
|
||||
type = DEVICE_TYPE_LEDSTRIP;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Fill in debug controller information |
|
||||
\*---------------------------------------------------------*/
|
||||
description = name_value + " Device";
|
||||
vendor = name_value + " Vendor String";
|
||||
location = name_value + " Location String";
|
||||
version = name_value + " Version String";
|
||||
serial = name_value + " Serial String";
|
||||
flags |= CONTROLLER_FLAG_MANUALLY_CONFIGURABLE_NAME | CONTROLLER_FLAG_MANUALLY_CONFIGURABLE_DEVICE_SPECIFIC;
|
||||
|
||||
if(name_setting != "")
|
||||
{
|
||||
name_value = name_setting;
|
||||
}
|
||||
|
||||
if((flags & CONTROLLER_FLAG_MANUALLY_CONFIGURED_NAME) == 0)
|
||||
{
|
||||
name = name_value;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create test configuration |
|
||||
\*---------------------------------------------------------*/
|
||||
nlohmann::json configuration_json;
|
||||
JsonUtils::JsonParse(configuration, configuration_json);
|
||||
|
||||
configuration_json["schema"]["test_string"]["title"] = "String Setting";
|
||||
configuration_json["schema"]["test_string"]["type"] = "string";
|
||||
|
||||
configuration_json["schema"]["test_bool"]["title"] = "Boolean Setting";
|
||||
configuration_json["schema"]["test_bool"]["type"] = "bool";
|
||||
|
||||
configuration_json["schema"]["test_enum"]["title"] = "String Enum Setting";
|
||||
configuration_json["schema"]["test_enum"]["type"] = "string";
|
||||
configuration_json["schema"]["test_enum"]["enum"][0] = "Option 1";
|
||||
configuration_json["schema"]["test_enum"]["enum"][1] = "Option 2";
|
||||
configuration_json["schema"]["test_enum"]["enum"][2] = "Option 3";
|
||||
|
||||
configuration_json["schema"]["test_enum_int"]["title"] = "Integer Enum Setting";
|
||||
configuration_json["schema"]["test_enum_int"]["type"] = "integer";
|
||||
configuration_json["schema"]["test_enum_int"]["enum"][0] = 2;
|
||||
configuration_json["schema"]["test_enum_int"]["enum"][1] = 4;
|
||||
configuration_json["schema"]["test_enum_int"]["enum"][2] = 8;
|
||||
|
||||
configuration_json["schema"]["test_int"]["title"] = "Integer Setting";
|
||||
configuration_json["schema"]["test_int"]["type"] = "integer";
|
||||
|
||||
if((flags & CONTROLLER_FLAG_MANUALLY_CONFIGURED_DEVICE_SPECIFIC) == 0)
|
||||
{
|
||||
configuration_json["configuration"]["test_string"] = "This is a test";
|
||||
configuration_json["configuration"]["test_bool"] = true;
|
||||
configuration_json["configuration"]["test_enum"] = "Option 2";
|
||||
configuration_json["configuration"]["test_enum_int"] = 4;
|
||||
configuration_json["configuration"]["test_int"] = 12345;
|
||||
}
|
||||
|
||||
configuration = configuration_json.dump();
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_Debug::SetupZones()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
@@ -181,6 +220,7 @@ void RGBController_Debug::SetupZones()
|
||||
/*-------------------------------------------------*\
|
||||
| Clear any existing color/LED configuration |
|
||||
\*-------------------------------------------------*/
|
||||
led_alt_names.clear();
|
||||
leds.clear();
|
||||
colors.clear();
|
||||
|
||||
@@ -216,9 +256,9 @@ void RGBController_Debug::SetupZones()
|
||||
continue;
|
||||
}
|
||||
|
||||
custom_zone.leds_min = ZoneJson["leds_min"];
|
||||
custom_zone.leds_max = ZoneJson["leds_max"];
|
||||
custom_zone.leds_count = ZoneJson["leds_count"];
|
||||
custom_zone.leds_min = JsonUtils::JsonGetInt(ZoneJson, "leds_min");
|
||||
custom_zone.leds_max = JsonUtils::JsonGetInt(ZoneJson, "leds_max");
|
||||
custom_zone.leds_count = JsonUtils::JsonGetInt(ZoneJson, "leds_count");
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Fill in the matrix map |
|
||||
@@ -241,8 +281,8 @@ void RGBController_Debug::SetupZones()
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int H = ZoneJson["matrix_width"];
|
||||
unsigned int W = ZoneJson["matrix_height"];
|
||||
unsigned int H = JsonUtils::JsonGetInt(ZoneJson, "matrix_width");
|
||||
unsigned int W = JsonUtils::JsonGetInt(ZoneJson, "matrix_height");
|
||||
|
||||
BadVal = ((unsigned int)ZoneJson["matrix_map"].size() != H);
|
||||
|
||||
@@ -333,36 +373,11 @@ void RGBController_Debug::SetupZones()
|
||||
}
|
||||
else
|
||||
{
|
||||
bool zone_single = true;
|
||||
bool zone_linear = true;
|
||||
bool zone_resizable = false;
|
||||
bool zone_keyboard = false;
|
||||
bool zone_underglow = false;
|
||||
|
||||
if(debug_settings.contains("single"))
|
||||
{
|
||||
zone_single = debug_settings["single"];
|
||||
}
|
||||
|
||||
if(debug_settings.contains("linear"))
|
||||
{
|
||||
zone_linear = debug_settings["linear"];
|
||||
}
|
||||
|
||||
if(debug_settings.contains("resizable"))
|
||||
{
|
||||
zone_resizable = debug_settings["resizable"];
|
||||
}
|
||||
|
||||
if(debug_settings.contains("keyboard"))
|
||||
{
|
||||
zone_keyboard = debug_settings["keyboard"];
|
||||
}
|
||||
|
||||
if(debug_settings.contains("underglow"))
|
||||
{
|
||||
zone_underglow = debug_settings["underglow"];
|
||||
}
|
||||
bool zone_single = JsonUtils::JsonGetBool(debug_settings, "single", true);
|
||||
bool zone_linear = JsonUtils::JsonGetBool(debug_settings, "linear", true);
|
||||
bool zone_resizable = JsonUtils::JsonGetBool(debug_settings, "resizable", false);
|
||||
bool zone_keyboard = JsonUtils::JsonGetBool(debug_settings, "keyboard", false);
|
||||
bool zone_underglow = JsonUtils::JsonGetBool(debug_settings, "underglow", false);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create a single zone/LED |
|
||||
@@ -371,21 +386,23 @@ void RGBController_Debug::SetupZones()
|
||||
{
|
||||
zone single_zone;
|
||||
|
||||
single_zone.name = "Single Zone";
|
||||
single_zone.type = ZONE_TYPE_SINGLE;
|
||||
single_zone.leds_min = 1;
|
||||
single_zone.leds_max = 1;
|
||||
single_zone.leds_count = 1;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones.push_back(single_zone);
|
||||
}
|
||||
else
|
||||
|
||||
zones[zone_idx].name = "Single Zone";
|
||||
zones[zone_idx].type = ZONE_TYPE_SINGLE;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones[zone_idx] = single_zone;
|
||||
zones[zone_idx].flags = ZONE_FLAG_MANUALLY_CONFIGURABLE_DEVICE_SPECIFIC;
|
||||
}
|
||||
|
||||
zones[zone_idx].leds_min = 1;
|
||||
zones[zone_idx].leds_max = 1;
|
||||
zones[zone_idx].leds_count = 1;
|
||||
|
||||
led single_led;
|
||||
|
||||
single_led.name = "Single LED";
|
||||
@@ -394,6 +411,27 @@ void RGBController_Debug::SetupZones()
|
||||
|
||||
led_alt_names.push_back("");
|
||||
|
||||
nlohmann::json configuration_json;
|
||||
JsonUtils::JsonParse(configuration, configuration_json);
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
/*-----------------------------------------*\
|
||||
| Create test configuration |
|
||||
\*-----------------------------------------*/
|
||||
configuration_json["zones"][zone_idx]["schema"]["color_order"]["title"] = "Color Order";
|
||||
configuration_json["zones"][zone_idx]["schema"]["color_order"]["type"] = "string";
|
||||
configuration_json["zones"][zone_idx]["schema"]["color_order"]["enum"][0] = "RGB";
|
||||
configuration_json["zones"][zone_idx]["schema"]["color_order"]["enum"][1] = "GRB";
|
||||
}
|
||||
|
||||
if((zones[zone_idx].flags & ZONE_FLAG_MANUALLY_CONFIGURED_DEVICE_SPECIFIC) == 0)
|
||||
{
|
||||
configuration_json["zones"][zone_idx]["configuration"]["color_order"] = "RGB";
|
||||
}
|
||||
|
||||
configuration = configuration_json.dump();
|
||||
|
||||
zone_idx++;
|
||||
}
|
||||
|
||||
@@ -404,22 +442,18 @@ void RGBController_Debug::SetupZones()
|
||||
{
|
||||
zone linear_zone;
|
||||
|
||||
linear_zone.name = "Linear Zone";
|
||||
linear_zone.type = ZONE_TYPE_LINEAR;
|
||||
linear_zone.leds_min = 10;
|
||||
linear_zone.leds_max = 10;
|
||||
linear_zone.leds_count = 10;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones.push_back(linear_zone);
|
||||
}
|
||||
else
|
||||
{
|
||||
zones[zone_idx] = linear_zone;
|
||||
}
|
||||
|
||||
for(std::size_t led_idx = 0; led_idx < 10; led_idx++)
|
||||
zones[zone_idx].name = "Linear Zone";
|
||||
zones[zone_idx].type = ZONE_TYPE_LINEAR;
|
||||
zones[zone_idx].leds_min = 10;
|
||||
zones[zone_idx].leds_max = 10;
|
||||
zones[zone_idx].leds_count = 10;
|
||||
|
||||
for(std::size_t led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
|
||||
{
|
||||
led linear_led;
|
||||
|
||||
@@ -441,6 +475,24 @@ void RGBController_Debug::SetupZones()
|
||||
KEYBOARD_LAYOUT layout = KEYBOARD_LAYOUT::KEYBOARD_LAYOUT_ANSI_QWERTY;
|
||||
KEYBOARD_SIZE size = KEYBOARD_SIZE::KEYBOARD_SIZE_FULL;
|
||||
|
||||
nlohmann::json configuration_json;
|
||||
JsonUtils::JsonParse(configuration, configuration_json);
|
||||
|
||||
zone keyboard_zone;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones.push_back(keyboard_zone);
|
||||
}
|
||||
|
||||
zones[zone_idx].name = "Keyboard Zone";
|
||||
zones[zone_idx].type = ZONE_TYPE_MATRIX;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones[zone_idx].flags = ZONE_FLAG_MANUALLY_CONFIGURABLE_DEVICE_SPECIFIC | ZONE_FLAG_ZONE_GEOMETRY_MAY_CHANGE;
|
||||
}
|
||||
|
||||
if(debug_settings.contains("layout"))
|
||||
{
|
||||
KEYBOARD_LAYOUT temp_layout = debug_settings["layout"];
|
||||
@@ -451,6 +503,29 @@ void RGBController_Debug::SetupZones()
|
||||
}
|
||||
}
|
||||
|
||||
if(zones[zone_idx].flags & ZONE_FLAG_MANUALLY_CONFIGURED_DEVICE_SPECIFIC)
|
||||
{
|
||||
if(configuration_json.contains("zones") && (zone_idx < (int)configuration_json["zones"].size()))
|
||||
{
|
||||
if(configuration_json["zones"][zone_idx].contains("configuration"))
|
||||
{
|
||||
if(configuration_json["zones"][zone_idx]["configuration"].contains("layout"))
|
||||
{
|
||||
std::string layout_string = configuration_json["zones"][zone_idx]["configuration"]["layout"];
|
||||
|
||||
for(std::size_t layout_idx = 0; layout_idx < NUM_LAYOUTS; layout_idx++)
|
||||
{
|
||||
if(layout_names[layout_idx] == layout_string)
|
||||
{
|
||||
layout = (KEYBOARD_LAYOUT)layout_idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(debug_settings.contains("size"))
|
||||
{
|
||||
size = debug_settings["size"];
|
||||
@@ -458,8 +533,6 @@ void RGBController_Debug::SetupZones()
|
||||
|
||||
KeyboardLayoutManager new_kb(layout, size);
|
||||
|
||||
description += ", Layout: " + layout_names[layout] + ", Size: " + new_kb.GetName();
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Check for custom key inserts and swaps |
|
||||
\*---------------------------------------------*/
|
||||
@@ -518,25 +591,12 @@ void RGBController_Debug::SetupZones()
|
||||
new_kb.ChangeKeys(change);
|
||||
}
|
||||
|
||||
zone keyboard_zone;
|
||||
zones[zone_idx].leds_min = new_kb.GetKeyCount();
|
||||
zones[zone_idx].leds_max = new_kb.GetKeyCount();
|
||||
zones[zone_idx].leds_count = new_kb.GetKeyCount();
|
||||
zones[zone_idx].matrix_map = new_kb.GetKeyMap(KEYBOARD_MAP_FILL_TYPE_COUNT);
|
||||
|
||||
keyboard_zone.name = "Keyboard Zone";
|
||||
keyboard_zone.type = ZONE_TYPE_MATRIX;
|
||||
keyboard_zone.leds_min = new_kb.GetKeyCount();
|
||||
keyboard_zone.leds_max = new_kb.GetKeyCount();
|
||||
keyboard_zone.leds_count = new_kb.GetKeyCount();
|
||||
keyboard_zone.matrix_map = new_kb.GetKeyMap(KEYBOARD_MAP_FILL_TYPE_COUNT);
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones.push_back(keyboard_zone);
|
||||
}
|
||||
else
|
||||
{
|
||||
zones[zone_idx] = keyboard_zone;
|
||||
}
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < keyboard_zone.leds_count; led_idx++)
|
||||
for(unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
|
||||
{
|
||||
led keyboard_led;
|
||||
|
||||
@@ -547,6 +607,28 @@ void RGBController_Debug::SetupZones()
|
||||
led_alt_names.push_back(new_kb.GetKeyAltNameAt(led_idx));
|
||||
}
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
/*-----------------------------------------*\
|
||||
| Create test configuration |
|
||||
\*-----------------------------------------*/
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["title"] = "Layout";
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["type"] = "string";
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["enum"][0] = "Default",
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["enum"][1] = "ANSI QWERTY";
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["enum"][2] = "ISO QWERTY";
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["enum"][3] = "ISO QWERTZ";
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["enum"][4] = "ISO AZERTY";
|
||||
configuration_json["zones"][zone_idx]["schema"]["layout"]["enum"][5] = "JIS";
|
||||
}
|
||||
|
||||
if((zones[zone_idx].flags & ZONE_FLAG_MANUALLY_CONFIGURED_DEVICE_SPECIFIC) == 0)
|
||||
{
|
||||
configuration_json["zones"][zone_idx]["configuration"]["layout"] = "Default";
|
||||
}
|
||||
|
||||
configuration = configuration_json.dump();
|
||||
|
||||
zone_idx++;
|
||||
}
|
||||
|
||||
@@ -647,6 +729,11 @@ void RGBController_Debug::SetupZones()
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_Debug::DeviceConfigureDevice()
|
||||
{
|
||||
SetupDevice();
|
||||
}
|
||||
|
||||
void RGBController_Debug::DeviceConfigureZone(int zone_idx)
|
||||
{
|
||||
if((size_t)zone_idx < zones.size())
|
||||
@@ -674,3 +761,13 @@ void RGBController_Debug::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_Debug::DeviceUpdateDeviceSpecificConfiguration()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_Debug::DeviceUpdateDeviceSpecificZoneConfiguration(int zone)
|
||||
{
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ public:
|
||||
RGBController_Debug(bool custom, json settings);
|
||||
~RGBController_Debug();
|
||||
|
||||
void SetupDevice();
|
||||
void SetupZones();
|
||||
|
||||
void DeviceConfigureDevice();
|
||||
void DeviceConfigureZone(int zone_idx);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
@@ -33,6 +35,9 @@ public:
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
void DeviceUpdateDeviceSpecificConfiguration();
|
||||
void DeviceUpdateDeviceSpecificZoneConfiguration(int zone);
|
||||
|
||||
private:
|
||||
json debug_settings;
|
||||
bool custom_controller;
|
||||
|
||||
@@ -235,8 +235,7 @@ void RGBController_E131::SetupZones()
|
||||
led_zone.leds_count = devices[zone_idx].num_leds;
|
||||
led_zone.flags = ZONE_FLAG_MANUALLY_CONFIGURABLE_TYPE
|
||||
| ZONE_FLAG_MANUALLY_CONFIGURABLE_MATRIX_MAP
|
||||
| ZONE_FLAG_MANUALLY_CONFIGURABLE_SEGMENTS
|
||||
| ZONE_FLAG_MANUALLY_CONFIGURABLE_COLOR_ORDER;
|
||||
| ZONE_FLAG_MANUALLY_CONFIGURABLE_SEGMENTS;
|
||||
|
||||
zones.push_back(led_zone);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ ENESMBusController::ENESMBusController(ENESMBusInterface* interface, ene_dev_id
|
||||
| If this is running with TRACE or higher loglevel |
|
||||
| then dump the entire Feature list to log |
|
||||
\*-------------------------------------------------*/
|
||||
if(LogManager::get()->getLoglevel() >= LL_TRACE)
|
||||
if(LogManager::get()->GetLogLevel() >= LL_TRACE)
|
||||
{
|
||||
LOG_TRACE("[ENE SMBus] ENE config table for 0x%02X:", dev);
|
||||
LOG_TRACE(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", config_table[0], config_table[1], config_table[2], config_table[3],
|
||||
|
||||
@@ -154,7 +154,7 @@ DetectedControllers DetectENESMBusDRAMControllers(std::vector<i2c_smbus_interfac
|
||||
{
|
||||
int address_list_idx = -1;
|
||||
|
||||
IF_DRAM_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_DRAM_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
LOG_DEBUG("[ENE SMBus DRAM] Remapping ENE SMBus RAM modules on 0x77");
|
||||
|
||||
@@ -220,9 +220,9 @@ DetectedControllers DetectENESMBusMotherboardControllers(std::vector<i2c_smbus_i
|
||||
for(unsigned int bus = 0; bus < buses.size(); bus++)
|
||||
{
|
||||
// Add ENE (ASUS Aura) motherboard controllers
|
||||
IF_MOBO_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_MOBO_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
if(buses[bus]->pci_subsystem_vendor == ASUS_SUB_VEN || buses[bus]->pci_subsystem_vendor == 0 || buses[bus]->pci_subsystem_vendor == 0xFFFF)
|
||||
if(buses[bus]->info.pci_subsystem_vendor == ASUS_SUB_VEN || buses[bus]->info.pci_subsystem_vendor == 0 || buses[bus]->info.pci_subsystem_vendor == 0xFFFF)
|
||||
{
|
||||
for(unsigned int address_list_idx = 0; address_list_idx < AURA_MOBO_ADDRESS_COUNT; address_list_idx++)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ ene_interface_type ENESMBusInterface_i2c_smbus::GetInterfaceType()
|
||||
|
||||
std::string ENESMBusInterface_i2c_smbus::GetLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
return("I2C: " + return_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ DetectedControllers DetectEVGAAmpereGPUControllers(i2c_smbus_interface* bus, uin
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
EVGAGPUv3Controller* controller;
|
||||
RGBController_EVGAGPUv3* rgb_controller;
|
||||
|
||||
@@ -26,7 +26,7 @@ EVGAGPUv3Controller::~EVGAGPUv3Controller()
|
||||
|
||||
std::string EVGAGPUv3Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
|
||||
@@ -25,7 +25,7 @@ EVGAGP102Controller::~EVGAGP102Controller()
|
||||
|
||||
std::string EVGAGP102Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", zi.dev_addr);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -21,7 +21,7 @@ DetectedControllers DetectEVGAGP102GPUControllers(i2c_smbus_interface* bus, uint
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
std::vector<EVGAGP102Controller*> controllers;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ EVGAGPUv1Controller::~EVGAGPUv1Controller()
|
||||
|
||||
std::string EVGAGPUv1Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -20,7 +20,7 @@ DetectedControllers DetectEVGAPascalGPUControllers(i2c_smbus_interface* bus, uin
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
EVGAGPUv1Controller* controller = new EVGAGPUv1Controller(bus, address, name);
|
||||
RGBController_EVGAGPUv1* rgb_controller = new RGBController_EVGAGPUv1(controller);
|
||||
|
||||
@@ -32,7 +32,7 @@ EVGAACX30SMBusController::~EVGAACX30SMBusController()
|
||||
|
||||
std::string EVGAACX30SMBusController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -46,9 +46,9 @@ DetectedControllers DetectAcx30SMBusControllers(std::vector<i2c_smbus_interface
|
||||
|
||||
for(unsigned int bus = 0; bus < buses.size(); bus++)
|
||||
{
|
||||
IF_MOBO_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_MOBO_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
if(buses[bus]->pci_subsystem_vendor == EVGA_SUB_VEN)
|
||||
if(buses[bus]->info.pci_subsystem_vendor == EVGA_SUB_VEN)
|
||||
{
|
||||
LOG_DEBUG(SMBUS_CHECK_DEVICE_MESSAGE_EN, EVGA_DETECTOR_NAME, bus, VENDOR_NAME, SMBUS_ADDRESS);
|
||||
// Check for ACX 30 controller at 0x28
|
||||
|
||||
@@ -25,7 +25,7 @@ EVGAGPUv2Controller::~EVGAGPUv2Controller()
|
||||
|
||||
std::string EVGAGPUv2Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
|
||||
@@ -19,7 +19,7 @@ DetectedControllers DetectEVGATuringGPUControllers(i2c_smbus_interface* bus, uin
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
EVGAGPUv2Controller* controller = new EVGAGPUv2Controller(bus, address, name);
|
||||
RGBController_EVGAGPUv2* rgb_controller = new RGBController_EVGAGPUv2(controller);
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include "ElgatoLightStripController.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "ElgatoLightStripController.h"
|
||||
#include "JsonUtils.h"
|
||||
#include "LogManager.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
@@ -58,7 +59,8 @@ ElgatoLightStripController::ElgatoLightStripController(std::string ip)
|
||||
}
|
||||
|
||||
std::string result = recv_list[5];
|
||||
json elgato_lightstrip_data = json::parse(result);
|
||||
json elgato_lightstrip_data;
|
||||
JsonUtils::JsonParse(result, elgato_lightstrip_data);
|
||||
|
||||
firmware_version = elgato_lightstrip_data["firmwareVersion"];
|
||||
serialnumber = elgato_lightstrip_data["serialNumber"];
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ GainwardGPUv1Controller::~GainwardGPUv1Controller()
|
||||
|
||||
std::string GainwardGPUv1Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ GainwardGPUv2Controller::~GainwardGPUv2Controller() = default;
|
||||
|
||||
std::string GainwardGPUv2Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -26,7 +26,7 @@ GalaxGPUv1Controller::~GalaxGPUv1Controller()
|
||||
|
||||
std::string GalaxGPUv1Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -26,7 +26,7 @@ GalaxGPUv2Controller::~GalaxGPUv2Controller()
|
||||
|
||||
std::string GalaxGPUv2Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ RGBFusion2BlackwellGPUController::~RGBFusion2BlackwellGPUController()
|
||||
|
||||
std::string RGBFusion2BlackwellGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
|
||||
bool TestForGigabyteRGBFusion2BlackwellGPUController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
if(bus->pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
if(bus->info.pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ unsigned int RGBFusion2DRAMController::GetLEDCount()
|
||||
|
||||
std::string RGBFusion2DRAMController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ DetectedControllers DetectGigabyteRGBFusion2DRAMControllers(std::vector<i2c_smbu
|
||||
|
||||
for(unsigned int bus = 0; bus < buses.size(); bus++)
|
||||
{
|
||||
IF_DRAM_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_DRAM_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
// Check for RGB Fusion 2 DRAM controller at 0x67
|
||||
if(TestForGigabyteRGBFusion2DRAMController(buses[bus], 0x67))
|
||||
|
||||
@@ -28,7 +28,7 @@ RGBFusion2GPUController::~RGBFusion2GPUController()
|
||||
|
||||
std::string RGBFusion2GPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
|
||||
bool TestForGigabyteRGBFusion2GPUController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
if(bus->pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
if(bus->info.pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ std::string RGBFusion2SMBusController::GetDeviceName()
|
||||
|
||||
std::string RGBFusion2SMBusController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+3
-3
@@ -114,16 +114,16 @@ DetectedControllers DetectGigabyteRGBFusion2SMBusControllers(std::vector<i2c_smb
|
||||
LOG_DEBUG(GIGABYTE_FOUND_MB_MESSAGE_EN, DETECTOR_NAME, dmi.getMainboard().c_str());
|
||||
for(unsigned int bus = 0; bus < buses.size(); bus++)
|
||||
{
|
||||
IF_MOBO_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_MOBO_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
if(buses[bus]->pci_subsystem_vendor == GIGABYTE_SUB_VEN)
|
||||
if(buses[bus]->info.pci_subsystem_vendor == GIGABYTE_SUB_VEN)
|
||||
{
|
||||
/*-------------------------------------*\
|
||||
| TODO - Is this necessary? Or an |
|
||||
| artifact of my own system? Skip dmcd |
|
||||
| devices |
|
||||
\*-------------------------------------*/
|
||||
std::string device_name = std::string(buses[bus]->device_name);
|
||||
std::string device_name = std::string(buses[bus]->info.device_name);
|
||||
|
||||
if(device_name.find("dmdc") == std::string::npos)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ std::string RGBFusionController::GetDeviceName()
|
||||
|
||||
std::string RGBFusionController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -49,9 +49,9 @@ DetectedControllers DetectGigabyteRGBFusionControllers(std::vector<i2c_smbus_int
|
||||
|
||||
for(unsigned int bus = 0; bus < buses.size(); bus++)
|
||||
{
|
||||
IF_MOBO_SMBUS(buses[bus]->pci_vendor, buses[bus]->pci_device)
|
||||
IF_MOBO_SMBUS(buses[bus]->info.pci_vendor, buses[bus]->info.pci_device)
|
||||
{
|
||||
if(buses[bus]->pci_subsystem_vendor == GIGABYTE_SUB_VEN)
|
||||
if(buses[bus]->info.pci_subsystem_vendor == GIGABYTE_SUB_VEN)
|
||||
{
|
||||
LOG_DEBUG(SMBUS_CHECK_DEVICE_MESSAGE_EN, DETECTOR_NAME, bus, VENDOR_NAME, SMBUS_ADDRESS);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ RGBFusionGPUController::~RGBFusionGPUController()
|
||||
|
||||
std::string RGBFusionGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "base64.hpp"
|
||||
#include "GoveeController.h"
|
||||
#include "JsonUtils.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace std::chrono_literals;
|
||||
@@ -106,7 +107,8 @@ void GoveeController::ReceiveBroadcast(char* recv_buf, int size)
|
||||
/*-----------------------------------------------------*\
|
||||
| Convert null-terminated response to JSON |
|
||||
\*-----------------------------------------------------*/
|
||||
json response = json::parse(recv_buf);
|
||||
json response;
|
||||
JsonUtils::JsonParse(recv_buf, response);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check if the response contains the method name |
|
||||
|
||||
@@ -40,7 +40,7 @@ HyperXDRAMController::~HyperXDRAMController()
|
||||
|
||||
std::string HyperXDRAMController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -55,7 +55,7 @@ DetectedControllers DetectHyperXDRAMControllers(i2c_smbus_interface* bus, std::v
|
||||
unsigned char slots_valid = 0x00;
|
||||
|
||||
// Check for HyperX controller at 0x27
|
||||
LOG_DEBUG("[%s] Testing bus %d at address 0x27", HYPERX_CONTROLLER_NAME, bus->port_id);
|
||||
LOG_DEBUG("[%s] Testing bus %d at address 0x27", HYPERX_CONTROLLER_NAME, bus->info.port_id);
|
||||
|
||||
if(TestForHyperXDRAMController(bus, 0x27))
|
||||
{
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstdint>
|
||||
#include "KasaSmartController.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "JsonUtils.h"
|
||||
#include "KasaSmartController.h"
|
||||
#include "hsv.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
@@ -64,11 +65,7 @@ bool KasaSmartController::Initialize()
|
||||
}
|
||||
|
||||
json system_information;
|
||||
try
|
||||
{
|
||||
system_information = json::parse(system_info_json);
|
||||
}
|
||||
catch (json::parse_error&)
|
||||
if(!JsonUtils::JsonParse(system_info_json, system_information))
|
||||
{
|
||||
/*-----------------------*\
|
||||
| Can't parse system info |
|
||||
|
||||
@@ -28,7 +28,7 @@ KingstonFuryDRAMController::KingstonFuryDRAMController(i2c_smbus_interface* bus,
|
||||
|
||||
std::string KingstonFuryDRAMController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
return_string.append(", addresses [");
|
||||
for(std::size_t idx = 0; idx < slots.size(); idx++)
|
||||
{
|
||||
|
||||
@@ -104,7 +104,7 @@ void LEDStripController::InitializeI2C(char* i2cname)
|
||||
{
|
||||
for(unsigned int i2c_idx = 0; i2c_idx < ResourceManager::get()->GetI2CBuses().size(); i2c_idx++)
|
||||
{
|
||||
if(ResourceManager::get()->GetI2CBuses()[i2c_idx]->device_name == std::string(i2cname))
|
||||
if(ResourceManager::get()->GetI2CBuses()[i2c_idx]->info.device_name == std::string(i2cname))
|
||||
{
|
||||
if(i2c_addr < 128)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ std::string LEDStripController::GetLocation()
|
||||
}
|
||||
else if(i2cport != NULL)
|
||||
{
|
||||
return("I2C: " + std::string(i2cport->device_name) + ", Address " + std::to_string(i2c_addr));
|
||||
return("I2C: " + std::string(i2cport->info.device_name) + ", Address " + std::to_string(i2c_addr));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -74,7 +74,7 @@ RGBController_LenovoUSB::RGBController_LenovoUSB(LenovoUSBController* controller
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
vendor = "Lenovo";
|
||||
|
||||
if(LogManager::get()->getLoglevel() >= LL_TRACE)
|
||||
if(LogManager::get()->GetLogLevel() >= LL_TRACE)
|
||||
{
|
||||
DumpControllerInformation();
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ void logitech_device::initialiseDevice()
|
||||
| If this is running with DEBUG or higher loglevel then |
|
||||
| dump the entire Feature list to log |
|
||||
\*-----------------------------------------------------------------*/
|
||||
if(LogManager::get()->getLoglevel() > 4)
|
||||
if(LogManager::get()->GetLogLevel() >= LL_DEBUG)
|
||||
{
|
||||
getDeviceFeatureList(); //This will populate the feature list
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ MSIGPUController::~MSIGPUController()
|
||||
|
||||
std::string MSIGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -18,7 +18,7 @@ DetectedControllers DetectMSIGPUControllers(i2c_smbus_interface* bus, uint8_t i2
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if((bus->pci_vendor != NVIDIA_VEN || bus->port_id == 1) && (bus->pci_vendor != AMD_GPU_VEN || is_amd_gpu_i2c_bus(bus)))
|
||||
if((bus->info.pci_vendor != NVIDIA_VEN || bus->info.port_id == 1) && (bus->info.pci_vendor != AMD_GPU_VEN || is_amd_gpu_i2c_bus(bus)))
|
||||
{
|
||||
MSIGPUController* controller = new MSIGPUController(bus, i2c_addr, name);
|
||||
RGBController_MSIGPU* rgb_controller = new RGBController_MSIGPU(controller);
|
||||
|
||||
@@ -29,7 +29,7 @@ MSIGPUv2Controller::~MSIGPUv2Controller()
|
||||
|
||||
std::string MSIGPUv2Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -19,9 +19,9 @@ DetectedControllers DetectMSIGPUv2Controllers(i2c_smbus_interface* bus, uint8_t
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->pci_vendor != NVIDIA_VEN || bus->port_id == 1)
|
||||
if(bus->info.pci_vendor != NVIDIA_VEN || bus->info.port_id == 1)
|
||||
{
|
||||
int msi_gpu_id = bus->pci_subsystem_device | bus->pci_device << 16;
|
||||
int msi_gpu_id = bus->info.pci_subsystem_device | bus->info.pci_device << 16;
|
||||
MSIGPUv2Controller* controller = new MSIGPUv2Controller(bus, i2c_addr, name);
|
||||
RGBController_MSIGPUv2* rgb_controller = new RGBController_MSIGPUv2(controller, msi_gpu_id);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ ManliGPUController::~ManliGPUController()
|
||||
|
||||
std::string ManliGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "NanoleafController.h"
|
||||
#include "LogManager.h"
|
||||
#include "httplib.h"
|
||||
#include "JsonUtils.h"
|
||||
|
||||
long APIRequest(std::string method, std::string location, std::string URI, json* request_data = nullptr, json* response_data = nullptr)
|
||||
{
|
||||
@@ -91,7 +92,7 @@ long APIRequest(std::string method, std::string location, std::string URI, json*
|
||||
{
|
||||
if(response_data)
|
||||
{
|
||||
*response_data = json::parse(body);
|
||||
JsonUtils::JsonParse(body, *response_data);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -27,7 +27,7 @@ PNYARGBEpicXGPUController::~PNYARGBEpicXGPUController()
|
||||
|
||||
std::string PNYARGBEpicXGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", i2c_addr);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -21,7 +21,7 @@ DetectedControllers DetectPNYARGBEpicXGPUSmallControllers(i2c_smbus_interface* b
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
PNYARGBEpicXGPUController* controller = new PNYARGBEpicXGPUController(bus, i2c_addr, name, false);
|
||||
RGBController_PNYARGBEpicXGPU* rgb_controller = new RGBController_PNYARGBEpicXGPU(controller);
|
||||
@@ -36,7 +36,7 @@ DetectedControllers DetectPNYARGBEpicXGPULargeControllers(i2c_smbus_interface* b
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
PNYARGBEpicXGPUController* controller = new PNYARGBEpicXGPUController(bus, i2c_addr, name, true);
|
||||
RGBController_PNYARGBEpicXGPU* rgb_controller = new RGBController_PNYARGBEpicXGPU(controller);
|
||||
|
||||
@@ -30,7 +30,7 @@ std::string PNYGPUController::GetDeviceName()
|
||||
|
||||
std::string PNYGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -19,7 +19,7 @@ DetectedControllers DetectPNYGPUControllers(i2c_smbus_interface* bus, uint8_t i2
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
PNYGPUController* controller = new PNYGPUController(bus, i2c_addr, name);
|
||||
RGBController_PNYGPU* rgb_controller = new RGBController_PNYGPU(controller);
|
||||
|
||||
@@ -25,7 +25,7 @@ PNYLovelaceGPUController::~PNYLovelaceGPUController()
|
||||
|
||||
std::string PNYLovelaceGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -19,7 +19,7 @@ DetectedControllers DetectPNYLovelaceGPUControllers(i2c_smbus_interface* bus, ui
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
PNYLovelaceGPUController* controller = new PNYLovelaceGPUController(bus, i2c_addr, name);
|
||||
RGBController_PNYLovelaceGPU* rgb_controller = new RGBController_PNYLovelaceGPU(controller);
|
||||
|
||||
@@ -25,7 +25,7 @@ PalitGPUController::~PalitGPUController()
|
||||
|
||||
std::string PalitGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -21,7 +21,7 @@ DetectedControllers DetectPalitGPUControllers(i2c_smbus_interface* bus, uint8_t
|
||||
{
|
||||
DetectedControllers detected_controllers;
|
||||
|
||||
if(bus->port_id == 1)
|
||||
if(bus->info.port_id == 1)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Check for PALIT string |
|
||||
|
||||
@@ -46,7 +46,7 @@ std::string PatriotViperController::GetDeviceName()
|
||||
|
||||
std::string PatriotViperController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -45,7 +45,7 @@ DetectedControllers DetectPatriotViperControllers(i2c_smbus_interface* bus, std:
|
||||
/*-----------------------------------------------------*\
|
||||
| Check for Patriot Viper controller at 0x77 |
|
||||
\*-----------------------------------------------------*/
|
||||
LOG_DEBUG("[%s] Testing bus %d at address 0x77", PATRIOT_CONTROLLER_NAME, bus->port_id);
|
||||
LOG_DEBUG("[%s] Testing bus %d at address 0x77", PATRIOT_CONTROLLER_NAME, bus->info.port_id);
|
||||
|
||||
if(TestForPatriotViperController(bus, 0x77))
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ std::string PatriotViperSteelController::GetDeviceName()
|
||||
|
||||
std::string PatriotViperSteelController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -43,7 +43,7 @@ DetectedControllers DetectPatriotViperSteelControllers(i2c_smbus_interface* bus,
|
||||
/*-----------------------------------------------------*\
|
||||
| Check for Patriot Viper controller at 0x77 |
|
||||
\*-----------------------------------------------------*/
|
||||
LOG_DEBUG("[%s] Testing bus %d at address 0x77", PATRIOT_CONTROLLER_NAME, bus->port_id);
|
||||
LOG_DEBUG("[%s] Testing bus %d at address 0x77", PATRIOT_CONTROLLER_NAME, bus->info.port_id);
|
||||
|
||||
if(TestForPatriotViperSteelController(bus, 0x77))
|
||||
{
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "PhilipsWizController.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "JsonUtils.h"
|
||||
#include "PhilipsWizController.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace std::chrono_literals;
|
||||
@@ -194,7 +195,8 @@ void PhilipsWizController::ReceiveThreadFunction()
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Convert null-terminated response to JSON |
|
||||
\*-----------------------------------------------------------------*/
|
||||
json response = json::parse(recv_buf);
|
||||
json response;
|
||||
JsonUtils::JsonParse(recv_buf, response);
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Check if the response contains the method name |
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ PowerColorRedDevilV1Controller::PowerColorRedDevilV1Controller(i2c_smbus_interfa
|
||||
this->dev = dev;
|
||||
this->name = dev_name;
|
||||
|
||||
if(bus->pci_device > AMD_NAVI10_DEV) // Only Navi 2 cards have this mode
|
||||
if(bus->info.pci_device > AMD_NAVI10_DEV) // Only Navi 2 cards have this mode
|
||||
{
|
||||
this->has_sync_mode = true;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ PowerColorRedDevilV1Controller::~PowerColorRedDevilV1Controller()
|
||||
|
||||
std::string PowerColorRedDevilV1Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ PowerColorRedDevilV2Controller::~PowerColorRedDevilV2Controller()
|
||||
|
||||
std::string PowerColorRedDevilV2Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
@@ -164,4 +164,4 @@ int PowerColorRedDevilV2Controller::RegisterWrite(unsigned char reg, unsigned ch
|
||||
int ret = bus->i2c_smbus_write_i2c_block_data(dev, reg, 3, data);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ enum
|
||||
|
||||
bool TestForSapphireGPUController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
if(bus->pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
if(bus->info.pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ SapphireNitroGlowV1Controller::~SapphireNitroGlowV1Controller()
|
||||
|
||||
std::string SapphireNitroGlowV1Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ SapphireNitroGlowV3Controller::~SapphireNitroGlowV3Controller()
|
||||
|
||||
std::string SapphireNitroGlowV3Controller::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -25,7 +25,7 @@ TForceXtreemController::~TForceXtreemController()
|
||||
|
||||
std::string TForceXtreemController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
|
||||
@@ -29,7 +29,7 @@ ZotacBlackwellGPUController::~ZotacBlackwellGPUController()
|
||||
|
||||
std::string ZotacBlackwellGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -24,7 +24,7 @@ ZotacTuringGPUController::~ZotacTuringGPUController()
|
||||
|
||||
std::string ZotacTuringGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
@@ -30,7 +30,7 @@ ZotacV2GPUController::~ZotacV2GPUController()
|
||||
|
||||
std::string ZotacV2GPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
std::string return_string(bus->info.device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
|
||||
+11
-23
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include "DetectionManager.h"
|
||||
#include "JsonUtils.h"
|
||||
#include "LogManager.h"
|
||||
#include "pci_ids.h"
|
||||
#include "ProfileManager.h"
|
||||
@@ -30,11 +31,6 @@ using namespace std::chrono_literals;
|
||||
\*---------------------------------------------------------*/
|
||||
const char* DETECTIONMANAGER = "DetectionManager";
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Define a macro for QT lupdate to parse |
|
||||
\*---------------------------------------------------------*/
|
||||
#define QT_TRANSLATE_NOOP(scope, x) x
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Warning Strings |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -374,7 +370,7 @@ void DetectionManager::UnregisterDetectionCallback(DetectionCallback callback, v
|
||||
\*---------------------------------------------------------*/
|
||||
void DetectionManager::RegisterI2CBus(i2c_smbus_interface *bus)
|
||||
{
|
||||
LOG_INFO("[%s] Registering I2C interface: %s Device %04X:%04X Subsystem: %04X:%04X", DETECTIONMANAGER, bus->device_name, bus->pci_vendor, bus->pci_device, bus->pci_subsystem_vendor, bus->pci_subsystem_device);
|
||||
LOG_INFO("[%s] Registering I2C interface: %s Device %04X:%04X Subsystem: %04X:%04X", DETECTIONMANAGER, bus->info.device_name, bus->info.pci_vendor, bus->info.pci_device, bus->info.pci_subsystem_vendor, bus->info.pci_subsystem_device);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the new bus to the list |
|
||||
@@ -597,8 +593,6 @@ void DetectionManager::BackgroundDetectDevices()
|
||||
hid_device_info* current_hid_device;
|
||||
json detector_settings;
|
||||
hid_device_info* hid_devices = NULL;
|
||||
bool hid_safe_mode = false;
|
||||
unsigned int initial_detection_delay_ms = 0;
|
||||
|
||||
LOG_INFO("------------------------------------------------------");
|
||||
LOG_INFO("| Start device detection |");
|
||||
@@ -621,18 +615,12 @@ void DetectionManager::BackgroundDetectDevices()
|
||||
/*-----------------------------------------------------*\
|
||||
| Check HID safe mode setting |
|
||||
\*-----------------------------------------------------*/
|
||||
if(detector_settings.contains("hid_safe_mode"))
|
||||
{
|
||||
hid_safe_mode = detector_settings["hid_safe_mode"];
|
||||
}
|
||||
bool hid_safe_mode = JsonUtils::JsonGetBool(detector_settings, "hid_safe_mode");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check initial detection delay setting |
|
||||
\*-----------------------------------------------------*/
|
||||
if(detector_settings.contains("initial_detection_delay_ms"))
|
||||
{
|
||||
initial_detection_delay_ms = detector_settings["initial_detection_delay_ms"];
|
||||
}
|
||||
unsigned int initial_detection_delay_ms = JsonUtils::JsonGetInt(detector_settings, "initial_detection_delay_ms");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If configured, delay detection for the configured |
|
||||
@@ -926,7 +914,7 @@ void DetectionManager::BackgroundDetectI2CDRAMDevices(json detector_settings)
|
||||
|
||||
for(std::size_t bus = 0; bus < i2c_buses.size() && IsAnyDimmDetectorEnabled(detector_settings); bus++)
|
||||
{
|
||||
IF_DRAM_SMBUS(i2c_buses[bus]->pci_vendor, i2c_buses[bus]->pci_device)
|
||||
IF_DRAM_SMBUS(i2c_buses[bus]->info.pci_vendor, i2c_buses[bus]->info.pci_device)
|
||||
{
|
||||
std::vector<SPDWrapper> slots;
|
||||
SPDMemoryType dram_type = SPD_RESERVED;
|
||||
@@ -1019,10 +1007,10 @@ void DetectionManager::BackgroundDetectI2CPCIDevices(json detector_settings)
|
||||
|
||||
for(std::size_t bus = 0; bus < i2c_buses.size(); bus++)
|
||||
{
|
||||
if(i2c_buses[bus]->pci_vendor == i2c_pci_device_detectors[i2c_detector_idx].ven_id &&
|
||||
i2c_buses[bus]->pci_device == i2c_pci_device_detectors[i2c_detector_idx].dev_id &&
|
||||
i2c_buses[bus]->pci_subsystem_vendor == i2c_pci_device_detectors[i2c_detector_idx].subven_id &&
|
||||
i2c_buses[bus]->pci_subsystem_device == i2c_pci_device_detectors[i2c_detector_idx].subdev_id)
|
||||
if(i2c_buses[bus]->info.pci_vendor == i2c_pci_device_detectors[i2c_detector_idx].ven_id &&
|
||||
i2c_buses[bus]->info.pci_device == i2c_pci_device_detectors[i2c_detector_idx].dev_id &&
|
||||
i2c_buses[bus]->info.pci_subsystem_vendor == i2c_pci_device_detectors[i2c_detector_idx].subven_id &&
|
||||
i2c_buses[bus]->info.pci_subsystem_device == i2c_pci_device_detectors[i2c_detector_idx].subdev_id)
|
||||
{
|
||||
DetectedControllers detected_controllers = i2c_pci_device_detectors[i2c_detector_idx].function(i2c_buses[bus], i2c_pci_device_detectors[i2c_detector_idx].i2c_addr, i2c_pci_device_detectors[i2c_detector_idx].name);
|
||||
|
||||
@@ -1324,7 +1312,7 @@ void DetectionManager::BackgroundHIDInit()
|
||||
\*---------------------------------------------------------*/
|
||||
void DetectionManager::RunHIDDetector(hid_device_info* current_hid_device, json detector_settings)
|
||||
{
|
||||
if(LogManager::get()->getLoglevel() >= LL_DEBUG)
|
||||
if(LogManager::get()->GetLogLevel() >= LL_DEBUG)
|
||||
{
|
||||
const char* manu_name = StringUtils::wchar_to_char(current_hid_device->manufacturer_string);
|
||||
const char* prod_name = StringUtils::wchar_to_char(current_hid_device->product_string);
|
||||
@@ -1438,7 +1426,7 @@ void DetectionManager::RunHIDDetector(hid_device_info* current_hid_device, json
|
||||
|
||||
void DetectionManager::RunHIDWrappedDetector(const hidapi_wrapper* wrapper, hid_device_info* current_hid_device, json detector_settings)
|
||||
{
|
||||
if(LogManager::get()->getLoglevel() >= LL_DEBUG)
|
||||
if(LogManager::get()->GetLogLevel() >= LL_DEBUG)
|
||||
{
|
||||
const char* manu_name = StringUtils::wchar_to_char(current_hid_device->manufacturer_string);
|
||||
const char* prod_name = StringUtils::wchar_to_char(current_hid_device->product_string);
|
||||
|
||||
+51
-40
@@ -45,45 +45,47 @@ Each packet starts with a header that indicates the packet is an OpenRGB SDK pac
|
||||
|
||||
The following IDs represent different SDK commands. Each ID packet has a certain format of data associated with it, which will be explained under each ID's section of this document. Gaps have been left in the ID values to allow for future expansion. The same ID values are often used for both request and response packets.
|
||||
|
||||
| Value | Name | Description | Protocol Version |
|
||||
| ----- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ---------------- |
|
||||
| 0 | [NET_PACKET_ID_REQUEST_CONTROLLER_COUNT](#net_packet_id_request_controller_count) | Request RGBController device count/device IDs from server | 0 |
|
||||
| 1 | [NET_PACKET_ID_REQUEST_CONTROLLER_DATA](#net_packet_id_request_controller_data) | Request RGBController data block | 0 |
|
||||
| 10 | [NET_PACKET_ID_ACK](#net_packet_id_ack) | Acknowledgement | 6 |
|
||||
| 40 | [NET_PACKET_ID_REQUEST_PROTOCOL_VERSION](#net_packet_id_request_protocol_version) | Request OpenRGB SDK protocol version from server | 1* |
|
||||
| 50 | [NET_PACKET_ID_SET_CLIENT_NAME](#net_packet_id_set_client_name) | Send client name string to server | 0 |
|
||||
| 51 | [NET_PACKET_ID_SET_SERVER_NAME](#net_packet_id_set_server_name) | Send server name string to client | 6 |
|
||||
| 52 | [NET_PACKET_ID_SET_CLIENT_FLAGS](#net_packet_id_set_client_flags) | Send client flags to server | 6 |
|
||||
| 53 | [NET_PACKET_ID_SET_SERVER_FLAGS](#net_packet_id_set_server_flags) | Send server flags to client | 6 |
|
||||
| 100 | [NET_PACKET_ID_DEVICE_LIST_UPDATED](#net_packet_id_device_list_updated) | Indicate to clients that device list has updated | 1 |
|
||||
| 101 | [NET_PACKET_ID_DETECTION_STARTED](#net_packet_id_detection_started) | Indicate to clients that detection started | 6 |
|
||||
| 102 | [NET_PACKET_ID_DETECTION_PROGRESS_CHANGED](#net_packet_id_detection_progress_changed) | Indicate to clients that detection progress changed | 6 |
|
||||
| 103 | [NET_PACKET_ID_DETECTION_COMPLETE](#net_packet_id_detection_complete) | Indicate to clients that detection completed | 6 |
|
||||
| 140 | [NET_PACKET_ID_REQUEST_RESCAN_DEVICES](#net_packet_id_request_rescan_devices) | Request server to rescan devices | 5 |
|
||||
| 150 | [NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST](#net_packet_id_profilemanager_get_profile_list) | Get profile list | 2 |
|
||||
| 151 | [NET_PACKET_ID_PROFILEMANAGER_SAVE_PROFILE](#net_packet_id_profilemanager_save_profile) | Save current configuration in a new profile | 2 |
|
||||
| 152 | [NET_PACKET_ID_PROFILEMANAGER_LOAD_PROFILE](#net_packet_id_profilemanager_load_profile) | Load a given profile | 2 |
|
||||
| 153 | [NET_PACKET_ID_PROFILEMANAGER_DELETE_PROFILE](#net_packet_id_profilemanager_delete_profile) | Delete a given profile | 2 |
|
||||
| 154 | [NET_PACKET_ID_PROFILEMANAGER_UPLOAD_PROFILE](#net_packet_id_profilemanager_upload_profile) | Upload a profile to the server in JSON format | 6 |
|
||||
| 155 | [NET_PACKET_ID_PROFILEMANAGER_DOWNLOAD_PROFILE](#net_packet_id_profilemanager_download_profile) | Download a profile from the server in JSON format | 6 |
|
||||
| 156 | [NET_PACKET_ID_PROFILEMANAGER_GET_ACTIVE_PROFILE](#net_packet_id_profilemanager_get_active_profile) | Get the active profile name | 6 |
|
||||
| 200 | [NET_PACKET_ID_PLUGINMANAGER_GET_PLUGIN_LIST](#net_packet_id_pluginmanager_get_plugin_list) | Get list of plugins | 4 |
|
||||
| 201 | [NET_PACKET_ID_PLUGINMANAGER_PLUGIN_SPECIFIC](#net_packet_id_pluginmanager_plugin_specific) | Interact with a plugin | 4 |
|
||||
| 250 | [NET_PACKET_ID_SETTINGSMANAGER_GET_SETTINGS](#net_packet_id_settingsmanager_get_settings) | Get settings for a given key in JSON format | 6 |
|
||||
| 251 | [NET_PACKET_ID_SETTINGSMANAGER_SET_SETTINGS](#net_packet_id_settingsmanager_set_settings) | Set settings for a given key in JSON format | 6 |
|
||||
| 252 | [NET_PACKET_ID_SETTINGSMANAGER_SAVE_SETTINGS](#net_packet_id_settingsmanager_save_settings) | Save settings | 6 |
|
||||
| 1000 | [NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE](#net_packet_id_rgbcontroller_resizezone) | RGBController::ResizeZone() | 0 |
|
||||
| 1001 | [NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS](#net_packet_id_rgbcontroller_clearsegments) | RGBController::ClearSegments() | 5 |
|
||||
| 1002 | [NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT](#net_packet_id_rgbcontroller_addsegment) | RGBController::AddSegment() | 5 |
|
||||
| 1003 | [NET_PACKET_ID_RGBCONTROLLER_CONFIGUREZONE](#net_packet_id_rgbcontroller_configurezone) | RGBController::ConfigureZone() | 6 |
|
||||
| 1050 | [NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS](#net_packet_id_rgbcontroller_updateleds) | RGBController::UpdateLEDs() | 0 |
|
||||
| 1051 | [NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS](#net_packet_id_rgbcontroller_updatezoneleds) | RGBController::UpdateZoneLEDs() | 0 |
|
||||
| 1052 | [NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED](#net_packet_id_rgbcontroller_updatesingleled) | RGBController::UpdateSingleLED() | 0 |
|
||||
| 1100 | [NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE](#net_packet_id_rgbcontroller_setcustommode) | RGBController::SetCustomMode() | 0 |
|
||||
| 1101 | [NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE](#net_packet_id_rgbcontroller_updatemode) | RGBController::UpdateMode() | 0 |
|
||||
| 1102 | [NET_PACKET_ID_RGBCONTROLLER_SAVEMODE](#net_packet_id_rgbcontroller_savemode) | RGBController::SaveMode() | 3 |
|
||||
| 1103 | [NET_PACKET_ID_RGBCONTROLLER_UPDATEZONEMODE](#net_packet_id_rgbcontroller_updatezonemode) | RGBController::UpdateZoneMode() | 6 |
|
||||
| 1150 | [NET_PACKET_ID_RGBCONTROLLER_SIGNALUPDATE](#net_packet_id_rgbcontroller_signalupdate) | RGBController::SignalUpdate() | 6 |
|
||||
| Value | Name | Description | Protocol Version |
|
||||
| ----- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ---------------- |
|
||||
| 0 | [NET_PACKET_ID_REQUEST_CONTROLLER_COUNT](#net_packet_id_request_controller_count) | Request RGBController device count/device IDs from server | 0 |
|
||||
| 1 | [NET_PACKET_ID_REQUEST_CONTROLLER_DATA](#net_packet_id_request_controller_data) | Request RGBController data block | 0 |
|
||||
| 10 | [NET_PACKET_ID_ACK](#net_packet_id_ack) | Acknowledgement | 6 |
|
||||
| 40 | [NET_PACKET_ID_REQUEST_PROTOCOL_VERSION](#net_packet_id_request_protocol_version) | Request OpenRGB SDK protocol version from server | 1* |
|
||||
| 50 | [NET_PACKET_ID_SET_CLIENT_NAME](#net_packet_id_set_client_name) | Send client name string to server | 0 |
|
||||
| 51 | [NET_PACKET_ID_SET_SERVER_NAME](#net_packet_id_set_server_name) | Send server name string to client | 6 |
|
||||
| 52 | [NET_PACKET_ID_SET_CLIENT_FLAGS](#net_packet_id_set_client_flags) | Send client flags to server | 6 |
|
||||
| 53 | [NET_PACKET_ID_SET_SERVER_FLAGS](#net_packet_id_set_server_flags) | Send server flags to client | 6 |
|
||||
| 100 | [NET_PACKET_ID_DEVICE_LIST_UPDATED](#net_packet_id_device_list_updated) | Indicate to clients that device list has updated | 1 |
|
||||
| 101 | [NET_PACKET_ID_DETECTION_STARTED](#net_packet_id_detection_started) | Indicate to clients that detection started | 6 |
|
||||
| 102 | [NET_PACKET_ID_DETECTION_PROGRESS_CHANGED](#net_packet_id_detection_progress_changed) | Indicate to clients that detection progress changed | 6 |
|
||||
| 103 | [NET_PACKET_ID_DETECTION_COMPLETE](#net_packet_id_detection_complete) | Indicate to clients that detection completed | 6 |
|
||||
| 140 | [NET_PACKET_ID_REQUEST_RESCAN_DEVICES](#net_packet_id_request_rescan_devices) | Request server to rescan devices | 5 |
|
||||
| 150 | [NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST](#net_packet_id_profilemanager_get_profile_list) | Get profile list | 2 |
|
||||
| 151 | [NET_PACKET_ID_PROFILEMANAGER_SAVE_PROFILE](#net_packet_id_profilemanager_save_profile) | Save current configuration in a new profile | 2 |
|
||||
| 152 | [NET_PACKET_ID_PROFILEMANAGER_LOAD_PROFILE](#net_packet_id_profilemanager_load_profile) | Load a given profile | 2 |
|
||||
| 153 | [NET_PACKET_ID_PROFILEMANAGER_DELETE_PROFILE](#net_packet_id_profilemanager_delete_profile) | Delete a given profile | 2 |
|
||||
| 154 | [NET_PACKET_ID_PROFILEMANAGER_UPLOAD_PROFILE](#net_packet_id_profilemanager_upload_profile) | Upload a profile to the server in JSON format | 6 |
|
||||
| 155 | [NET_PACKET_ID_PROFILEMANAGER_DOWNLOAD_PROFILE](#net_packet_id_profilemanager_download_profile) | Download a profile from the server in JSON format | 6 |
|
||||
| 156 | [NET_PACKET_ID_PROFILEMANAGER_GET_ACTIVE_PROFILE](#net_packet_id_profilemanager_get_active_profile) | Get the active profile name | 6 |
|
||||
| 200 | [NET_PACKET_ID_PLUGINMANAGER_GET_PLUGIN_LIST](#net_packet_id_pluginmanager_get_plugin_list) | Get list of plugins | 4 |
|
||||
| 201 | [NET_PACKET_ID_PLUGINMANAGER_PLUGIN_SPECIFIC](#net_packet_id_pluginmanager_plugin_specific) | Interact with a plugin | 4 |
|
||||
| 250 | [NET_PACKET_ID_SETTINGSMANAGER_GET_SETTINGS](#net_packet_id_settingsmanager_get_settings) | Get settings for a given key in JSON format | 6 |
|
||||
| 251 | [NET_PACKET_ID_SETTINGSMANAGER_SET_SETTINGS](#net_packet_id_settingsmanager_set_settings) | Set settings for a given key in JSON format | 6 |
|
||||
| 252 | [NET_PACKET_ID_SETTINGSMANAGER_SAVE_SETTINGS](#net_packet_id_settingsmanager_save_settings) | Save settings | 6 |
|
||||
| 1000 | [NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE](#net_packet_id_rgbcontroller_resizezone) | RGBController::ResizeZone() | 0 |
|
||||
| 1001 | [NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS](#net_packet_id_rgbcontroller_clearsegments) | RGBController::ClearSegments() | 5 |
|
||||
| 1002 | [NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT](#net_packet_id_rgbcontroller_addsegment) | RGBController::AddSegment() | 5 |
|
||||
| 1003 | [NET_PACKET_ID_RGBCONTROLLER_CONFIGUREZONE](#net_packet_id_rgbcontroller_configurezone) | RGBController::ConfigureZone() | 6 |
|
||||
| 1050 | [NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS](#net_packet_id_rgbcontroller_updateleds) | RGBController::UpdateLEDs() | 0 |
|
||||
| 1051 | [NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS](#net_packet_id_rgbcontroller_updatezoneleds) | RGBController::UpdateZoneLEDs() | 0 |
|
||||
| 1052 | [NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED](#net_packet_id_rgbcontroller_updatesingleled) | RGBController::UpdateSingleLED() | 0 |
|
||||
| 1100 | [NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE](#net_packet_id_rgbcontroller_setcustommode) | RGBController::SetCustomMode() | 0 |
|
||||
| 1101 | [NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE](#net_packet_id_rgbcontroller_updatemode) | RGBController::UpdateMode() | 0 |
|
||||
| 1102 | [NET_PACKET_ID_RGBCONTROLLER_SAVEMODE](#net_packet_id_rgbcontroller_savemode) | RGBController::SaveMode() | 3 |
|
||||
| 1103 | [NET_PACKET_ID_RGBCONTROLLER_UPDATEZONEMODE](#net_packet_id_rgbcontroller_updatezonemode) | RGBController::UpdateZoneMode() | 6 |
|
||||
| 1130 | [NET_PACKET_ID_RGBCONTROLLER_SETDEVICESPECIFICCONFIGURATION](#net_packet_id_rgbcontroller_setdevicespecificconfiguration) | RGBController::SetDeviceSpecificConfiguration | 6 |
|
||||
| 1131 | [NET_PACKET_ID_RGBCONTROLLER_SETDEVICESPECIFICZONECONFIGURATION](#net_packet_id_rgbcontroller_setdevicespecificzoneconfiguration) | RGBController::SetDeviceSpecificZoneConfiguration | 6 |
|
||||
| 1150 | [NET_PACKET_ID_RGBCONTROLLER_SIGNALUPDATE](#net_packet_id_rgbcontroller_signalupdate) | RGBController::SignalUpdate() | 6 |
|
||||
|
||||
\* The [NET_PACKET_ID_REQUEST_PROTOCOL_VERSION](#net_packet_id_request_protocol_version) packet was not present in protocol version 0, but clients supporting protocol versions 1+ should always send this packet. If no response is received, it should be assumed that the server is using protocol 0.
|
||||
|
||||
@@ -162,6 +164,8 @@ The Device Data block represents an entire `RGBController`. This data block is
|
||||
| 2 | unsigned short | num_led_alt_names | 5 | Number of LED alternate name strings |
|
||||
| Variable | LED Alternate Name[num_led_alt_names] | led_alt_names | 5 | See [LED Alternate Name Data](#led-alternate-names-data) block format table. Repeat num_led_alt_names times |
|
||||
| 4 | unsigned int | flags | 5 | RGBController flags field value |
|
||||
| 4 | unsigned int | configuration_len | 6 | Length of RGBController configuration field string, including null termination |
|
||||
| configuration_len | char[configuration_len] | configuration | | RGBController configuration field string value, including null termination |
|
||||
|
||||
## Mode Data
|
||||
|
||||
@@ -206,7 +210,6 @@ The Zone Data block represents one entry in the `RGBController::zones` vector.
|
||||
| 2 | unsigned short | zone_num_modes | 6 | Number of modes in zone |
|
||||
| 4 | int | zone_active_mode | 6 | Zone active_mode field value |
|
||||
| Variable | Mode Data[zone_num_modes] | zone_modes | 6 | See [Mode Data](#mode-data) block format table. Repeat zone_num_modes times |
|
||||
| 4 | unsigned int | zone_color_order | 6 | Zone color_order field value |
|
||||
|
||||
## Segment Data
|
||||
|
||||
@@ -575,6 +578,14 @@ The client uses this ID to call the SaveMode() function of an RGBController devi
|
||||
|
||||
The client uses this ID to call the UpdateZoneMode() function of an RGBController device. The packet contains a data block. The format of the data block is shown below. The `pkt_dev_id` of this request's header indicates which controller you are calling UpdateZoneMode() on. See the [Device IDs](#device-ids) section for more information.
|
||||
|
||||
## NET_PACKET_ID_RGBCONTROLLER_SETDEVICESPECIFICCONFIGURATION
|
||||
|
||||
The client uses this ID to call the SetDeviceSpecificConfiguration function of an RGBController device. The `pkt_dev_id` of this request's header indicates which controller you are calling SetDeviceSpecificConfiguration on. See the [Device IDs](#device-ids) section for more information.
|
||||
|
||||
## NET_PACKET_ID_RGBCONTROLLER_SETDEVICESPECIFICZONECONFIGURATION
|
||||
|
||||
The client uses this ID to call the SetDeviceSpecificZoneConfiguration function of an RGBController device. The `pkt_dev_id` of this request's header indicates which controller you are calling SetDeviceSpecificZoneConfiguration on. See the [Device IDs](#device-ids) section for more information.
|
||||
|
||||
## NET_PACKET_ID_RGBCONTROLLER_SIGNALUPDATE
|
||||
|
||||
The server uses this ID to signal the client that SignalUpdate() was called on an RGBController device. The packet contains a data block. The format of the data block is shown below. The `pkt_dev_id` of this request's header indicates which controller signalled SignalUpdate(). See the [Device IDs](#device-ids) section for more information.
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| JsonUtils.cpp |
|
||||
| |
|
||||
| JSON utility functions |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "JsonUtils.h"
|
||||
|
||||
bool JsonUtils::JsonGetBool(nlohmann::json& val, std::string key, bool dft)
|
||||
{
|
||||
if((val.contains(key)) && (val[key].type() == nlohmann::json::value_t::boolean))
|
||||
{
|
||||
return((bool)val[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(dft);
|
||||
}
|
||||
}
|
||||
|
||||
int JsonUtils::JsonGetInt(nlohmann::json& val, std::string key, int dft)
|
||||
{
|
||||
if((val.contains(key)) &&
|
||||
((val[key].type() == nlohmann::json::value_t::number_integer) ||
|
||||
(val[key].type() == nlohmann::json::value_t::number_unsigned) ||
|
||||
(val[key].type() == nlohmann::json::value_t::number_float)))
|
||||
{
|
||||
return((int)val[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(dft);
|
||||
}
|
||||
}
|
||||
|
||||
std::string JsonUtils::JsonGetString(nlohmann::json& val, std::string key, std::string dft, bool allow_empty)
|
||||
{
|
||||
if((val.contains(key)) && (val[key].type() == nlohmann::json::value_t::string))
|
||||
{
|
||||
std::string ret_val = (std::string)val[key];
|
||||
|
||||
if((!allow_empty) && (ret_val == ""))
|
||||
{
|
||||
return(dft);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(ret_val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return(dft);
|
||||
}
|
||||
}
|
||||
|
||||
bool JsonUtils::JsonParse(std::string json_string, nlohmann::json& json_ref)
|
||||
{
|
||||
try
|
||||
{
|
||||
json_ref = nlohmann::json::parse(json_string);
|
||||
return(true);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| JsonUtils.h |
|
||||
| |
|
||||
| JSON utility functions |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
class JsonUtils
|
||||
{
|
||||
public:
|
||||
static bool JsonGetBool(nlohmann::json& val, std::string key, bool dft = false);
|
||||
static int JsonGetInt(nlohmann::json& val, std::string key, int dft = 0);
|
||||
static std::string JsonGetString(nlohmann::json& val, std::string key, std::string dft = "", bool allow_empty = true);
|
||||
static bool JsonParse(std::string json_string, nlohmann::json& json_ref);
|
||||
};
|
||||
+378
-284
@@ -7,17 +7,19 @@
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "LogManager.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <stdarg.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
|
||||
#include "filesystem.h"
|
||||
#include "JsonUtils.h"
|
||||
#include "LogManager.h"
|
||||
#include "NetworkClient.h"
|
||||
#include "NetworkServer.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
const char* LogManager::log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:", "Dialog:"};
|
||||
const char* LogManager::LOG_CODES[] = {"Fatal", "Error", "Warning", "Info", "Verbose", "Debug", "Trace", "Dialog"};
|
||||
|
||||
const char* TimestampPattern = "%04d%02d%02d_%02d%02d%02d";
|
||||
|
||||
@@ -26,45 +28,127 @@ const char* TimestampPattern = "%04d%02d%02d_%02d%02d%02d";
|
||||
\*---------------------------------------------------------*/
|
||||
const char* TimestampRegex = "[0-9]{8}_[0-9]{6}";
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| LogManager name for log entries |
|
||||
\*---------------------------------------------------------*/
|
||||
const char* LOGMANAGER = "LogManager";
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| LogManager Global Instance Pointer |
|
||||
\*---------------------------------------------------------*/
|
||||
LogManager* LogManager::instance;
|
||||
|
||||
LogManager::LogManager()
|
||||
{
|
||||
base_clock = std::chrono::steady_clock::now();
|
||||
log_console_enabled = false;
|
||||
log_file_enabled = true;
|
||||
}
|
||||
|
||||
LogManager* LogManager::get()
|
||||
{
|
||||
static LogManager* _instance = nullptr;
|
||||
static std::mutex instance_mutex;
|
||||
std::lock_guard<std::mutex> grd(instance_mutex);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create a new instance if one does not exist |
|
||||
| Initialize global instance pointer the when created |
|
||||
| There should only ever be one instance of |
|
||||
| LogManager |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!_instance)
|
||||
if(!instance)
|
||||
{
|
||||
_instance = new LogManager();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
unsigned int LogManager::getLoglevel()
|
||||
{
|
||||
if(log_console_enabled)
|
||||
{
|
||||
return(LL_TRACE);
|
||||
instance = this;
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| If, for whatever reason, LogManager already exists, |
|
||||
| delete this instance as only one should exist |
|
||||
\*-----------------------------------------------------*/
|
||||
else
|
||||
{
|
||||
return(loglevel);
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
|
||||
base_clock = std::chrono::steady_clock::now();
|
||||
log_console_enabled = false;
|
||||
loglevel = LL_INFO;
|
||||
print_source = false;
|
||||
verbosity = LL_WARNING;
|
||||
}
|
||||
|
||||
void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
LogManager::~LogManager()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> grd(entry_mutex);
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| LogManager Global Instance Accessor |
|
||||
\*---------------------------------------------------------*/
|
||||
LogManager* LogManager::get()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| If LogManager does not exist yet, create it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!instance)
|
||||
{
|
||||
instance = new LogManager();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Callback Registration |
|
||||
\*---------------------------------------------------------*/
|
||||
void LogManager::RegisterLogManagerCallback(LogManagerCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
LogManagerCallbackMutex.lock();
|
||||
|
||||
for(std::size_t idx = 0; idx < LogManagerCallbacks.size(); idx++)
|
||||
{
|
||||
if(LogManagerCallbacks[idx] == new_callback && LogManagerCallbackArgs[idx] == new_callback_arg)
|
||||
{
|
||||
LogManagerCallbackMutex.unlock();
|
||||
|
||||
LOG_TRACE("[%s] Tried to register an already registered LogManager callback, skipping. Total callbacks registered: %d", LOGMANAGER, LogManagerCallbacks.size());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LogManagerCallbacks.push_back(new_callback);
|
||||
LogManagerCallbackArgs.push_back(new_callback_arg);
|
||||
|
||||
LogManagerCallbackMutex.unlock();
|
||||
|
||||
LOG_TRACE("[%s] Registered LogManager callback. Total callbacks registered: %d", LOGMANAGER, LogManagerCallbacks.size());
|
||||
}
|
||||
|
||||
void LogManager::UnregisterLogManagerCallback(LogManagerCallback callback, void * callback_arg)
|
||||
{
|
||||
LogManagerCallbackMutex.lock();
|
||||
|
||||
for(std::size_t idx = 0; idx < LogManagerCallbacks.size(); idx++)
|
||||
{
|
||||
if(LogManagerCallbacks[idx] == callback && LogManagerCallbackArgs[idx] == callback_arg)
|
||||
{
|
||||
LogManagerCallbacks.erase(LogManagerCallbacks.begin() + idx);
|
||||
LogManagerCallbackArgs.erase(LogManagerCallbackArgs.begin() + idx);
|
||||
}
|
||||
}
|
||||
|
||||
LogManagerCallbackMutex.unlock();
|
||||
|
||||
LOG_TRACE("[%s] Unregistered LogManager callback. Total callbacks registered: %d", LOGMANAGER, LogManagerCallbackArgs.size());
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Configuration |
|
||||
\*---------------------------------------------------------*/
|
||||
void LogManager::Configure(json config, const filesystem::path& config_dir)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock the entry mitex while configuring |
|
||||
\*-----------------------------------------------------*/
|
||||
std::lock_guard<std::recursive_mutex> guard(entry_mutex);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Close the log file if it is already open |
|
||||
\*-----------------------------------------------------*/
|
||||
if(log_stream.is_open())
|
||||
{
|
||||
log_stream.close();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the log is not open, create a new log file |
|
||||
@@ -78,43 +162,19 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
| current "logfile", starting with the oldest ones |
|
||||
| (according to the timestamp in their filename) |
|
||||
| i.e. with the lexicographically smallest filename |
|
||||
| 0 or less equals no limit (default) |
|
||||
| 0 or less equals no limit |
|
||||
\*-------------------------------------------------*/
|
||||
int loglimit = 0;
|
||||
if(config.contains("file_count_limit") && config["file_count_limit"].is_number_integer())
|
||||
{
|
||||
loglimit = config["file_count_limit"];
|
||||
}
|
||||
|
||||
if(config.contains("log_file"))
|
||||
{
|
||||
log_file_enabled = config["log_file"];
|
||||
}
|
||||
int loglimit = JsonUtils::JsonGetInt(config, "file_count_limit", 10);
|
||||
bool log_file_enabled = JsonUtils::JsonGetBool(config, "log_file", true);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Default template for the logfile name |
|
||||
| The # symbol is replaced with a timestamp |
|
||||
\*-------------------------------------------------*/
|
||||
std::string logtempl = "OpenRGB_#.log";
|
||||
std::string logtemp = JsonUtils::JsonGetString(config, "logfile", "OpenRGB_#.log", false);
|
||||
|
||||
if(log_file_enabled)
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| If the logfile is defined in the |
|
||||
| configuration, use the configured name |
|
||||
\*---------------------------------------------*/
|
||||
if(config.contains("logfile"))
|
||||
{
|
||||
const json& logfile_obj = config["logfile"];
|
||||
if(logfile_obj.is_string())
|
||||
{
|
||||
std::string tmpname = config["logfile"];
|
||||
if(!tmpname.empty())
|
||||
{
|
||||
logtempl = tmpname;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------*\
|
||||
| If the # symbol is found in the log file |
|
||||
| name, replace it with a timestamp |
|
||||
@@ -124,8 +184,8 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
char time_string[64];
|
||||
snprintf(time_string, 64, TimestampPattern, 1900 + tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
|
||||
|
||||
std::string logname = logtempl;
|
||||
size_t oct = logname.find("#");
|
||||
std::string logname = logtemp;
|
||||
std::size_t oct = logname.find("#");
|
||||
if(oct != logname.npos)
|
||||
{
|
||||
logname.replace(oct, 1, time_string);
|
||||
@@ -137,7 +197,7 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
filesystem::path p = filesystem::u8path(logname);
|
||||
if(p.is_relative())
|
||||
{
|
||||
p = defaultDir / "logs" / logname;
|
||||
p = config_dir / "logs" / logname;
|
||||
}
|
||||
filesystem::create_directories(p.parent_path());
|
||||
|
||||
@@ -145,7 +205,7 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
| "Log rotation": remove old log files |
|
||||
| exceeding the current configured limit |
|
||||
\*---------------------------------------------*/
|
||||
rotate_logs(p.parent_path(), filesystem::u8path(logtempl).filename(), loglimit);
|
||||
LogRotate(p.parent_path(), filesystem::u8path(logtemp).filename(), loglimit);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Open the logfile |
|
||||
@@ -166,57 +226,258 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
/*-----------------------------------------------------*\
|
||||
| Check loglevel configuration |
|
||||
\*-----------------------------------------------------*/
|
||||
if(config.contains("loglevel"))
|
||||
{
|
||||
const json& loglevel_obj = config["loglevel"];
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set the log level if configured |
|
||||
\*-------------------------------------------------*/
|
||||
if(loglevel_obj.is_number_integer())
|
||||
{
|
||||
loglevel = loglevel_obj;
|
||||
}
|
||||
}
|
||||
loglevel = JsonUtils::JsonGetInt(config, "loglevel", LL_INFO);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check log console configuration |
|
||||
\*-----------------------------------------------------*/
|
||||
if(config.contains("log_console"))
|
||||
{
|
||||
log_console_enabled = config["log_console"];
|
||||
}
|
||||
log_console_enabled = JsonUtils::JsonGetBool(config, "log_console");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Flush the log |
|
||||
\*-----------------------------------------------------*/
|
||||
_flush();
|
||||
LogFlush();
|
||||
}
|
||||
|
||||
void LogManager::_flush()
|
||||
/*---------------------------------------------------------*\
|
||||
| Log Buffer Functions |
|
||||
\*---------------------------------------------------------*/
|
||||
void LogManager::ClearLogBuffer()
|
||||
{
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI()))
|
||||
{
|
||||
ResourceManager::get()->GetLocalClient()->LogManager_ClearLogBuffer();
|
||||
}
|
||||
|
||||
all_messages.clear();
|
||||
}
|
||||
|
||||
std::vector<PLogMessage> LogManager::GetLogBuffer()
|
||||
{
|
||||
return(all_messages);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Log Level Functions |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned int LogManager::GetLogLevel()
|
||||
{
|
||||
return(loglevel);
|
||||
}
|
||||
|
||||
unsigned int LogManager::GetVerbosity()
|
||||
{
|
||||
return(verbosity);
|
||||
}
|
||||
|
||||
void LogManager::SetLogLevel(unsigned int level, bool local_only)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Check that the new log level is valid, otherwise set |
|
||||
| it within the valid range |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the server's log level if local client |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!local_only && ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsLogManagerAPI()))
|
||||
{
|
||||
ResourceManager::get()->GetLocalClient()->LogManager_SetLogLevel(level);
|
||||
}
|
||||
|
||||
LOG_DEBUG("[%s] LogLevel set to %d", LOGMANAGER, level);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the new log level |
|
||||
\*-----------------------------------------------------*/
|
||||
loglevel = level;
|
||||
}
|
||||
|
||||
void LogManager::SetVerbosity(unsigned int level)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Check that the new verbosity is valid, otherwise set |
|
||||
| it within the valid range |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
LOG_DEBUG("[%s] Verbosity set to %d", LOGMANAGER, level);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the new verbosity |
|
||||
\*-----------------------------------------------------*/
|
||||
verbosity = level;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Log Format Functions |
|
||||
\*---------------------------------------------------------*/
|
||||
void LogManager::SetPrintSource(bool print)
|
||||
{
|
||||
LOG_DEBUG("[LogManager] Source code location printouts were %s", print ? "enabled" : "disabled");
|
||||
print_source = print;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Logging Functions |
|
||||
\*---------------------------------------------------------*/
|
||||
void LogManager::LogEntry(const char* filename, int line, unsigned int level, const char* fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
|
||||
LogEntry_va(filename, line, level, fmt, va);
|
||||
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void LogManager::LogEntry_message(PLogMessage message)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock the entry mutex while adding an entry |
|
||||
\*-----------------------------------------------------*/
|
||||
std::lock_guard<std::recursive_mutex> guard(entry_mutex);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If this is a dialog message, call the dialog show |
|
||||
| callback |
|
||||
\*-----------------------------------------------------*/
|
||||
if(message->level == LL_DIALOG)
|
||||
{
|
||||
for(std::size_t idx = 0; idx < LogManagerCallbacks.size(); idx++)
|
||||
{
|
||||
LogManagerCallbacks[idx](LogManagerCallbackArgs[idx], LOGMANAGER_UPDATE_REASON_SHOW_DIALOG, message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(std::size_t idx = 0; idx < LogManagerCallbacks.size(); idx++)
|
||||
{
|
||||
LogManagerCallbacks[idx](LogManagerCallbackArgs[idx], LOGMANAGER_UPDATE_REASON_LOG_ENTRY, message);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the message is within the current verbosity, print |
|
||||
| it on the screen |
|
||||
\*-----------------------------------------------------*/
|
||||
if(message->level <= verbosity || message->level == LL_DIALOG)
|
||||
{
|
||||
std::cout << std::left << "[" << std::setw(10) << message->timestamp << "]";
|
||||
std::cout << std::left << "[" << std::setw(7) << LOG_CODES[message->level] << "]";
|
||||
if(print_source)
|
||||
{
|
||||
std::cout << " [" << message->filename << ":" << message->line << "]";
|
||||
}
|
||||
std::cout << message->text;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the message to the logfile queue |
|
||||
\*-----------------------------------------------------*/
|
||||
temp_messages.push_back(message);
|
||||
|
||||
if(log_console_enabled)
|
||||
{
|
||||
all_messages.push_back(message);
|
||||
|
||||
NetworkServer* server = ResourceManager::get()->GetServer();
|
||||
|
||||
if(server)
|
||||
{
|
||||
server->SignalLogManagerLoggedEntry(*message);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Flush the queues |
|
||||
\*-----------------------------------------------------*/
|
||||
LogFlush();
|
||||
}
|
||||
|
||||
void LogManager::LogEntry_va(const char* filename, int line, unsigned int level, const char* fmt, va_list va)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| If a critical message occurs, enable source |
|
||||
| printing and set loglevel and verbosity to highest |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level == LL_FATAL)
|
||||
{
|
||||
print_source = true;
|
||||
loglevel = LL_DEBUG;
|
||||
verbosity = LL_DEBUG;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create a new message |
|
||||
\*-----------------------------------------------------*/
|
||||
PLogMessage message = std::make_shared<LogMessage>();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Resize the buffer, then fill in the message text |
|
||||
\*-----------------------------------------------------*/
|
||||
va_list va2;
|
||||
va_copy(va2, va);
|
||||
int len = vsnprintf(nullptr, 0, fmt, va);
|
||||
message->text.resize(len);
|
||||
vsnprintf(&(message->text[0]), len + 1, fmt, va2);
|
||||
va_end(va2);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in message information |
|
||||
\*-----------------------------------------------------*/
|
||||
message->level = level;
|
||||
message->filename = filename;
|
||||
message->line = line;
|
||||
message->timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - base_clock).count();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove newlines in the log text unless this is a |
|
||||
| dialog |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level != LL_DIALOG)
|
||||
{
|
||||
message->text.erase(std::remove(message->text.begin(), message->text.end(), '\n'), message->text.end());
|
||||
message->text.erase(std::remove(message->text.begin(), message->text.end(), '\r'), message->text.end());
|
||||
}
|
||||
|
||||
LogEntry_message(message);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Private Functions |
|
||||
\*---------------------------------------------------------*/
|
||||
void LogManager::LogFlush()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock the entry mutex while flushing |
|
||||
\*-----------------------------------------------------*/
|
||||
std::lock_guard<std::recursive_mutex> guard(entry_mutex);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the log is open, write out buffered messages |
|
||||
\*-----------------------------------------------------*/
|
||||
if(log_stream.is_open())
|
||||
{
|
||||
for(size_t msg = 0; msg < temp_messages.size(); ++msg)
|
||||
for(std::size_t message_idx = 0; message_idx < temp_messages.size(); message_idx++)
|
||||
{
|
||||
if(temp_messages[msg]->level <= loglevel || temp_messages[msg]->level == LL_DIALOG)
|
||||
if(temp_messages[message_idx]->level <= loglevel || temp_messages[message_idx]->level == LL_DIALOG)
|
||||
{
|
||||
/*-----------------------------------------*\
|
||||
| Put the timestamp here |
|
||||
\*-----------------------------------------*/
|
||||
std::chrono::milliseconds counter = std::chrono::duration_cast<std::chrono::milliseconds>(temp_messages[msg]->counted_second);
|
||||
log_stream << std::left << std::setw(6) << counter.count() << "|";
|
||||
log_stream << std::left << std::setw(9) << log_codes[temp_messages[msg]->level];
|
||||
log_stream << temp_messages[msg]->buffer;
|
||||
|
||||
log_stream << std::left << "[" << std::setw(10) << temp_messages[message_idx]->timestamp << "]";
|
||||
log_stream << std::left << "[" << std::setw(7) << LOG_CODES[temp_messages[message_idx]->level] << "]";
|
||||
if(print_source)
|
||||
{
|
||||
log_stream << " [" << temp_messages[msg]->filename << ":" << temp_messages[msg]->line << "]";
|
||||
std::cout << " [" << temp_messages[message_idx]->filename << ":" << temp_messages[message_idx]->line << "]";
|
||||
}
|
||||
|
||||
log_stream << temp_messages[message_idx]->text;
|
||||
log_stream << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -233,177 +494,7 @@ void LogManager::_flush()
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::flush()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> grd(entry_mutex);
|
||||
_flush();
|
||||
}
|
||||
|
||||
void LogManager::append_va(const char* filename, int line, unsigned int level, const char* fmt, va_list va)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> grd(entry_mutex);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If a critical message occurs, enable source |
|
||||
| printing and set loglevel and verbosity to highest |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level == LL_FATAL)
|
||||
{
|
||||
print_source = true;
|
||||
loglevel = LL_DEBUG;
|
||||
verbosity = LL_DEBUG;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create a new message |
|
||||
\*-----------------------------------------------------*/
|
||||
PLogMessage mes = std::make_shared<LogMessage>();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Resize the buffer, then fill in the message text |
|
||||
\*-----------------------------------------------------*/
|
||||
va_list va2;
|
||||
va_copy(va2, va);
|
||||
int len = vsnprintf(nullptr, 0, fmt, va);
|
||||
mes->buffer.resize(len);
|
||||
vsnprintf(&(mes->buffer[0]), len + 1, fmt, va2);
|
||||
va_end(va2);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in message information |
|
||||
\*-----------------------------------------------------*/
|
||||
mes->level = level;
|
||||
mes->filename = filename;
|
||||
mes->line = line;
|
||||
mes->counted_second = std::chrono::steady_clock::now() - base_clock;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If this is a dialog message, call the dialog show |
|
||||
| callback |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level == LL_DIALOG)
|
||||
{
|
||||
for(size_t idx = 0; idx < dialog_show_callbacks.size(); idx++)
|
||||
{
|
||||
dialog_show_callbacks[idx](dialog_show_callback_args[idx], mes);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the message is within the current verbosity, print |
|
||||
| it on the screen |
|
||||
| TODO: Put the timestamp here |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level <= verbosity || level == LL_DIALOG)
|
||||
{
|
||||
std::cout << mes->buffer;
|
||||
if(print_source)
|
||||
{
|
||||
std::cout << " [" << mes->filename << ":" << mes->line << "]";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the message to the logfile queue |
|
||||
\*-----------------------------------------------------*/
|
||||
temp_messages.push_back(mes);
|
||||
|
||||
if(log_console_enabled)
|
||||
{
|
||||
all_messages.push_back(mes);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Flush the queues |
|
||||
\*-----------------------------------------------------*/
|
||||
_flush();
|
||||
}
|
||||
|
||||
std::vector<PLogMessage> LogManager::messages()
|
||||
{
|
||||
return all_messages;
|
||||
}
|
||||
|
||||
void LogManager::clearMessages()
|
||||
{
|
||||
all_messages.clear();
|
||||
}
|
||||
|
||||
void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
|
||||
append_va(filename, line, level, fmt, va);
|
||||
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void LogManager::setLoglevel(unsigned int level)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Check that the new log level is valid, otherwise set |
|
||||
| it within the valid range |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
LOG_DEBUG("[LogManager] Loglevel set to %d", level);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the new log level |
|
||||
\*-----------------------------------------------------*/
|
||||
loglevel = level;
|
||||
}
|
||||
|
||||
void LogManager::setVerbosity(unsigned int level)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Check that the new verbosity is valid, otherwise set |
|
||||
| it within the valid range |
|
||||
\*-----------------------------------------------------*/
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
LOG_DEBUG("[LogManager] Verbosity set to %d", level);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the new verbosity |
|
||||
\*-----------------------------------------------------*/
|
||||
verbosity = level;
|
||||
}
|
||||
|
||||
void LogManager::setPrintSource(bool v)
|
||||
{
|
||||
LOG_DEBUG("[LogManager] Source code location printouts were %s", v ? "enabled" : "disabled");
|
||||
print_source = v;
|
||||
}
|
||||
|
||||
void LogManager::RegisterDialogShowCallback(LogDialogShowCallback callback, void* receiver)
|
||||
{
|
||||
LOG_DEBUG("[LogManager] dialog show callback registered");
|
||||
dialog_show_callbacks.push_back(callback);
|
||||
dialog_show_callback_args.push_back(receiver);
|
||||
}
|
||||
|
||||
void LogManager::UnregisterDialogShowCallback(LogDialogShowCallback callback, void* receiver)
|
||||
{
|
||||
for(size_t idx = 0; idx < dialog_show_callbacks.size(); idx++)
|
||||
{
|
||||
if(dialog_show_callbacks[idx] == callback && dialog_show_callback_args[idx] == receiver)
|
||||
{
|
||||
dialog_show_callbacks.erase(dialog_show_callbacks.begin() + idx);
|
||||
dialog_show_callback_args.erase(dialog_show_callback_args.begin() + idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::rotate_logs(const filesystem::path& folder, const filesystem::path& templ, int max_count)
|
||||
void LogManager::LogRotate(const filesystem::path& folder, const filesystem::path& templ, std::size_t max_count)
|
||||
{
|
||||
if(max_count < 1)
|
||||
{
|
||||
@@ -419,7 +510,7 @@ void LogManager::rotate_logs(const filesystem::path& folder, const filesystem::p
|
||||
| backslash |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string regex_templ = "^";
|
||||
for(size_t i = 0; i < templ2.size(); ++i)
|
||||
for(std::size_t i = 0; i < templ2.size(); ++i)
|
||||
{
|
||||
switch(templ2[i])
|
||||
{
|
||||
@@ -486,26 +577,29 @@ void LogManager::rotate_logs(const filesystem::path& folder, const filesystem::p
|
||||
| the one we're about to create for max_count <= 0 and |
|
||||
| to prevent any possible errors in the above logic |
|
||||
\*-----------------------------------------------------*/
|
||||
size_t remove_count = valid_paths.size() - max_count + 1;
|
||||
if(remove_count > valid_paths.size())
|
||||
if(valid_paths.size() > (max_count - 1))
|
||||
{
|
||||
remove_count = valid_paths.size();
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < remove_count; ++i)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Uses error code to force the `remove` call to be |
|
||||
| `noexcept` |
|
||||
\*-------------------------------------------------*/
|
||||
std::error_code ec;
|
||||
if(filesystem::remove(valid_paths[i], ec))
|
||||
std::size_t remove_count = valid_paths.size() - max_count + 1;
|
||||
if(remove_count > valid_paths.size())
|
||||
{
|
||||
LOG_VERBOSE("[LogManager] Removed log file [%s] during rotation", valid_paths[i].u8string().c_str());
|
||||
remove_count = valid_paths.size();
|
||||
}
|
||||
else
|
||||
|
||||
for(std::size_t i = 0; i < remove_count; ++i)
|
||||
{
|
||||
LOG_WARNING("[LogManager] Failed to remove log file [%s] during rotation: %s", valid_paths[i].u8string().c_str(), ec.message().c_str());
|
||||
/*-------------------------------------------------*\
|
||||
| Uses error code to force the `remove` call to be |
|
||||
| `noexcept` |
|
||||
\*-------------------------------------------------*/
|
||||
std::error_code ec;
|
||||
if(filesystem::remove(valid_paths[i], ec))
|
||||
{
|
||||
LOG_VERBOSE("[LogManager] Removed log file [%s] during rotation", valid_paths[i].u8string().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[LogManager] Failed to remove log file [%s] during rotation: %s", valid_paths[i].u8string().c_str(), ec.message().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+126
-66
@@ -7,8 +7,7 @@
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#ifndef LOGMANAGER_H
|
||||
#define LOGMANAGER_H
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
@@ -41,77 +40,140 @@ enum
|
||||
LL_DIALOG // Log messages to be shown in a GUI dialog box
|
||||
};
|
||||
|
||||
struct LogMessage
|
||||
typedef struct
|
||||
{
|
||||
std::string buffer;
|
||||
unsigned int level;
|
||||
const char* filename;
|
||||
int line;
|
||||
std::chrono::duration<double> counted_second;
|
||||
// int timestamp or float time_offset? TBD
|
||||
};
|
||||
unsigned int level;
|
||||
unsigned int line;
|
||||
unsigned int timestamp;
|
||||
std::string filename;
|
||||
std::string text;
|
||||
} LogMessage;
|
||||
|
||||
typedef std::shared_ptr<LogMessage> PLogMessage;
|
||||
typedef void(*LogDialogShowCallback)(void*, PLogMessage);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Callback Types |
|
||||
\*---------------------------------------------------------*/
|
||||
typedef void(*LogManagerCallback)(void*, unsigned int, PLogMessage);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| LogManager Update Reason Codes |
|
||||
\*---------------------------------------------------------*/
|
||||
enum
|
||||
{
|
||||
LOGMANAGER_UPDATE_REASON_LOG_ENTRY, /* Log entry */
|
||||
LOGMANAGER_UPDATE_REASON_SHOW_DIALOG, /* Show dialog */
|
||||
};
|
||||
|
||||
class LogManager
|
||||
{
|
||||
private:
|
||||
LogManager();
|
||||
LogManager(const LogManager&) = delete;
|
||||
LogManager(LogManager&&) = delete;
|
||||
~LogManager();
|
||||
std::recursive_mutex entry_mutex;
|
||||
std::mutex section_mutex;
|
||||
std::ofstream log_stream;
|
||||
|
||||
std::vector<LogDialogShowCallback> dialog_show_callbacks;
|
||||
std::vector<void*> dialog_show_callback_args;
|
||||
|
||||
// A temporary log message storage to hold them until the stream opens
|
||||
std::vector<PLogMessage> temp_messages;
|
||||
|
||||
// A log message storage that will be displayed in the app
|
||||
std::vector<PLogMessage> all_messages;
|
||||
|
||||
// A flag that marks if the message source file name and line number should be printed on screen
|
||||
bool print_source = false;
|
||||
|
||||
// Logfile max level
|
||||
unsigned int loglevel = LL_INFO;
|
||||
|
||||
// Verbosity (stdout) max level
|
||||
unsigned int verbosity = LL_WARNING;
|
||||
|
||||
//Clock from LogManager creation
|
||||
std::chrono::time_point<std::chrono::steady_clock> base_clock;
|
||||
|
||||
// A non-guarded flush()
|
||||
void _flush();
|
||||
|
||||
void rotate_logs(const filesystem::path& folder, const filesystem::path& templ, int max_count);
|
||||
|
||||
public:
|
||||
static LogManager* get();
|
||||
void configure(json config, const filesystem::path & defaultDir);
|
||||
void flush();
|
||||
void append(const char* filename, int line, unsigned int level, const char* fmt, ...);
|
||||
void append_va(const char* filename, int line, unsigned int level, const char* fmt, va_list va);
|
||||
void setLoglevel(unsigned int);
|
||||
void setVerbosity(unsigned int);
|
||||
void setPrintSource(bool);
|
||||
void RegisterDialogShowCallback(LogDialogShowCallback callback, void* receiver);
|
||||
void UnregisterDialogShowCallback(LogDialogShowCallback callback, void* receiver);
|
||||
unsigned int getLoglevel();
|
||||
unsigned int getVerbosity() {return verbosity;}
|
||||
void clearMessages();
|
||||
std::vector<PLogMessage> messages();
|
||||
LogManager();
|
||||
~LogManager();
|
||||
|
||||
bool log_console_enabled;
|
||||
bool log_file_enabled;
|
||||
static const char* log_codes[];
|
||||
/*-----------------------------------------------------*\
|
||||
| LogManager Global Instance Accessor |
|
||||
\*-----------------------------------------------------*/
|
||||
static LogManager* get();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Callback Registration |
|
||||
\*-----------------------------------------------------*/
|
||||
void RegisterLogManagerCallback(LogManagerCallback callback, void* receiver);
|
||||
void UnregisterLogManagerCallback(LogManagerCallback callback, void* receiver);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Configuration |
|
||||
\*-----------------------------------------------------*/
|
||||
void Configure(json config, const filesystem::path& config_dir);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Buffer Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ClearLogBuffer();
|
||||
std::vector<PLogMessage> GetLogBuffer();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Level Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int GetLogLevel();
|
||||
unsigned int GetVerbosity();
|
||||
|
||||
void SetLogLevel(unsigned int, bool local_only = false);
|
||||
void SetVerbosity(unsigned int);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Format Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void SetPrintSource(bool print);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Entry Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void LogEntry(const char* filename, int line, unsigned int level, const char* fmt, ...);
|
||||
void LogEntry_message(PLogMessage message);
|
||||
void LogEntry_va(const char* filename, int line, unsigned int level, const char* fmt, va_list va);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Code String Constants |
|
||||
\*-----------------------------------------------------*/
|
||||
static const char* LOG_CODES[];
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------*\
|
||||
| Static pointer to shared instance of LogManager |
|
||||
\*-----------------------------------------------------*/
|
||||
static LogManager* instance;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Levels |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int loglevel;
|
||||
unsigned int verbosity;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Formatting |
|
||||
\*-----------------------------------------------------*/
|
||||
std::chrono::time_point<std::chrono::steady_clock>
|
||||
base_clock;
|
||||
bool log_console_enabled;
|
||||
bool print_source;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Mutexes |
|
||||
\*-----------------------------------------------------*/
|
||||
std::recursive_mutex entry_mutex;
|
||||
std::mutex section_mutex;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log File Output Stream |
|
||||
\*-----------------------------------------------------*/
|
||||
std::ofstream log_stream;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| LogManager Callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<LogManagerCallback> LogManagerCallbacks;
|
||||
std::vector<void *> LogManagerCallbackArgs;
|
||||
std::mutex LogManagerCallbackMutex;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log Buffers |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<PLogMessage> temp_messages;
|
||||
std::vector<PLogMessage> all_messages;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void LogFlush();
|
||||
void LogRotate(const filesystem::path& folder, const filesystem::path& templ, std::size_t max_count);
|
||||
};
|
||||
|
||||
#define LogAppend(level, ...) LogManager::get()->append(__FILE__, __LINE__, level, __VA_ARGS__)
|
||||
/*---------------------------------------------------------*\
|
||||
| Log Macros |
|
||||
\*---------------------------------------------------------*/
|
||||
#define LogAppend(level, ...) LogManager::get()->LogEntry(__FILE__, __LINE__, level, __VA_ARGS__)
|
||||
#define LOG_FATAL(...) LogAppend(LL_FATAL, __VA_ARGS__)
|
||||
#define LOG_ERROR(...) LogAppend(LL_ERROR, __VA_ARGS__)
|
||||
#define LOG_WARNING(...) LogAppend(LL_WARNING, __VA_ARGS__)
|
||||
@@ -120,5 +182,3 @@ public:
|
||||
#define LOG_DEBUG(...) LogAppend(LL_DEBUG, __VA_ARGS__)
|
||||
#define LOG_TRACE(...) LogAppend(LL_TRACE, __VA_ARGS__)
|
||||
#define LOG_DIALOG(...) LogAppend(LL_DIALOG, __VA_ARGS__)
|
||||
|
||||
#endif // LOGMANAGER_H
|
||||
|
||||
+824
-373
File diff suppressed because it is too large
Load Diff
+66
-23
@@ -13,8 +13,10 @@
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include "i2c_smbus.h"
|
||||
#include "RGBController.h"
|
||||
#include "NetworkProtocol.h"
|
||||
#include "net_port.h"
|
||||
@@ -22,7 +24,7 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Callback Types |
|
||||
\*---------------------------------------------------------*/
|
||||
typedef void (*NetworkClientCallback)(void *, unsigned int);
|
||||
typedef void (*NetworkClientCallback)(void*, unsigned int);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| NetworkClient Update Reason Codes |
|
||||
@@ -43,7 +45,23 @@ enum
|
||||
NETWORKCLIENT_UPDATE_REASON_PROFILEMANAGER_ACTIVE_PROFILE_CHANGED, /* Active profile changed */
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
NetPacketHeader header;
|
||||
unsigned char* data;
|
||||
} NetworkClientListenerThreadQueueEntry;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int id;
|
||||
unsigned int index;
|
||||
std::queue<NetworkClientListenerThreadQueueEntry> queue;
|
||||
std::mutex queue_mutex;
|
||||
std::mutex start_mutex;
|
||||
std::condition_variable start_cv;
|
||||
std::thread* thread;
|
||||
std::atomic<bool> online;
|
||||
} NetworkClientListenerThread;
|
||||
|
||||
class NetworkClient
|
||||
{
|
||||
@@ -62,6 +80,7 @@ public:
|
||||
bool GetOnline();
|
||||
std::string GetServerName();
|
||||
bool GetSupportsRGBControllerAPI();
|
||||
bool GetSupportsLogManagerAPI();
|
||||
bool GetSupportsProfileManagerAPI();
|
||||
bool GetSupportsPluginManagerAPI();
|
||||
bool GetSupportsSettingsManagerAPI();
|
||||
@@ -85,7 +104,12 @@ public:
|
||||
| Client Callback functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ClearCallbacks();
|
||||
void RegisterNetworkClientCallback(NetworkClientCallback new_callback, void * new_callback_arg);
|
||||
void RegisterNetworkClientCallback(NetworkClientCallback new_callback, void* new_callback_arg);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Device Info Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<i2c_smbus_info> GetI2CBusInfo();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| DetectionManager functions |
|
||||
@@ -93,6 +117,14 @@ public:
|
||||
unsigned int DetectionManager_GetDetectionPercent();
|
||||
std::string DetectionManager_GetDetectionString();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| LogManager functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void LogManager_ClearLogBuffer();
|
||||
void LogManager_GetLogBuffer();
|
||||
unsigned int LogManager_GetLogLevel();
|
||||
void LogManager_SetLogLevel(unsigned int log_level);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| ProfileManager functions |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -109,6 +141,8 @@ public:
|
||||
| SettingsManager functions |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string SettingsManager_GetSettings(std::string settings_key);
|
||||
std::string SettingsManager_GetSettingsSchema(std::string settings_key);
|
||||
void SettingsManager_ModifySettings(std::string settings_json_str);
|
||||
void SettingsManager_SaveSettings();
|
||||
void SettingsManager_SetSettings(std::string settings_json_str);
|
||||
|
||||
@@ -118,19 +152,24 @@ public:
|
||||
std::vector<RGBController*>& GetRGBControllers();
|
||||
|
||||
void SendRequest_RGBController_ClearSegments(unsigned int dev_idx, int zone);
|
||||
void SendRequest_RGBController_AddSegment(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_ConfigureZone(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_AddSegment(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_ConfigureZone(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
void SendRequest_RGBController_ConfigureDevice(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_SetHidden(unsigned int dev_idx, bool hidden);
|
||||
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
|
||||
void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateZoneMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_UpdateZoneMode(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
|
||||
void SendRequest_RGBController_SetDeviceSpecificConfiguration(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
void SendRequest_RGBController_SetDeviceSpecificZoneConfiguration(unsigned int dev_idx, unsigned char* data_ptr, unsigned int data_size);
|
||||
|
||||
void WaitOnControllerData();
|
||||
|
||||
@@ -151,7 +190,7 @@ private:
|
||||
std::mutex send_in_progress;
|
||||
|
||||
NetPacketHeader response_header;
|
||||
char * response_data_ptr;
|
||||
unsigned char* response_data_ptr;
|
||||
std::mutex waiting_on_response_mutex;
|
||||
std::condition_variable waiting_on_response_cv;
|
||||
|
||||
@@ -186,6 +225,7 @@ private:
|
||||
std::condition_variable connection_cv;
|
||||
std::thread * ConnectionThread;
|
||||
std::thread * ListenThread;
|
||||
NetworkClientListenerThread* profilemanager_thread;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Callbacks |
|
||||
@@ -198,7 +238,7 @@ private:
|
||||
| Controller list |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ControllerListMutex;
|
||||
std::vector<RGBController *> server_controllers;
|
||||
std::vector<RGBController*> server_controllers;
|
||||
std::vector<unsigned int> server_controller_ids;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -217,23 +257,26 @@ private:
|
||||
\*-----------------------------------------------------*/
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction();
|
||||
void ProfileManagerListenThread(NetworkClientListenerThread* this_thread);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private Client functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_id);
|
||||
void ProcessReply_ControllerIDs(unsigned int data_size, char * data_ptr);
|
||||
void ProcessReply_ProtocolVersion(unsigned int data_size, char * data);
|
||||
void ProcessRequest_DetectionProgressChanged(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, unsigned char* data_ptr, unsigned int dev_id);
|
||||
void ProcessReply_ControllerIDs(unsigned int data_size, unsigned char* data_ptr);
|
||||
void ProcessReply_ProtocolVersion(unsigned int data_size, unsigned char* data_ptr);
|
||||
void ProcessRequest_DetectionProgressChanged(unsigned int data_size, unsigned char* data_ptr);
|
||||
void ProcessRequest_DeviceListChanged();
|
||||
void ProcessRequest_RGBController_SignalUpdate(unsigned int data_size, char * data, unsigned int dev_id);
|
||||
void ProcessRequest_ServerFlags(unsigned int data_size, char * data);
|
||||
void ProcessRequest_ServerString(unsigned int data_size, char * data);
|
||||
void ProcessRequest_RGBController_SignalUpdate(unsigned int data_size, unsigned char* data_ptr, unsigned int dev_id);
|
||||
void ProcessRequest_ServerFlags(unsigned int data_size, unsigned char* data_ptr);
|
||||
void ProcessRequest_ServerString(unsigned int data_size, unsigned char* data_ptr);
|
||||
|
||||
void ProcessRequest_ProfileManager_ActiveProfileChanged(unsigned int data_size, char * data);
|
||||
void ProcessRequest_LogManager_LoggedEntry(unsigned int data_size, unsigned char* data_ptr);
|
||||
|
||||
void ProcessRequest_ProfileManager_ActiveProfileChanged(unsigned int data_size, unsigned char* data_ptr);
|
||||
void ProcessRequest_ProfileManager_ProfileAboutToLoad();
|
||||
void ProcessRequest_ProfileManager_ProfileListUpdated(unsigned int data_size, char * data);
|
||||
void ProcessRequest_ProfileManager_ProfileLoaded(unsigned int data_size, char * data);
|
||||
void ProcessRequest_ProfileManager_ProfileListUpdated(unsigned int data_size, unsigned char* data_ptr);
|
||||
void ProcessRequest_ProfileManager_ProfileLoaded(unsigned int data_size, unsigned char* data_ptr);
|
||||
|
||||
void SendData_ClientFlags();
|
||||
void SendData_ClientString();
|
||||
@@ -245,7 +288,7 @@ private:
|
||||
/*-----------------------------------------------------*\
|
||||
| Private ProfileManager functions |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<std::string> * ProcessReply_ProfileList(unsigned int data_size, char * data);
|
||||
std::vector<std::string>* ProcessReply_ProfileList(unsigned int data_size, unsigned char* data_ptr);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private helper functions |
|
||||
|
||||
+33
-9
@@ -71,9 +71,10 @@ typedef struct
|
||||
enum
|
||||
{
|
||||
NET_CLIENT_FLAG_SUPPORTS_RGBCONTROLLER = ( 1 << 0 ), /* Client supports RGBController API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_PROFILEMANAGER = ( 1 << 1 ), /* Client supports ProfileManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_PLUGINMANAGER = ( 1 << 2 ), /* Client supports PluginManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_SETTINGSMANAGER = ( 1 << 3 ), /* Client supports SettingsManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_LOGMANAGER = ( 1 << 1 ), /* Client supports LogManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_PROFILEMANAGER = ( 1 << 2 ), /* Client supports ProfileManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_PLUGINMANAGER = ( 1 << 3 ), /* Client supports PluginManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_SETTINGSMANAGER = ( 1 << 4 ), /* Client supports SettingsManager API */
|
||||
|
||||
NET_CLIENT_FLAG_REQUEST_LOCAL_CLIENT = ( 1 << 16 ), /* Request local client */
|
||||
};
|
||||
@@ -81,10 +82,11 @@ enum
|
||||
enum
|
||||
{
|
||||
NET_SERVER_FLAG_SUPPORTS_RGBCONTROLLER = ( 1 << 0 ), /* Server supports RGBController API */
|
||||
NET_SERVER_FLAG_SUPPORTS_PROFILEMANAGER = ( 1 << 1 ), /* Server supports ProfileManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_PLUGINMANAGER = ( 1 << 2 ), /* Server supports PluginManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_SETTINGSMANAGER = ( 1 << 3 ), /* Server supports SettingsManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_DETECTION = ( 1 << 4 ), /* Server supports detection functions */
|
||||
NET_SERVER_FLAG_SUPPORTS_LOGMANAGER = ( 1 << 1 ), /* Server supports LogManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_PROFILEMANAGER = ( 1 << 2 ), /* Server supports ProfileManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_PLUGINMANAGER = ( 1 << 3 ), /* Server supports PluginManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_SETTINGSMANAGER = ( 1 << 4 ), /* Server supports SettingsManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_DETECTION = ( 1 << 5 ), /* Server supports detection functions */
|
||||
|
||||
NET_SERVER_FLAG_LOCAL_CLIENT = ( 1 << 16), /* Confirm that client is local client */
|
||||
};
|
||||
@@ -114,6 +116,8 @@ enum
|
||||
NET_PACKET_ID_DETECTION_PROGRESS_CHANGED = 102, /* Indicate to clients that detection progress changed */
|
||||
NET_PACKET_ID_DETECTION_COMPLETE = 103, /* Indicate to clients that detection completed */
|
||||
|
||||
NET_PACKET_ID_GET_I2C_BUS_INFO = 120, /* Request list of I2C bus info */
|
||||
|
||||
NET_PACKET_ID_REQUEST_RESCAN_DEVICES = 140, /* Request rescan of devices */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
@@ -147,8 +151,20 @@ enum
|
||||
| SettingsManager functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_SETTINGSMANAGER_GET_SETTINGS = 250, /* Get settings for a given key in JSON format */
|
||||
NET_PACKET_ID_SETTINGSMANAGER_SET_SETTINGS = 251, /* Set settings for a given key in JSON format */
|
||||
NET_PACKET_ID_SETTINGSMANAGER_SAVE_SETTINGS = 252, /* Save settings */
|
||||
NET_PACKET_ID_SETTINGSMANAGER_GET_SETTINGS_SCHEMA
|
||||
= 251, /* Get settings schema for given key in JSON format */
|
||||
NET_PACKET_ID_SETTINGSMANAGER_MODIFY_SETTINGS = 252, /* Modify settings for a given key in JSON format */
|
||||
NET_PACKET_ID_SETTINGSMANAGER_SET_SETTINGS = 253, /* Set settings for a given key in JSON format */
|
||||
NET_PACKET_ID_SETTINGSMANAGER_SAVE_SETTINGS = 254, /* Save settings */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| LogManager functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_LOGMANAGER_CLEAR_LOG_BUFFER = 300, /* LogManager::ClearLogBuffer() */
|
||||
NET_PACKET_ID_LOGMANAGER_GET_LOG_BUFFER = 301, /* LogManager::GetLogBuffer() */
|
||||
NET_PACKET_ID_LOGMANAGER_GET_LOG_LEVEL = 302, /* LogManager::GetLogLevel() */
|
||||
NET_PACKET_ID_LOGMANAGER_SET_LOG_LEVEL = 303, /* LogManager::SetLogLevel() */
|
||||
NET_PACKET_ID_LOGMANAGER_LOGGED_ENTRY = 304, /* LogManager::LogEntry Callback */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| RGBController functions |
|
||||
@@ -157,6 +173,8 @@ enum
|
||||
NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS = 1001, /* RGBController::ClearSegments() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT = 1002, /* RGBController::AddSegment() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_CONFIGUREZONE = 1003, /* RGBController::ConfigureZone() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_CONFIGUREDEVICE = 1004, /* RGBController::ConfigureDevice() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETHIDDEN = 1005, /* RGBController::SetHidden() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
|
||||
@@ -167,6 +185,12 @@ enum
|
||||
NET_PACKET_ID_RGBCONTROLLER_SAVEMODE = 1102, /* RGBController::SaveMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONEMODE = 1103, /* RGBController::UpdateZoneMode() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETDEVICESPECIFICCONFIGURATION
|
||||
= 1130, /* RGBController::SetDeviceSpecificConfiguration() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETDEVICESPECIFICZONECONFIGURATION
|
||||
= 1131, /* RGBController:: */
|
||||
/* SetDeviceSpecificZoneConfiguration() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_SIGNALUPDATE = 1150, /* RGBController::SignalUpdate() */
|
||||
};
|
||||
|
||||
|
||||
+1276
-480
File diff suppressed because it is too large
Load Diff
+96
-76
@@ -17,6 +17,7 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <queue>
|
||||
#include "LogManager.h"
|
||||
#include "RGBController.h"
|
||||
#include "NetworkProtocol.h"
|
||||
#include "net_port.h"
|
||||
@@ -28,14 +29,35 @@
|
||||
#define MAXSOCK 32
|
||||
#define TCP_TIMEOUT_SECONDS 5
|
||||
|
||||
typedef void (*NetServerCallback)(void *);
|
||||
typedef void (*NetServerCallback)(void*);
|
||||
|
||||
class NetworkClientInfo
|
||||
{
|
||||
public:
|
||||
NetworkClientInfo();
|
||||
~NetworkClientInfo();
|
||||
|
||||
SOCKET client_sock;
|
||||
unsigned int client_flags;
|
||||
std::thread* client_listen_thread;
|
||||
std::string client_string;
|
||||
unsigned int client_protocol_version;
|
||||
std::string client_ip;
|
||||
bool client_is_local;
|
||||
bool client_is_local_client;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
RGBController* controller;
|
||||
unsigned int id;
|
||||
} NetworkControllerID;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
NetPacketHeader header;
|
||||
char * data;
|
||||
SOCKET client_sock;
|
||||
unsigned int client_protocol_version;
|
||||
unsigned char* data;
|
||||
NetworkClientInfo* client_info;
|
||||
} NetworkServerControllerThreadQueueEntry;
|
||||
|
||||
typedef struct
|
||||
@@ -46,32 +68,10 @@ typedef struct
|
||||
std::mutex queue_mutex;
|
||||
std::mutex start_mutex;
|
||||
std::condition_variable start_cv;
|
||||
std::thread * thread;
|
||||
std::thread* thread;
|
||||
std::atomic<bool> online;
|
||||
} NetworkServerControllerThread;
|
||||
|
||||
class NetworkClientInfo
|
||||
{
|
||||
public:
|
||||
NetworkClientInfo();
|
||||
~NetworkClientInfo();
|
||||
|
||||
SOCKET client_sock;
|
||||
unsigned int client_flags;
|
||||
std::thread * client_listen_thread;
|
||||
std::string client_string;
|
||||
unsigned int client_protocol_version;
|
||||
std::string client_ip;
|
||||
bool client_is_local;
|
||||
bool client_is_local_client;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
RGBController * controller;
|
||||
unsigned int id;
|
||||
} NetworkControllerID;
|
||||
|
||||
class NetworkServer
|
||||
{
|
||||
public:
|
||||
@@ -98,12 +98,13 @@ public:
|
||||
/*-----------------------------------------------------*\
|
||||
| Callback functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
void RegisterClientInfoChangeCallback(NetServerCallback, void* new_callback_arg);
|
||||
void RegisterServerListeningChangeCallback(NetServerCallback, void* new_callback_arg);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Functions for forwarding callback sigals over network |
|
||||
\*-----------------------------------------------------*/
|
||||
void SignalLogManagerLoggedEntry(LogMessage& logged_entry);
|
||||
void SignalProfileManagerUpdate(unsigned int update_reason);
|
||||
void SignalResourceManagerUpdate(unsigned int update_reason);
|
||||
|
||||
@@ -124,7 +125,7 @@ public:
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Interface functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void SetControllers(std::vector<RGBController *>);
|
||||
void SetControllers(std::vector<RGBController*>);
|
||||
void SetPluginManager(PluginManagerInterface* plugin_manager_pointer);
|
||||
void SetProfileManager(ProfileManagerInterface* profile_manager_pointer);
|
||||
void SetSettingsManager(SettingsManagerInterface* settings_manager_pointer);
|
||||
@@ -133,7 +134,7 @@ public:
|
||||
|
||||
void SendRequest_ProfileManager_ActiveProfileChanged(std::string profile_name);
|
||||
void SendRequest_ProfileManager_ProfileLoaded(std::string profile_json_string);
|
||||
void SendRequest_RGBController_SignalUpdate(RGBController * controller_ptr, unsigned int update_reason);
|
||||
void SendRequest_RGBController_SignalUpdate(RGBController* controller_ptr, unsigned int update_reason);
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -156,33 +157,33 @@ private:
|
||||
std::vector<NetworkControllerID> controller_ids;
|
||||
std::shared_mutex controller_ids_mutex;
|
||||
unsigned int controller_next_idx;
|
||||
std::vector<RGBController *> controllers;
|
||||
std::vector<NetworkServerControllerThread *> controller_threads;
|
||||
std::vector<RGBController*> controllers;
|
||||
std::vector<NetworkServerControllerThread*> controller_threads;
|
||||
std::shared_mutex controller_threads_mutex;
|
||||
bool controller_updating;
|
||||
|
||||
NetworkServerControllerThread * profilemanager_thread;
|
||||
NetworkServerControllerThread* profilemanager_thread;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server clients |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ServerClientsMutex;
|
||||
std::vector<NetworkClientInfo *> ServerClients;
|
||||
std::thread * ConnectionThread[MAXSOCK];
|
||||
std::vector<NetworkClientInfo*> ServerClients;
|
||||
std::thread* ConnectionThread[MAXSOCK];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client information change callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
std::vector<void*> ClientInfoChangeCallbackArgs;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server listening change callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ServerListeningChangeMutex;
|
||||
std::vector<NetServerCallback> ServerListeningChangeCallbacks;
|
||||
std::vector<void *> ServerListeningChangeCallbackArgs;
|
||||
std::vector<void*> ServerListeningChangeCallbackArgs;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Pointers to components that integrate with server |
|
||||
@@ -217,57 +218,76 @@ private:
|
||||
| Server Thread functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ConnectionThreadFunction(int socket_idx);
|
||||
void ControllerListenThread(NetworkServerControllerThread * this_thread);
|
||||
void ListenThreadFunction(NetworkClientInfo * client_sock);
|
||||
void ProfileManagerListenThread(NetworkServerControllerThread * this_thread);
|
||||
void ControllerListenThread(NetworkServerControllerThread* this_thread);
|
||||
void ListenThreadFunction(NetworkClientInfo* client_info);
|
||||
void ProfileManagerListenThread(NetworkServerControllerThread* this_thread);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Protocol functions |
|
||||
\*-----------------------------------------------------*/
|
||||
NetPacketStatus ProcessRequest_ClientFlags(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_ClientFlags(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_ClientProtocolVersion(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_ClientString(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_RescanDevices();
|
||||
|
||||
NetPacketStatus ProcessRequest_ProfileManager_ClearActiveProfile();
|
||||
NetPacketStatus ProcessRequest_ProfileManager_DeleteProfile(unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_DownloadProfile(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_GetActiveProfile(SOCKET client_sock);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_GetProfileList(SOCKET client_sock);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_LoadProfile(unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_SaveProfile(unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_UploadProfile(unsigned int data_size, char * data);
|
||||
NetPacketStatus ProcessRequest_GetI2CBusInfo(NetworkClientInfo* client_info);
|
||||
|
||||
NetPacketStatus ProcessRequest_RGBController_AddSegment(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_ClearSegments(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_ConfigureZone(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_ResizeZone(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_SetCustomMode(unsigned int controller_id, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateLEDs(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateSaveMode(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version, bool save_mode);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateSingleLED(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateZoneLEDs(unsigned int controller_id, unsigned char* data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateZoneMode(unsigned int controller_id, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_LogManager_ClearLogBuffer(NetworkClientInfo* client_info);
|
||||
NetPacketStatus ProcessRequest_LogManager_GetLogBuffer(NetworkClientInfo* client_info);
|
||||
NetPacketStatus ProcessRequest_LogManager_GetLogLevel(NetworkClientInfo* client_info);
|
||||
NetPacketStatus ProcessRequest_LogManager_SetLogLevel(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
|
||||
void SendAck(SOCKET client_sock, unsigned int acked_pkt_dev_id, unsigned int acked_pkt_id, NetPacketStatus status, unsigned int protocol_version);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_ClearActiveProfile(NetworkClientInfo* client_info);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_DeleteProfile(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_DownloadProfile(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_GetActiveProfile(NetworkClientInfo* client_info);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_GetProfileList(NetworkClientInfo* client_info);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_LoadProfile(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_SaveProfile(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_ProfileManager_UploadProfile(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
|
||||
void SendReply_ControllerCount(SOCKET client_sock, unsigned int protocol_version);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_id, unsigned int protocol_version);
|
||||
void SendReply_ProtocolVersion(SOCKET client_sock);
|
||||
void SendReply_ServerFlags(SOCKET client_sock);
|
||||
void SendReply_ServerString(SOCKET client_sock);
|
||||
NetPacketStatus ProcessRequest_SettingsManager_GetSettings(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_SettingsManager_GetSettingsSchema(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_SettingsManager_ModifySettings(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_SettingsManager_SetSettings(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
NetPacketStatus ProcessRequest_SettingsManager_SaveSettings(NetworkClientInfo* client_info);
|
||||
|
||||
void SendReply_PluginList(SOCKET client_sock);
|
||||
void SendReply_PluginSpecific(SOCKET client_sock, unsigned int pkt_type, unsigned char* data, unsigned int data_size);
|
||||
NetPacketStatus ProcessRequest_RGBController_AddSegment(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_ClearSegments(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_ConfigureZone(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_ResizeZone(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_ConfigureDevice(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_SetCustomMode(NetworkClientInfo* client_info, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_SetDeviceSpecificConfiguration(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_SetDeviceSpecificZoneConfiguration(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_SetHidden(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateLEDs(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateSaveMode(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id, bool save_mode);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateSingleLED(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateZoneLEDs(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
NetPacketStatus ProcessRequest_RGBController_UpdateZoneMode(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int controller_id);
|
||||
|
||||
void SendRequest_DetectionCompleted(SOCKET client_sock, unsigned int protocol_version);
|
||||
void SendRequest_DetectionProgress(SOCKET client_sock, unsigned int protocol_version, unsigned int detection_percent, std::string detection_string);
|
||||
void SendRequest_DetectionStarted(SOCKET client_sock, unsigned int protocol_version);
|
||||
void SendRequest_DeviceListChanged(SOCKET client_sock);
|
||||
void SendAck(NetworkClientInfo* client_info, unsigned int acked_pkt_dev_id, unsigned int acked_pkt_id, NetPacketStatus status);
|
||||
|
||||
void SendRequest_ProfileManager_ActiveProfileChanged(SOCKET client_sock, std::string active_profile);
|
||||
void SendReply_ControllerCount(NetworkClientInfo* client_info);
|
||||
void SendReply_ControllerData(NetworkClientInfo* client_info, unsigned int dev_id, unsigned int protocol_version);
|
||||
void SendReply_ProtocolVersion(NetworkClientInfo* client_info);
|
||||
void SendReply_ServerFlags(NetworkClientInfo* client_info);
|
||||
void SendReply_ServerString(NetworkClientInfo* client_info);
|
||||
|
||||
void SendReply_PluginList(NetworkClientInfo* client_info);
|
||||
void SendReply_PluginSpecific(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr, unsigned int pkt_id);
|
||||
|
||||
void SendRequest_DetectionCompleted(NetworkClientInfo* client_info);
|
||||
void SendRequest_DetectionProgress(NetworkClientInfo* client_info, unsigned int detection_percent, std::string detection_string);
|
||||
void SendRequest_DetectionStarted(NetworkClientInfo* client_info);
|
||||
void SendRequest_DeviceListChanged(NetworkClientInfo* client_info);
|
||||
|
||||
void SendRequest_LoggedEntry(NetworkClientInfo* client_info, unsigned int data_size, unsigned char* data_ptr);
|
||||
|
||||
void SendRequest_ProfileManager_ActiveProfileChanged(NetworkClientInfo* client_info, std::string active_profile);
|
||||
void SendRequest_ProfileManager_ProfileAboutToLoad();
|
||||
void SendRequest_ProfileManager_ProfileListChanged(SOCKET client_sock, unsigned char *profile_list_description);
|
||||
void SendRequest_ProfileManager_ProfileListChanged(NetworkClientInfo* client_info, unsigned char* profile_list_description);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private helper functions |
|
||||
|
||||
+8
-5
@@ -87,14 +87,14 @@ DEFINES +=
|
||||
#-----------------------------------------------------------------------------------------------#
|
||||
FORMS += $$files("qt/*.ui", true)
|
||||
|
||||
for(iter, FORMS) {
|
||||
GUI_H = $$files("qt/*.h", true)
|
||||
GUI_CPP = $$files("qt/*.cpp", true)
|
||||
|
||||
for(iter, $$list($$GUI_H)) {
|
||||
GUI_INCLUDES += $$dirname(iter)
|
||||
}
|
||||
GUI_INCLUDES = $$unique(GUI_INCLUDES)
|
||||
|
||||
GUI_H = $$files("qt/*.h", true)
|
||||
GUI_CPP = $$files("qt/*.cpp", true)
|
||||
|
||||
CONTROLLER_H = $$files("Controllers/*.h", true)
|
||||
CONTROLLER_CPP = $$files("Controllers/*.cpp", true)
|
||||
|
||||
@@ -166,6 +166,7 @@ HEADERS +=
|
||||
Colors.h \
|
||||
dependencies/ColorWheel/ColorWheel.h \
|
||||
dependencies/json/nlohmann/json.hpp \
|
||||
JsonUtils.h \
|
||||
LogManager.h \
|
||||
NetworkClient.h \
|
||||
NetworkProtocol.h \
|
||||
@@ -174,7 +175,7 @@ HEADERS +=
|
||||
PluginManager.h \
|
||||
ProfileManager.h \
|
||||
ResourceManager.h \
|
||||
ResourceManagerInterface.h \
|
||||
ResourceManagerCallback.h \
|
||||
SettingsManager.h \
|
||||
DetectionManager.h \
|
||||
dmiinfo/dmiinfo.h \
|
||||
@@ -238,6 +239,7 @@ SOURCES +=
|
||||
cli.cpp \
|
||||
DetectionManager.cpp \
|
||||
dmiinfo/dmiinfo.cpp \
|
||||
JsonUtils.cpp \
|
||||
LogManager.cpp \
|
||||
NetworkClient.cpp \
|
||||
NetworkProtocol.cpp \
|
||||
@@ -266,6 +268,7 @@ SOURCES +=
|
||||
RGBController/RGBController_Dummy.cpp \
|
||||
RGBController/RGBControllerKeyNames.cpp \
|
||||
RGBController/RGBController_Network.cpp \
|
||||
RGBController/RGBController_Virtual.cpp \
|
||||
|
||||
RESOURCES += \
|
||||
qt/resources.qrc \
|
||||
|
||||
+44
-18
@@ -10,6 +10,7 @@
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "OpenRGBPluginAPI.h"
|
||||
#include "RGBController_Virtual.h"
|
||||
|
||||
OpenRGBPluginAPI::OpenRGBPluginAPI()
|
||||
{
|
||||
@@ -23,12 +24,12 @@ OpenRGBPluginAPI::OpenRGBPluginAPI()
|
||||
/*---------------------------------------------------------*\
|
||||
| LogManager APIs |
|
||||
\*---------------------------------------------------------*/
|
||||
void OpenRGBPluginAPI::append(const char* filename, int line, unsigned int level, const char* fmt, ...)
|
||||
void OpenRGBPluginAPI::LogEntry(const char* filename, int line, unsigned int level, const char* fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
|
||||
log_manager->append_va(filename, line, level, fmt, va);
|
||||
log_manager->LogEntry_va(filename, line, level, fmt, va);
|
||||
|
||||
va_end(va);
|
||||
}
|
||||
@@ -36,35 +37,42 @@ void OpenRGBPluginAPI::append(const char* filename, int line, unsigned int level
|
||||
/*---------------------------------------------------------*\
|
||||
| PluginManager APIs |
|
||||
\*---------------------------------------------------------*/
|
||||
static void CallRegisterRGBController(OpenRGBPluginAPI * this_ptr, RGBController * rgb_controller)
|
||||
RGBControllerInterface* OpenRGBPluginAPI::CreateVirtualRGBController(RGBController_Setup* setup)
|
||||
{
|
||||
this_ptr->RegisterRGBController(rgb_controller);
|
||||
RGBController_Virtual* rgb_controller = new RGBController_Virtual(setup);
|
||||
|
||||
return(rgb_controller);
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::RegisterRGBControllerInThread(RGBController * rgb_controller)
|
||||
static void CallRegisterVirtualRGBController(OpenRGBPluginAPI* this_ptr, RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
this_ptr->RegisterVirtualRGBController(rgb_controller);
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::RegisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| To avoid deadlocks if this is called from a UI thread |
|
||||
| run the register operation in a background thread. |
|
||||
\*-----------------------------------------------------*/
|
||||
std::thread register_thread(CallRegisterRGBController, this, rgb_controller);
|
||||
std::thread register_thread(CallRegisterVirtualRGBController, this, rgb_controller);
|
||||
register_thread.detach();
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::RegisterRGBController(RGBController * rgb_controller)
|
||||
void OpenRGBPluginAPI::RegisterVirtualRGBController(RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
LOG_INFO("[PluginManager] Registering RGB controller %s", rgb_controller->GetName().c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mark this controller as locally owned |
|
||||
\*-----------------------------------------------------*/
|
||||
rgb_controller->flags &= ~CONTROLLER_FLAG_REMOTE;
|
||||
rgb_controller->flags |= CONTROLLER_FLAG_LOCAL;
|
||||
((RGBController*)rgb_controller)->flags &= ~CONTROLLER_FLAG_REMOTE;
|
||||
((RGBController*)rgb_controller)->flags |= CONTROLLER_FLAG_LOCAL;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the new controller to the list |
|
||||
\*-----------------------------------------------------*/
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
rgb_controllers.push_back((RGBController*)rgb_controller);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Signal device list update in ResourceManager |
|
||||
@@ -72,12 +80,12 @@ void OpenRGBPluginAPI::RegisterRGBController(RGBController * rgb_controller)
|
||||
ResourceManager::get()->UpdateDeviceList();
|
||||
}
|
||||
|
||||
static void CallUnregisterRGBController(OpenRGBPluginAPI * this_ptr, RGBController * rgb_controller)
|
||||
static void CallUnregisterVirtualRGBController(OpenRGBPluginAPI* this_ptr, RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
this_ptr->UnregisterRGBController(rgb_controller);
|
||||
this_ptr->UnregisterVirtualRGBController(rgb_controller);
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::UnregisterRGBController(RGBController * rgb_controller)
|
||||
void OpenRGBPluginAPI::UnregisterVirtualRGBController(RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
LOG_INFO("[PluginManager] Unregistering RGB controller %s", rgb_controller->GetName().c_str());
|
||||
|
||||
@@ -90,7 +98,7 @@ void OpenRGBPluginAPI::UnregisterRGBController(RGBController * rgb_controller)
|
||||
| Find the controller to remove and remove it from the |
|
||||
| master list |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<RGBController*>::iterator rgb_it = std::find(rgb_controllers.begin(), rgb_controllers.end(), rgb_controller);
|
||||
std::vector<RGBController*>::iterator rgb_it = std::find(rgb_controllers.begin(), rgb_controllers.end(), (RGBController*)rgb_controller);
|
||||
|
||||
if(rgb_it != rgb_controllers.end())
|
||||
{
|
||||
@@ -103,16 +111,29 @@ void OpenRGBPluginAPI::UnregisterRGBController(RGBController * rgb_controller)
|
||||
ResourceManager::get()->UpdateDeviceList();
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::UnregisterRGBControllerInThread(RGBController * rgb_controller)
|
||||
void OpenRGBPluginAPI::UnregisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| To avoid deadlocks if this is called from a UI thread |
|
||||
| run the unregister operation in a background thread. |
|
||||
\*-----------------------------------------------------*/
|
||||
std::thread unregister_thread(CallUnregisterRGBController, this, rgb_controller);
|
||||
std::thread unregister_thread(CallUnregisterVirtualRGBController, this, rgb_controller);
|
||||
unregister_thread.detach();
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::UpdateVirtualRGBController(RGBControllerInterface* rgb_controller, RGBController_Setup* setup)
|
||||
{
|
||||
if(rgb_controller)
|
||||
{
|
||||
((RGBController_Virtual*)rgb_controller)->UpdateVirtualController(setup);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::DeleteVirtualRGBController(RGBControllerInterface* rgb_controller)
|
||||
{
|
||||
delete (RGBController*)rgb_controller;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| ProfileManager APIs |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -154,14 +175,19 @@ std::string OpenRGBPluginAPI::GetDetectionString()
|
||||
return(resource_manager->GetDetectionString());
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::RescanDevices()
|
||||
{
|
||||
resource_manager->RescanDevices();
|
||||
}
|
||||
|
||||
void OpenRGBPluginAPI::WaitForDetection()
|
||||
{
|
||||
resource_manager->WaitForDetection();
|
||||
}
|
||||
|
||||
std::vector<RGBController*> & OpenRGBPluginAPI::GetRGBControllers()
|
||||
std::vector<RGBControllerInterface*> OpenRGBPluginAPI::GetRGBControllers()
|
||||
{
|
||||
return(resource_manager->GetRGBControllers());
|
||||
return(resource_manager->GetRGBControllerInterfaces());
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
|
||||
+27
-23
@@ -26,49 +26,53 @@ public:
|
||||
/*-----------------------------------------------------*\
|
||||
| LogManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
void append(const char* filename, int line, unsigned int level, const char* fmt, ...);
|
||||
void LogEntry(const char* filename, int line, unsigned int level, const char* fmt, ...);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| PluginManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
void RegisterRGBController(RGBController * rgb_controller);
|
||||
void RegisterRGBControllerInThread(RGBController * rgb_controller);
|
||||
void UnregisterRGBController(RGBController * rgb_controller);
|
||||
void UnregisterRGBControllerInThread(RGBController * rgb_controller);
|
||||
RGBControllerInterface* CreateVirtualRGBController(RGBController_Setup* setup);
|
||||
void DeleteVirtualRGBController(RGBControllerInterface* rgb_controller);
|
||||
void RegisterVirtualRGBController(RGBControllerInterface* rgb_controller);
|
||||
void RegisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller);
|
||||
void UnregisterVirtualRGBController(RGBControllerInterface* rgb_controller);
|
||||
void UpdateVirtualRGBController(RGBControllerInterface* rgb_controller, RGBController_Setup* setup);
|
||||
void UnregisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| ProfileManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
void ClearActiveProfile();
|
||||
std::vector<std::string> GetProfileList();
|
||||
bool LoadProfile(std::string profile_name);
|
||||
void ClearActiveProfile();
|
||||
std::vector<std::string> GetProfileList();
|
||||
bool LoadProfile(std::string profile_name);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| ResourceManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
filesystem::path GetConfigurationDirectory();
|
||||
bool GetDetectionEnabled();
|
||||
unsigned int GetDetectionPercent();
|
||||
std::string GetDetectionString();
|
||||
void WaitForDetection();
|
||||
std::vector<RGBController*> & GetRGBControllers();
|
||||
filesystem::path GetConfigurationDirectory();
|
||||
bool GetDetectionEnabled();
|
||||
unsigned int GetDetectionPercent();
|
||||
std::string GetDetectionString();
|
||||
void RescanDevices();
|
||||
void WaitForDetection();
|
||||
std::vector<RGBControllerInterface*> GetRGBControllers();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| SettingsManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
nlohmann::json GetSettings(std::string settings_key);
|
||||
void SaveSettings();
|
||||
void SetSettings(std::string settings_key, nlohmann::json new_settings);
|
||||
nlohmann::json GetSettings(std::string settings_key);
|
||||
void SaveSettings();
|
||||
void SetSettings(std::string settings_key, nlohmann::json new_settings);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| RGBControllers registered by plugin |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<RGBController*> rgb_controllers;
|
||||
std::vector<RGBController*> rgb_controllers;
|
||||
|
||||
private:
|
||||
LogManager * log_manager;
|
||||
PluginManagerInterface * plugin_manager;
|
||||
ProfileManager * profile_manager;
|
||||
ResourceManager * resource_manager;
|
||||
SettingsManager * settings_manager;
|
||||
LogManager * log_manager;
|
||||
PluginManagerInterface * plugin_manager;
|
||||
ProfileManager * profile_manager;
|
||||
ResourceManager * resource_manager;
|
||||
SettingsManager * settings_manager;
|
||||
};
|
||||
|
||||
+38
-33
@@ -15,11 +15,11 @@
|
||||
#include <QtPlugin>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "filesystem.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBControllerInterface.h"
|
||||
|
||||
#define OpenRGBPluginInterface_IID "com.OpenRGBPluginInterface"
|
||||
#define OpenRGBPluginInterface_IID "org.openrgb.OpenRGBPluginInterface"
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| OpenRGB Plugin API Versions |
|
||||
@@ -77,69 +77,74 @@ public:
|
||||
/*-----------------------------------------------------*\
|
||||
| LogManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual void append(const char* filename, int line, unsigned int level, const char* fmt, ...) = 0;
|
||||
virtual void LogEntry(const char* filename, int line, unsigned int level, const char* fmt, ...) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| PluginManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual void RegisterRGBController(RGBController * controller) = 0;
|
||||
virtual void RegisterRGBControllerInThread(RGBController * controller) = 0;
|
||||
virtual void UnregisterRGBController(RGBController * controller) = 0;
|
||||
virtual void UnregisterRGBControllerInThread(RGBController * controller) = 0;
|
||||
virtual RGBControllerInterface* CreateVirtualRGBController(RGBController_Setup* setup) = 0;
|
||||
virtual void DeleteVirtualRGBController(RGBControllerInterface* rgb_controller) = 0;
|
||||
virtual void RegisterVirtualRGBController(RGBControllerInterface* rgb_controller) = 0;
|
||||
virtual void RegisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller) = 0;
|
||||
virtual void UnregisterVirtualRGBController(RGBControllerInterface* rgb_controller) = 0;
|
||||
virtual void UpdateVirtualRGBController(RGBControllerInterface* rgb_controller, RGBController_Setup* setup) = 0;
|
||||
virtual void UnregisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| ProfileManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual void ClearActiveProfile() = 0;
|
||||
virtual std::vector<std::string> GetProfileList() = 0;
|
||||
virtual bool LoadProfile(std::string profile_name) = 0;
|
||||
virtual void ClearActiveProfile() = 0;
|
||||
virtual std::vector<std::string> GetProfileList() = 0;
|
||||
virtual bool LoadProfile(std::string profile_name) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| ResourceManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual filesystem::path GetConfigurationDirectory() = 0;
|
||||
virtual bool GetDetectionEnabled() = 0;
|
||||
virtual unsigned int GetDetectionPercent() = 0;
|
||||
virtual std::string GetDetectionString() = 0;
|
||||
virtual void WaitForDetection() = 0;
|
||||
virtual std::vector<RGBController*> & GetRGBControllers() = 0;
|
||||
virtual filesystem::path GetConfigurationDirectory() = 0;
|
||||
virtual bool GetDetectionEnabled() = 0;
|
||||
virtual unsigned int GetDetectionPercent() = 0;
|
||||
virtual std::string GetDetectionString() = 0;
|
||||
virtual void RescanDevices() = 0;
|
||||
virtual void WaitForDetection() = 0;
|
||||
virtual std::vector<RGBControllerInterface*> GetRGBControllers() = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| SettingsManager APIs |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual nlohmann::json GetSettings(std::string settings_key) = 0;
|
||||
virtual void SaveSettings() = 0;
|
||||
virtual void SetSettings(std::string settings_key, nlohmann::json new_settings) = 0;
|
||||
virtual nlohmann::json GetSettings(std::string settings_key) = 0;
|
||||
virtual void SaveSettings() = 0;
|
||||
virtual void SetSettings(std::string settings_key, nlohmann::json new_settings) = 0;
|
||||
};
|
||||
|
||||
class OpenRGBPluginInterface
|
||||
{
|
||||
public:
|
||||
virtual ~OpenRGBPluginInterface() {}
|
||||
virtual ~OpenRGBPluginInterface() {}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Plugin Information |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual OpenRGBPluginInfo GetPluginInfo() = 0;
|
||||
virtual unsigned int GetPluginAPIVersion() = 0;
|
||||
virtual OpenRGBPluginInfo GetPluginInfo() = 0;
|
||||
virtual unsigned int GetPluginAPIVersion() = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Plugin Functionality |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual void Load(OpenRGBPluginAPIInterface* plugin_api_ptr) = 0;
|
||||
virtual QWidget* GetWidget() = 0;
|
||||
virtual QMenu* GetTrayMenu() = 0;
|
||||
virtual void Unload() = 0;
|
||||
virtual void OnProfileAboutToLoad() = 0;
|
||||
virtual void OnProfileLoad(nlohmann::json profile_data) = 0;
|
||||
virtual nlohmann::json OnProfileSave() = 0;
|
||||
virtual unsigned char* OnSDKCommand(unsigned int pkt_id, unsigned char * pkt_data, unsigned int *pkt_size) = 0;
|
||||
virtual void Load(OpenRGBPluginAPIInterface* plugin_api_ptr) = 0;
|
||||
virtual QWidget* GetWidget() = 0;
|
||||
virtual QMenu* GetTrayMenu() = 0;
|
||||
virtual void Unload() = 0;
|
||||
virtual void OnProfileAboutToLoad() = 0;
|
||||
virtual void OnProfileLoad(nlohmann::json profile_data) = 0;
|
||||
virtual nlohmann::json OnProfileSave() = 0;
|
||||
virtual unsigned char* OnSDKCommand(unsigned int pkt_id, unsigned char * pkt_data, unsigned int *pkt_size) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Update Signals |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual void ProfileManagerUpdated(unsigned int update_reason) = 0;
|
||||
virtual void ResourceManagerUpdated(unsigned int update_reason) = 0;
|
||||
virtual void ProfileManagerUpdated(unsigned int update_reason) = 0;
|
||||
virtual void ResourceManagerUpdated(unsigned int update_reason) = 0;
|
||||
virtual void SettingsManagerUpdated(unsigned int update_reason) = 0;
|
||||
};
|
||||
|
||||
Q_DECLARE_INTERFACE(OpenRGBPluginInterface, OpenRGBPluginInterface_IID)
|
||||
|
||||
+323
-242
@@ -18,6 +18,11 @@
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| PluginManager name for log entries |
|
||||
\*---------------------------------------------------------*/
|
||||
const char* PLUGINMANAGER = "PluginManager";
|
||||
|
||||
void PluginManagerProfileManagerCallback(void * this_ptr, unsigned int update_reason)
|
||||
{
|
||||
PluginManager * this_obj = (PluginManager *)this_ptr;
|
||||
@@ -32,6 +37,13 @@ void PluginManagerResourceManagerCallback(void * this_ptr, unsigned int update_r
|
||||
this_obj->ResourceManagerCallback(update_reason);
|
||||
}
|
||||
|
||||
void PluginManagerSettingsManagerCallback(void * this_ptr, unsigned int update_reason)
|
||||
{
|
||||
PluginManager * this_obj = (PluginManager *)this_ptr;
|
||||
|
||||
this_obj->SettingsManagerCallback(update_reason);
|
||||
}
|
||||
|
||||
PluginManager::PluginManager()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -54,6 +66,7 @@ PluginManager::PluginManager()
|
||||
\*-----------------------------------------------------*/
|
||||
ResourceManager::get()->GetProfileManager()->RegisterProfileManagerCallback(PluginManagerProfileManagerCallback, this);
|
||||
ResourceManager::get()->RegisterResourceManagerCallback(PluginManagerResourceManagerCallback, this);
|
||||
ResourceManager::get()->GetSettingsManager()->RegisterSettingsManagerCallback(PluginManagerSettingsManagerCallback, this);
|
||||
}
|
||||
|
||||
PluginManager::~PluginManager()
|
||||
@@ -61,8 +74,9 @@ PluginManager::~PluginManager()
|
||||
/*-----------------------------------------------------*\
|
||||
| Unegister callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
ResourceManager::get()->GetProfileManager()->RegisterProfileManagerCallback(PluginManagerProfileManagerCallback, this);
|
||||
ResourceManager::get()->RegisterResourceManagerCallback(PluginManagerResourceManagerCallback, this);
|
||||
ResourceManager::get()->GetProfileManager()->UnregisterProfileManagerCallback(PluginManagerProfileManagerCallback, this);
|
||||
ResourceManager::get()->UnregisterResourceManagerCallback(PluginManagerResourceManagerCallback, this);
|
||||
ResourceManager::get()->GetSettingsManager()->UnregisterSettingsManagerCallback(PluginManagerSettingsManagerCallback, this);
|
||||
}
|
||||
|
||||
void PluginManager::RegisterAddPluginCallback(AddPluginCallback new_callback, void * new_callback_arg)
|
||||
@@ -79,35 +93,36 @@ void PluginManager::RegisterRemovePluginCallback(RemovePluginCallback new_callba
|
||||
|
||||
void PluginManager::ScanAndLoadPlugins()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the user plugins directory |
|
||||
| |
|
||||
| The user plugins directory is a directory named "plugins" |
|
||||
| in the configuration directory |
|
||||
\*---------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the user plugins directory |
|
||||
| |
|
||||
| The user plugins directory is a directory named |
|
||||
| "plugins" in the configuration directory |
|
||||
\*-----------------------------------------------------*/
|
||||
filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory() / plugins_path;
|
||||
ScanAndLoadPluginsFrom(plugins_dir, false);
|
||||
|
||||
#ifdef OPENRGB_SYSTEM_PLUGIN_DIRECTORY
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the system plugins directory |
|
||||
| |
|
||||
| The system plugin directory can be set during build time, |
|
||||
| e.g. by the package maintainer to load plugins installed |
|
||||
| via package manager |
|
||||
\*---------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the system plugins directory |
|
||||
| |
|
||||
| The system plugin directory can be set during build |
|
||||
| time, e.g. by the package maintainer to load plugins |
|
||||
| installed via package manager |
|
||||
\*-----------------------------------------------------*/
|
||||
ScanAndLoadPluginsFrom(OPENRGB_SYSTEM_PLUGIN_DIRECTORY, true);
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the exe folder plugins directory (Windows) |
|
||||
| |
|
||||
| On Windows, system plugins are located in a folder called |
|
||||
| "plugins" inside the folder where the OpenRGB.exe file is |
|
||||
| installed. Typically, C:\Program Files\OpenRGB but other |
|
||||
| install paths are allowed. |
|
||||
\*---------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the exe folder plugins directory (Windows) |
|
||||
| |
|
||||
| On Windows, system plugins are located in a folder |
|
||||
| called "plugins" inside the folder where the |
|
||||
| OpenRGB.exe file is installed. Typically, |
|
||||
| C:\Program Files\OpenRGB but other install paths are |
|
||||
| allowed. |
|
||||
\*-----------------------------------------------------*/
|
||||
char path[MAX_PATH];
|
||||
GetModuleFileName(NULL, path, MAX_PATH);
|
||||
|
||||
@@ -122,11 +137,11 @@ void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir,
|
||||
{
|
||||
if(is_system)
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Scanning system plugin directory: %s", plugins_dir.generic_u8string().c_str());
|
||||
LOG_TRACE("[%s] Scanning system plugin directory: %s", PLUGINMANAGER, plugins_dir.generic_u8string().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Scanning user plugin directory: %s", plugins_dir.generic_u8string().c_str());
|
||||
LOG_TRACE("[%s] Scanning user plugin directory: %s", PLUGINMANAGER, plugins_dir.generic_u8string().c_str());
|
||||
}
|
||||
|
||||
if(!filesystem::is_directory(plugins_dir))
|
||||
@@ -134,10 +149,9 @@ void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir,
|
||||
return;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Get a list of all files in the plugins directory |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get a list of all files in the plugins directory |
|
||||
\*-----------------------------------------------------*/
|
||||
for(const filesystem::directory_entry& entry: filesystem::directory_iterator(plugins_dir))
|
||||
{
|
||||
if(filesystem::is_directory(entry.path()))
|
||||
@@ -146,42 +160,40 @@ void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir,
|
||||
}
|
||||
|
||||
filesystem::path plugin_path = entry.path();
|
||||
LOG_TRACE("[PluginManager] Found plugin file %s", plugin_path.filename().generic_u8string().c_str());
|
||||
LOG_TRACE("[%s] Found plugin file %s", PLUGINMANAGER, plugin_path.filename().generic_u8string().c_str());
|
||||
AddPlugin(plugin_path, is_system);
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
{
|
||||
OpenRGBPluginInterface* plugin = nullptr;
|
||||
/*-----------------------------------------------------*\
|
||||
| Prepare variables and open plugin settings |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginInterface* plugin = nullptr;
|
||||
unsigned int plugin_idx;
|
||||
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
|
||||
|
||||
unsigned int plugin_idx;
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Open plugin settings |
|
||||
\*---------------------------------------------------------------------*/
|
||||
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Check if this plugin is on the remove list |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove this plugin if it is on the remove list |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_settings.contains("plugins_remove"))
|
||||
{
|
||||
for(unsigned int plugin_remove_idx = 0; plugin_remove_idx < plugin_settings["plugins_remove"].size(); plugin_remove_idx++)
|
||||
for(std::size_t plugin_remove_idx = 0; plugin_remove_idx < plugin_settings["plugins_remove"].size(); plugin_remove_idx++)
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Checking remove %d, %s", plugin_remove_idx, to_string(plugin_settings["plugins_remove"][plugin_remove_idx]).c_str());
|
||||
LOG_WARNING("[%s] Checking remove %d, %s", PLUGINMANAGER, plugin_remove_idx, to_string(plugin_settings["plugins_remove"][plugin_remove_idx]).c_str());
|
||||
|
||||
if(plugin_settings["plugins_remove"][plugin_remove_idx] == path.generic_u8string())
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Delete the plugin file |
|
||||
\*---------------------------------------------------------*/
|
||||
/*-----------------------------------------*\
|
||||
| Delete the plugin file |
|
||||
\*-----------------------------------------*/
|
||||
filesystem::remove(path);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Erase the plugin from the remove list |
|
||||
\*-----------------------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Erase the plugin from the remove list |
|
||||
\*---------------------------------------------*/
|
||||
plugin_settings["plugins_remove"].erase(plugin_remove_idx);
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
@@ -189,183 +201,231 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Search active plugins to see if this path already |
|
||||
| exists |
|
||||
\*-----------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
break;
|
||||
LOG_WARNING("[%s] Plugin file %s already in list, skipping.", PLUGINMANAGER, path.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the path does not match an existing entry, create a new entry |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
/*-----------------------------------------------------*\
|
||||
| Create a QPluginLoader and extract the metadata |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string path_string = path.generic_u8string();
|
||||
QPluginLoader* loader = new QPluginLoader(QString::fromStdString(path_string));
|
||||
QJsonObject metadata = loader->metaData();
|
||||
unsigned int plugin_api_version = 0;
|
||||
QString plugin_commit;
|
||||
QString plugin_id = "incompatible";
|
||||
QString plugin_name = "Incompatible Plugin";
|
||||
QString plugin_url;
|
||||
QString plugin_version;
|
||||
|
||||
if(metadata.contains("MetaData"))
|
||||
{
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Create a QPluginLoader and load the plugin |
|
||||
\*-----------------------------------------------------------------*/
|
||||
std::string path_string = path.generic_u8string();
|
||||
QPluginLoader* loader = new QPluginLoader(QString::fromStdString(path_string));
|
||||
QObject* instance = loader->instance();
|
||||
metadata = metadata.value("MetaData").toObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[%s] Plugin %s does not have a MetaData field, skipping.", PLUGINMANAGER, path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(metadata.contains("OpenRGBPluginAPIVersion"))
|
||||
{
|
||||
plugin_api_version = metadata.value("OpenRGBPluginAPIVersion").toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[%s] Plugin %s does not have an OpenRGBPluginAPIVersion field, skipping.", PLUGINMANAGER, path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(metadata.contains("Id"))
|
||||
{
|
||||
plugin_id = metadata.value("Id").toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[%s] Plugin %s does not have an Id field, skipping.", PLUGINMANAGER, path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(metadata.contains("Commit"))
|
||||
{
|
||||
plugin_commit = metadata.value("Commit").toString();
|
||||
}
|
||||
|
||||
if(metadata.contains("Name"))
|
||||
{
|
||||
plugin_name = metadata.value("Name").toString();
|
||||
}
|
||||
|
||||
if(metadata.contains("Url"))
|
||||
{
|
||||
plugin_url = metadata.value("Url").toString();
|
||||
}
|
||||
|
||||
if(metadata.contains("VersionStr"))
|
||||
{
|
||||
plugin_version = metadata.value("VersionStr").toString();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create a new plugin entry to add to the list |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginEntry entry;
|
||||
|
||||
entry.api = new OpenRGBPluginAPI();
|
||||
entry.api_version = plugin_api_version;
|
||||
entry.enabled = false;
|
||||
entry.info.Commit = plugin_commit.toStdString();
|
||||
entry.info.Description = "This plugin is not compatible with this version of OpenRGB.";
|
||||
entry.info.Name = plugin_name.toStdString();
|
||||
entry.info.URL = plugin_url.toStdString();
|
||||
entry.info.Version = plugin_version.toStdString();
|
||||
entry.id = plugin_id;
|
||||
entry.incompatible = (plugin_api_version == OPENRGB_PLUGIN_API_VERSION);
|
||||
entry.is_system = is_system;
|
||||
entry.loader = loader;
|
||||
entry.path = path_string;
|
||||
entry.plugin = plugin;
|
||||
entry.widget = nullptr;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check to see if this plugin's ID already exists |
|
||||
\*-----------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(plugin_id == ActivePlugins[plugin_idx].id)
|
||||
{
|
||||
entry.info.Description = "This plugin has a duplicate ID as an already loaded plugin and cannot be loaded.";
|
||||
LOG_WARNING("[%s] Plugin ID %s already in list.", PLUGINMANAGER, plugin_id.toStdString().c_str());
|
||||
goto add_plugin_entry;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If metadata indicates a matching API version, |
|
||||
| continue loading |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_api_version == OPENRGB_PLUGIN_API_VERSION)
|
||||
{
|
||||
QObject* instance = loader->instance();
|
||||
|
||||
if(!loader->isLoaded())
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be loaded: %s", path.c_str(), loader->errorString().toStdString().c_str());
|
||||
LOG_WARNING("[%s] Plugin %s cannot be loaded: %s", PLUGINMANAGER, path.c_str(), loader->errorString().toStdString().c_str());
|
||||
goto add_plugin_entry;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Check that the plugin is valid, then check the API version |
|
||||
\*-----------------------------------------------------------------*/
|
||||
if(instance)
|
||||
if(!instance)
|
||||
{
|
||||
plugin = qobject_cast<OpenRGBPluginInterface*>(instance);
|
||||
LOG_WARNING("[%s] Plugin %s cannot be instantiated.", PLUGINMANAGER, path.c_str());
|
||||
goto add_plugin_entry;
|
||||
}
|
||||
|
||||
if(plugin)
|
||||
/*-------------------------------------------------*\
|
||||
| Initialize the plugin pointer |
|
||||
\*-------------------------------------------------*/
|
||||
plugin = qobject_cast<OpenRGBPluginInterface*>(instance);
|
||||
|
||||
if(!plugin)
|
||||
{
|
||||
LOG_WARNING("[%s] Plugin %s cannot be casted to OpenRGBPluginInterface", PLUGINMANAGER, path.c_str());
|
||||
goto add_plugin_entry;
|
||||
}
|
||||
|
||||
if(plugin->GetPluginAPIVersion() != OPENRGB_PLUGIN_API_VERSION)
|
||||
{
|
||||
LOG_WARNING("[%s] Plugin %s has a compatible API version", PLUGINMANAGER, path.c_str());
|
||||
goto add_plugin_entry;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get the plugin information |
|
||||
\*-------------------------------------------------*/
|
||||
OpenRGBPluginInfo info = plugin->GetPluginInfo();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Search the settings to see if it is enabled |
|
||||
\*-------------------------------------------------*/
|
||||
std::string name = "";
|
||||
std::string description = "";
|
||||
bool enabled = true;
|
||||
bool found = false;
|
||||
unsigned int plugin_ct = 0;
|
||||
|
||||
if(plugin_settings.contains("plugins"))
|
||||
{
|
||||
plugin_ct = (unsigned int)plugin_settings["plugins"].size();
|
||||
|
||||
for(unsigned int plugin_settings_idx = 0; plugin_settings_idx < plugin_settings["plugins"].size(); plugin_settings_idx++)
|
||||
{
|
||||
if(plugin->GetPluginAPIVersion() == OPENRGB_PLUGIN_API_VERSION)
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("name"))
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Plugin %s has a compatible API version", path.c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the plugin information |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginInfo info = plugin->GetPluginInfo();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Search the settings to see if it is enabled |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string name = "";
|
||||
std::string description = "";
|
||||
bool enabled = true;
|
||||
bool found = false;
|
||||
unsigned int plugin_ct = 0;
|
||||
|
||||
if(plugin_settings.contains("plugins"))
|
||||
{
|
||||
plugin_ct = (unsigned int)plugin_settings["plugins"].size();
|
||||
|
||||
for(unsigned int plugin_settings_idx = 0; plugin_settings_idx < plugin_settings["plugins"].size(); plugin_settings_idx++)
|
||||
{
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("name"))
|
||||
{
|
||||
name = plugin_settings["plugins"][plugin_settings_idx]["name"];
|
||||
}
|
||||
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("description"))
|
||||
{
|
||||
description = plugin_settings["plugins"][plugin_settings_idx]["description"];
|
||||
}
|
||||
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("enabled"))
|
||||
{
|
||||
enabled = plugin_settings["plugins"][plugin_settings_idx]["enabled"];
|
||||
}
|
||||
|
||||
if((info.Name == name)
|
||||
&&(info.Description == description))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the plugin was not in the list, add it to the list |
|
||||
| and default it to enabled, then save the settings |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!found)
|
||||
{
|
||||
plugin_settings["plugins"][plugin_ct]["name"] = info.Name;
|
||||
plugin_settings["plugins"][plugin_ct]["description"] = info.Description;
|
||||
plugin_settings["plugins"][plugin_ct]["enabled"] = enabled;
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
|
||||
LOG_VERBOSE("[PluginManager] Loaded plugin %s", info.Name.c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the plugin to the PluginManager active plugins |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginEntry entry;
|
||||
|
||||
entry.info = info;
|
||||
entry.plugin = plugin;
|
||||
entry.api = new OpenRGBPluginAPI();
|
||||
entry.loader = loader;
|
||||
entry.path = path_string;
|
||||
entry.enabled = enabled;
|
||||
entry.widget = nullptr;
|
||||
entry.incompatible = false;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
entry.is_system = is_system;
|
||||
|
||||
loader->unload();
|
||||
|
||||
ActivePlugins.push_back(entry);
|
||||
|
||||
if(entry.enabled)
|
||||
{
|
||||
LoadPlugin(&ActivePlugins.back());
|
||||
}
|
||||
name = plugin_settings["plugins"][plugin_settings_idx]["name"];
|
||||
}
|
||||
else
|
||||
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("description"))
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in a plugin information object with text showing |
|
||||
| the plugin is incompatible |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginInfo info;
|
||||
description = plugin_settings["plugins"][plugin_settings_idx]["description"];
|
||||
}
|
||||
|
||||
info.Name = "Incompatible Plugin";
|
||||
info.Description = "This plugin is not compatible with this version of OpenRGB.";
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("enabled"))
|
||||
{
|
||||
enabled = plugin_settings["plugins"][plugin_settings_idx]["enabled"];
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the plugin to the PluginManager active plugins |
|
||||
| but mark it as incompatible |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginEntry entry;
|
||||
|
||||
entry.info = info;
|
||||
entry.plugin = plugin;
|
||||
entry.api = new OpenRGBPluginAPI();
|
||||
entry.loader = loader;
|
||||
entry.path = path_string;
|
||||
entry.enabled = false;
|
||||
entry.widget = nullptr;
|
||||
entry.incompatible = true;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
entry.is_system = is_system;
|
||||
|
||||
loader->unload();
|
||||
|
||||
PluginManager::ActivePlugins.push_back(entry);
|
||||
|
||||
bool unloaded = loader->unload();
|
||||
|
||||
LOG_WARNING("[PluginManager] Plugin %s has an incompatible API version", path.c_str());
|
||||
|
||||
if(!unloaded)
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be unloaded", path.c_str());
|
||||
}
|
||||
if((info.Name == name)
|
||||
&&(info.Description == description))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be casted to OpenRGBPluginInterface", path.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the plugin was not in the list, add it to the |
|
||||
| list and default it to enabled, then save the |
|
||||
| settings |
|
||||
\*-------------------------------------------------*/
|
||||
if(!found)
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be instantiated.", path.c_str());
|
||||
plugin_settings["plugins"][plugin_ct]["name"] = info.Name;
|
||||
plugin_settings["plugins"][plugin_ct]["description"] = info.Description;
|
||||
plugin_settings["plugins"][plugin_ct]["enabled"] = enabled;
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
|
||||
LOG_VERBOSE("[%s] Loaded plugin %s", PLUGINMANAGER, info.Name.c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the plugin to the PluginManager active plugins |
|
||||
\*-----------------------------------------------------*/
|
||||
entry.enabled = enabled;
|
||||
entry.info = info;
|
||||
entry.incompatible = false;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
}
|
||||
|
||||
add_plugin_entry:
|
||||
loader->unload();
|
||||
|
||||
ActivePlugins.push_back(entry);
|
||||
|
||||
if(entry.enabled)
|
||||
{
|
||||
LoadPlugin(&ActivePlugins.back());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,11 +433,12 @@ void PluginManager::RemovePlugin(const filesystem::path& path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
LOG_TRACE("[PluginManager] Attempting to remove plugin %s", path.c_str());
|
||||
LOG_TRACE("[%s] Attempting to remove plugin %s", PLUGINMANAGER, path.c_str());
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Search active plugins to see if this path already |
|
||||
| exists |
|
||||
\*-----------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
@@ -386,27 +447,29 @@ void PluginManager::RemovePlugin(const filesystem::path& path)
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active plugins list, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active |
|
||||
| plugins list, return |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Plugin %s not active", path.c_str());
|
||||
LOG_TRACE("[%s] Plugin %s not active", PLUGINMANAGER, path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the selected plugin is in the list and loaded, unload it |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If the selected plugin is in the list and loaded, |
|
||||
| unload it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(ActivePlugins[plugin_idx].loader->isLoaded())
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Plugin %s is active, unloading", path.c_str());
|
||||
LOG_TRACE("[%s] Plugin %s is active, unloading", PLUGINMANAGER, path.c_str());
|
||||
UnloadPlugin(&ActivePlugins[plugin_idx]);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Remove the plugin from the active plugins list |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove the plugin from the active plugins list |
|
||||
\*-----------------------------------------------------*/
|
||||
ActivePlugins.erase(ActivePlugins.begin() + plugin_idx);
|
||||
}
|
||||
|
||||
@@ -414,9 +477,10 @@ void PluginManager::EnablePlugin(const filesystem::path& path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Search active plugins to see if this path already |
|
||||
| exists |
|
||||
\*-----------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
@@ -425,9 +489,10 @@ void PluginManager::EnablePlugin(const filesystem::path& path)
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active plugins list, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active |
|
||||
| plugins list, return |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
return;
|
||||
@@ -439,17 +504,19 @@ void PluginManager::EnablePlugin(const filesystem::path& path)
|
||||
|
||||
void PluginManager::LoadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
{
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin is in the list but is incompatible, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If the plugin is in the list but is incompatible, |
|
||||
| return |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_entry->incompatible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the selected plugin is in the list but not loaded, load it |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If the selected plugin is in the list but not loaded, |
|
||||
| load it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!plugin_entry->loader->isLoaded())
|
||||
{
|
||||
plugin_entry->loader->load();
|
||||
@@ -468,9 +535,9 @@ void PluginManager::LoadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
|
||||
plugin->Load(plugin_entry->api);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Call the Add Plugin callback |
|
||||
\*-------------------------------------------------*/
|
||||
/*-------------------------------------*\
|
||||
| Call the Add Plugin callback |
|
||||
\*-------------------------------------*/
|
||||
if(AddPluginCallbackArg != nullptr)
|
||||
{
|
||||
AddPluginCallbackVal(AddPluginCallbackArg, plugin_entry);
|
||||
@@ -485,9 +552,10 @@ void PluginManager::DisablePlugin(const filesystem::path& path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Search active plugins to see if this path already |
|
||||
| exists |
|
||||
\*-----------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
@@ -496,9 +564,10 @@ void PluginManager::DisablePlugin(const filesystem::path& path)
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active plugins list, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active |
|
||||
| plugins list, return |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
return;
|
||||
@@ -510,9 +579,10 @@ void PluginManager::DisablePlugin(const filesystem::path& path)
|
||||
|
||||
void PluginManager::UnloadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
{
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the selected plugin is in the list and loaded, unload it |
|
||||
\*---------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If the selected plugin is in the list and loaded, |
|
||||
| unload it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_entry->loader->isLoaded())
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
@@ -532,16 +602,16 @@ void PluginManager::UnloadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
|
||||
if(!unloaded)
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be unloaded", plugin_entry->path.c_str());
|
||||
LOG_WARNING("[%s] Plugin %s cannot be unloaded", PLUGINMANAGER, plugin_entry->path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Plugin %s successfully unloaded", plugin_entry->path.c_str());
|
||||
LOG_TRACE("[%s] Plugin %s successfully unloaded", PLUGINMANAGER, plugin_entry->path.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Plugin %s was already unloaded", plugin_entry->path.c_str());
|
||||
LOG_TRACE("[%s] Plugin %s was already unloaded", PLUGINMANAGER, plugin_entry->path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,6 +752,17 @@ void PluginManager::ResourceManagerCallback(unsigned int update_reason)
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::SettingsManagerCallback(unsigned int update_reason)
|
||||
{
|
||||
for(std::size_t plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(ActivePlugins[plugin_idx].enabled && ActivePlugins[plugin_idx].loader->isLoaded())
|
||||
{
|
||||
ActivePlugins[plugin_idx].plugin->SettingsManagerUpdated(update_reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Plugin Information |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
#include <QDir>
|
||||
#include "OpenRGBPluginInterface.h"
|
||||
#include "PluginManagerInterface.h"
|
||||
#include "RGBController.h"
|
||||
|
||||
struct OpenRGBPluginEntry
|
||||
{
|
||||
OpenRGBPluginInfo info;
|
||||
OpenRGBPluginInterface* plugin;
|
||||
OpenRGBPluginAPIInterface* api;
|
||||
QString id;
|
||||
QPluginLoader* loader;
|
||||
QWidget* widget;
|
||||
QMenu* traymenu;
|
||||
@@ -94,6 +96,7 @@ public:
|
||||
\*-----------------------------------------------------*/
|
||||
void ProfileManagerCallback(unsigned int update_reason);
|
||||
void ResourceManagerCallback(unsigned int update_reason);
|
||||
void SettingsManagerCallback(unsigned int update_reason);
|
||||
|
||||
std::vector<OpenRGBPluginEntry> ActivePlugins;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user