Server sends a request to the client when the device list is updated

This commit is contained in:
Adam Honse 2020-09-27 22:12:34 +00:00
parent 854bc099f7
commit 60fd721586
5 changed files with 68 additions and 4 deletions

View file

@ -29,8 +29,10 @@ enum
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/
NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */ NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */
NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */ NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */ NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */
/*----------------------------------------------------------------------------------------------------------*\ /*----------------------------------------------------------------------------------------------------------*\
| RGBController class functions | | RGBController class functions |
\*----------------------------------------------------------------------------------------------------------*/ \*----------------------------------------------------------------------------------------------------------*/

View file

@ -54,6 +54,18 @@ void NetworkServer::ClientInfoChanged()
ClientInfoChangeMutex.unlock(); ClientInfoChangeMutex.unlock();
} }
void NetworkServer::DeviceListChanged()
{
/*-------------------------------------------------*\
| 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);
}
}
unsigned short NetworkServer::GetPort() unsigned short NetworkServer::GetPort()
{ {
return port_num; return port_num;
@ -646,3 +658,19 @@ void NetworkServer::SendReply_ControllerData(SOCKET client_sock, unsigned int de
send(client_sock, (const char *)reply_data, reply_size, 0); send(client_sock, (const char *)reply_data, reply_size, 0);
} }
} }
void NetworkServer::SendRequest_DeviceListChanged(SOCKET client_sock)
{
NetPacketHeader pkt_hdr;
pkt_hdr.pkt_magic[0] = 'O';
pkt_hdr.pkt_magic[1] = 'R';
pkt_hdr.pkt_magic[2] = 'G';
pkt_hdr.pkt_magic[3] = 'B';
pkt_hdr.pkt_dev_idx = 0;
pkt_hdr.pkt_id = NET_PACKET_ID_DEVICE_LIST_UPDATED;
pkt_hdr.pkt_size = 0;
send(client_sock, (char *)&pkt_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
}

View file

@ -38,6 +38,7 @@ public:
const char * GetClientIP(unsigned int client_num); const char * GetClientIP(unsigned int client_num);
void ClientInfoChanged(); void ClientInfoChanged();
void DeviceListChanged();
void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg); void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg);
void SetPort(unsigned short new_port); void SetPort(unsigned short new_port);
@ -53,6 +54,8 @@ public:
void SendReply_ControllerCount(SOCKET client_sock); void SendReply_ControllerCount(SOCKET client_sock);
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx); void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx);
void SendRequest_DeviceListChanged(SOCKET client_sock);
protected: protected:
unsigned short port_num; unsigned short port_num;
bool server_online; bool server_online;

View file

@ -1,3 +1,14 @@
/*-----------------------------------------*\
| ResourceManager.cpp |
| |
| OpenRGB Resource Manager controls access |
| to application components including |
| RGBControllers, I2C interfaces, and |
| network SDK components |
| |
| Adam Honse (CalcProgrammer1) 9/27/2020 |
\*-----------------------------------------*/
#include "ResourceManager.h" #include "ResourceManager.h"
#include "ProfileManager.h" #include "ProfileManager.h"
@ -21,10 +32,13 @@ ResourceManager *ResourceManager::get()
ResourceManager::ResourceManager() ResourceManager::ResourceManager()
{ {
detection_percent = 100; /*-------------------------------------------------------------------------*\
detection_string = ""; | Initialize Detection Variables |
\*-------------------------------------------------------------------------*/
detection_percent = 100;
detection_string = "";
detection_is_required = false; detection_is_required = false;
DetectDevicesThread = nullptr; DetectDevicesThread = nullptr;
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
| Initialize Server Instance | | Initialize Server Instance |
@ -86,13 +100,19 @@ void ResourceManager::DeviceListChanged()
DeviceListChangeMutex.lock(); DeviceListChangeMutex.lock();
/*-------------------------------------------------*\ /*-------------------------------------------------*\
| Client info has changed, call the callbacks | | Device list has changed, call the callbacks |
\*-------------------------------------------------*/ \*-------------------------------------------------*/
for(unsigned int callback_idx = 0; callback_idx < DeviceListChangeCallbacks.size(); callback_idx++) for(unsigned int callback_idx = 0; callback_idx < DeviceListChangeCallbacks.size(); callback_idx++)
{ {
DeviceListChangeCallbacks[callback_idx](DeviceListChangeCallbackArgs[callback_idx]); DeviceListChangeCallbacks[callback_idx](DeviceListChangeCallbackArgs[callback_idx]);
} }
/*-------------------------------------------------*\
| Device list has changed, inform all clients |
| connected to this server |
\*-------------------------------------------------*/
server->DeviceListChanged();
DeviceListChangeMutex.unlock(); DeviceListChangeMutex.unlock();
} }

View file

@ -1,3 +1,14 @@
/*-----------------------------------------*\
| ResourceManager.h |
| |
| OpenRGB Resource Manager controls access |
| to application components including |
| RGBControllers, I2C interfaces, and |
| network SDK components |
| |
| Adam Honse (CalcProgrammer1) 9/27/2020 |
\*-----------------------------------------*/
#pragma once #pragma once
#include <memory> #include <memory>