SDK Listening Options

This commit is contained in:
B Horn 2022-07-17 20:30:15 +00:00 committed by Adam Honse
parent 241ea0a8ef
commit 640eb7905c
12 changed files with 415 additions and 256 deletions

View file

@ -29,7 +29,7 @@ using namespace std::chrono_literals;
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
{
strcpy(port_ip, "127.0.0.1");
port_ip = "127.0.0.1";
port_num = OPENRGB_SDK_PORT;
client_sock = -1;
server_connected = false;
@ -68,9 +68,9 @@ void NetworkClient::ClientInfoChanged()
ClientInfoChangeMutex.unlock();
}
const char * NetworkClient::GetIP()
std::string NetworkClient::GetIP()
{
return(port_ip);
return port_ip;
}
unsigned short NetworkClient::GetPort()
@ -110,15 +110,15 @@ void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callb
ClientInfoChangeCallbackArgs.push_back(new_callback_arg);
}
void NetworkClient::SetIP(const char *new_ip)
void NetworkClient::SetIP(std::string new_ip)
{
if(server_connected == false)
{
strcpy(port_ip, new_ip);
port_ip = new_ip;
}
}
void NetworkClient::SetName(const char *new_name)
void NetworkClient::SetName(std::string new_name)
{
client_name = new_name;
@ -142,7 +142,7 @@ void NetworkClient::StartClient()
char port_str[6];
snprintf(port_str, 6, "%d", port_num);
port.tcp_client(port_ip, port_str);
port.tcp_client(port_ip.c_str(), port_str);
client_active = true;
@ -157,6 +157,9 @@ void NetworkClient::StartClient()
void NetworkClient::StopClient()
{
server_connected = false;
client_active = false;
if(server_connected)
{
shutdown(client_sock, SD_RECEIVE);

View file

@ -26,7 +26,7 @@ public:
void ClientInfoChanged();
bool GetConnected();
const char * GetIP();
std::string GetIP();
unsigned short GetPort();
unsigned int GetProtocolVersion();
bool GetOnline();
@ -34,8 +34,8 @@ public:
void ClearCallbacks();
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
void SetIP(const char *new_ip);
void SetName(const char *new_name);
void SetIP(std::string new_ip);
void SetName(std::string new_name);
void SetPort(unsigned short new_port);
void StartClient();
@ -89,7 +89,7 @@ private:
SOCKET client_sock;
std::string client_name;
net_port port;
char port_ip[20];
std::string port_ip;
unsigned short port_num;
bool client_active;
bool controller_data_received;

View file

@ -18,6 +18,11 @@
\*-----------------------------------------------------*/
#define OPENRGB_SDK_PROTOCOL_VERSION 3
/*-----------------------------------------------------*\
| Default Interface to bind to. |
\*-----------------------------------------------------*/
#define OPENRGB_SDK_HOST "0.0.0.0"
/*-----------------------------------------------------*\
| Default OpenRGB SDK port is 6742 |
| This is "ORGB" on a phone keypad |

View file

@ -35,8 +35,11 @@ using namespace std::chrono_literals;
NetworkClientInfo::NetworkClientInfo()
{
client_string = "Client";
client_ip = OPENRGB_SDK_HOST;
client_sock = INVALID_SOCKET;
client_listen_thread = nullptr;
client_protocol_version = 0;
}
NetworkClientInfo::~NetworkClientInfo()
@ -52,10 +55,14 @@ NetworkClientInfo::~NetworkClientInfo()
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
{
host = OPENRGB_SDK_HOST;
port_num = OPENRGB_SDK_PORT;
server_online = false;
server_listening = false;
ConnectionThread = nullptr;
for(int i = 0; i < MAXSOCK; i++)
{
ConnectionThread[i] = nullptr;
}
profile_manager = nullptr;
}
@ -106,6 +113,11 @@ void NetworkServer::ServerListeningChanged()
ServerListeningChangeMutex.unlock();
}
std::string NetworkServer::GetHost()
{
return host;
}
unsigned short NetworkServer::GetPort()
{
return port_num;
@ -154,7 +166,7 @@ const char * NetworkServer::GetClientIP(unsigned int client_num)
if(client_num < ServerClients.size())
{
result = ServerClients[client_num]->client_ip;
result = ServerClients[client_num]->client_ip.c_str();
}
else
{
@ -198,6 +210,14 @@ void NetworkServer::RegisterServerListeningChangeCallback(NetServerCallback new_
ServerListeningChangeCallbackArgs.push_back(new_callback_arg);
}
void NetworkServer::SetHost(std::string new_host)
{
if(server_online == false)
{
host = new_host;
}
}
void NetworkServer::SetPort(unsigned short new_port)
{
if(server_online == false)
@ -208,45 +228,56 @@ void NetworkServer::SetPort(unsigned short new_port)
void NetworkServer::StartServer()
{
int err;
struct addrinfo hints, *res, *result;
//Start a TCP server and launch threads
char port_str[6];
snprintf(port_str, 6, "%d", port_num);
sockaddr_in myAddress;
socket_count = 0;
/*-------------------------------------------------*\
| Windows requires WSAStartup before using sockets |
\*-------------------------------------------------*/
#ifdef WIN32
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
{
WSACleanup();
return;
}
#endif
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
err = getaddrinfo(host.c_str(), port_str, &hints, &result);
if(err)
{
printf("Error: Unable to get address.\n");
WSACleanup();
return;
}
/*-------------------------------------------------*\
| Create the server socket |
| Create a server socket for each address returned. |
\*-------------------------------------------------*/
server_sock = socket(AF_INET, SOCK_STREAM, 0);
if (server_sock == INVALID_SOCKET)
for(res = result; res && socket_count < MAXSOCK; res = res->ai_next)
{
server_sock[socket_count] = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if(server_sock[socket_count] == INVALID_SOCKET)
{
printf("Error: network socket could not be created\n");
WSACleanup();
return;
}
/*-------------------------------------------------*\
| Fill in server address info with port value |
\*-------------------------------------------------*/
myAddress.sin_family = AF_INET;
myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
myAddress.sin_port = htons(atoi(port_str));
/*-------------------------------------------------*\
| Bind the server socket |
\*-------------------------------------------------*/
if (bind(server_sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
if(bind(server_sock[socket_count], res->ai_addr, res->ai_addrlen) == SOCKET_ERROR)
{
if(errno == EADDRINUSE)
{
@ -282,18 +313,27 @@ void NetworkServer::StartServer()
/*-------------------------------------------------*\
| Set socket options - no delay |
\*-------------------------------------------------*/
setsockopt(server_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
setsockopt(server_sock[socket_count], IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
socket_count += 1;
}
freeaddrinfo(result);
server_online = true;
/*-------------------------------------------------*\
| Start the connection thread |
\*-------------------------------------------------*/
ConnectionThread = new std::thread(&NetworkServer::ConnectionThreadFunction, this);
ConnectionThread->detach();
for(int curr_socket = 0; curr_socket < socket_count; curr_socket++)
{
ConnectionThread[curr_socket] = new std::thread(&NetworkServer::ConnectionThreadFunction, this, curr_socket);
ConnectionThread[curr_socket]->detach();
}
}
void NetworkServer::StopServer()
{
int curr_socket;
server_online = false;
ServerClientsMutex.lock();
@ -305,16 +345,24 @@ void NetworkServer::StopServer()
ServerClients.clear();
shutdown(server_sock, SD_RECEIVE);
closesocket(server_sock);
for(curr_socket = 0; curr_socket < socket_count; curr_socket++)
{
shutdown(server_sock[curr_socket], SD_RECEIVE);
closesocket(server_sock[curr_socket]);
}
ServerClientsMutex.unlock();
if(ConnectionThread)
for(curr_socket = 0; curr_socket < socket_count; curr_socket++)
{
delete ConnectionThread;
ConnectionThread = nullptr;
if(ConnectionThread[curr_socket])
{
delete ConnectionThread[curr_socket];
ConnectionThread[curr_socket] = nullptr;
}
}
socket_count = 0;
/*-------------------------------------------------*\
| Client info has changed, call the callbacks |
@ -322,7 +370,7 @@ void NetworkServer::StopServer()
ClientInfoChanged();
}
void NetworkServer::ConnectionThreadFunction()
void NetworkServer::ConnectionThreadFunction(int socket_idx)
{
//This thread handles client connections
@ -339,7 +387,7 @@ void NetworkServer::ConnectionThreadFunction()
| server socket. This call blocks until a |
| connection is established |
\*-------------------------------------------------*/
if(listen(server_sock, 10) < 0)
if(listen(server_sock[socket_idx], 10) < 0)
{
printf("Connection thread closed\r\n");
server_online = false;
@ -353,9 +401,7 @@ void NetworkServer::ConnectionThreadFunction()
/*-------------------------------------------------*\
| Accept the client connection |
\*-------------------------------------------------*/
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
client_info->client_sock = accept_select(server_sock, (struct sockaddr *)&client_addr, &client_addr_len);
client_info->client_sock = accept_select(server_sock[socket_idx]);
if(client_info->client_sock < 0)
{
@ -376,9 +422,27 @@ void NetworkServer::ConnectionThreadFunction()
ioctlsocket(client_info->client_sock, FIONBIO, &arg);
setsockopt(client_info->client_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
inet_ntop(AF_INET, &client_addr.sin_addr, client_info->client_ip, INET_ADDRSTRLEN);
/*-------------------------------------------------*\
| Discover the remote hosts IP |
\*-------------------------------------------------*/
struct sockaddr_storage tmp_addr;
char ipstr[INET6_ADDRSTRLEN];
socklen_t len;
len = sizeof(tmp_addr);
getpeername(client_info->client_sock, (struct sockaddr*)&tmp_addr, &len);
client_info->client_string = "Client";
if(tmp_addr.ss_family == AF_INET)
{
struct sockaddr_in *s_4 = (struct sockaddr_in *)&tmp_addr;
inet_ntop(AF_INET, &s_4->sin_addr, ipstr, sizeof(ipstr));
client_info->client_ip = ipstr;
}
else
{
struct sockaddr_in6 *s_6 = (struct sockaddr_in6 *)&tmp_addr;
inet_ntop(AF_INET6, &s_6->sin6_addr, ipstr, sizeof(ipstr));
client_info->client_ip = ipstr;
}
/* We need to lock before the thread could possibly finish */
ServerClientsMutex.lock();
@ -402,7 +466,7 @@ void NetworkServer::ConnectionThreadFunction()
ServerListeningChanged();
}
int NetworkServer::accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
int NetworkServer::accept_select(int sockfd)
{
fd_set set;
struct timeval timeout;
@ -428,7 +492,7 @@ int NetworkServer::accept_select(int sockfd, struct sockaddr *addr, socklen_t *a
else
{
// socket has something to read
return(accept(sockfd, addr, addrlen));
return(accept(sockfd, NULL, NULL));
}
}
}

View file

@ -17,6 +17,7 @@
#pragma once
#define MAXSOCK 32
#define TCP_TIMEOUT_SECONDS 5
typedef void (*NetServerCallback)(void *);
@ -31,7 +32,7 @@ public:
std::thread * client_listen_thread;
std::string client_string;
unsigned int client_protocol_version;
char client_ip[INET_ADDRSTRLEN];
std::string client_ip;
};
class NetworkServer
@ -40,6 +41,7 @@ public:
NetworkServer(std::vector<RGBController *>& control);
~NetworkServer();
std::string GetHost();
unsigned short GetPort();
bool GetOnline();
bool GetListening();
@ -55,12 +57,13 @@ public:
void ServerListeningChanged();
void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg);
void SetHost(std::string host);
void SetPort(unsigned short new_port);
void StartServer();
void StopServer();
void ConnectionThreadFunction();
void ConnectionThreadFunction(int socket_idx);
void ListenThreadFunction(NetworkClientInfo * client_sock);
void ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data);
@ -76,6 +79,7 @@ public:
void SetProfileManager(ProfileManagerInterface* profile_manager_pointer);
protected:
std::string host;
unsigned short port_num;
bool server_online;
bool server_listening;
@ -84,7 +88,7 @@ protected:
std::mutex ServerClientsMutex;
std::vector<NetworkClientInfo *> ServerClients;
std::thread * ConnectionThread;
std::thread * ConnectionThread[MAXSOCK];
std::mutex ClientInfoChangeMutex;
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
@ -101,8 +105,9 @@ private:
WSADATA wsa;
#endif
SOCKET server_sock;
int socket_count;
SOCKET server_sock[MAXSOCK];
int accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int accept_select(int sockfd);
int recv_select(SOCKET s, char *buf, int len, int flags);
};

26
cli.cpp
View file

@ -993,6 +993,7 @@ unsigned int cli_pre_detection(int argc, char *argv[])
int arg_index = 1;
unsigned int cfg_args = 0;
unsigned int ret_flags = 0;
std::string server_host = OPENRGB_SDK_HOST;
unsigned short server_port = OPENRGB_SDK_PORT;
bool server_start = false;
bool print_help = false;
@ -1150,6 +1151,27 @@ unsigned int cli_pre_detection(int argc, char *argv[])
cfg_args++;
arg_index++;
}
/*---------------------------------------------------------*\
| --server-host |
\*---------------------------------------------------------*/
else if(option == "--server-host")
{
if (argument != "")
{
std::string host = argument;
server_host = host;
server_start = true;
}
else
{
std::cout << "Error: Missing argument for --server-host" << std::endl;
print_help = true;
break;
}
cfg_args++;
arg_index++;
}
/*---------------------------------------------------------*\
| --loglevel |
@ -1382,7 +1404,9 @@ unsigned int cli_pre_detection(int argc, char *argv[])
if(server_start)
{
ResourceManager::get()->GetServer()->SetPort(server_port);
NetworkServer * server = ResourceManager::get()->GetServer();
server->SetHost(server_host);
server->SetPort(server_port);
ret_flags |= RET_FLAG_START_SERVER;
}

View file

@ -47,7 +47,7 @@ bool net_port::udp_client(const char * client_name, const char * port)
sockaddr_in myAddress;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
{
WSACleanup();
return(false);
@ -55,7 +55,7 @@ bool net_port::udp_client(const char * client_name, const char * port)
#endif
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == INVALID_SOCKET)
if(sock == INVALID_SOCKET)
{
WSACleanup();
return(false);
@ -65,7 +65,7 @@ bool net_port::udp_client(const char * client_name, const char * port)
myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
myAddress.sin_port = htons(0);
if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
if(bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
{
WSACleanup();
return false;
@ -107,7 +107,7 @@ bool net_port::tcp_client(const char * client_name, const char * port)
result_list = NULL;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
{
WSACleanup();
return(false);
@ -116,7 +116,7 @@ bool net_port::tcp_client(const char * client_name, const char * port)
port = strtok((char *)port, "\r");
hints.ai_family = AF_INET;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo(client_name, port, &hints, &result_list);
@ -131,11 +131,13 @@ bool net_port::tcp_client(const char * client_name, const char * port)
bool net_port::tcp_client_connect()
{
struct addrinfo *res;
connected = false;
for(res = result_list; res; res = res->ai_next)
{
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if(sock == INVALID_SOCKET)
{
WSACleanup();
return(false);
@ -152,7 +154,7 @@ bool net_port::tcp_client_connect()
connected = false;
return(false);
}
connect(sock, result_list->ai_addr, result_list->ai_addrlen);
connect(sock, res->ai_addr, res->ai_addrlen);
FD_ZERO(&fdset);
FD_SET(sock, &fdset);
@ -165,14 +167,14 @@ bool net_port::tcp_client_connect()
\*-------------------------------------------------*/
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1)
if(select(sock + 1, NULL, &fdset, NULL, &tv) == 1)
{
char so_error;
socklen_t len = sizeof(so_error);
getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
if (so_error == 0)
if(so_error == 0)
{
connected = true;
arg = 0;
@ -201,7 +203,7 @@ bool net_port::tcp_server(const char * port)
| Windows requires WSAStartup before using sockets |
\*-------------------------------------------------*/
#ifdef WIN32
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
{
WSACleanup();
return false;
@ -212,7 +214,7 @@ bool net_port::tcp_server(const char * port)
| Create the server socket |
\*-------------------------------------------------*/
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
if(sock == INVALID_SOCKET)
{
WSACleanup();
return false;
@ -230,7 +232,7 @@ bool net_port::tcp_server(const char * port)
/*-------------------------------------------------*\
| Bind the server socket |
\*-------------------------------------------------*/
if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
if(bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
{
WSACleanup();
return false;
@ -299,7 +301,7 @@ int net_port::tcp_write(char * buffer, int length)
timeval waitd;
fd_set writefd;
for (unsigned int i = 0; i < clients.size(); i++)
for(unsigned int i = 0; i < clients.size(); i++)
{
val = length;
@ -309,11 +311,11 @@ int net_port::tcp_write(char * buffer, int length)
waitd.tv_sec = 5;
waitd.tv_usec = 0;
if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd))
if(select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd))
{
val = send(*(clients[i]), (const char *)&length, sizeof(length), 0);
if (val == -1)
if(val == -1)
{
clients.erase(clients.begin() + i);
return 0;
@ -328,17 +330,17 @@ int net_port::tcp_write(char * buffer, int length)
waitd.tv_sec = 5;
waitd.tv_usec = 0;
if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd))
if(select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd))
{
val = send(*(clients[i]), buffer, length, 0);
if (val == -1)
if(val == -1)
{
clients.erase(clients.begin() + i);
return 0;
}
if (val != length)
if(val != length)
{
ret = val;
}

View file

@ -30,6 +30,7 @@ OpenRGBServerInfoPage::~OpenRGBServerInfoPage()
void OpenRGBServerInfoPage::UpdateInfo()
{
ui->ServerHostValue->setText(network_server->GetHost().c_str());
ui->ServerPortValue->setText(std::to_string(network_server->GetPort()).c_str());
if(network_server->GetListening() && !network_server->GetOnline())
@ -37,6 +38,7 @@ void OpenRGBServerInfoPage::UpdateInfo()
ui->ServerStatusValue->setText(tr("Stopping..."));
ui->ServerStartButton->setEnabled(false);
ui->ServerStopButton->setEnabled(false);
ui->ServerHostValue->setEnabled(false);
ui->ServerPortValue->setEnabled(false);
}
else if(network_server->GetListening())
@ -44,6 +46,7 @@ void OpenRGBServerInfoPage::UpdateInfo()
ui->ServerStatusValue->setText(tr("Online"));
ui->ServerStartButton->setEnabled(false);
ui->ServerStopButton->setEnabled(true);
ui->ServerHostValue->setEnabled(false);
ui->ServerPortValue->setEnabled(false);
}
else
@ -51,6 +54,7 @@ void OpenRGBServerInfoPage::UpdateInfo()
ui->ServerStatusValue->setText(tr("Offline"));
ui->ServerStartButton->setEnabled(true);
ui->ServerStopButton->setEnabled(false);
ui->ServerHostValue->setEnabled(true);
ui->ServerPortValue->setEnabled(true);
}
@ -73,6 +77,7 @@ void Ui::OpenRGBServerInfoPage::on_ServerStartButton_clicked()
{
if(network_server->GetOnline() == false)
{
network_server->SetHost(ui->ServerHostValue->text().toStdString());
network_server->SetPort(ui->ServerPortValue->text().toInt());
network_server->StartServer();

View file

@ -14,20 +14,65 @@
<string>Server info page</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="3">
<item row="2" column="3">
<widget class="QPushButton" name="ServerStopButton">
<property name="text">
<string>Stop Server</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="ServerPortLabel">
<property name="text">
<string>Server Port:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="ServerClientsLabel">
<property name="text">
<string>Connected Clients:</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<widget class="QTreeWidget" name="ServerClientTree">
<property name="columnCount">
<number>0</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="ServerPortValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="ServerStatusLabel">
<property name="text">
<string>Server Status:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="ServerStartButton">
<property name="text">
<string>Start Server</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="ServerStatusValue">
<property name="text">
<string>Offline</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
@ -41,36 +86,15 @@
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="ServerStartButton">
<item row="1" column="0">
<widget class="QLabel" name="ServerHostLabel">
<property name="text">
<string>Start Server</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="QTreeWidget" name="ServerClientTree">
<property name="columnCount">
<number>0</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="ServerStatusLabel">
<property name="text">
<string>Server Status:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="ServerStatusValue">
<property name="text">
<string>Offline</string>
<string>Server Host:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ServerPortValue">
<widget class="QLineEdit" name="ServerHostValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -79,13 +103,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="ServerClientsLabel">
<property name="text">
<string>Connected Clients:</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>

View file

@ -114,6 +114,9 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) :
/*---------------------------------------------------------*\
| Text boxes |
\*---------------------------------------------------------*/
ui->TextServerHost->setText(QString::fromStdString(autostart_settings["host"]));
ui->TextServerHost->setEnabled(autostart_settings["setserverhost"]);
ui->TextServerPort->setText(QString::fromStdString(autostart_settings["port"]));
ui->TextServerPort->setEnabled(autostart_settings["setserverport"]);
@ -132,6 +135,7 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) :
ui->CheckboxAutoStartMinimized->setChecked(autostart_settings["setminimized"]);
ui->CheckboxAutoStartClient->setChecked(autostart_settings["setclient"]);
ui->CheckboxAutoStartServer->setChecked(autostart_settings["setserver"]);
ui->CheckboxAutoStartSetServerHost->setChecked(autostart_settings["setserverhost"]);
ui->CheckboxAutoStartSetServerPort->setChecked(autostart_settings["setserverport"]);
ui->CheckboxAutoStartCustom->setChecked(autostart_settings["setcustom"]);
@ -331,6 +335,12 @@ void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartServer_clicked()
SaveAutoStartSetting("setserver", ui->CheckboxAutoStartServer->isChecked());
}
void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartSetServerHost_clicked()
{
SaveAutoStartSetting("setserverhost", ui->CheckboxAutoStartSetServerHost->isChecked());
ui->TextServerHost->setEnabled(ui->CheckboxAutoStartSetServerHost->isChecked());
}
void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartSetServerPort_clicked()
{
SaveAutoStartSetting("setserverport", ui->CheckboxAutoStartSetServerPort->isChecked());
@ -355,6 +365,11 @@ void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartCustom_clicked()
ui->TextCustomArgs->setEnabled(ui->CheckboxAutoStartCustom->isChecked());
}
void Ui::OpenRGBSettingsPage::on_TextServerHost_textChanged(QString host)
{
SaveAutoStartSetting("host", host);
}
void Ui::OpenRGBSettingsPage::on_TextServerPort_textChanged(QString port)
{
SaveAutoStartSetting("port", port);
@ -411,9 +426,11 @@ void OpenRGBSettingsPage::SetAutoStartVisibility(bool visible)
ui->CheckboxAutoStartMinimized->hide();
ui->CheckboxAutoStartProfile->hide();
ui->CheckboxAutoStartServer->hide();
ui->CheckboxAutoStartSetServerHost->hide();
ui->CheckboxAutoStartSetServerPort->hide();
ui->TextCustomArgs->hide();
ui->TextClientHost->hide();
ui->TextServerHost->hide();
ui->TextServerPort->hide();
ui->AutoStartStatusLabel->hide();
}
@ -425,9 +442,11 @@ void OpenRGBSettingsPage::SetAutoStartVisibility(bool visible)
ui->CheckboxAutoStartMinimized->show();
ui->CheckboxAutoStartProfile->show();
ui->CheckboxAutoStartServer->show();
ui->CheckboxAutoStartSetServerHost->show();
ui->CheckboxAutoStartSetServerPort->show();
ui->TextCustomArgs->show();
ui->TextClientHost->show();
ui->TextServerHost->show();
ui->TextServerPort->show();
ui->AutoStartStatusLabel->show();
}
@ -438,6 +457,7 @@ void OpenRGBSettingsPage::ConfigureAutoStart()
std::map<std::string, std::tuple<std::string, std::string, bool>> autostart_map = {
{"setminimized", {"--startminimized","",false}},
{"setserver", {"--server","",false}},
{"setserverhost", {"--server-host","host",false}},
{"setserverport", {"--server-port","port",false}},
{"setclient", {"--client","client",false}},
{"setprofile", {"--profile","profile",true}},
@ -533,6 +553,7 @@ void OpenRGBSettingsPage::CreateAutoStartSettings()
{
std::map<std::string, std::string> autostart_default_map_string = {
{"custom", ""},
{"host", "0.0.0.0"},
{"port", "6742"},
{"client","localhost:6742"},
{"profile",ui->ComboBoxAutoStartProfile->count() > 0 ? ui->ComboBoxAutoStartProfile->itemText(0).toStdString(): ""}
@ -543,6 +564,7 @@ void OpenRGBSettingsPage::CreateAutoStartSettings()
{"setminimized", false},
{"setclient", false},
{"setserver", false},
{"setserverhost", false},
{"setserverport", false},
{"setcustom", false},
{"setprofile", false},

View file

@ -48,10 +48,12 @@ private slots:
void on_CheckboxAutoStartServer_clicked();
void on_CheckboxAutoStartClient_clicked();
void on_CheckboxAutoStartProfile_clicked();
void on_TextServerHost_textChanged(const QString);
void on_TextServerPort_textChanged(const QString);
void on_TextClientHost_textChanged(const QString);
void on_TextCustomArgs_textChanged(const QString);
void on_ComboBoxAutoStartProfile_currentTextChanged(const QString);
void on_CheckboxAutoStartSetServerHost_clicked();
void on_CheckboxAutoStartSetServerPort_clicked();
void on_CheckboxAutoStartCustom_clicked();
void on_CheckboxRunZoneChecks_clicked();

View file

@ -29,13 +29,30 @@
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>-204</y>
<width>427</width>
<height>670</height>
<x>-67</x>
<y>-258</y>
<width>465</width>
<height>724</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="14" column="0">
<widget class="QCheckBox" name="CheckboxAutoStart">
<property name="text">
<string>Start At Login</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="CheckboxSaveGeometry">
<property name="text">
<string>Save Geometry On Close</string>
</property>
</widget>
</item>
<item row="25" column="1">
<widget class="QComboBox" name="ComboBoxExitProfile"/>
</item>
<item row="10" column="0">
<widget class="QCheckBox" name="CheckboxLogConsole">
<property name="text">
@ -43,6 +60,51 @@
</property>
</widget>
</item>
<item row="26" column="0">
<widget class="QLabel" name="AutoStartStatusLabel">
<property name="text">
<string>Start at Login Status</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QCheckBox" name="CheckboxAMDSMBusReduceCPU">
<property name="text">
<string>AMD SMBus: Reduce CPU Usage (restart required)</string>
</property>
</widget>
</item>
<item row="23" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartCustom">
<property name="text">
<string>Custom Arguments</string>
</property>
</widget>
</item>
<item row="19" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartServer">
<property name="text">
<string>Start Server</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="ThemeLabel">
<property name="text">
<string>Theme (restart required)</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="LogManagerSettingsLabel">
<property name="text">
<string>Log Manager Settings:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="ComboBoxTheme"/>
</item>
<item row="18" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartMinimized">
<property name="text">
@ -50,24 +112,30 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="CheckboxLoadGeometry">
<item row="2" column="0">
<widget class="QLabel" name="UserInterfaceSettingsLabel">
<property name="text">
<string>Load Window Geometry</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="DriversSettingsLabel">
<property name="text">
<string>Drivers Settings</string>
<string>User Interface Settings:</string>
</property>
</widget>
</item>
<item row="22" column="1">
<widget class="QLineEdit" name="TextCustomArgs"/>
<widget class="QLineEdit" name="TextClientHost"/>
</item>
<item row="20" column="0">
<item row="21" column="1">
<widget class="QLineEdit" name="TextServerPort">
<property name="inputMask">
<string>90000</string>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item row="21" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartSetServerPort">
<property name="text">
<string>Set Server Port</string>
@ -81,52 +149,17 @@
</property>
</widget>
</item>
<item row="19" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartServer">
<item row="13" column="0">
<widget class="QLabel" name="AutoStartLabel">
<property name="text">
<string>Start Server</string>
<string>Start At Login Settings:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="UserInterfaceSettingsLabel">
<property name="text">
<string>User Interface Settings:</string>
</property>
</widget>
<item row="24" column="1">
<widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="CheckboxTrayIconGreyscale">
<property name="text">
<string>Greyscale Tray Icon</string>
</property>
</widget>
</item>
<item row="21" column="1">
<widget class="QLineEdit" name="TextClientHost"/>
</item>
<item row="9" column="0">
<widget class="QLabel" name="LogManagerSettingsLabel">
<property name="text">
<string>Log Manager Settings:</string>
</property>
</widget>
</item>
<item row="22" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartCustom">
<property name="text">
<string>Custom Arguments</string>
</property>
</widget>
</item>
<item row="23" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartProfile">
<property name="text">
<string>Load Profile</string>
</property>
</widget>
</item>
<item row="26" column="0">
<item row="27" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -142,74 +175,20 @@
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="ComboBoxTheme"/>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="CheckboxAutoStart">
<item row="6" column="0">
<widget class="QCheckBox" name="CheckboxLoadGeometry">
<property name="text">
<string>Start At Login</string>
<string>Load Window Geometry</string>
</property>
</widget>
</item>
<item row="20" column="1">
<widget class="QLineEdit" name="TextServerPort">
<property name="inputMask">
<string>90000</string>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QCheckBox" name="CheckboxAMDSMBusReduceCPU">
<property name="text">
<string>AMD SMBus: Reduce CPU Usage (restart required)</string>
</property>
</widget>
</item>
<item row="21" column="0">
<item row="22" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartClient">
<property name="text">
<string>Start Client</string>
</property>
</widget>
</item>
<item row="23" column="1">
<widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
</item>
<item row="13" column="0">
<widget class="QLabel" name="AutoStartLabel">
<property name="text">
<string>Start At Login Settings:</string>
</property>
</widget>
</item>
<item row="25" column="0">
<widget class="QLabel" name="AutoStartStatusLabel">
<property name="text">
<string>Start at Login Status</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="CheckboxSaveGeometry">
<property name="text">
<string>Save Geometry On Close</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="ThemeLabel">
<property name="text">
<string>Theme (restart required)</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="CheckboxRunZoneChecks">
<property name="text">
@ -217,15 +196,46 @@
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="DriversSettingsLabel">
<property name="text">
<string>Drivers Settings</string>
</property>
</widget>
</item>
<item row="24" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartProfile">
<property name="text">
<string>Load Profile</string>
</property>
</widget>
</item>
<item row="23" column="1">
<widget class="QLineEdit" name="TextCustomArgs"/>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="CheckboxTrayIconGreyscale">
<property name="text">
<string>Greyscale Tray Icon</string>
</property>
</widget>
</item>
<item row="25" column="0">
<widget class="QCheckBox" name="CheckboxSetOnExit">
<property name="text">
<string>Set Profile on Exit</string>
</property>
</widget>
</item>
<item row="24" column="1">
<widget class="QComboBox" name="ComboBoxExitProfile"/>
<item row="20" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartSetServerHost">
<property name="text">
<string>Set Server Host</string>
</property>
</widget>
</item>
<item row="20" column="1">
<widget class="QLineEdit" name="TextServerHost"/>
</item>
</layout>
</widget>