diff --git a/NetworkProtocol.h b/NetworkProtocol.h index 3af28414..10ca9836 100644 --- a/NetworkProtocol.h +++ b/NetworkProtocol.h @@ -29,8 +29,10 @@ enum \*----------------------------------------------------------------------------------------------------------*/ 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_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 | \*----------------------------------------------------------------------------------------------------------*/ diff --git a/NetworkServer.cpp b/NetworkServer.cpp index 1fff4336..34968c47 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -54,6 +54,18 @@ void NetworkServer::ClientInfoChanged() 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() { 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); } } + +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); +} diff --git a/NetworkServer.h b/NetworkServer.h index c1017ec1..3a38bdab 100644 --- a/NetworkServer.h +++ b/NetworkServer.h @@ -38,6 +38,7 @@ public: const char * GetClientIP(unsigned int client_num); void ClientInfoChanged(); + void DeviceListChanged(); void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg); void SetPort(unsigned short new_port); @@ -53,6 +54,8 @@ public: void SendReply_ControllerCount(SOCKET client_sock); void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx); + void SendRequest_DeviceListChanged(SOCKET client_sock); + protected: unsigned short port_num; bool server_online; diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 97e2d619..30bd8410 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -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 "ProfileManager.h" @@ -21,10 +32,13 @@ ResourceManager *ResourceManager::get() ResourceManager::ResourceManager() { - detection_percent = 100; - detection_string = ""; + /*-------------------------------------------------------------------------*\ + | Initialize Detection Variables | + \*-------------------------------------------------------------------------*/ + detection_percent = 100; + detection_string = ""; detection_is_required = false; - DetectDevicesThread = nullptr; + DetectDevicesThread = nullptr; /*-------------------------------------------------------------------------*\ | Initialize Server Instance | @@ -86,13 +100,19 @@ void ResourceManager::DeviceListChanged() 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++) { DeviceListChangeCallbacks[callback_idx](DeviceListChangeCallbackArgs[callback_idx]); } + /*-------------------------------------------------*\ + | Device list has changed, inform all clients | + | connected to this server | + \*-------------------------------------------------*/ + server->DeviceListChanged(); + DeviceListChangeMutex.unlock(); } diff --git a/ResourceManager.h b/ResourceManager.h index e79284d0..98ea84f9 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -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 #include