Server freed from ResourceManager

Commit amended to revert OpenRGBInterfaces.h header (may reconsider in the future) by Adam Honse
<calcprogrammer1@gmail.com>
This commit is contained in:
k1-801 2021-04-25 02:34:56 +04:00 committed by Adam Honse
parent a6bc30a31c
commit 02ba8a799e
3 changed files with 29 additions and 6 deletions

View file

@ -7,7 +7,6 @@
\*-----------------------------------------*/ \*-----------------------------------------*/
#include "NetworkServer.h" #include "NetworkServer.h"
#include "ResourceManager.h"
#include <cstring> #include <cstring>
#ifndef WIN32 #ifndef WIN32
@ -40,6 +39,7 @@ NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controller
server_online = false; server_online = false;
server_listening = false; server_listening = false;
ConnectionThread = nullptr; ConnectionThread = nullptr;
profile_manager = nullptr;
} }
NetworkServer::~NetworkServer() NetworkServer::~NetworkServer()
@ -683,7 +683,10 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break; break;
} }
ResourceManager::get()->GetProfileManager()->SaveProfile(data); if(profile_manager)
{
profile_manager->SaveProfile(data);
}
break; break;
@ -693,9 +696,12 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break; break;
} }
ResourceManager::get()->GetProfileManager()->LoadProfile(data); if(profile_manager)
{
profile_manager->LoadProfile(data);
}
for(RGBController* controller : ResourceManager::get()->GetRGBControllers()) for(RGBController* controller : controllers)
{ {
controller->UpdateLEDs(); controller->UpdateLEDs();
} }
@ -708,7 +714,10 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
break; break;
} }
ResourceManager::get()->GetProfileManager()->DeleteProfile(data); if(profile_manager)
{
profile_manager->DeleteProfile(data);
}
break; break;
} }
@ -876,7 +885,10 @@ void NetworkServer::SendRequest_DeviceListChanged(SOCKET client_sock)
void NetworkServer::SendReply_ProfileList(SOCKET client_sock) void NetworkServer::SendReply_ProfileList(SOCKET client_sock)
{ {
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); if(!profile_manager)
{
return;
}
NetPacketHeader reply_hdr; NetPacketHeader reply_hdr;
unsigned char *reply_data = profile_manager->GetProfileListDescription(); unsigned char *reply_data = profile_manager->GetProfileListDescription();
@ -897,3 +909,8 @@ void NetworkServer::SendReply_ProfileList(SOCKET client_sock)
send(client_sock, (const char *)reply_data, reply_size, 0); send(client_sock, (const char *)reply_data, reply_size, 0);
} }
void NetworkServer::SetProfileManager(ProfileManagerInterface* profile_manager_pointer)
{
profile_manager = profile_manager_pointer;
}

View file

@ -9,6 +9,7 @@
#include "RGBController.h" #include "RGBController.h"
#include "NetworkProtocol.h" #include "NetworkProtocol.h"
#include "net_port.h" #include "net_port.h"
#include "ProfileManager.h"
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -68,6 +69,8 @@ public:
void SendRequest_DeviceListChanged(SOCKET client_sock); void SendRequest_DeviceListChanged(SOCKET client_sock);
void SendReply_ProfileList(SOCKET client_sock); void SendReply_ProfileList(SOCKET client_sock);
void SetProfileManager(ProfileManagerInterface* profile_manager_pointer);
protected: protected:
unsigned short port_num; unsigned short port_num;
bool server_online; bool server_online;
@ -87,6 +90,8 @@ protected:
std::vector<NetServerCallback> ServerListeningChangeCallbacks; std::vector<NetServerCallback> ServerListeningChangeCallbacks;
std::vector<void *> ServerListeningChangeCallbackArgs; std::vector<void *> ServerListeningChangeCallbackArgs;
ProfileManagerInterface* profile_manager;
private: private:
#ifdef WIN32 #ifdef WIN32
WSADATA wsa; WSADATA wsa;

View file

@ -52,6 +52,7 @@ ResourceManager::ResourceManager()
| Load sizes list from file | | Load sizes list from file |
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
profile_manager = new ProfileManager(GetConfigurationDirectory()); profile_manager = new ProfileManager(GetConfigurationDirectory());
server->SetProfileManager(profile_manager);
rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes", true); rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes", true);
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\