mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-04-07 15:37:33 -04:00
[WIP] Rework server initialization
* Only create server instance if server is actually needed
* Pass initial server host and port through ResourceManager
* Allow setting default server host and port in Server settings
This commit is contained in:
@@ -911,7 +911,12 @@ void ProfileManager::SetActiveProfile(std::string profile_name)
|
||||
{
|
||||
active_profile = profile_name;
|
||||
|
||||
ResourceManager::get()->GetServer()->SendRequest_ProfileManager_ActiveProfileChanged(active_profile);
|
||||
NetworkServer* server = ResourceManager::get()->GetServer();
|
||||
|
||||
if(server)
|
||||
{
|
||||
server->SendRequest_ProfileManager_ActiveProfileChanged(active_profile);
|
||||
}
|
||||
|
||||
SignalProfileManagerUpdate(PROFILEMANAGER_UPDATE_REASON_ACTIVE_PROFILE_CHANGED);
|
||||
}
|
||||
@@ -969,7 +974,12 @@ void ProfileManager::SetProfileListFromDescription(unsigned int /*data_size*/, c
|
||||
|
||||
void ProfileManager::SignalProfileManagerUpdate(unsigned int update_reason)
|
||||
{
|
||||
ResourceManager::get()->GetServer()->SignalProfileManagerUpdate(update_reason);
|
||||
NetworkServer* server = ResourceManager::get()->GetServer();
|
||||
|
||||
if(server)
|
||||
{
|
||||
server->SignalProfileManagerUpdate(update_reason);
|
||||
}
|
||||
|
||||
ProfileManagerCallbackMutex.lock();
|
||||
|
||||
@@ -1355,7 +1365,12 @@ bool ProfileManager::LoadProfileWithOptions
|
||||
plugin_manager->OnProfileAboutToLoad();
|
||||
}
|
||||
|
||||
ResourceManager::get()->GetServer()->ProfileManager_ProfileAboutToLoad();
|
||||
NetworkServer* server = ResourceManager::get()->GetServer();
|
||||
|
||||
if(server)
|
||||
{
|
||||
server->ProfileManager_ProfileAboutToLoad();
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get the list of controllers from the resource |
|
||||
@@ -1384,14 +1399,20 @@ bool ProfileManager::LoadProfileWithOptions
|
||||
/*-------------------------------------------------*\
|
||||
| Notify local client |
|
||||
\*-------------------------------------------------*/
|
||||
ResourceManager::get()->GetServer()->SendRequest_ProfileManager_ProfileLoaded(profile_json.dump());
|
||||
if(server)
|
||||
{
|
||||
server->SendRequest_ProfileManager_ProfileLoaded(profile_json.dump());
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Update active profile |
|
||||
\*-------------------------------------------------*/
|
||||
SetActiveProfile(profile_name);
|
||||
|
||||
ResourceManager::get()->GetServer()->SendRequest_ProfileManager_ActiveProfileChanged(active_profile);
|
||||
if(server)
|
||||
{
|
||||
server->SendRequest_ProfileManager_ActiveProfileChanged(active_profile);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -135,6 +135,9 @@ ResourceManager::ResourceManager()
|
||||
detection_enabled = true;
|
||||
init_finished = false;
|
||||
plugin_manager = NULL;
|
||||
server = NULL;
|
||||
server_host = OPENRGB_SDK_HOST;
|
||||
server_port = OPENRGB_SDK_PORT;
|
||||
|
||||
SetupConfigurationDirectory();
|
||||
|
||||
@@ -150,44 +153,10 @@ ResourceManager::ResourceManager()
|
||||
\*-----------------------------------------------------*/
|
||||
LogManager::get()->configure(settings_manager->GetSettings("LogManager"), GetConfigurationDirectory());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize Server Instance |
|
||||
| If configured, pass through full controller list |
|
||||
| including clients. Otherwise, pass only local |
|
||||
| hardware controllers |
|
||||
\*-----------------------------------------------------*/
|
||||
json server_settings = settings_manager->GetSettings("Server");
|
||||
bool legacy_workaround = false;
|
||||
|
||||
server = new NetworkServer();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set server name |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string titleString = "OpenRGB ";
|
||||
titleString.append(VERSION_STRING);
|
||||
|
||||
server->SetName(titleString);
|
||||
server->SetSettingsManager(settings_manager);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Enable legacy SDK workaround in server if configured |
|
||||
\*-----------------------------------------------------*/
|
||||
if(server_settings.contains("legacy_workaround"))
|
||||
{
|
||||
legacy_workaround = server_settings["legacy_workaround"];
|
||||
}
|
||||
|
||||
if(legacy_workaround)
|
||||
{
|
||||
server->SetLegacyWorkaroundEnable(true);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Load sizes list from file |
|
||||
\*-----------------------------------------------------*/
|
||||
profile_manager = new ProfileManager(GetConfigurationDirectory());
|
||||
server->SetProfileManager(profile_manager);
|
||||
}
|
||||
|
||||
ResourceManager::~ResourceManager()
|
||||
@@ -269,7 +238,21 @@ void ResourceManager::SetConfigurationDirectory(const filesystem::path &director
|
||||
void ResourceManager::SetPluginManager(PluginManagerInterface* plugin_manager_ptr)
|
||||
{
|
||||
plugin_manager = plugin_manager_ptr;
|
||||
server->SetPluginManager(plugin_manager);
|
||||
|
||||
if(server)
|
||||
{
|
||||
server->SetPluginManager(plugin_manager);
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::SetServerHost(std::string new_server_host)
|
||||
{
|
||||
server_host = new_server_host;
|
||||
}
|
||||
|
||||
void ResourceManager::SetServerPort(unsigned short new_server_port)
|
||||
{
|
||||
server_port = new_server_port;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -494,21 +477,24 @@ void ResourceManager::UpdateDeviceList()
|
||||
/*-----------------------------------------------------*\
|
||||
| Update server list |
|
||||
\*-----------------------------------------------------*/
|
||||
json server_settings = settings_manager->GetSettings("Server");
|
||||
bool all_controllers = false;
|
||||
if(server)
|
||||
{
|
||||
json server_settings = settings_manager->GetSettings("Server");
|
||||
bool all_controllers = false;
|
||||
|
||||
if(server_settings.contains("all_controllers"))
|
||||
{
|
||||
all_controllers = server_settings["all_controllers"];
|
||||
}
|
||||
if(server_settings.contains("all_controllers"))
|
||||
{
|
||||
all_controllers = server_settings["all_controllers"];
|
||||
}
|
||||
|
||||
if(all_controllers)
|
||||
{
|
||||
server->SetControllers(rgb_controllers);
|
||||
}
|
||||
else
|
||||
{
|
||||
server->SetControllers(rgb_controllers_hw);
|
||||
if(all_controllers)
|
||||
{
|
||||
server->SetControllers(rgb_controllers);
|
||||
}
|
||||
else
|
||||
{
|
||||
server->SetControllers(rgb_controllers_hw);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -532,7 +518,10 @@ void ResourceManager::WaitForDetection()
|
||||
\*---------------------------------------------------------*/
|
||||
void ResourceManager::SignalResourceManagerUpdate(unsigned int update_reason)
|
||||
{
|
||||
server->SignalResourceManagerUpdate(update_reason);
|
||||
if(server)
|
||||
{
|
||||
server->SignalResourceManagerUpdate(update_reason);
|
||||
}
|
||||
|
||||
ResourceManagerCallbackMutex.lock();
|
||||
|
||||
@@ -729,8 +718,9 @@ void ResourceManager::Initialize(bool tryConnect, bool detectDevices, bool start
|
||||
\*-----------------------------------------------------*/
|
||||
if(start_server)
|
||||
{
|
||||
GetServer()->StartServer();
|
||||
if(!GetServer()->GetOnline())
|
||||
InitializeServer();
|
||||
server->StartServer();
|
||||
if(!server->GetOnline())
|
||||
{
|
||||
LOG_DEBUG("[%s] Server failed to start", RESOURCEMANAGER);
|
||||
}
|
||||
@@ -760,6 +750,52 @@ void ResourceManager::Initialize(bool tryConnect, bool detectDevices, bool start
|
||||
init_finished = true;
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeServer()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize Server Instance |
|
||||
| If configured, pass through full controller list |
|
||||
| including clients. Otherwise, pass only local |
|
||||
| hardware controllers |
|
||||
\*-----------------------------------------------------*/
|
||||
json server_settings = settings_manager->GetSettings("Server");
|
||||
bool legacy_workaround = false;
|
||||
|
||||
server = new NetworkServer();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set server name |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string titleString = "OpenRGB ";
|
||||
titleString.append(VERSION_STRING);
|
||||
|
||||
server->SetName(titleString);
|
||||
server->SetSettingsManager(settings_manager);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Enable legacy SDK workaround in server if configured |
|
||||
\*-----------------------------------------------------*/
|
||||
if(server_settings.contains("legacy_workaround"))
|
||||
{
|
||||
legacy_workaround = server_settings["legacy_workaround"];
|
||||
}
|
||||
|
||||
if(legacy_workaround)
|
||||
{
|
||||
server->SetLegacyWorkaroundEnable(true);
|
||||
}
|
||||
|
||||
server->SetProfileManager(profile_manager);
|
||||
|
||||
if(plugin_manager)
|
||||
{
|
||||
server->SetPluginManager(plugin_manager);
|
||||
}
|
||||
|
||||
server->SetHost(server_host);
|
||||
server->SetPort(server_port);
|
||||
}
|
||||
|
||||
void ResourceManager::WaitForInitialization()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
||||
@@ -62,6 +62,8 @@ public:
|
||||
|
||||
void SetConfigurationDirectory(const filesystem::path &directory);
|
||||
void SetPluginManager(PluginManagerInterface* plugin_manager_ptr);
|
||||
void SetServerHost(std::string server_host);
|
||||
void SetServerPort(unsigned short server_port);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Network Client Registration |
|
||||
@@ -99,6 +101,7 @@ public:
|
||||
void SignalResourceManagerUpdate(unsigned int update_reason);
|
||||
|
||||
void Initialize(bool tryConnect, bool detectDevices, bool startServer, bool applyPostOptions);
|
||||
void InitializeServer();
|
||||
|
||||
void WaitForInitialization();
|
||||
|
||||
@@ -170,6 +173,8 @@ private:
|
||||
| Network Server |
|
||||
\*-----------------------------------------------------*/
|
||||
NetworkServer* server;
|
||||
std::string server_host;
|
||||
unsigned short server_port;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Network Clients |
|
||||
|
||||
15
cli.cpp
15
cli.cpp
@@ -1408,14 +1408,14 @@ unsigned int cli_pre_detection(int argc, char* argv[])
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--server-port")
|
||||
{
|
||||
if (argument != "")
|
||||
if(argument != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
int port = std::stoi(argument);
|
||||
if (port >= 1024 && port <= 65535)
|
||||
if(port >= 1024 && port <= 65535)
|
||||
{
|
||||
server_port = port;
|
||||
ResourceManager::get()->SetServerPort(port);
|
||||
server_start = true;
|
||||
}
|
||||
else
|
||||
@@ -1446,11 +1446,9 @@ unsigned int cli_pre_detection(int argc, char* argv[])
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--server-host")
|
||||
{
|
||||
if (argument != "")
|
||||
if(argument != "")
|
||||
{
|
||||
std::string host = argument;
|
||||
|
||||
server_host = host;
|
||||
ResourceManager::get()->SetServerHost(argument);
|
||||
server_start = true;
|
||||
}
|
||||
else
|
||||
@@ -1694,9 +1692,6 @@ unsigned int cli_pre_detection(int argc, char* argv[])
|
||||
|
||||
if(server_start)
|
||||
{
|
||||
NetworkServer * server = ResourceManager::get()->GetServer();
|
||||
server->SetHost(server_host);
|
||||
server->SetPort(server_port);
|
||||
ret_flags |= RET_FLAG_START_SERVER;
|
||||
}
|
||||
|
||||
|
||||
@@ -364,7 +364,7 @@ OpenRGBDialog::OpenRGBDialog(QWidget *parent) : QMainWindow(parent), ui(new Ui::
|
||||
/*-----------------------------------------------------*\
|
||||
| Add Server Tab |
|
||||
\*-----------------------------------------------------*/
|
||||
AddServerTab();
|
||||
//AddServerTab();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the Software Info page |
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<y>-746</y>
|
||||
<width>516</width>
|
||||
<height>1262</height>
|
||||
<height>1327</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
@@ -220,17 +220,48 @@
|
||||
<string>Server</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_8">
|
||||
<item row="0" column="0">
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="LineEditServerHost">
|
||||
<property name="text">
|
||||
<string>127.0.0.1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="LabelServerHost">
|
||||
<property name="text">
|
||||
<string>Server Host</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="CheckboxLegacyWorkaround">
|
||||
<property name="text">
|
||||
<string>Legacy Workaround</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="CheckboxAllDevices">
|
||||
<property name="text">
|
||||
<string>Serve All Devices (Including those from client connections)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="CheckboxLegacyWorkaround">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="LabelServerPort">
|
||||
<property name="text">
|
||||
<string>Legacy Workaround</string>
|
||||
<string>Server Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="SpinBoxServerPort">
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>6742</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user