mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-07-08 12:25:07 -04:00
Add network request for requesting list of USB devices in local client mode
This commit is contained in:
@@ -1291,6 +1291,10 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo* client_info)
|
||||
status = ProcessRequest_GetHIDDeviceInfo(client_info);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_GET_USB_DEVICE_INFO:
|
||||
status = ProcessRequest_GetUSBDeviceInfo(client_info);
|
||||
break;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| LogManager functions |
|
||||
\*-------------------------------------------------*/
|
||||
@@ -1773,6 +1777,90 @@ NetPacketStatus NetworkServer::ProcessRequest_GetI2CBusInfo(NetworkClientInfo* c
|
||||
return(NET_PACKET_STATUS_OK);
|
||||
}
|
||||
|
||||
NetPacketStatus NetworkServer::ProcessRequest_GetUSBDeviceInfo(NetworkClientInfo* client_info)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Require local client for this packet |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!client_info->client_is_local_client)
|
||||
{
|
||||
return(NET_PACKET_STATUS_ERROR_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
std::vector<USBDeviceInfo> device_info = ResourceManager::get()->GetUSBDeviceInfo();
|
||||
|
||||
unsigned int data_size = 0;
|
||||
unsigned int device_count = (unsigned int)device_info.size();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*-----------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(device_count);
|
||||
|
||||
for(unsigned int device_idx = 0; device_idx < device_count; device_idx++)
|
||||
{
|
||||
data_size += sizeof(device_info[device_idx].vendor_id);
|
||||
data_size += sizeof(device_info[device_idx].product_id);
|
||||
data_size += sizeof(unsigned short);
|
||||
data_size += (unsigned int)strlen(device_info[device_idx].serial_number.c_str()) + 1;
|
||||
data_size += sizeof(unsigned short);
|
||||
data_size += (unsigned int)strlen(device_info[device_idx].manufacturer_string.c_str()) + 1;
|
||||
data_size += sizeof(unsigned short);
|
||||
data_size += (unsigned int)strlen(device_info[device_idx].product_string.c_str()) + 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data |
|
||||
\*-----------------------------------------------------*/
|
||||
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, &device_count, sizeof(device_count));
|
||||
data_ptr += sizeof(device_count);
|
||||
|
||||
for(unsigned int device_idx = 0; device_idx < device_count; device_idx++)
|
||||
{
|
||||
memcpy(data_ptr, &device_info[device_idx].vendor_id, sizeof(device_info[device_idx].vendor_id));
|
||||
data_ptr += sizeof(device_info[device_idx].vendor_id);
|
||||
|
||||
memcpy(data_ptr, &device_info[device_idx].product_id, sizeof(device_info[device_idx].product_id));
|
||||
data_ptr += sizeof(device_info[device_idx].product_id);
|
||||
|
||||
unsigned short serial_number_size = (unsigned short)strlen(device_info[device_idx].serial_number.c_str()) + 1;
|
||||
memcpy(data_ptr, &serial_number_size, sizeof(serial_number_size));
|
||||
data_ptr += sizeof(serial_number_size);
|
||||
memcpy(data_ptr, device_info[device_idx].serial_number.c_str(), serial_number_size);
|
||||
data_ptr += serial_number_size;
|
||||
|
||||
unsigned short manufacturer_string_size = (unsigned short)strlen(device_info[device_idx].manufacturer_string.c_str()) + 1;
|
||||
memcpy(data_ptr, &manufacturer_string_size, sizeof(manufacturer_string_size));
|
||||
data_ptr += sizeof(manufacturer_string_size);
|
||||
memcpy(data_ptr, device_info[device_idx].manufacturer_string.c_str(), manufacturer_string_size);
|
||||
data_ptr += manufacturer_string_size;
|
||||
|
||||
unsigned short product_string_size = (unsigned short)strlen(device_info[device_idx].product_string.c_str()) + 1;
|
||||
memcpy(data_ptr, &product_string_size, sizeof(product_string_size));
|
||||
data_ptr += sizeof(product_string_size);
|
||||
memcpy(data_ptr, device_info[device_idx].product_string.c_str(), product_string_size);
|
||||
data_ptr += product_string_size;
|
||||
}
|
||||
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_GET_USB_DEVICE_INFO, data_size);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_info->client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_info->client_sock, (char *)data_buf, reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
|
||||
return(NET_PACKET_STATUS_OK);
|
||||
}
|
||||
|
||||
NetPacketStatus NetworkServer::ProcessRequest_LogManager_ClearLogBuffer(NetworkClientInfo* client_info)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
||||
Reference in New Issue
Block a user