mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-01-17 03:27:51 -05:00
[WIP] SDK Version 6 Updates
* SDK Protocol
* Server sends its name to client
* ProfileManager
* Rename existing profile commands
* Add Upload Profile, Download Profile, and Get Active Profile commands
* SettingsManager
* Add Get, Set, and Save Settings commands
* NetworkServer
* Formatting cleanup
* Use per-controller threads for handling NetworkServer controller-specific packets to avoid delays from controller mutexes
* NetworkClient
* Formatting cleanup
* RGBController
* Clean up and modularize descriptor functions
This commit is contained in:
@@ -150,33 +150,46 @@ The Mode Data block represents one entry in the `RGBController::modes` vector.
|
||||
|
||||
The Zone Data block represents one entry in the `RGBController::zones` vector.
|
||||
|
||||
| Size | Format | Name | Protocol Version | Description |
|
||||
| ---------------------- | --------------------------------- | ------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------ |
|
||||
| 2 | unsigned short | zone_name_len | 0 | Length of zone name string, including null termination |
|
||||
| zone_name_len | char[zone_name_len] | zone_name | 0 | Zone name string value, including null termination |
|
||||
| 4 | int | zone_type | 0 | Zone type value |
|
||||
| 4 | unsigned int | zone_leds_min | 0 | Zone leds_min value |
|
||||
| 4 | unsigned int | zone_leds_max | 0 | Zone leds_max value |
|
||||
| 4 | unsigned int | zone_leds_count | 0 | Zone leds_count value |
|
||||
| 2 | unsigned short | zone_matrix_len | 0 | Zone matrix length if matrix_map exists: (matrix_map width * height * 4) + 8 OTHERWISE 0 if matrix_map NULL |
|
||||
| 4* | unsigned int | zone_matrix_height | 0 | Zone matrix_map height (*only if matrix_map exists) |
|
||||
| 4* | unsigned int | zone_matrix_width | 0 | Zone matrix_map width (*only if matrix_map exists) |
|
||||
| (zone_matrix_len - 8)* | unsigned int[zone_matrix_len - 8] | zone_matrix_data | 0 | Zone matrix_map data (*only if matrix_map exists) |
|
||||
| 2 | unsigned short | num_segments | 4 | Number of segments in zone |
|
||||
| Variable | Segment Data[num_segments] | segments | 4 | See [Segment Data](#segment-data) block format table. Repeat num_segments times |
|
||||
| 4 | unsigned int | zone_flags | 5 | Zone flags value |
|
||||
| Size | Format | Name | Protocol Version | Description |
|
||||
| ---------------------- | --------------------------------- | ------------------- | ---------------- | -------------------------------------------------------------------------------------- |
|
||||
| 2 | unsigned short | zone_name_len | 0 | Length of zone name string, including null termination |
|
||||
| zone_name_len | char[zone_name_len] | zone_name | 0 | Zone name string value, including null termination |
|
||||
| 4 | int | zone_type | 0 | Zone type value |
|
||||
| 4 | unsigned int | zone_leds_min | 0 | Zone leds_min value |
|
||||
| 4 | unsigned int | zone_leds_max | 0 | Zone leds_max value |
|
||||
| 4 | unsigned int | zone_leds_count | 0 | Zone leds_count value |
|
||||
| 2 | unsigned short | zone_matrix_len | 0 | Zone matrix map length if matrix_map exists, otherwise 0 if matrix_map NULL |
|
||||
| zone_matrix_len | Matrix Map Data | zone_matrix_map | 0 | See [Matrix Map Data](#matrix-map-data) block format table, only if matrix_map exists. |
|
||||
| 2 | unsigned short | num_segments | 4 | Number of segments in zone |
|
||||
| Variable | Segment Data[num_segments] | segments | 4 | See [Segment Data](#segment-data) block format table. Repeat num_segments times |
|
||||
| 4 | unsigned int | zone_flags | 5 | Zone flags value |
|
||||
| 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 |
|
||||
|
||||
## Segment Data
|
||||
|
||||
The Segment Data block represents one entry in the `RGBController::zones::segments` vector. This data block was introduced in protocol version 4.
|
||||
|
||||
| Size | Format | Name | Protocol Version | Description |
|
||||
| ---------------- | ---------------------- | ------------------ | ---------------- | --------------------------------------------------------- |
|
||||
| 2 | unsigned short | segment_name_len | 4 | Length of segment name string, including null termination |
|
||||
| segment_name_len | char[segment_name_len] | segment_name | 4 | Segment name string value, including null termination |
|
||||
| 4 | int | segment_type | 4 | Segment type value |
|
||||
| 4 | unsigned int | segment_start_idx | 4 | Segment start_idx value |
|
||||
| 4 | unsigned int | segment_leds_count | 4 | Segment leds_count value |
|
||||
| Size | Format | Name | Protocol Version | Description |
|
||||
| ------------------ | ---------------------- | ------------------ | ---------------- | -------------------------------------------------------------------------------------- |
|
||||
| 2 | unsigned short | segment_name_len | 4 | Length of segment name string, including null termination |
|
||||
| segment_name_len | char[segment_name_len] | segment_name | 4 | Segment name string value, including null termination |
|
||||
| 4 | int | segment_type | 4 | Segment type value |
|
||||
| 4 | unsigned int | segment_start_idx | 4 | Segment start_idx value |
|
||||
| 4 | unsigned int | segment_leds_count | 4 | Segment leds_count value |
|
||||
| 2 | unsigned short | segment_matrix_len | 6 | Segment matrix map length if matrix_map exists, otherwise 0 if matrix_map NULL |
|
||||
| segment_matrix_len | Matrix Map Data | segment_matrix_map | 6 | See [Matrix Map Data](#matrix-map-data) block format table, only if matrix_map exists. |
|
||||
|
||||
## Matrix Map Data
|
||||
|
||||
The Matrix Map Data block represents the matrix_map_type type. This data block was introduced in protocol version 0.
|
||||
|
||||
| Size | Format | Name | Protocol Version | Description |
|
||||
| ---------------------- | -------------------------------------------------- | ----------------- | ---------------- | ----------------- |
|
||||
| 4 | unsigned int | matrix_map_height | 0 | Matrix_map height |
|
||||
| 4 | unsigned int | matrix_map_width | 0 | Matrix_map width |
|
||||
| (zone_matrix_len - 8)* | unsigned int[matrix_map_height * matrix_map_width] | matrix_map_data | 0 | Matrix_map data |
|
||||
|
||||
## LED Data
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
221
NetworkClient.h
221
NetworkClient.h
@@ -11,6 +11,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
@@ -26,104 +27,166 @@ public:
|
||||
NetworkClient(std::vector<RGBController *>& control);
|
||||
~NetworkClient();
|
||||
|
||||
void ClientInfoChanged();
|
||||
/*-----------------------------------------------------*\
|
||||
| Client Information functions |
|
||||
\*-----------------------------------------------------*/
|
||||
bool GetConnected();
|
||||
std::string GetIP();
|
||||
unsigned short GetPort();
|
||||
unsigned int GetProtocolVersion();
|
||||
bool GetOnline();
|
||||
std::string GetServerName();
|
||||
|
||||
bool GetConnected();
|
||||
std::string GetIP();
|
||||
unsigned short GetPort();
|
||||
unsigned int GetProtocolVersion();
|
||||
bool GetOnline();
|
||||
/*-----------------------------------------------------*\
|
||||
| Client Control functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void SetIP(std::string new_ip);
|
||||
void SetName(std::string new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
void ClearCallbacks();
|
||||
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
|
||||
void StartClient();
|
||||
void StopClient();
|
||||
|
||||
void SetIP(std::string new_ip);
|
||||
void SetName(std::string new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
void SendRequest_ControllerData(unsigned int dev_idx);
|
||||
void SendRequest_RescanDevices();
|
||||
|
||||
void StartClient();
|
||||
void StopClient();
|
||||
/*-----------------------------------------------------*\
|
||||
| Client Callback functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ClearCallbacks();
|
||||
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
|
||||
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction();
|
||||
/*-----------------------------------------------------*\
|
||||
| ProfileManager functions |
|
||||
\*-----------------------------------------------------*/
|
||||
char * ProfileManager_GetProfileList();
|
||||
void ProfileManager_LoadProfile(std::string profile_name);
|
||||
void ProfileManager_SaveProfile(std::string profile_name);
|
||||
void ProfileManager_DeleteProfile(std::string profile_name);
|
||||
void ProfileManager_UploadProfile(std::string profile_json_str);
|
||||
std::string ProfileManager_DownloadProfile(std::string profile_name);
|
||||
std::string ProfileManager_GetActiveProfile();
|
||||
|
||||
void WaitOnControllerData();
|
||||
/*-----------------------------------------------------*\
|
||||
| SettingsManager functions |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string SettingsManager_GetSettings(std::string settings_key);
|
||||
void SettingsManager_SaveSettings();
|
||||
void SettingsManager_SetSettings(std::string settings_json_str);
|
||||
|
||||
void ProcessReply_ControllerCount(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx);
|
||||
void ProcessReply_ProtocolVersion(unsigned int data_size, char * data);
|
||||
/*-----------------------------------------------------*\
|
||||
| RGBController functions |
|
||||
\*-----------------------------------------------------*/
|
||||
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_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
|
||||
void ProcessRequest_DeviceListChanged();
|
||||
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 SendData_ClientString();
|
||||
void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_ControllerCount();
|
||||
void SendRequest_ControllerData(unsigned int dev_idx);
|
||||
void SendRequest_ProtocolVersion();
|
||||
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_RescanDevices();
|
||||
|
||||
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_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
|
||||
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_SetCustomMode(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
|
||||
|
||||
std::vector<std::string> * ProcessReply_ProfileList(unsigned int data_size, char * data);
|
||||
|
||||
void SendRequest_GetProfileList();
|
||||
void SendRequest_LoadProfile(std::string profile_name);
|
||||
void SendRequest_SaveProfile(std::string profile_name);
|
||||
void SendRequest_DeleteProfile(std::string profile_name);
|
||||
|
||||
std::vector<RGBController *> server_controllers;
|
||||
|
||||
std::mutex ControllerListMutex;
|
||||
|
||||
protected:
|
||||
std::vector<RGBController *>& controllers;
|
||||
void WaitOnControllerData();
|
||||
|
||||
std::vector<RGBController *> server_controllers;
|
||||
|
||||
private:
|
||||
SOCKET client_sock;
|
||||
std::string client_name;
|
||||
net_port port;
|
||||
std::string port_ip;
|
||||
unsigned short port_num;
|
||||
std::atomic<bool> client_active;
|
||||
bool client_string_sent;
|
||||
bool controller_data_received;
|
||||
bool controller_data_requested;
|
||||
bool protocol_initialized;
|
||||
bool server_connected;
|
||||
bool server_initialized;
|
||||
bool server_reinitialize;
|
||||
unsigned int server_controller_count;
|
||||
bool server_controller_count_requested;
|
||||
bool server_controller_count_received;
|
||||
unsigned int server_protocol_version;
|
||||
bool server_protocol_version_received;
|
||||
bool change_in_progress;
|
||||
unsigned int requested_controllers;
|
||||
std::mutex send_in_progress;
|
||||
/*-----------------------------------------------------*\
|
||||
| Client state variables |
|
||||
\*-----------------------------------------------------*/
|
||||
std::atomic<bool> client_active;
|
||||
bool client_string_sent;
|
||||
bool controller_data_received;
|
||||
bool controller_data_requested;
|
||||
bool protocol_initialized;
|
||||
bool change_in_progress;
|
||||
unsigned int requested_controllers;
|
||||
std::mutex send_in_progress;
|
||||
|
||||
std::mutex connection_mutex;
|
||||
std::condition_variable connection_cv;
|
||||
NetPacketHeader response_header;
|
||||
char * response_data_ptr;
|
||||
std::mutex waiting_on_response_mutex;
|
||||
std::condition_variable waiting_on_response_cv;
|
||||
|
||||
std::thread * ConnectionThread;
|
||||
std::thread * ListenThread;
|
||||
/*-----------------------------------------------------*\
|
||||
| Client information |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string client_name;
|
||||
SOCKET client_sock;
|
||||
net_port port;
|
||||
std::string port_ip;
|
||||
unsigned short port_num;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server information |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string server_name;
|
||||
bool server_connected;
|
||||
bool server_initialized;
|
||||
bool server_reinitialize;
|
||||
unsigned int server_controller_count;
|
||||
bool server_controller_count_requested;
|
||||
bool server_controller_count_received;
|
||||
unsigned int server_protocol_version;
|
||||
bool server_protocol_version_received;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client threads |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex connection_mutex;
|
||||
std::condition_variable connection_cv;
|
||||
std::thread * ConnectionThread;
|
||||
std::thread * ListenThread;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetClientCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
/*-----------------------------------------------------*\
|
||||
| Controller list |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ControllerListMutex;
|
||||
std::vector<RGBController *>& controllers;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client callback signal functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ClientInfoChanged();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client thread functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private Client functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ProcessReply_ControllerCount(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx);
|
||||
void ProcessReply_ProtocolVersion(unsigned int data_size, char * data);
|
||||
void ProcessRequest_DeviceListChanged();
|
||||
void ProcessRequest_ServerString(unsigned int data_size, char * data);
|
||||
|
||||
void SendData_ClientString();
|
||||
void SendRequest_ControllerCount();
|
||||
void SendRequest_ProtocolVersion();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private ProfileManager functions |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<std::string> * ProcessReply_ProfileList(unsigned int data_size, char * data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private helper functions |
|
||||
\*-----------------------------------------------------*/
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
};
|
||||
|
||||
@@ -61,33 +61,51 @@ enum
|
||||
NET_PACKET_ID_REQUEST_PROTOCOL_VERSION = 40, /* Request OpenRGB SDK protocol version from server */
|
||||
|
||||
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
|
||||
NET_PACKET_ID_SET_SERVER_NAME = 51, /* Send server name string to client */
|
||||
|
||||
NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */
|
||||
|
||||
NET_PACKET_ID_REQUEST_RESCAN_DEVICES = 140, /* Request rescan of devices */
|
||||
|
||||
NET_PACKET_ID_REQUEST_PROFILE_LIST = 150, /* Request profile list */
|
||||
NET_PACKET_ID_REQUEST_SAVE_PROFILE = 151, /* Save current configuration in a new profile */
|
||||
NET_PACKET_ID_REQUEST_LOAD_PROFILE = 152, /* Load a given profile */
|
||||
NET_PACKET_ID_REQUEST_DELETE_PROFILE = 153, /* Delete a given profile */
|
||||
|
||||
NET_PACKET_ID_REQUEST_PLUGIN_LIST = 200, /* Request list of plugins */
|
||||
NET_PACKET_ID_PLUGIN_SPECIFIC = 201, /* Interact with a plugin */
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| ProfileManager functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST = 150, /* Get profile list */
|
||||
NET_PACKET_ID_PROFILEMANAGER_SAVE_PROFILE = 151, /* Save current configuration in a new profile */
|
||||
NET_PACKET_ID_PROFILEMANAGER_LOAD_PROFILE = 152, /* Load a given profile */
|
||||
NET_PACKET_ID_PROFILEMANAGER_DELETE_PROFILE = 153, /* Delete a given profile */
|
||||
NET_PACKET_ID_PROFILEMANAGER_UPLOAD_PROFILE = 154, /* Upload a profile to the server in JSON format */
|
||||
NET_PACKET_ID_PROFILEMANAGER_DOWNLOAD_PROFILE = 155, /* Download a profile from the server in JSON format*/
|
||||
NET_PACKET_ID_PROFILEMANAGER_GET_ACTIVE_PROFILE = 156, /* Get the active profile name */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| RGBController class functions |
|
||||
| PluginManager functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS = 1001, /* RGBController::ClearSegments() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT = 1002, /* RGBController::AddSegment() */
|
||||
NET_PACKET_ID_PLUGINMANAGER_GET_PLUGIN_LIST = 200, /* Get list of plugins */
|
||||
NET_PACKET_ID_PLUGINMANAGER_PLUGIN_SPECIFIC = 201, /* Interact with a plugin */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| 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_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_SAVEMODE = 1102, /* RGBController::SaveMode() */
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| RGBController functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS = 1001, /* RGBController::ClearSegments() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT = 1002, /* RGBController::AddSegment() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_SAVEMODE = 1102, /* RGBController::SaveMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONEMODE = 1103, /* RGBController::UpdateZoneMode() */
|
||||
};
|
||||
|
||||
void InitNetPacketHeader
|
||||
|
||||
1217
NetworkServer.cpp
1217
NetworkServer.cpp
File diff suppressed because it is too large
Load Diff
169
NetworkServer.h
169
NetworkServer.h
@@ -11,21 +11,44 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <queue>
|
||||
#include "RGBController.h"
|
||||
#include "NetworkProtocol.h"
|
||||
#include "net_port.h"
|
||||
#include "PluginManagerInterface.h"
|
||||
#include "ProfileManager.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "SettingsManager.h"
|
||||
|
||||
#define MAXSOCK 32
|
||||
#define TCP_TIMEOUT_SECONDS 5
|
||||
|
||||
typedef void (*NetServerCallback)(void *);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * data;
|
||||
unsigned int id;
|
||||
unsigned int size;
|
||||
unsigned int client_protocol_version;
|
||||
} NetworkServerControllerThreadQueueEntry;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int index;
|
||||
std::queue<NetworkServerControllerThreadQueueEntry> queue;
|
||||
std::mutex queue_mutex;
|
||||
std::mutex start_mutex;
|
||||
std::condition_variable start_cv;
|
||||
std::thread * thread;
|
||||
std::atomic<bool> online;
|
||||
} NetworkServerControllerThread;
|
||||
|
||||
class NetworkClientInfo
|
||||
{
|
||||
public:
|
||||
@@ -45,6 +68,9 @@ public:
|
||||
NetworkServer(std::vector<RGBController *>& control);
|
||||
~NetworkServer();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Information functions |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string GetHost();
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
@@ -54,73 +80,130 @@ public:
|
||||
const char * GetClientIP(unsigned int client_num);
|
||||
unsigned int GetClientProtocolVersion(unsigned int client_num);
|
||||
|
||||
void ClientInfoChanged();
|
||||
/*-----------------------------------------------------*\
|
||||
| Callback functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void DeviceListChanged();
|
||||
void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
|
||||
void ServerListeningChanged();
|
||||
void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Configuration functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void SetHost(std::string host);
|
||||
void SetLegacyWorkaroundEnable(bool enable);
|
||||
void SetName(std::string new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Control functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void StartServer();
|
||||
void StopServer();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Interface functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void SetPluginManager(PluginManagerInterface* plugin_manager_pointer);
|
||||
void SetProfileManager(ProfileManagerInterface* profile_manager_pointer);
|
||||
void SetSettingsManager(SettingsManagerInterface* settings_manager_pointer);
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------*\
|
||||
| Server variables |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string host;
|
||||
bool legacy_workaround_enabled;
|
||||
unsigned short port_num;
|
||||
std::mutex send_in_progress;
|
||||
std::string server_name;
|
||||
std::atomic<bool> server_online;
|
||||
std::atomic<bool> server_listening;
|
||||
SOCKET server_sock[MAXSOCK];
|
||||
int socket_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server controller list |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<RGBController *>& controllers;
|
||||
std::vector<NetworkServerControllerThread *> controller_threads;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server clients |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ServerClientsMutex;
|
||||
std::vector<NetworkClientInfo *> ServerClients;
|
||||
std::thread * ConnectionThread[MAXSOCK];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client information change callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server listening change callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
std::mutex ServerListeningChangeMutex;
|
||||
std::vector<NetServerCallback> ServerListeningChangeCallbacks;
|
||||
std::vector<void *> ServerListeningChangeCallbackArgs;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Pointers to components that integrate with server |
|
||||
\*-----------------------------------------------------*/
|
||||
PluginManagerInterface* plugin_manager;
|
||||
ProfileManagerInterface* profile_manager;
|
||||
SettingsManagerInterface* settings_manager;
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
/*-----------------------------------------------------*\
|
||||
| Windows-specific WSA data |
|
||||
\*-----------------------------------------------------*/
|
||||
WSADATA wsa;
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server callback signal functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ClientInfoChanged();
|
||||
void ServerListeningChanged();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Thread functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ConnectionThreadFunction(int socket_idx);
|
||||
void ControllerListenThread(NetworkServerControllerThread * this_thread);
|
||||
void ListenThreadFunction(NetworkClientInfo * client_sock);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Protocol functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
void ProcessRequest_RescanDevices();
|
||||
|
||||
void ProcessRequest_RGBController_AddSegment(std::size_t controller_idx, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
void ProcessRequest_RGBController_UpdateLEDs(std::size_t controller_idx, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
void ProcessRequest_RGBController_UpdateSaveMode(std::size_t controller_idx, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
void ProcessRequest_RGBController_UpdateSingleLED(std::size_t controller_idx, unsigned char * data_ptr);
|
||||
void ProcessRequest_RGBController_UpdateZoneLEDs(std::size_t controller_idx, unsigned char* data_ptr);
|
||||
void ProcessRequest_RGBController_UpdateZoneMode(std::size_t controller_idx, unsigned char * data_ptr, unsigned int protocol_version);
|
||||
|
||||
void SendReply_ControllerCount(SOCKET client_sock);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx, unsigned int protocol_version);
|
||||
void SendReply_ProtocolVersion(SOCKET client_sock);
|
||||
void SendReply_ServerString(SOCKET client_sock);
|
||||
|
||||
void SendRequest_DeviceListChanged(SOCKET client_sock);
|
||||
void SendReply_ProfileList(SOCKET client_sock);
|
||||
void SendReply_PluginList(SOCKET client_sock);
|
||||
void SendReply_PluginSpecific(SOCKET client_sock, unsigned int pkt_type, unsigned char* data, unsigned int data_size);
|
||||
|
||||
void SetPluginManager(PluginManagerInterface* plugin_manager_pointer);
|
||||
void SetProfileManager(ProfileManagerInterface* profile_manager_pointer);
|
||||
|
||||
protected:
|
||||
std::string host;
|
||||
unsigned short port_num;
|
||||
std::atomic<bool> server_online;
|
||||
std::atomic<bool> server_listening;
|
||||
|
||||
std::vector<RGBController *>& controllers;
|
||||
|
||||
std::mutex ServerClientsMutex;
|
||||
std::vector<NetworkClientInfo *> ServerClients;
|
||||
std::thread * ConnectionThread[MAXSOCK];
|
||||
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
std::mutex ServerListeningChangeMutex;
|
||||
std::vector<NetServerCallback> ServerListeningChangeCallbacks;
|
||||
std::vector<void *> ServerListeningChangeCallbackArgs;
|
||||
|
||||
PluginManagerInterface* plugin_manager;
|
||||
ProfileManagerInterface* profile_manager;
|
||||
|
||||
std::mutex send_in_progress;
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
WSADATA wsa;
|
||||
#endif
|
||||
|
||||
bool legacy_workaround_enabled;
|
||||
int socket_count;
|
||||
SOCKET server_sock[MAXSOCK];
|
||||
|
||||
int accept_select(int sockfd);
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
/*-----------------------------------------------------*\
|
||||
| Private helper functions |
|
||||
\*-----------------------------------------------------*/
|
||||
int accept_select(int sockfd);
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
};
|
||||
|
||||
@@ -97,12 +97,22 @@ ProfileManager::~ProfileManager()
|
||||
|
||||
void ProfileManager::DeleteProfile(std::string profile_name)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Clean up the profile name |
|
||||
\*-----------------------------------------------------*/
|
||||
profile_name = StringUtils::remove_null_terminating_chars(profile_name);
|
||||
|
||||
filesystem::path filename = profile_directory / profile_name;
|
||||
filename.concat(".json");
|
||||
if(ResourceManager::get()->IsLocalClient())
|
||||
{
|
||||
ResourceManager::get()->GetLocalClient()->ProfileManager_DeleteProfile(profile_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
filesystem::path filename = profile_directory / profile_name;
|
||||
filename.concat(".json");
|
||||
|
||||
filesystem::remove(filename);
|
||||
filesystem::remove(filename);
|
||||
}
|
||||
|
||||
UpdateProfileList();
|
||||
}
|
||||
@@ -230,22 +240,31 @@ bool ProfileManager::LoadProfile(std::string profile_name)
|
||||
|
||||
nlohmann::json ProfileManager::ReadProfileJSON(std::string profile_name)
|
||||
{
|
||||
nlohmann::json profile_json;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Clean up the profile name |
|
||||
\*-----------------------------------------------------*/
|
||||
profile_name = StringUtils::remove_null_terminating_chars(profile_name);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| File extension for v6+ profiles is .json |
|
||||
\*-----------------------------------------------------*/
|
||||
profile_name += ".json";
|
||||
if(ResourceManager::get()->IsLocalClient())
|
||||
{
|
||||
profile_json = nlohmann::json::parse(ResourceManager::get()->GetLocalClient()->ProfileManager_DownloadProfile(profile_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| File extension for v6+ profiles is .json |
|
||||
\*-------------------------------------------------*/
|
||||
profile_name += ".json";
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Read the profile JSON from the file |
|
||||
\*-----------------------------------------------------*/
|
||||
filesystem::path profile_path = profile_directory / filesystem::u8path(profile_name);
|
||||
/*-------------------------------------------------*\
|
||||
| Read the profile JSON from the file |
|
||||
\*-------------------------------------------------*/
|
||||
filesystem::path profile_path = profile_directory / filesystem::u8path(profile_name);
|
||||
|
||||
nlohmann::json profile_json = ReadProfileFileJSON(profile_path);
|
||||
profile_json = ReadProfileFileJSON(profile_path);
|
||||
}
|
||||
|
||||
return(profile_json);
|
||||
}
|
||||
@@ -299,15 +318,25 @@ bool ProfileManager::SaveProfile(std::string profile_name)
|
||||
profile_json["plugins"] = plugin_manager->OnProfileSave();
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Save the profile to file from the JSON |
|
||||
\*-------------------------------------------------*/
|
||||
SaveProfileFromJSON(profile_json);
|
||||
if(ResourceManager::get()->IsLocalClient())
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Upload the profile to the server |
|
||||
\*---------------------------------------------*/
|
||||
ResourceManager::get()->GetLocalClient()->ProfileManager_UploadProfile(profile_json.dump());
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Update the profile list |
|
||||
\*-------------------------------------------------*/
|
||||
UpdateProfileList();
|
||||
/*---------------------------------------------*\
|
||||
| Update the profile list |
|
||||
\*---------------------------------------------*/
|
||||
UpdateProfileList();
|
||||
}
|
||||
else
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Save the profile to file from the JSON |
|
||||
\*---------------------------------------------*/
|
||||
SaveProfileFromJSON(profile_json);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -341,6 +370,11 @@ bool ProfileManager::SaveProfileFromJSON(nlohmann::json profile_json)
|
||||
\*-------------------------------------------------*/
|
||||
profile_file.close();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Update the profile list |
|
||||
\*-------------------------------------------------*/
|
||||
UpdateProfileList();
|
||||
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
@@ -447,29 +481,42 @@ void ProfileManager::UpdateProfileList()
|
||||
{
|
||||
profile_list.clear();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Load profiles by looking for .json files in profile |
|
||||
| directory |
|
||||
\*-----------------------------------------------------*/
|
||||
for(const filesystem::directory_entry &entry : filesystem::directory_iterator(profile_directory))
|
||||
if(ResourceManager::get()->IsLocalClient())
|
||||
{
|
||||
std::string filename = entry.path().filename().string();
|
||||
char * profile_data = ResourceManager::get()->GetLocalClient()->ProfileManager_GetProfileList();
|
||||
|
||||
if(filename.find(".json") != std::string::npos)
|
||||
if(profile_data != NULL)
|
||||
{
|
||||
LOG_INFO("[ProfileManager] Found file: %s attempting to validate header", filename.c_str());
|
||||
SetProfileListFromDescription(profile_data);
|
||||
delete[] profile_data;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Load profiles by looking for .json files in |
|
||||
| profile directory |
|
||||
\*-------------------------------------------------*/
|
||||
for(const filesystem::directory_entry &entry : filesystem::directory_iterator(profile_directory))
|
||||
{
|
||||
std::string filename = entry.path().filename().string();
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Open input file in binary mode |
|
||||
\*---------------------------------------------*/
|
||||
filesystem::path file_path = profile_directory;
|
||||
file_path.append(filename);
|
||||
|
||||
nlohmann::json profile_json = ReadProfileFileJSON(file_path);
|
||||
|
||||
if(!profile_json.empty())
|
||||
if(filename.find(".json") != std::string::npos)
|
||||
{
|
||||
profile_list.push_back(filename.erase(filename.length() - 5));
|
||||
LOG_INFO("[ProfileManager] Found file: %s attempting to validate header", filename.c_str());
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Open input file in binary mode |
|
||||
\*-----------------------------------------*/
|
||||
filesystem::path file_path = profile_directory;
|
||||
file_path.append(filename);
|
||||
|
||||
nlohmann::json profile_json = ReadProfileFileJSON(file_path);
|
||||
|
||||
if(!profile_json.empty())
|
||||
{
|
||||
profile_list.push_back(filename.erase(filename.length() - 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -284,189 +284,194 @@ public:
|
||||
/*-----------------------------------------------------*\
|
||||
| Controller Information |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual std::string GetName() = 0;
|
||||
virtual std::string GetVendor() = 0;
|
||||
virtual std::string GetDescription() = 0;
|
||||
virtual std::string GetVersion() = 0;
|
||||
virtual std::string GetSerial() = 0;
|
||||
virtual std::string GetLocation() = 0;
|
||||
virtual std::string GetName() = 0;
|
||||
virtual std::string GetVendor() = 0;
|
||||
virtual std::string GetDescription() = 0;
|
||||
virtual std::string GetVersion() = 0;
|
||||
virtual std::string GetSerial() = 0;
|
||||
virtual std::string GetLocation() = 0;
|
||||
|
||||
virtual device_type GetDeviceType() = 0;
|
||||
virtual unsigned int GetFlags() = 0;
|
||||
virtual device_type GetDeviceType() = 0;
|
||||
virtual unsigned int GetFlags() = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Hidden Flag Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual bool GetHidden() = 0;
|
||||
virtual void SetHidden(bool hidden) = 0;
|
||||
virtual bool GetHidden() = 0;
|
||||
virtual void SetHidden(bool hidden) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zone Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual int GetZoneActiveMode(unsigned int zone) = 0;
|
||||
virtual RGBColor GetZoneColor(unsigned int zone, unsigned int color_index) = 0;
|
||||
virtual RGBColor* GetZoneColorsPointer(unsigned int zone) = 0;
|
||||
virtual std::size_t GetZoneCount() = 0;
|
||||
virtual unsigned int GetZoneFlags(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneLEDsCount(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneLEDsMax(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneLEDsMin(unsigned int zone) = 0;
|
||||
virtual bool GetZoneMatrixMapAvailable(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneMatrixMapHeight(unsigned int zone) = 0;
|
||||
virtual const unsigned int * GetZoneMatrixMap(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneMatrixMapWidth(unsigned int zone) = 0;
|
||||
virtual std::size_t GetZoneModeCount(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneModeBrightness(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeBrightnessMax(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeBrightnessMin(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual RGBColor GetZoneModeColor(unsigned int zone, unsigned int mode, unsigned int color_index) = 0;
|
||||
virtual unsigned int GetZoneModeColorMode(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual std::size_t GetZoneModeColorsCount(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeColorsMax(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeColorsMin(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeDirection(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeFlags(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual std::string GetZoneModeName(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeSpeed(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeSpeedMax(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeSpeedMin(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual int GetZoneModeValue(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual std::string GetZoneName(unsigned int zone) = 0;
|
||||
virtual std::size_t GetZoneSegmentCount(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneSegmentLEDsCount(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual bool GetZoneSegmentMatrixMapAvailable(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentMatrixMapHeight(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual const unsigned int * GetZoneSegmentMatrixMap(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentMatrixMapWidth(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual std::string GetZoneSegmentName(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentStartIndex(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentType(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneStartIndex(unsigned int zone) = 0;
|
||||
virtual zone_type GetZoneType(unsigned int zone) = 0;
|
||||
virtual int GetZoneActiveMode(unsigned int zone) = 0;
|
||||
virtual RGBColor GetZoneColor(unsigned int zone, unsigned int color_index) = 0;
|
||||
virtual RGBColor* GetZoneColorsPointer(unsigned int zone) = 0;
|
||||
virtual std::size_t GetZoneCount() = 0;
|
||||
virtual unsigned int GetZoneFlags(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneLEDsCount(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneLEDsMax(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneLEDsMin(unsigned int zone) = 0;
|
||||
virtual bool GetZoneMatrixMapAvailable(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneMatrixMapHeight(unsigned int zone) = 0;
|
||||
virtual const unsigned int * GetZoneMatrixMap(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneMatrixMapWidth(unsigned int zone) = 0;
|
||||
virtual std::size_t GetZoneModeCount(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneModeBrightness(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeBrightnessMax(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeBrightnessMin(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual RGBColor GetZoneModeColor(unsigned int zone, unsigned int mode, unsigned int color_index) = 0;
|
||||
virtual unsigned int GetZoneModeColorMode(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual std::size_t GetZoneModeColorsCount(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeColorsMax(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeColorsMin(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeDirection(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeFlags(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual std::string GetZoneModeName(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeSpeed(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeSpeedMax(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual unsigned int GetZoneModeSpeedMin(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual int GetZoneModeValue(unsigned int zone, unsigned int mode) = 0;
|
||||
virtual std::string GetZoneName(unsigned int zone) = 0;
|
||||
virtual std::size_t GetZoneSegmentCount(unsigned int zone) = 0;
|
||||
virtual unsigned int GetZoneSegmentLEDsCount(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual bool GetZoneSegmentMatrixMapAvailable(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentMatrixMapHeight(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual const unsigned int * GetZoneSegmentMatrixMap(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentMatrixMapWidth(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual std::string GetZoneSegmentName(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentStartIndex(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneSegmentType(unsigned int zone, unsigned int segment) = 0;
|
||||
virtual unsigned int GetZoneStartIndex(unsigned int zone) = 0;
|
||||
virtual zone_type GetZoneType(unsigned int zone) = 0;
|
||||
|
||||
virtual unsigned int GetLEDsInZone(unsigned int zone) = 0;
|
||||
virtual unsigned int GetLEDsInZone(unsigned int zone) = 0;
|
||||
|
||||
virtual void SetZoneActiveMode(unsigned int zone, int mode) = 0;
|
||||
virtual void SetZoneModeBrightness(unsigned int zone, unsigned int mode, unsigned int brightness) = 0;
|
||||
virtual void SetZoneModeColor(unsigned int zone, unsigned int mode, unsigned int color_index, RGBColor color) = 0;
|
||||
virtual void SetZoneModeColorMode(unsigned int zone, unsigned int mode, unsigned int color_mode) = 0;
|
||||
virtual void SetZoneModeColorsCount(unsigned int zone, unsigned int mode, std::size_t count) = 0;
|
||||
virtual void SetZoneModeDirection(unsigned int zone, unsigned int mode, unsigned int direction) = 0;
|
||||
virtual void SetZoneModeSpeed(unsigned int zone, unsigned int mode, unsigned int speed) = 0;
|
||||
virtual void SetZoneActiveMode(unsigned int zone, int mode) = 0;
|
||||
virtual void SetZoneModeBrightness(unsigned int zone, unsigned int mode, unsigned int brightness) = 0;
|
||||
virtual void SetZoneModeColor(unsigned int zone, unsigned int mode, unsigned int color_index, RGBColor color) = 0;
|
||||
virtual void SetZoneModeColorMode(unsigned int zone, unsigned int mode, unsigned int color_mode) = 0;
|
||||
virtual void SetZoneModeColorsCount(unsigned int zone, unsigned int mode, std::size_t count) = 0;
|
||||
virtual void SetZoneModeDirection(unsigned int zone, unsigned int mode, unsigned int direction) = 0;
|
||||
virtual void SetZoneModeSpeed(unsigned int zone, unsigned int mode, unsigned int speed) = 0;
|
||||
|
||||
virtual bool SupportsPerZoneModes() = 0;
|
||||
virtual bool SupportsPerZoneModes() = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mode Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual std::size_t GetModeCount() = 0;
|
||||
virtual unsigned int GetModeBrightness(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeBrightnessMax(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeBrightnessMin(unsigned int mode) = 0;
|
||||
virtual RGBColor GetModeColor(unsigned int mode, unsigned int color_index) = 0;
|
||||
virtual unsigned int GetModeColorMode(unsigned int mode) = 0;
|
||||
virtual std::size_t GetModeColorsCount(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeColorsMax(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeColorsMin(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeDirection(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeFlags(unsigned int mode) = 0;
|
||||
virtual std::string GetModeName(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeSpeed(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeSpeedMax(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeSpeedMin(unsigned int mode) = 0;
|
||||
virtual int GetModeValue(unsigned int mode) = 0;
|
||||
virtual std::size_t GetModeCount() = 0;
|
||||
virtual unsigned int GetModeBrightness(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeBrightnessMax(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeBrightnessMin(unsigned int mode) = 0;
|
||||
virtual RGBColor GetModeColor(unsigned int mode, unsigned int color_index) = 0;
|
||||
virtual unsigned int GetModeColorMode(unsigned int mode) = 0;
|
||||
virtual std::size_t GetModeColorsCount(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeColorsMax(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeColorsMin(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeDirection(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeFlags(unsigned int mode) = 0;
|
||||
virtual std::string GetModeName(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeSpeed(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeSpeedMax(unsigned int mode) = 0;
|
||||
virtual unsigned int GetModeSpeedMin(unsigned int mode) = 0;
|
||||
virtual int GetModeValue(unsigned int mode) = 0;
|
||||
|
||||
virtual void SetModeBrightness(unsigned int mode, unsigned int brightness) = 0;
|
||||
virtual void SetModeColor(unsigned int mode, unsigned int color_index, RGBColor color) = 0;
|
||||
virtual void SetModeColorMode(unsigned int mode, unsigned int color_mode) = 0;
|
||||
virtual void SetModeColorsCount(unsigned int mode, std::size_t count) = 0;
|
||||
virtual void SetModeDirection(unsigned int mode, unsigned int direction) = 0;
|
||||
virtual void SetModeSpeed(unsigned int mode, unsigned int speed) = 0;
|
||||
virtual void SetModeBrightness(unsigned int mode, unsigned int brightness) = 0;
|
||||
virtual void SetModeColor(unsigned int mode, unsigned int color_index, RGBColor color) = 0;
|
||||
virtual void SetModeColorMode(unsigned int mode, unsigned int color_mode) = 0;
|
||||
virtual void SetModeColorsCount(unsigned int mode, std::size_t count) = 0;
|
||||
virtual void SetModeDirection(unsigned int mode, unsigned int direction) = 0;
|
||||
virtual void SetModeSpeed(unsigned int mode, unsigned int speed) = 0;
|
||||
|
||||
virtual int GetActiveMode() = 0;
|
||||
virtual void SetActiveMode(int mode) = 0;
|
||||
virtual void SetCustomMode() = 0;
|
||||
virtual int GetActiveMode() = 0;
|
||||
virtual void SetActiveMode(int mode) = 0;
|
||||
virtual void SetCustomMode() = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| LED Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual std::size_t GetLEDCount() = 0;
|
||||
virtual std::string GetLEDName(unsigned int led) = 0;
|
||||
virtual unsigned int GetLEDValue(unsigned int led) = 0;
|
||||
virtual std::size_t GetLEDCount() = 0;
|
||||
virtual std::string GetLEDName(unsigned int led) = 0;
|
||||
virtual unsigned int GetLEDValue(unsigned int led) = 0;
|
||||
|
||||
virtual std::string GetLEDDisplayName(unsigned int led) = 0;
|
||||
virtual std::string GetLEDDisplayName(unsigned int led) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Color Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual RGBColor GetColor(unsigned int led) = 0;
|
||||
virtual RGBColor* GetColorsPointer() = 0;
|
||||
virtual void SetColor(unsigned int led, RGBColor color) = 0;
|
||||
virtual RGBColor GetColor(unsigned int led) = 0;
|
||||
virtual RGBColor* GetColorsPointer() = 0;
|
||||
virtual void SetColor(unsigned int led, RGBColor color) = 0;
|
||||
|
||||
virtual void SetAllColors(RGBColor color) = 0;
|
||||
virtual void SetAllZoneColors(int zone, RGBColor color) = 0;
|
||||
virtual void SetAllColors(RGBColor color) = 0;
|
||||
virtual void SetAllZoneColors(int zone, RGBColor color) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Serialized Description Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual unsigned char * GetDeviceDescription(unsigned int protocol_version) = 0;
|
||||
virtual void ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char * GetColorDescriptionData(unsigned char* data_ptr, unsigned int protocol_version) = 0;
|
||||
virtual unsigned int GetColorDescriptionSize(unsigned int protocol_version) = 0;
|
||||
virtual unsigned char * GetDeviceDescriptionData(unsigned char* data_ptr, unsigned int protocol_version) = 0;
|
||||
virtual unsigned int GetDeviceDescriptionSize(unsigned int protocol_version) = 0;
|
||||
virtual unsigned char * GetLEDDescriptionData(unsigned char* data_ptr, led led, unsigned int protocol_version) = 0;
|
||||
virtual unsigned int GetLEDDescriptionSize(led led, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char * GetMatrixMapDescriptionData(unsigned char* data_ptr, matrix_map_type* matrix_map, unsigned int protocol_version) = 0;
|
||||
virtual unsigned int GetMatrixMapDescriptionSize(matrix_map_type* matrix_map, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char * GetModeDescriptionData(unsigned char* data_ptr, mode mode, unsigned int protocol_version) = 0;
|
||||
virtual unsigned int GetModeDescriptionSize(mode mode, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char * GetSegmentDescriptionData(unsigned char* data_ptr, segment segment, unsigned int protocol_version) = 0;
|
||||
virtual unsigned int GetSegmentDescriptionSize(segment segment, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char * GetZoneDescriptionData(unsigned char* data_ptr, zone zone, unsigned int protocol_version) = 0;
|
||||
virtual unsigned int GetZoneDescriptionSize(zone zone, unsigned int protocol_version) = 0;
|
||||
|
||||
virtual unsigned char * GetModeDescription(int mode, unsigned int protocol_version) = 0;
|
||||
virtual void SetModeDescription(unsigned char* data_buf, unsigned int protocol_version) = 0;
|
||||
|
||||
virtual unsigned char * GetColorDescription() = 0;
|
||||
virtual void SetColorDescription(unsigned char* data_buf) = 0;
|
||||
|
||||
virtual unsigned char * GetZoneColorDescription(int zone) = 0;
|
||||
virtual void SetZoneColorDescription(unsigned char* data_buf) = 0;
|
||||
|
||||
virtual unsigned char * GetSingleLEDColorDescription(int led) = 0;
|
||||
virtual void SetSingleLEDColorDescription(unsigned char* data_buf) = 0;
|
||||
|
||||
virtual unsigned char * GetSegmentDescription(int zone, segment new_segment) = 0;
|
||||
virtual void SetSegmentDescription(unsigned char* data_buf) = 0;
|
||||
virtual unsigned char* SetColorDescription(unsigned char* data_ptr, unsigned int protocol_version, bool resize = false) = 0;
|
||||
virtual unsigned char* SetDeviceDescription(unsigned char* data_ptr, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char* SetLEDDescription(unsigned char* data_ptr, led* led, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char* SetMatrixMapDescription(unsigned char* data_ptr, matrix_map_type* matrix_map, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char* SetModeDescription(unsigned char* data_ptr, mode* mode, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char* SetSegmentDescription(unsigned char* data_ptr, segment* segment, unsigned int protocol_version) = 0;
|
||||
virtual unsigned char* SetZoneDescription(unsigned char* data_ptr, zone* zone, unsigned int protocol_version) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| JSON Description Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual nlohmann::json GetDeviceDescriptionJSON() = 0;
|
||||
virtual nlohmann::json GetLEDDescriptionJSON(led led) = 0;
|
||||
virtual nlohmann::json GetMatrixMapDescriptionJSON(matrix_map_type* matrix_map) = 0;
|
||||
virtual nlohmann::json GetModeDescriptionJSON(mode mode) = 0;
|
||||
virtual nlohmann::json GetSegmentDescriptionJSON(segment segment) = 0;
|
||||
virtual nlohmann::json GetZoneDescriptionJSON(zone zone) = 0;
|
||||
virtual nlohmann::json GetDeviceDescriptionJSON() = 0;
|
||||
virtual nlohmann::json GetLEDDescriptionJSON(led led) = 0;
|
||||
virtual nlohmann::json GetMatrixMapDescriptionJSON(matrix_map_type* matrix_map) = 0;
|
||||
virtual nlohmann::json GetModeDescriptionJSON(mode mode) = 0;
|
||||
virtual nlohmann::json GetSegmentDescriptionJSON(segment segment) = 0;
|
||||
virtual nlohmann::json GetZoneDescriptionJSON(zone zone) = 0;
|
||||
|
||||
virtual void SetDeviceDescriptionJSON(nlohmann::json controller_json) = 0;
|
||||
virtual led SetLEDDescriptionJSON(nlohmann::json led_json) = 0;
|
||||
virtual matrix_map_type* SetMatrixMapDescriptionJSON(nlohmann::json matrix_map_json) = 0;
|
||||
virtual mode SetModeDescriptionJSON(nlohmann::json mode_json) = 0;
|
||||
virtual segment SetSegmentDescriptionJSON(nlohmann::json segment_json) = 0;
|
||||
virtual zone SetZoneDescriptionJSON(nlohmann::json zone_json) = 0;
|
||||
virtual void SetDeviceDescriptionJSON(nlohmann::json controller_json) = 0;
|
||||
virtual led SetLEDDescriptionJSON(nlohmann::json led_json) = 0;
|
||||
virtual matrix_map_type* SetMatrixMapDescriptionJSON(nlohmann::json matrix_map_json) = 0;
|
||||
virtual mode SetModeDescriptionJSON(nlohmann::json mode_json) = 0;
|
||||
virtual segment SetSegmentDescriptionJSON(nlohmann::json segment_json) = 0;
|
||||
virtual zone SetZoneDescriptionJSON(nlohmann::json zone_json) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Update Callback Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual void RegisterUpdateCallback(RGBControllerCallback new_callback, void * new_callback_arg) = 0;
|
||||
virtual void UnregisterUpdateCallback(void * callback_arg) = 0;
|
||||
virtual void ClearCallbacks() = 0;
|
||||
virtual void SignalUpdate(unsigned int update_reason) = 0;
|
||||
virtual void RegisterUpdateCallback(RGBControllerCallback new_callback, void * new_callback_arg) = 0;
|
||||
virtual void UnregisterUpdateCallback(void * callback_arg) = 0;
|
||||
virtual void ClearCallbacks() = 0;
|
||||
virtual void SignalUpdate(unsigned int update_reason) = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Device Update Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual void UpdateLEDs() = 0;
|
||||
virtual void UpdateZoneLEDs(int zone) = 0;
|
||||
virtual void UpdateSingleLED(int led) = 0;
|
||||
virtual void UpdateLEDs() = 0;
|
||||
virtual void UpdateZoneLEDs(int zone) = 0;
|
||||
virtual void UpdateSingleLED(int led) = 0;
|
||||
|
||||
virtual void UpdateMode() = 0;
|
||||
virtual void UpdateZoneMode(int zone) = 0;
|
||||
virtual void SaveMode() = 0;
|
||||
virtual void UpdateMode() = 0;
|
||||
virtual void UpdateZoneMode(int zone) = 0;
|
||||
virtual void SaveMode() = 0;
|
||||
|
||||
virtual void ClearSegments(int zone) = 0;
|
||||
virtual void AddSegment(int zone, segment new_segment) = 0;
|
||||
virtual void ClearSegments(int zone) = 0;
|
||||
virtual void AddSegment(int zone, segment new_segment) = 0;
|
||||
|
||||
virtual void ResizeZone(int zone, int new_size) = 0;
|
||||
virtual void ResizeZone(int zone, int new_size) = 0;
|
||||
};
|
||||
|
||||
class RGBController : public RGBControllerInterface
|
||||
@@ -605,23 +610,28 @@ public:
|
||||
/*-----------------------------------------------------*\
|
||||
| Serialized Description Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char * GetDeviceDescription(unsigned int protocol_version);
|
||||
void ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version);
|
||||
unsigned char * GetColorDescriptionData(unsigned char* data_ptr, unsigned int protocol_version);
|
||||
unsigned int GetColorDescriptionSize(unsigned int protocol_version);
|
||||
unsigned char * GetDeviceDescriptionData(unsigned char* data_ptr, unsigned int protocol_version);
|
||||
unsigned int GetDeviceDescriptionSize(unsigned int protocol_version);
|
||||
unsigned char * GetLEDDescriptionData(unsigned char* data_ptr, led led, unsigned int protocol_version);
|
||||
unsigned int GetLEDDescriptionSize(led led, unsigned int protocol_version);
|
||||
unsigned char * GetMatrixMapDescriptionData(unsigned char* data_ptr, matrix_map_type* matrix_map, unsigned int protocol_version);
|
||||
unsigned int GetMatrixMapDescriptionSize(matrix_map_type* matrix_map, unsigned int protocol_version);
|
||||
unsigned char * GetModeDescriptionData(unsigned char* data_ptr, mode mode, unsigned int protocol_version);
|
||||
unsigned int GetModeDescriptionSize(mode mode, unsigned int protocol_version);
|
||||
unsigned char * GetSegmentDescriptionData(unsigned char* data_ptr, segment segment, unsigned int protocol_version);
|
||||
unsigned int GetSegmentDescriptionSize(segment segment, unsigned int protocol_version);
|
||||
unsigned char * GetZoneDescriptionData(unsigned char* data_ptr, zone zone, unsigned int protocol_version);
|
||||
unsigned int GetZoneDescriptionSize(zone zone, unsigned int protocol_version);
|
||||
|
||||
unsigned char * GetModeDescription(int mode, unsigned int protocol_version);
|
||||
void SetModeDescription(unsigned char* data_buf, unsigned int protocol_version);
|
||||
|
||||
unsigned char * GetColorDescription();
|
||||
void SetColorDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetZoneColorDescription(int zone);
|
||||
void SetZoneColorDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetSingleLEDColorDescription(int led);
|
||||
void SetSingleLEDColorDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetSegmentDescription(int zone, segment new_segment);
|
||||
void SetSegmentDescription(unsigned char* data_buf);
|
||||
unsigned char* SetColorDescription(unsigned char* data_ptr, unsigned int protocol_version, bool resize = false);
|
||||
unsigned char* SetDeviceDescription(unsigned char* data_ptr, unsigned int protocol_version);
|
||||
unsigned char* SetLEDDescription(unsigned char* data_ptr, led* led, unsigned int protocol_version);
|
||||
unsigned char* SetMatrixMapDescription(unsigned char* data_ptr, matrix_map_type* matrix_map, unsigned int protocol_version);
|
||||
unsigned char* SetModeDescription(unsigned char* data_ptr, mode* mode, unsigned int protocol_version);
|
||||
unsigned char* SetSegmentDescription(unsigned char* data_ptr, segment* segment, unsigned int protocol_version);
|
||||
unsigned char* SetZoneDescription(unsigned char* data_ptr, zone* zone, unsigned int protocol_version);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| JSON Description Functions |
|
||||
@@ -707,6 +717,11 @@ protected:
|
||||
std::vector<mode> modes; /* Modes */
|
||||
std::vector<zone> zones; /* Zones */
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Access mutex variables |
|
||||
\*-----------------------------------------------------*/
|
||||
std::shared_mutex AccessMutex;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Functions not part of interface for internal use only |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -729,16 +744,12 @@ private:
|
||||
std::vector<RGBControllerCallback> UpdateCallbacks;
|
||||
std::vector<void *> UpdateCallbackArgs;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Access mutex variables |
|
||||
\*-----------------------------------------------------*/
|
||||
std::shared_mutex AccessMutex;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Certain internal OpenRGB framework classes can modify |
|
||||
| protected members |
|
||||
\*-----------------------------------------------------*/
|
||||
friend class NetworkClient;
|
||||
friend class NetworkServer;
|
||||
friend class ProfileManager;
|
||||
friend class ResourceManager;
|
||||
};
|
||||
|
||||
@@ -20,11 +20,6 @@ RGBController_Network::RGBController_Network(NetworkClient * client_ptr, unsigne
|
||||
dev_idx = dev_idx_val;
|
||||
}
|
||||
|
||||
void RGBController_Network::SetupZones()
|
||||
{
|
||||
//Don't send anything, this function should only process on host
|
||||
}
|
||||
|
||||
void RGBController_Network::ClearSegments(int zone)
|
||||
{
|
||||
client->SendRequest_RGBController_ClearSegments(dev_idx, zone);
|
||||
@@ -35,14 +30,54 @@ void RGBController_Network::ClearSegments(int zone)
|
||||
|
||||
void RGBController_Network::AddSegment(int zone, segment new_segment)
|
||||
{
|
||||
unsigned char * data = GetSegmentDescription(zone, new_segment);
|
||||
unsigned int size;
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.lock_shared();
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize variables |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int data_size = 0;
|
||||
|
||||
client->SendRequest_RGBController_AddSegment(dev_idx, data, size);
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*-----------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(zone);
|
||||
data_size += GetSegmentDescriptionSize(new_segment, client->GetProtocolVersion());
|
||||
|
||||
delete[] data;
|
||||
/*-----------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char * data_buf = new unsigned char[data_size];
|
||||
unsigned char * data_ptr = data_buf;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in zone index |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &zone, sizeof(zone));
|
||||
data_ptr += sizeof(zone);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in segment description |
|
||||
\*-----------------------------------------------------*/
|
||||
data_ptr = GetSegmentDescriptionData(data_ptr, new_segment, client->GetProtocolVersion());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Unlock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.unlock_shared();
|
||||
|
||||
client->SendRequest_RGBController_AddSegment(dev_idx, data_buf, data_size);
|
||||
|
||||
delete[] data_buf;
|
||||
|
||||
client->SendRequest_ControllerData(dev_idx);
|
||||
client->WaitOnControllerData();
|
||||
@@ -58,7 +93,7 @@ void RGBController_Network::ResizeZone(int zone, int new_size)
|
||||
|
||||
void RGBController_Network::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char * data = GetColorDescription();
|
||||
unsigned char * data = CreateUpdateLEDsPacket(client->GetProtocolVersion());
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
@@ -70,7 +105,7 @@ void RGBController_Network::DeviceUpdateLEDs()
|
||||
|
||||
void RGBController_Network::DeviceUpdateZoneLEDs(int zone)
|
||||
{
|
||||
unsigned char * data = GetZoneColorDescription(zone);
|
||||
unsigned char * data = CreateUpdateZoneLEDsPacket(zone);
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
@@ -82,7 +117,7 @@ void RGBController_Network::DeviceUpdateZoneLEDs(int zone)
|
||||
|
||||
void RGBController_Network::DeviceUpdateSingleLED(int led)
|
||||
{
|
||||
unsigned char * data = GetSingleLEDColorDescription(led);
|
||||
unsigned char * data = CreateUpdateSingleLEDPacket(led);
|
||||
|
||||
client->SendRequest_RGBController_UpdateSingleLED(dev_idx, data, sizeof(int) + sizeof(RGBColor));
|
||||
|
||||
@@ -99,22 +134,34 @@ void RGBController_Network::SetCustomMode()
|
||||
|
||||
void RGBController_Network::DeviceUpdateMode()
|
||||
{
|
||||
unsigned char * data = GetModeDescription(active_mode, client->GetProtocolVersion());
|
||||
unsigned int size;
|
||||
unsigned char * data;
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
data = CreateUpdateModePacket(active_mode, &size, client->GetProtocolVersion());
|
||||
|
||||
client->SendRequest_RGBController_UpdateMode(dev_idx, data, size);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void RGBController_Network::DeviceUpdateZoneMode(int zone)
|
||||
{
|
||||
unsigned char * data;
|
||||
unsigned int size;
|
||||
|
||||
data = CreateUpdateZoneModePacket(zone, zones[zone].active_mode, &size, client->GetProtocolVersion());
|
||||
|
||||
client->SendRequest_RGBController_UpdateZoneMode(dev_idx, data, size);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void RGBController_Network::DeviceSaveMode()
|
||||
{
|
||||
unsigned char * data = GetModeDescription(active_mode, client->GetProtocolVersion());
|
||||
unsigned int size;
|
||||
unsigned char * data;
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
data = CreateUpdateModePacket(active_mode, &size, client->GetProtocolVersion());
|
||||
|
||||
client->SendRequest_RGBController_SaveMode(dev_idx, data, size);
|
||||
|
||||
@@ -134,3 +181,264 @@ void RGBController_Network::UpdateLEDs()
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Network::UpdateMode()
|
||||
{
|
||||
DeviceUpdateMode();
|
||||
}
|
||||
|
||||
unsigned char * RGBController_Network::CreateUpdateLEDsPacket(unsigned int protocol_version)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.lock_shared();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize variables |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int data_size = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*-----------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += GetColorDescriptionSize(protocol_version);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char * data_buf = new unsigned char[data_size];
|
||||
unsigned char * data_ptr = data_buf;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data |
|
||||
\*-----------------------------------------------------*/
|
||||
data_ptr = GetColorDescriptionData(data_ptr, protocol_version);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Unlock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.unlock_shared();
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
unsigned char * RGBController_Network::CreateUpdateModePacket(int mode_idx, unsigned int* size, unsigned int protocol_version)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.lock_shared();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize variables |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int data_size = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*-----------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(mode_idx);
|
||||
data_size += GetModeDescriptionSize(modes[mode_idx], protocol_version);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char* data_buf = new unsigned char[data_size];
|
||||
unsigned char* data_ptr = data_buf;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in mode index |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &mode_idx, sizeof(mode_idx));
|
||||
data_ptr += sizeof(mode_idx);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in mode description |
|
||||
\*-----------------------------------------------------*/
|
||||
data_ptr = GetModeDescriptionData(data_ptr, modes[mode_idx], protocol_version);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Unlock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.unlock_shared();
|
||||
|
||||
*size = data_size;
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
unsigned char * RGBController_Network::CreateUpdateSingleLEDPacket(int led)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.lock_shared();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fixed size descrption: |
|
||||
| int: LED index |
|
||||
| RGBColor: LED color |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[sizeof(int) + sizeof(RGBColor)];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in LED index |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&data_buf[0], &led, sizeof(int));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in LED color |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&data_buf[sizeof(led)], &colors[led], sizeof(RGBColor));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Unlock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.unlock_shared();
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
unsigned char * RGBController_Network::CreateUpdateZoneLEDsPacket(int zone)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.lock_shared();
|
||||
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
|
||||
unsigned short num_colors = zones[zone].leds_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*-----------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(zone);
|
||||
data_size += sizeof(num_colors);
|
||||
data_size += num_colors * sizeof(RGBColor);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[data_size];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in zone index |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zone, sizeof(zone));
|
||||
data_ptr += sizeof(zone);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &num_colors, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*-------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zones[zone].colors[color_index], sizeof(zones[zone].colors[color_index]));
|
||||
data_ptr += sizeof(zones[zone].colors[color_index]);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Unlock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.unlock_shared();
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
unsigned char * RGBController_Network::CreateUpdateZoneModePacket(int zone_idx, int mode_idx, unsigned int* size, unsigned int protocol_version)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Lock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.lock_shared();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize variables |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int data_size = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*-----------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(zone_idx);
|
||||
data_size += sizeof(mode_idx);
|
||||
|
||||
if(mode_idx >= 0)
|
||||
{
|
||||
data_size += GetModeDescriptionSize(zones[zone_idx].modes[mode_idx], protocol_version);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char* data_buf = new unsigned char[data_size];
|
||||
unsigned char* data_ptr = data_buf;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in zone index |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &zone_idx, sizeof(zone_idx));
|
||||
data_ptr += sizeof(zone_idx);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in mode index |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(data_ptr, &mode_idx, sizeof(mode_idx));
|
||||
data_ptr += sizeof(mode_idx);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in mode description |
|
||||
\*-----------------------------------------------------*/
|
||||
if(mode_idx >= 0)
|
||||
{
|
||||
data_ptr = GetModeDescriptionData(data_ptr, zones[zone_idx].modes[mode_idx], protocol_version);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Unlock access mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
AccessMutex.unlock_shared();
|
||||
|
||||
*size = data_size;
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ class RGBController_Network : public RGBController
|
||||
public:
|
||||
RGBController_Network(NetworkClient * client_ptr, unsigned int dev_idx_val);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ClearSegments(int zone);
|
||||
void AddSegment(int zone, segment new_segment);
|
||||
void ResizeZone(int zone, int new_size);
|
||||
@@ -32,11 +30,19 @@ public:
|
||||
|
||||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
void DeviceUpdateZoneMode(int zone);
|
||||
void DeviceSaveMode();
|
||||
|
||||
void UpdateLEDs();
|
||||
void UpdateMode();
|
||||
|
||||
private:
|
||||
NetworkClient * client;
|
||||
unsigned int dev_idx;
|
||||
|
||||
unsigned char * CreateUpdateLEDsPacket(unsigned int protocol_version);
|
||||
unsigned char * CreateUpdateModePacket(int mode_idx, unsigned int* size, unsigned int protocol_version);
|
||||
unsigned char * CreateUpdateSingleLEDPacket(int led);
|
||||
unsigned char * CreateUpdateZoneLEDsPacket(int zone);
|
||||
unsigned char * CreateUpdateZoneModePacket(int zone_idx, int mode_idx, unsigned int* size, unsigned int protocol_version);
|
||||
};
|
||||
|
||||
@@ -194,6 +194,15 @@ ResourceManager::ResourceManager()
|
||||
server = new NetworkServer(rgb_controllers_hw);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set server name |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string titleString = "OpenRGB ";
|
||||
titleString.append(VERSION_STRING);
|
||||
|
||||
server->SetName(titleString);
|
||||
server->SetSettingsManager(settings_manager);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Enable legacy SDK workaround in server if configured |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -1797,6 +1806,7 @@ void ResourceManager::InitCoroutine()
|
||||
| detection if the local server was connected |
|
||||
\*---------------------------------------------*/
|
||||
auto_connection_active = true;
|
||||
profile_manager->UpdateProfileList();
|
||||
DisableDetection();
|
||||
}
|
||||
|
||||
@@ -2123,3 +2133,13 @@ bool ResourceManager::IsAnyDimmDetectorEnabled(json &detector_settings)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ResourceManager::IsLocalClient()
|
||||
{
|
||||
return(auto_connection_active);
|
||||
}
|
||||
|
||||
NetworkClient* ResourceManager::GetLocalClient()
|
||||
{
|
||||
return(auto_connection_client);
|
||||
}
|
||||
|
||||
@@ -199,6 +199,9 @@ public:
|
||||
void WaitForInitialization();
|
||||
void WaitForDeviceDetection();
|
||||
|
||||
bool IsLocalClient();
|
||||
NetworkClient* GetLocalClient();
|
||||
|
||||
private:
|
||||
void UpdateDetectorSettings();
|
||||
void SetupConfigurationDirectory();
|
||||
|
||||
@@ -13,8 +13,22 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "SettingsManager.h"
|
||||
#include "LogManager.h"
|
||||
#include "NetworkClient.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "SettingsManager.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
static const std::string ui_settings_keys[7] =
|
||||
{
|
||||
"UserInterface",
|
||||
"AutoStart",
|
||||
"Theme",
|
||||
"Plugins",
|
||||
"Client",
|
||||
"LogManager",
|
||||
"Server"
|
||||
};
|
||||
|
||||
SettingsManager::SettingsManager()
|
||||
{
|
||||
@@ -28,31 +42,113 @@ SettingsManager::~SettingsManager()
|
||||
|
||||
json SettingsManager::GetSettings(std::string settings_key)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Check to see if the key exists in the settings store |
|
||||
| and return the settings associated with the key if it |
|
||||
| exists. We lock the mutex to protect the value from |
|
||||
| changing while data is being read and copy before |
|
||||
| unlocking. |
|
||||
\*-----------------------------------------------------*/
|
||||
json result;
|
||||
bool ui_settings_key = false;
|
||||
|
||||
mutex.lock();
|
||||
if(settings_data.contains(settings_key))
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove any excess null termination from settings key |
|
||||
\*-----------------------------------------------------*/
|
||||
settings_key = StringUtils::remove_null_terminating_chars(settings_key);
|
||||
|
||||
for(std::size_t settings_key_idx = 0; settings_key_idx < 7; settings_key_idx++)
|
||||
{
|
||||
result = settings_data[settings_key];
|
||||
if(settings_key == ui_settings_keys[settings_key_idx])
|
||||
{
|
||||
ui_settings_key = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mutex.unlock();
|
||||
if(!ui_settings_key && ResourceManager::get()->IsLocalClient())
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| If this is a local client, request the settings |
|
||||
| from the server |
|
||||
\*-------------------------------------------------*/
|
||||
try
|
||||
{
|
||||
result = nlohmann::json::parse(ResourceManager::get()->GetLocalClient()->SettingsManager_GetSettings(settings_key));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Check to see if the key exists in the settings |
|
||||
| store and return the settings associated with the |
|
||||
| key if it exists. We lock the mutex to protect |
|
||||
| the value from changing while data is being read |
|
||||
| and copy before unlocking. |
|
||||
\*-------------------------------------------------*/
|
||||
mutex.lock();
|
||||
if(settings_data.contains(settings_key))
|
||||
{
|
||||
result = settings_data[settings_key];
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SettingsManager::SetSettings(std::string settings_key, json new_settings)
|
||||
{
|
||||
mutex.lock();
|
||||
settings_data[settings_key] = new_settings;
|
||||
mutex.unlock();
|
||||
bool ui_settings_key = false;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove any excess null termination from settings key |
|
||||
\*-----------------------------------------------------*/
|
||||
settings_key = StringUtils::remove_null_terminating_chars(settings_key);
|
||||
|
||||
for(std::size_t settings_key_idx = 0; settings_key_idx < 7; settings_key_idx++)
|
||||
{
|
||||
if(settings_key == ui_settings_keys[settings_key_idx])
|
||||
{
|
||||
ui_settings_key = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui_settings_key && ResourceManager::get()->IsLocalClient())
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| If this is a local client, request the settings |
|
||||
| from the server |
|
||||
\*-------------------------------------------------*/
|
||||
nlohmann::json settings_json;
|
||||
|
||||
settings_json[settings_key] = new_settings;
|
||||
|
||||
ResourceManager::get()->GetLocalClient()->SettingsManager_SetSettings(settings_json.dump());
|
||||
}
|
||||
else
|
||||
{
|
||||
mutex.lock();
|
||||
settings_data[settings_key] = new_settings;
|
||||
mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManager::SetSettingsFromJsonString(std::string settings_json_str)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Parse the JSON string |
|
||||
\*-----------------------------------------------------*/
|
||||
nlohmann::json settings_json = nlohmann::json::parse(settings_json_str);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get key/value pairs from JSON, call SetSettings for |
|
||||
| each key. This use of `auto` is acceptable due to |
|
||||
| how the JSON library implements iterators, the type |
|
||||
| would change based on the library version. |
|
||||
\*-----------------------------------------------------*/
|
||||
for(auto& element : settings_json.items())
|
||||
{
|
||||
SetSettings(element.key(), element.value());
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManager::LoadSettings(const filesystem::path& filename)
|
||||
@@ -109,6 +205,15 @@ void SettingsManager::LoadSettings(const filesystem::path& filename)
|
||||
|
||||
void SettingsManager::SaveSettings()
|
||||
{
|
||||
if(ResourceManager::get()->IsLocalClient())
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| If this is a local client, save the settings on |
|
||||
| the server |
|
||||
\*-------------------------------------------------*/
|
||||
ResourceManager::get()->GetLocalClient()->SettingsManager_SaveSettings();
|
||||
}
|
||||
|
||||
mutex.lock();
|
||||
std::ofstream settings_file(settings_filename, std::ios::out | std::ios::binary);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ class SettingsManagerInterface
|
||||
public:
|
||||
virtual json GetSettings(std::string settings_key) = 0;
|
||||
virtual void SetSettings(std::string settings_key, json new_settings) = 0;
|
||||
virtual void SetSettingsFromJsonString(std::string settings_json_str) = 0;
|
||||
|
||||
virtual void LoadSettings(const filesystem::path& filename) = 0;
|
||||
virtual void SaveSettings() = 0;
|
||||
@@ -40,6 +41,7 @@ public:
|
||||
|
||||
json GetSettings(std::string settings_key) override;
|
||||
void SetSettings(std::string settings_key, json new_settings) override;
|
||||
void SetSettingsFromJsonString(std::string settings_json_str) override;
|
||||
|
||||
void LoadSettings(const filesystem::path& filename) override;
|
||||
void SaveSettings() override;
|
||||
|
||||
@@ -131,11 +131,29 @@ void OpenRGBClientInfoPage::UpdateInfo()
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the top level tree widget items and display the|
|
||||
| client IP addresses and protocol versions in them |
|
||||
| Create the top level tree widget items |
|
||||
\*-----------------------------------------------------*/
|
||||
QTreeWidgetItem* new_top_item = new QTreeWidgetItem(ui->ClientTree);
|
||||
new_top_item->setText(0, QString::fromStdString(ResourceManager::get()->GetClients()[client_idx]->GetIP()));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| First column, display the server IP and optionally |
|
||||
| the server name if it exists |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string server_name = ResourceManager::get()->GetClients()[client_idx]->GetServerName();
|
||||
std::string ip = ResourceManager::get()->GetClients()[client_idx]->GetIP();
|
||||
|
||||
if(server_name == "")
|
||||
{
|
||||
new_top_item->setText(0, QString::fromStdString(ip));
|
||||
}
|
||||
else
|
||||
{
|
||||
new_top_item->setText(0, QString::fromStdString(ip + ": " + server_name));
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Second column, display the protocol version |
|
||||
\*-----------------------------------------------------*/
|
||||
new_top_item->setText(1, QString::number(ResourceManager::get()->GetClients()[client_idx]->GetProtocolVersion()));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
|
||||
@@ -52,6 +52,12 @@ int startup(int argc, char* argv[], unsigned int ret_flags)
|
||||
\*-----------------------------------------------------*/
|
||||
int exitval = EXIT_SUCCESS;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Before opening GUI, wait for automatic connection so |
|
||||
| that settings and profiles can be updated from server |
|
||||
\*-----------------------------------------------------*/
|
||||
ResourceManager::get()->WaitForInitialization();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the command line parser indicates that the GUI |
|
||||
| should run, or if there were no command line |
|
||||
|
||||
Reference in New Issue
Block a user