Move network clients to Resource Manager
This commit is contained in:
parent
c1ac870035
commit
128bfc7792
4 changed files with 23 additions and 20 deletions
|
|
@ -101,6 +101,11 @@ NetworkServer* ResourceManager::GetServer()
|
|||
return(server);
|
||||
}
|
||||
|
||||
std::vector<NetworkClient*> ResourceManager::GetClients()
|
||||
{
|
||||
return(clients);
|
||||
}
|
||||
|
||||
unsigned int ResourceManager::GetDetectionPercent()
|
||||
{
|
||||
return (detection_percent.load());
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ public:
|
|||
|
||||
unsigned int GetDetectionPercent();
|
||||
const char* GetDetectionString();
|
||||
NetworkServer* GetServer();
|
||||
|
||||
std::vector<NetworkClient*> GetClients();
|
||||
NetworkServer* GetServer();
|
||||
|
||||
void DeviceListChanged();
|
||||
|
||||
|
|
@ -75,7 +77,7 @@ private:
|
|||
/*-------------------------------------------------------------------------------------*\
|
||||
| Network Clients |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
//std::vector<NetworkClient*> clients;
|
||||
std::vector<NetworkClient*> clients;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Detectors |
|
||||
|
|
|
|||
18
cli.cpp
18
cli.cpp
|
|
@ -22,7 +22,6 @@
|
|||
using namespace std::chrono_literals;
|
||||
|
||||
static ProfileManager* profile_manager;
|
||||
static NetworkServer* network_server;
|
||||
static std::string profile_save_filename = "";
|
||||
|
||||
enum
|
||||
|
|
@ -667,7 +666,7 @@ bool OptionSaveProfile(std::string argument)
|
|||
return(true);
|
||||
}
|
||||
|
||||
int ProcessOptions(int argc, char *argv[], Options *options, std::vector<NetworkClient*> &clients, std::vector<RGBController *> &rgb_controllers)
|
||||
int ProcessOptions(int argc, char *argv[], Options *options, std::vector<RGBController *> &rgb_controllers)
|
||||
{
|
||||
unsigned int ret_flags = 0;
|
||||
int arg_index = 1;
|
||||
|
|
@ -728,7 +727,7 @@ int ProcessOptions(int argc, char *argv[], Options *options, std::vector<Network
|
|||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
|
||||
clients.push_back(client);
|
||||
ResourceManager::get()->GetClients().push_back(client);
|
||||
|
||||
arg_index++;
|
||||
}
|
||||
|
|
@ -1030,26 +1029,25 @@ void WaitWhileServerOnline(NetworkServer* srv)
|
|||
};
|
||||
}
|
||||
|
||||
unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> &rgb_controllers, ProfileManager* profile_manager_in, NetworkServer* network_server_in, std::vector<NetworkClient*> &clients)
|
||||
unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> &rgb_controllers, ProfileManager* profile_manager_in)
|
||||
{
|
||||
profile_manager = profile_manager_in;
|
||||
network_server = network_server_in;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Process the argument options |
|
||||
\*---------------------------------------------------------*/
|
||||
Options options;
|
||||
unsigned int ret_flags = ProcessOptions(argc, argv, &options, clients, rgb_controllers);
|
||||
unsigned int ret_flags = ProcessOptions(argc, argv, &options, rgb_controllers);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| If the server was told to start, start it before returning|
|
||||
\*---------------------------------------------------------*/
|
||||
if(options.servOpts.start)
|
||||
{
|
||||
network_server->SetPort(options.servOpts.port);
|
||||
network_server->StartServer();
|
||||
ResourceManager::get()->GetServer()->SetPort(options.servOpts.port);
|
||||
ResourceManager::get()->GetServer()->StartServer();
|
||||
|
||||
if(network_server->GetOnline())
|
||||
if(ResourceManager::get()->GetServer()->GetOnline())
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| If the GUI has been started, return from cli_main. |
|
||||
|
|
@ -1058,7 +1056,7 @@ unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> &rgb_
|
|||
\*---------------------------------------------------------*/
|
||||
if((ret_flags & RET_FLAG_START_GUI) == 0)
|
||||
{
|
||||
WaitWhileServerOnline(network_server);
|
||||
WaitWhileServerOnline(ResourceManager::get()->GetServer());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
14
main.cpp
14
main.cpp
|
|
@ -22,12 +22,10 @@
|
|||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::vector<NetworkClient*> clients;
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| Command line functionality and return flags |
|
||||
\*-------------------------------------------------------------*/
|
||||
extern unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> &rgb_controllers, ProfileManager* profile_manager_in, NetworkServer* network_server_in, std::vector<NetworkClient*> &clients);
|
||||
extern unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> &rgb_controllers, ProfileManager* profile_manager_in);
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
@ -108,7 +106,7 @@ bool AttemptLocalConnection(std::vector<RGBController*> &rgb_controllers)
|
|||
}
|
||||
else
|
||||
{
|
||||
clients.push_back(client);
|
||||
ResourceManager::get()->GetClients().push_back(client);
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
|
@ -162,7 +160,7 @@ int main(int argc, char* argv[])
|
|||
unsigned int ret_flags = RET_FLAG_START_GUI;
|
||||
if(argc > 1)
|
||||
{
|
||||
ret_flags = cli_main(argc, argv, rgb_controllers, &profile_manager, ResourceManager::get()->GetServer(), clients);
|
||||
ret_flags = cli_main(argc, argv, rgb_controllers, &profile_manager);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
|
|
@ -182,16 +180,16 @@ int main(int argc, char* argv[])
|
|||
dlg.AddI2CToolsPage();
|
||||
}
|
||||
|
||||
if(clients.size() == 0)
|
||||
if(ResourceManager::get()->GetClients().size() == 0)
|
||||
{
|
||||
dlg.AddServerTab(ResourceManager::get()->GetServer());
|
||||
}
|
||||
|
||||
dlg.AddClientTab();
|
||||
|
||||
for(std::size_t client_idx = 0; client_idx < clients.size(); client_idx++)
|
||||
for(std::size_t client_idx = 0; client_idx < ResourceManager::get()->GetClients().size(); client_idx++)
|
||||
{
|
||||
dlg.AddClient(clients[client_idx]);
|
||||
dlg.AddClient(ResourceManager::get()->GetClients()[client_idx]);
|
||||
}
|
||||
|
||||
if(ret_flags & RET_FLAG_START_MINIMIZED)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue