Detection progress SDK integration, NetworkClient callback rework

This commit is contained in:
Adam Honse
2026-01-12 13:35:30 -06:00
parent 2fa77341ba
commit c820f0fec6
8 changed files with 324 additions and 76 deletions

View File

@@ -611,7 +611,10 @@ void DetectionManager::BackgroundDetectDevices()
{
if(initial_detection_delay_ms != 0)
{
LOG_INFO("[ResourceManager] Delaying detection for %d ms", initial_detection_delay_ms);
detection_string = "Waiting for detection delay";
SignalUpdate(DETECTIONMANAGER_UPDATE_REASON_DETECTION_PROGRESS_CHANGED);
LOG_INFO("[%s] Delaying detection for %d ms", DETECTIONMANAGER, initial_detection_delay_ms);
std::this_thread::sleep_for(initial_detection_delay_ms * 1ms);
}
@@ -1371,6 +1374,8 @@ void DetectionManager::ProcessCleanup()
{
WaitForDetection();
SignalUpdate(DETECTIONMANAGER_UPDATE_REASON_RGBCONTROLLER_LIST_CLEARED);
/*-----------------------------------------------------*\
| Make a copy of the list so that the controllers can |
| be deleted after the list is cleared |

View File

@@ -113,6 +113,7 @@ enum
DETECTIONMANAGER_UPDATE_REASON_I2C_BUS_REGISTERED, /* RegisterI2CBus() called */
DETECTIONMANAGER_UPDATE_REASON_RGBCONTROLLER_REGISTERED, /* RegisterRGBController() called */
DETECTIONMANAGER_UPDATE_REASON_RGBCONTROLLER_UNREGISTERED, /* UnregisterRGBController() called */
DETECTIONMANAGER_UPDATE_REASON_RGBCONTROLLER_LIST_CLEARED, /* RGBController list cleared */
DETECTIONMANAGER_UPDATE_REASON_DETECTION_STARTED, /* Detection started */
DETECTIONMANAGER_UPDATE_REASON_DETECTION_PROGRESS_CHANGED, /* Detection progress changed */
DETECTIONMANAGER_UPDATE_REASON_DETECTION_COMPLETE, /* Detection completed */

View File

@@ -42,6 +42,8 @@ NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controller
port_num = OPENRGB_SDK_PORT;
client_string_sent = false;
client_sock = -1;
detection_percent = 100;
detection_string = "";
protocol_initialized = false;
server_connected = false;
server_controller_count = 0;
@@ -153,7 +155,7 @@ void NetworkClient::StartClient()
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_CLIENT_STARTED);
}
void NetworkClient::StopClient()
@@ -200,7 +202,7 @@ void NetworkClient::StopClient()
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_CLIENT_STOPPED);
}
void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
@@ -240,6 +242,8 @@ void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
protocol_version = server_protocol_version;
}
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_PROTOCOL_NEGOTIATED);
send_in_progress.lock();
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
send(client_sock, (char *)&protocol_version, sizeof(unsigned int), MSG_NOSIGNAL);
@@ -266,14 +270,27 @@ void NetworkClient::SendRequest_RescanDevices()
\*---------------------------------------------------------*/
void NetworkClient::ClearCallbacks()
{
ClientInfoChangeCallbacks.clear();
ClientInfoChangeCallbackArgs.clear();
NetworkClientCallbacks.clear();
NetworkClientCallbackArgs.clear();
}
void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg)
void NetworkClient::RegisterNetworkClientCallback(NetworkClientCallback new_callback, void * new_callback_arg)
{
ClientInfoChangeCallbacks.push_back(new_callback);
ClientInfoChangeCallbackArgs.push_back(new_callback_arg);
NetworkClientCallbacks.push_back(new_callback);
NetworkClientCallbackArgs.push_back(new_callback_arg);
}
/*---------------------------------------------------------*\
| DetectionManager functions |
\*---------------------------------------------------------*/
unsigned int NetworkClient::DetectionManager_GetDetectionPercent()
{
return(detection_percent);
}
std::string NetworkClient::DetectionManager_GetDetectionString()
{
return(detection_string);
}
/*---------------------------------------------------------*\
@@ -646,21 +663,19 @@ void NetworkClient::WaitOnControllerData()
/*---------------------------------------------------------*\
| Client callback signal functions |
\*---------------------------------------------------------*/
void NetworkClient::ClientInfoChanged()
void NetworkClient::SignalNetworkClientUpdate(unsigned int update_reason)
{
ClientInfoChangeMutex.lock();
ControllerListMutex.lock();
NetworkClientCallbackMutex.lock();
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
for(unsigned int callback_idx = 0; callback_idx < ClientInfoChangeCallbacks.size(); callback_idx++)
for(unsigned int callback_idx = 0; callback_idx < NetworkClientCallbacks.size(); callback_idx++)
{
ClientInfoChangeCallbacks[callback_idx](ClientInfoChangeCallbackArgs[callback_idx]);
NetworkClientCallbacks[callback_idx](NetworkClientCallbackArgs[callback_idx], update_reason);
}
ControllerListMutex.unlock();
ClientInfoChangeMutex.unlock();
NetworkClientCallbackMutex.unlock();
}
/*---------------------------------------------------------*\
@@ -708,7 +723,7 @@ void NetworkClient::ConnectionThreadFunction()
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_CLIENT_CONNECTED);
}
else
{
@@ -842,7 +857,7 @@ void NetworkClient::ConnectionThreadFunction()
| Client info has changed, call the |
| callbacks |
\*-----------------------------------------*/
ClientInfoChanged();
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_DEVICE_LIST_UPDATED);
server_initialized = true;
}
@@ -975,6 +990,18 @@ void NetworkClient::ListenThreadFunction()
ProcessRequest_DeviceListChanged();
break;
case NET_PACKET_ID_DETECTION_STARTED:
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_DETECTION_STARTED);
break;
case NET_PACKET_ID_DETECTION_PROGRESS_CHANGED:
ProcessRequest_DetectionProgressChanged(header.pkt_size, data);
break;
case NET_PACKET_ID_DETECTION_COMPLETE:
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_DETECTION_COMPLETE);
break;
case NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST:
case NET_PACKET_ID_PROFILEMANAGER_DOWNLOAD_PROFILE:
case NET_PACKET_ID_PROFILEMANAGER_GET_ACTIVE_PROFILE:
@@ -1043,7 +1070,7 @@ listen_done:
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_CLIENT_DISCONNECTED);
}
/*---------------------------------------------------------*\
@@ -1122,6 +1149,25 @@ void NetworkClient::ProcessReply_ProtocolVersion(unsigned int data_size, char *
}
}
void NetworkClient::ProcessRequest_DetectionProgressChanged(unsigned int data_size, char * data)
{
if(data_size == *((unsigned int*) data))
{
data += sizeof(data_size);
memcpy(&detection_percent, data, sizeof(detection_percent));
data += sizeof(detection_percent);
unsigned short string_length;
memcpy(&string_length, data, sizeof(string_length));
data += sizeof(string_length);
detection_string.assign(data, string_length);
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_DETECTION_PROGRESS_CHANGED);
}
}
void NetworkClient::ProcessRequest_DeviceListChanged()
{
change_in_progress = true;
@@ -1157,7 +1203,7 @@ void NetworkClient::ProcessRequest_DeviceListChanged()
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_DEVICE_LIST_UPDATED);
/*---------------------------------------------------------*\
| Mark server as uninitialized and reset server |
@@ -1248,7 +1294,7 @@ void NetworkClient::ProcessRequest_ServerString(unsigned int data_size, char * d
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_SERVER_STRING_RECEIVED);
}
void NetworkClient::SendData_ClientString()

View File

@@ -19,7 +19,29 @@
#include "NetworkProtocol.h"
#include "net_port.h"
typedef void (*NetClientCallback)(void *);
/*---------------------------------------------------------*\
| Callback Types |
\*---------------------------------------------------------*/
typedef void (*NetworkClientCallback)(void *, unsigned int);
/*---------------------------------------------------------*\
| NetworkClient Update Reason Codes |
\*---------------------------------------------------------*/
enum
{
NETWORKCLIENT_UPDATE_REASON_CLIENT_STARTED, /* Client started */
NETWORKCLIENT_UPDATE_REASON_CLIENT_STOPPED, /* Client stopped */
NETWORKCLIENT_UPDATE_REASON_CLIENT_CONNECTED, /* Client connectedd */
NETWORKCLIENT_UPDATE_REASON_CLIENT_DISCONNECTED, /* Client disconnected */
NETWORKCLIENT_UPDATE_REASON_SERVER_STRING_RECEIVED, /* Server string received */
NETWORKCLIENT_UPDATE_REASON_PROTOCOL_NEGOTIATED, /* Protocol version negotiated */
NETWORKCLIENT_UPDATE_REASON_DEVICE_LIST_UPDATED, /* Device list updated */
NETWORKCLIENT_UPDATE_REASON_DETECTION_STARTED, /* Detection started */
NETWORKCLIENT_UPDATE_REASON_DETECTION_PROGRESS_CHANGED, /* Detection progress changed */
NETWORKCLIENT_UPDATE_REASON_DETECTION_COMPLETE, /* Detection completed */
};
class NetworkClient
{
@@ -54,7 +76,13 @@ public:
| Client Callback functions |
\*-----------------------------------------------------*/
void ClearCallbacks();
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
void RegisterNetworkClientCallback(NetworkClientCallback new_callback, void * new_callback_arg);
/*-----------------------------------------------------*\
| DetectionManager functions |
\*-----------------------------------------------------*/
unsigned int DetectionManager_GetDetectionPercent();
std::string DetectionManager_GetDetectionString();
/*-----------------------------------------------------*\
| ProfileManager functions |
@@ -146,9 +174,9 @@ private:
/*-----------------------------------------------------*\
| Callbacks |
\*-----------------------------------------------------*/
std::mutex ClientInfoChangeMutex;
std::vector<NetClientCallback> ClientInfoChangeCallbacks;
std::vector<void *> ClientInfoChangeCallbackArgs;
std::mutex NetworkClientCallbackMutex;
std::vector<NetworkClientCallback> NetworkClientCallbacks;
std::vector<void *> NetworkClientCallbackArgs;
/*-----------------------------------------------------*\
| Controller list |
@@ -156,10 +184,16 @@ private:
std::mutex ControllerListMutex;
std::vector<RGBController *>& controllers;
/*-----------------------------------------------------*\
| Detection variables |
\*-----------------------------------------------------*/
unsigned int detection_percent;
std::string detection_string;
/*-----------------------------------------------------*\
| Client callback signal functions |
\*-----------------------------------------------------*/
void ClientInfoChanged();
void SignalNetworkClientUpdate(unsigned int update_reason);
/*-----------------------------------------------------*\
| Client thread functions |
@@ -173,6 +207,7 @@ private:
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_DetectionProgressChanged(unsigned int data_size, char * data);
void ProcessRequest_DeviceListChanged();
void ProcessRequest_RGBController_SignalUpdate(unsigned int data_size, char * data, unsigned int dev_idx);
void ProcessRequest_ServerString(unsigned int data_size, char * data);

View File

@@ -64,6 +64,9 @@ enum
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_DETECTION_STARTED = 101, /* Indicate to clients that detection started */
NET_PACKET_ID_DETECTION_PROGRESS_CHANGED = 102, /* Indicate to clients that detection progress changed */
NET_PACKET_ID_DETECTION_COMPLETE = 103, /* Indicate to clients that detection completed */
NET_PACKET_ID_REQUEST_RESCAN_DEVICES = 140, /* Request rescan of devices */

View File

@@ -192,24 +192,25 @@ unsigned int NetworkServer::GetClientProtocolVersion(unsigned int client_num)
/*---------------------------------------------------------*\
| Callback functions |
\*---------------------------------------------------------*/
void NetworkServer::DeviceListChanged()
void NetworkServer::SignalResourceManagerUpdate(unsigned int update_reason)
{
/*-----------------------------------------------------*\
| Register the server's RGBController update handler |
| for each RGBController in the controllers list |
\*-----------------------------------------------------*/
for(std::size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
switch(update_reason)
{
controllers[controller_idx]->RegisterUpdateCallback(RGBController_UpdateCallback, this);
}
case RESOURCEMANAGER_UPDATE_REASON_DEVICE_LIST_UPDATED:
SignalDeviceListUpdated();
break;
/*-----------------------------------------------------*\
| Indicate to the clients that the controller list has |
| changed |
\*-----------------------------------------------------*/
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
{
SendRequest_DeviceListChanged(ServerClients[client_idx]->client_sock);
case RESOURCEMANAGER_UPDATE_REASON_DETECTION_STARTED:
SignalDetectionStarted();
break;
case RESOURCEMANAGER_UPDATE_REASON_DETECTION_PROGRESS_CHANGED:
SignalDetectionProgress();
break;
case RESOURCEMANAGER_UPDATE_REASON_DETECTION_COMPLETE:
SignalDetectionCompleted();
break;
}
}
@@ -419,7 +420,7 @@ void NetworkServer::StopServer()
/*-----------------------------------------------------*\
| Client info has changed, call the callbacks |
\*-----------------------------------------------------*/
ClientInfoChanged();
SignalClientInfoChanged();
}
/*---------------------------------------------------------*\
@@ -443,7 +444,7 @@ void NetworkServer::SetSettingsManager(SettingsManagerInterface* settings_manage
/*---------------------------------------------------------*\
| Server callback signal functions |
\*---------------------------------------------------------*/
void NetworkServer::ClientInfoChanged()
void NetworkServer::SignalClientInfoChanged()
{
ClientInfoChangeMutex.lock();
@@ -458,7 +459,64 @@ void NetworkServer::ClientInfoChanged()
ClientInfoChangeMutex.unlock();
}
void NetworkServer::ServerListeningChanged()
void NetworkServer::SignalDetectionCompleted()
{
/*-----------------------------------------------------*\
| Indicate to the clients that detection has completed |
\*-----------------------------------------------------*/
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
{
SendRequest_DetectionCompleted(ServerClients[client_idx]->client_sock, ServerClients[client_idx]->client_protocol_version);
}
}
void NetworkServer::SignalDetectionProgress()
{
unsigned int detection_percent = ResourceManager::get()->GetDetectionPercent();
std::string detection_string = ResourceManager::get()->GetDetectionString();
/*-----------------------------------------------------*\
| Indicate to the clients detection progress changed |
\*-----------------------------------------------------*/
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
{
SendRequest_DetectionProgress(ServerClients[client_idx]->client_sock, ServerClients[client_idx]->client_protocol_version, detection_percent, detection_string);
}
}
void NetworkServer::SignalDetectionStarted()
{
/*-----------------------------------------------------*\
| Indicate to the clients that detection has started |
\*-----------------------------------------------------*/
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
{
SendRequest_DetectionStarted(ServerClients[client_idx]->client_sock, ServerClients[client_idx]->client_protocol_version);
}
}
void NetworkServer::SignalDeviceListUpdated()
{
/*-----------------------------------------------------*\
| Register the server's RGBController update handler |
| for each RGBController in the controllers list |
\*-----------------------------------------------------*/
for(std::size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
{
controllers[controller_idx]->RegisterUpdateCallback(RGBController_UpdateCallback, this);
}
/*-----------------------------------------------------*\
| Indicate to the clients that the controller list has |
| changed |
\*-----------------------------------------------------*/
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
{
SendRequest_DeviceListChanged(ServerClients[client_idx]->client_sock);
}
}
void NetworkServer::SignalServerListeningChanged()
{
ServerListeningChangeMutex.lock();
@@ -504,7 +562,7 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
}
server_listening = true;
ServerListeningChanged();
SignalServerListeningChanged();
/*-------------------------------------------------*\
| Accept the client connection |
@@ -517,7 +575,7 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
server_online = false;
server_listening = false;
ServerListeningChanged();
SignalServerListeningChanged();
return;
}
@@ -569,13 +627,13 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
/*-------------------------------------------------*\
| Client info has changed, call the callbacks |
\*-------------------------------------------------*/
ClientInfoChanged();
SignalClientInfoChanged();
}
LOG_INFO("[NetworkServer] Connection thread closed");
server_online = false;
server_listening = false;
ServerListeningChanged();
SignalServerListeningChanged();
}
void NetworkServer::ControllerListenThread(NetworkServerControllerThread * this_thread)
@@ -1113,7 +1171,7 @@ listen_done:
/*-----------------------------------------------------*\
| Client info has changed, call the callbacks |
\*-----------------------------------------------------*/
ClientInfoChanged();
SignalClientInfoChanged();
}
/*---------------------------------------------------------*\
@@ -1147,7 +1205,7 @@ void NetworkServer::ProcessRequest_ClientProtocolVersion(SOCKET client_sock, uns
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalClientInfoChanged();
}
void NetworkServer::ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data)
@@ -1167,7 +1225,7 @@ void NetworkServer::ProcessRequest_ClientString(SOCKET client_sock, unsigned int
/*---------------------------------------------------------*\
| Client info has changed, call the callbacks |
\*---------------------------------------------------------*/
ClientInfoChanged();
SignalClientInfoChanged();
}
void NetworkServer::ProcessRequest_RescanDevices()
@@ -1704,6 +1762,74 @@ void NetworkServer::SendReply_PluginSpecific(SOCKET client_sock, unsigned int pk
delete [] data;
}
void NetworkServer::SendRequest_DetectionCompleted(SOCKET client_sock, unsigned int protocol_version)
{
if(protocol_version >= 6)
{
NetPacketHeader pkt_hdr;
InitNetPacketHeader(&pkt_hdr, 0, NET_PACKET_ID_DETECTION_COMPLETE, 0);
send_in_progress.lock();
send(client_sock, (char *)&pkt_hdr, sizeof(NetPacketHeader), 0);
send_in_progress.unlock();
}
}
void NetworkServer::SendRequest_DetectionProgress(SOCKET client_sock, unsigned int protocol_version, unsigned int detection_percent, std::string detection_string)
{
if(protocol_version >= 6)
{
unsigned int data_size;
unsigned short string_length;
NetPacketHeader reply_hdr;
string_length = strlen(detection_string.c_str()) + 1;
data_size = sizeof(data_size);
data_size += sizeof(detection_percent);
data_size += sizeof(string_length);
data_size += string_length;
unsigned char * data_buf = new unsigned char[data_size];
unsigned char * data_ptr = data_buf;
memcpy(data_ptr, &data_size, sizeof(data_size));
data_ptr += sizeof(data_size);
memcpy(data_ptr, &detection_percent, sizeof(detection_percent));
data_ptr += sizeof(detection_percent);
memcpy(data_ptr, &string_length, sizeof(string_length));
data_ptr += sizeof(string_length);
memcpy(data_ptr, detection_string.c_str(), string_length);
data_ptr += string_length;
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_DETECTION_PROGRESS_CHANGED, data_size);
send_in_progress.lock();
send(client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0);
send(client_sock, (const char *)data_buf, data_size, 0);
send_in_progress.unlock();
delete [] data_buf;
}
}
void NetworkServer::SendRequest_DetectionStarted(SOCKET client_sock, unsigned int protocol_version)
{
if(protocol_version >= 6)
{
NetPacketHeader pkt_hdr;
InitNetPacketHeader(&pkt_hdr, 0, NET_PACKET_ID_DETECTION_STARTED, 0);
send_in_progress.lock();
send(client_sock, (char *)&pkt_hdr, sizeof(NetPacketHeader), 0);
send_in_progress.unlock();
}
}
void NetworkServer::SendRequest_DeviceListChanged(SOCKET client_sock)
{
NetPacketHeader pkt_hdr;

View File

@@ -83,10 +83,14 @@ public:
/*-----------------------------------------------------*\
| Callback functions |
\*-----------------------------------------------------*/
void DeviceListChanged();
void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg);
void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg);
/*-----------------------------------------------------*\
| Functions for forwarding callback sigals over network |
\*-----------------------------------------------------*/
void SignalResourceManagerUpdate(unsigned int );
/*-----------------------------------------------------*\
| Server Configuration functions |
\*-----------------------------------------------------*/
@@ -169,8 +173,12 @@ private:
/*-----------------------------------------------------*\
| Server callback signal functions |
\*-----------------------------------------------------*/
void ClientInfoChanged();
void ServerListeningChanged();
void SignalClientInfoChanged();
void SignalDetectionCompleted();
void SignalDetectionProgress();
void SignalDetectionStarted();
void SignalDeviceListUpdated();
void SignalServerListeningChanged();
/*-----------------------------------------------------*\
| Server Thread functions |
@@ -202,6 +210,9 @@ private:
void SendReply_PluginList(SOCKET client_sock);
void SendReply_PluginSpecific(SOCKET client_sock, unsigned int pkt_type, unsigned char* data, unsigned int data_size);
void SendRequest_DetectionCompleted(SOCKET client_sock, unsigned int protocol_version);
void SendRequest_DetectionProgress(SOCKET client_sock, unsigned int protocol_version, unsigned int detection_percent, std::string detection_string);
void SendRequest_DetectionStarted(SOCKET client_sock, unsigned int protocol_version);
void SendRequest_DeviceListChanged(SOCKET client_sock);
/*-----------------------------------------------------*\

View File

@@ -45,7 +45,6 @@ static void ResourceManagerDetectionCallback(void * this_ptr, unsigned int updat
case DETECTIONMANAGER_UPDATE_REASON_DETECTION_STARTED:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DETECTION_STARTED);
this_obj->ClearLocalDevices();
break;
case DETECTIONMANAGER_UPDATE_REASON_RGBCONTROLLER_REGISTERED:
@@ -53,23 +52,43 @@ static void ResourceManagerDetectionCallback(void * this_ptr, unsigned int updat
this_obj->UpdateDeviceList();
break;
case DETECTIONMANAGER_UPDATE_REASON_RGBCONTROLLER_LIST_CLEARED:
this_obj->ClearLocalDevices();
break;
case DETECTIONMANAGER_UPDATE_REASON_DETECTION_PROGRESS_CHANGED:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DETECTION_PROGRESS_CHANGED);
break;
case DETECTIONMANAGER_UPDATE_REASON_DETECTION_COMPLETE:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DETECTION_COMPLETE);
this_obj->UpdateDeviceList();
break;
}
}
static void ResourceManagerNetworkClientInfoChangeCallback(void* this_ptr)
static void ResourceManagerNetworkClientCallback(void* this_ptr, unsigned int update_reason)
{
ResourceManager* this_obj = (ResourceManager*)this_ptr;
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_CLIENT_INFO_UPDATED);
this_obj->UpdateDeviceList();
switch(update_reason)
{
case NETWORKCLIENT_UPDATE_REASON_DEVICE_LIST_UPDATED:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_CLIENT_INFO_UPDATED);
this_obj->UpdateDeviceList();
break;
case NETWORKCLIENT_UPDATE_REASON_DETECTION_STARTED:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DETECTION_STARTED);
break;
case NETWORKCLIENT_UPDATE_REASON_DETECTION_PROGRESS_CHANGED:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DETECTION_PROGRESS_CHANGED);
break;
case NETWORKCLIENT_UPDATE_REASON_DETECTION_COMPLETE:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DETECTION_COMPLETE);
break;
}
}
/*---------------------------------------------------------*\
@@ -261,7 +280,7 @@ void ResourceManager::SetPluginManager(PluginManagerInterface* plugin_manager_pt
\*---------------------------------------------------------*/
void ResourceManager::RegisterNetworkClient(NetworkClient* new_client)
{
new_client->RegisterClientInfoChangeCallback(ResourceManagerNetworkClientInfoChangeCallback, this);
new_client->RegisterNetworkClientCallback(ResourceManagerNetworkClientCallback, this);
clients.push_back(new_client);
}
@@ -371,14 +390,26 @@ bool ResourceManager::GetDetectionEnabled()
unsigned int ResourceManager::GetDetectionPercent()
{
//TODO: get from DetectionManager or client
return DetectionManager::get()->GetDetectionPercent();
if(auto_connection_active && auto_connection_client != NULL)
{
return auto_connection_client->DetectionManager_GetDetectionPercent();
}
else
{
return DetectionManager::get()->GetDetectionPercent();
}
}
std::string ResourceManager::GetDetectionString()
{
//TODO: get from DetectionManager or client
return DetectionManager::get()->GetDetectionString();
if(auto_connection_active && auto_connection_client != NULL)
{
return auto_connection_client->DetectionManager_GetDetectionString();
}
else
{
return DetectionManager::get()->GetDetectionString();
}
}
void ResourceManager::RescanDevices()
@@ -445,12 +476,6 @@ void ResourceManager::ClearLocalDevices()
| Signal device list update |
\*-----------------------------------------------------*/
SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DEVICE_LIST_UPDATED);
/*-----------------------------------------------------*\
| Device list has changed, inform all clients connected |
| to this server |
\*-----------------------------------------------------*/
server->DeviceListChanged();
}
void ResourceManager::UpdateDeviceList()
@@ -502,12 +527,6 @@ void ResourceManager::UpdateDeviceList()
| Signal device list update |
\*-----------------------------------------------------*/
SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DEVICE_LIST_UPDATED);
/*-----------------------------------------------------*\
| Device list has changed, inform all clients connected |
| to this server |
\*-----------------------------------------------------*/
server->DeviceListChanged();
}
void ResourceManager::WaitForDetection()
@@ -520,6 +539,8 @@ void ResourceManager::WaitForDetection()
\*---------------------------------------------------------*/
void ResourceManager::SignalResourceManagerUpdate(unsigned int update_reason)
{
server->SignalResourceManagerUpdate(update_reason);
ResourceManagerCallbackMutex.lock();
for(std::size_t callback_idx = 0; callback_idx < ResourceManagerCallbacks.size(); callback_idx++)