diff --git a/source/Gui/ActivateUserDialog.cpp b/source/Gui/ActivateUserDialog.cpp index 797bc81c3..8e32b69bb 100644 --- a/source/Gui/ActivateUserDialog.cpp +++ b/source/Gui/ActivateUserDialog.cpp @@ -79,10 +79,10 @@ void _ActivateUserDialog::processIntern() void _ActivateUserDialog::onActivateUser() { - auto result = NetworkService::activateUser(_userName, _password, _userInfo, _confirmationCode); + auto result = NetworkService::get().activateUser(_userName, _password, _userInfo, _confirmationCode); if (result) { LoginErrorCode errorCode; - result |= NetworkService::login(errorCode, _userName, _password, _userInfo); + result |= NetworkService::get().login(errorCode, _userName, _password, _userInfo); } if (!result) { MessageDialog::get().information("Error", "An error occurred on the server. Your entered code may be incorrect.\nPlease try to register again."); diff --git a/source/Gui/BrowserWindow.cpp b/source/Gui/BrowserWindow.cpp index 7001dbff5..3c95fcc4e 100644 --- a/source/Gui/BrowserWindow.cpp +++ b/source/Gui/BrowserWindow.cpp @@ -180,7 +180,7 @@ void _BrowserWindow::refreshIntern(bool withRetry) for (auto& [workspaceId, workspace] : _workspaces) { workspace.rawTOs.clear(); - auto userName = NetworkService::getLoggedInUserName().value_or(""); + auto userName = NetworkService::get().getLoggedInUserName().value_or(""); for (auto const& rawTO : data.resourceTOs) { if (rawTO->resourceType == workspaceId.resourceType) { //public user items should also be visible in private workspace @@ -250,7 +250,7 @@ void _BrowserWindow::processToolbar() //login button ImGui::SameLine(); - ImGui::BeginDisabled(NetworkService::getLoggedInUserName().has_value()); + ImGui::BeginDisabled(NetworkService::get().getLoggedInUserName().has_value()); if (AlienImGui::ToolbarButton(ICON_FA_SIGN_IN_ALT)) { if (auto loginDialog = _loginDialog.lock()) { loginDialog->open(); @@ -261,10 +261,10 @@ void _BrowserWindow::processToolbar() //logout button ImGui::SameLine(); - ImGui::BeginDisabled(!NetworkService::getLoggedInUserName()); + ImGui::BeginDisabled(!NetworkService::get().getLoggedInUserName()); if (AlienImGui::ToolbarButton(ICON_FA_SIGN_OUT_ALT)) { if (auto loginDialog = _loginDialog.lock()) { - NetworkService::logout(); + NetworkService::get().logout(); onRefresh(); } } @@ -402,7 +402,7 @@ void _BrowserWindow::processWorkspaceSelectionAndFilter() ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - auto userName = NetworkService::getLoggedInUserName(); + auto userName = NetworkService::get().getLoggedInUserName(); auto privateWorkspaceString = userName.has_value() ? *userName + "'s private workspace" : "Private workspace (need to login)"; auto workspaceType_reordered = 2 - _currentWorkspace.workspaceType; //change the order for display if (AlienImGui::Switcher( @@ -464,7 +464,7 @@ void _BrowserWindow::processUserList() AlienImGui::Group("Simulators"); if (ImGui::BeginTable("Browser", 5, flags, ImVec2(0, 0), 0.0f)) { ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthFixed, scale(90.0f)); - auto isLoggedIn = NetworkService::getLoggedInUserName().has_value(); + auto isLoggedIn = NetworkService::get().getLoggedInUserName().has_value(); ImGui::TableSetupColumn( isLoggedIn ? "GPU model" : "GPU (visible if logged in)", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed, @@ -488,7 +488,7 @@ void _BrowserWindow::processUserList() ImGui::TableNextRow(0, scale(RowHeight)); ImGui::TableNextColumn(); - auto isBoldFont = isLoggedIn && *NetworkService::getLoggedInUserName() == item->userName; + auto isBoldFont = isLoggedIn && *NetworkService::get().getLoggedInUserName() == item->userName; if (item->online) { AlienImGui::OnlineSymbol(); @@ -551,13 +551,13 @@ void _BrowserWindow::processStatus() statusText += std::to_string(_userTOs.size()) + " simulators found"; statusText += std::string(" " ICON_FA_INFO_CIRCLE " "); - if (auto userName = NetworkService::getLoggedInUserName()) { - statusText += "Logged in as " + *userName + " @ " + NetworkService::getServerAddress(); // + ": "; + if (auto userName = NetworkService::get().getLoggedInUserName()) { + statusText += "Logged in as " + *userName + " @ " + NetworkService::get().getServerAddress(); // + ": "; } else { - statusText += "Not logged in to " + NetworkService::getServerAddress(); // + ": "; + statusText += "Not logged in to " + NetworkService::get().getServerAddress(); // + ": "; } - if (!NetworkService::getLoggedInUserName()) { + if (!NetworkService::get().getLoggedInUserName()) { statusText += std::string(" " ICON_FA_INFO_CIRCLE " "); statusText += "In order to share and upvote simulations you need to log in."; } @@ -1329,7 +1329,7 @@ void _BrowserWindow::onMoveResource(NetworkResourceTreeTO const& treeTO) //apply changes to server delayedExecution([rawTOs = rawTOs, this] { for (auto const& rawTO : rawTOs) { - if (!NetworkService::moveResource(rawTO->id, rawTO->workspaceType)) { + if (!NetworkService::get().moveResource(rawTO->id, rawTO->workspaceType)) { MessageDialog::get().information("Error", "Failed to move item."); refreshIntern(true); return; @@ -1370,7 +1370,7 @@ void _BrowserWindow::onToggleLike(NetworkResourceTreeTO const& to, int emojiType { CHECK(to->isLeaf()); auto& leaf = to->getLeaf(); - if (NetworkService::getLoggedInUserName()) { + if (NetworkService::get().getLoggedInUserName()) { //remove existing like auto findResult = _ownEmojiTypeBySimId.find(leaf.rawTO->id); @@ -1396,7 +1396,7 @@ void _BrowserWindow::onToggleLike(NetworkResourceTreeTO const& to, int emojiType } _userNamesByEmojiTypeBySimIdCache.erase(std::make_pair(leaf.rawTO->id, emojiType)); //invalidate cache entry - NetworkService::toggleReactToResource(leaf.rawTO->id, emojiType); + NetworkService::get().toggleReactToResource(leaf.rawTO->id, emojiType); } else { _loginDialog.lock()->open(); } @@ -1431,7 +1431,7 @@ bool _BrowserWindow::isOwner(NetworkResourceTreeTO const& treeTO) const auto const& workspace = _workspaces.at(_currentWorkspace); auto rawTOs = NetworkResourceService::getMatchingRawTOs(treeTO, workspace.rawTOs); - auto userName = NetworkService::getLoggedInUserName().value_or(""); + auto userName = NetworkService::get().getLoggedInUserName().value_or(""); return std::ranges::all_of(rawTOs, [&](NetworkResourceRawTO const& rawTO) { return rawTO->userName == userName; }); } diff --git a/source/Gui/CreateUserDialog.cpp b/source/Gui/CreateUserDialog.cpp index 26dc0f9f9..c4b11234c 100644 --- a/source/Gui/CreateUserDialog.cpp +++ b/source/Gui/CreateUserDialog.cpp @@ -61,7 +61,7 @@ void _CreateUserDialog::processIntern() void _CreateUserDialog::onCreateUser() { - if (NetworkService::createUser(_userName, _password, _email)) { + if (NetworkService::get().createUser(_userName, _password, _email)) { _activateUserDialog->open(_userName, _password, _userInfo); } else { MessageDialog::get().information( diff --git a/source/Gui/DeleteUserDialog.cpp b/source/Gui/DeleteUserDialog.cpp index 8b6a530c2..74ea43c4e 100644 --- a/source/Gui/DeleteUserDialog.cpp +++ b/source/Gui/DeleteUserDialog.cpp @@ -18,7 +18,7 @@ _DeleteUserDialog::_DeleteUserDialog(BrowserWindow const& browserWindow) void _DeleteUserDialog::processIntern() { AlienImGui::Text( - "Warning: All the data of the user '" + *NetworkService::getLoggedInUserName() + "Warning: All the data of the user '" + *NetworkService::get().getLoggedInUserName() + "' will be deleted on the server side.\nThese include the likes, the simulations and the account data."); AlienImGui::Separator(); @@ -28,7 +28,7 @@ void _DeleteUserDialog::processIntern() ImGui::BeginDisabled(_reenteredPassword.empty()); if (AlienImGui::Button("Delete")) { close(); - if (_reenteredPassword == *NetworkService::getPassword()) { + if (_reenteredPassword == *NetworkService::get().getPassword()) { onDelete(); } else { MessageDialog::get().information("Error", "The password does not match."); @@ -47,8 +47,8 @@ void _DeleteUserDialog::processIntern() void _DeleteUserDialog::onDelete() { - auto userName = *NetworkService::getLoggedInUserName(); - if (NetworkService::deleteUser()) { + auto userName = *NetworkService::get().getLoggedInUserName(); + if (NetworkService::get().deleteUser()) { _browserWindow->onRefresh(); MessageDialog::get().information("Information", "The user '" + userName + "' has been deleted.\nYou are logged out."); } else { diff --git a/source/Gui/EditSimulationDialog.cpp b/source/Gui/EditSimulationDialog.cpp index 80499dc25..366421f85 100644 --- a/source/Gui/EditSimulationDialog.cpp +++ b/source/Gui/EditSimulationDialog.cpp @@ -74,7 +74,7 @@ void _EditSimulationDialog::processForLeaf() if (AlienImGui::Button("OK")) { if (ValidationService::isStringValidForDatabase(_newName) && ValidationService::isStringValidForDatabase(_newDescription)) { delayedExecution([rawTO = rawTO, resourceTypeString = resourceTypeString, this] { - if (!NetworkService::editResource(rawTO->id, _newName, _newDescription)) { + if (!NetworkService::get().editResource(rawTO->id, _newName, _newDescription)) { showMessage("Error", "Failed to edit " + resourceTypeString + "."); } _browserWindow->onRefresh(); @@ -110,7 +110,7 @@ void _EditSimulationDialog::processForFolder() for (auto const& rawTO : _rawTOs) { auto nameWithoutOldFolder = rawTO->resourceName.substr(_origFolderName.size() + 1); auto newName = NetworkResourceService::concatenateFolderName({_newName, nameWithoutOldFolder}, false); - if (!NetworkService::editResource(rawTO->id, newName, rawTO->description)) { + if (!NetworkService::get().editResource(rawTO->id, newName, rawTO->description)) { showMessage("Error", "Failed to change folder name."); break; } diff --git a/source/Gui/MainWindow.cpp b/source/Gui/MainWindow.cpp index 8705a9471..30bfdb209 100644 --- a/source/Gui/MainWindow.cpp +++ b/source/Gui/MainWindow.cpp @@ -120,7 +120,7 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca //init services StyleRepository::get().init(); - NetworkService::init(); + NetworkService::get().init(); //init controllers, windows and dialogs Viewport::get().init(_simulationFacade); @@ -251,7 +251,7 @@ void _MainWindow::shutdown() _persisterFacade->shutdown(); _simulationFacade->closeSimulation(); - NetworkService::shutdown(); + NetworkService::get().shutdown(); } char const* _MainWindow::initGlfwAndReturnGlslVersion() @@ -409,30 +409,30 @@ void _MainWindow::processMenubar() _browserWindow->setOn(!_browserWindow->isOn()); } ImGui::Separator(); - ImGui::BeginDisabled((bool)NetworkService::getLoggedInUserName()); + ImGui::BeginDisabled((bool)NetworkService::get().getLoggedInUserName()); if (ImGui::MenuItem("Login", "ALT+L")) { _loginDialog->open(); } ImGui::EndDisabled(); - ImGui::BeginDisabled(!NetworkService::getLoggedInUserName()); + ImGui::BeginDisabled(!NetworkService::get().getLoggedInUserName()); if (ImGui::MenuItem("Logout", "ALT+T")) { - NetworkService::logout(); + NetworkService::get().logout(); _browserWindow->onRefresh(); } ImGui::EndDisabled(); - ImGui::BeginDisabled(!NetworkService::getLoggedInUserName()); + ImGui::BeginDisabled(!NetworkService::get().getLoggedInUserName()); if (ImGui::MenuItem("Upload simulation", "ALT+D")) { _uploadSimulationDialog->open(NetworkResourceType_Simulation); } ImGui::EndDisabled(); - ImGui::BeginDisabled(!NetworkService::getLoggedInUserName()); + ImGui::BeginDisabled(!NetworkService::get().getLoggedInUserName()); if (ImGui::MenuItem("Upload genome", "ALT+Q")) { _uploadSimulationDialog->open(NetworkResourceType_Genome); } ImGui::EndDisabled(); ImGui::Separator(); - ImGui::BeginDisabled(!NetworkService::getLoggedInUserName()); + ImGui::BeginDisabled(!NetworkService::get().getLoggedInUserName()); if (ImGui::MenuItem("Delete user", "ALT+J")) { _deleteUserDialog->open(); } @@ -602,20 +602,20 @@ void _MainWindow::processMenubar() if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_W)) { _browserWindow->setOn(!_browserWindow->isOn()); } - if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_L) && !NetworkService::getLoggedInUserName()) { + if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_L) && !NetworkService::get().getLoggedInUserName()) { _loginDialog->open(); } if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_T)) { - NetworkService::logout(); + NetworkService::get().logout(); _browserWindow->onRefresh(); } - if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_D) && NetworkService::getLoggedInUserName()) { + if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_D) && NetworkService::get().getLoggedInUserName()) { _uploadSimulationDialog->open(NetworkResourceType_Simulation); } - if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_Q) && NetworkService::getLoggedInUserName()) { + if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_Q) && NetworkService::get().getLoggedInUserName()) { _uploadSimulationDialog->open(NetworkResourceType_Genome); } - if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_J) && NetworkService::getLoggedInUserName()) { + if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_J) && NetworkService::get().getLoggedInUserName()) { _deleteUserDialog->open(); } diff --git a/source/Gui/NetworkSettingsDialog.cpp b/source/Gui/NetworkSettingsDialog.cpp index ee31340d0..ba5d2dc31 100644 --- a/source/Gui/NetworkSettingsDialog.cpp +++ b/source/Gui/NetworkSettingsDialog.cpp @@ -41,12 +41,12 @@ void _NetworkSettingsDialog::processIntern() void _NetworkSettingsDialog::openIntern() { - _origServerAddress = NetworkService::getServerAddress(); + _origServerAddress = NetworkService::get().getServerAddress(); _serverAddress = _origServerAddress; } void _NetworkSettingsDialog::onChangeSettings() { - NetworkService::setServerAddress(_serverAddress); + NetworkService::get().setServerAddress(_serverAddress); _browserWindow->onRefresh(); } diff --git a/source/Gui/NewPasswordDialog.cpp b/source/Gui/NewPasswordDialog.cpp index 1b02c7986..37465d6e5 100644 --- a/source/Gui/NewPasswordDialog.cpp +++ b/source/Gui/NewPasswordDialog.cpp @@ -58,10 +58,10 @@ void _NewPasswordDialog::processIntern() void _NewPasswordDialog::onNewPassword() { - auto result = NetworkService::setNewPassword(_userName, _newPassword, _confirmationCode); + auto result = NetworkService::get().setNewPassword(_userName, _newPassword, _confirmationCode); if (result) { LoginErrorCode errorCode; - result |= NetworkService::login(errorCode, _userName, _newPassword, _userInfo); + result |= NetworkService::get().login(errorCode, _userName, _newPassword, _userInfo); } if (!result) { MessageDialog::get().information("Error", "An error occurred on the server. Your entered code may be incorrect.\nPlease try to reset the password again."); diff --git a/source/Gui/ResetPasswordDialog.cpp b/source/Gui/ResetPasswordDialog.cpp index 64f6068ce..52597d279 100644 --- a/source/Gui/ResetPasswordDialog.cpp +++ b/source/Gui/ResetPasswordDialog.cpp @@ -52,7 +52,7 @@ void _ResetPasswordDialog::processIntern() void _ResetPasswordDialog::onResetPassword() { - if (NetworkService::resetPassword(_userName, _email)) { + if (NetworkService::get().resetPassword(_userName, _email)) { _newPasswordDialog->open(_userName, _userInfo); } else { MessageDialog::get().information( diff --git a/source/Gui/UploadSimulationDialog.cpp b/source/Gui/UploadSimulationDialog.cpp index c9214d179..a898c474c 100644 --- a/source/Gui/UploadSimulationDialog.cpp +++ b/source/Gui/UploadSimulationDialog.cpp @@ -58,7 +58,7 @@ _UploadSimulationDialog::~_UploadSimulationDialog() void _UploadSimulationDialog::open(NetworkResourceType resourceType, std::string const& folder) { - if (NetworkService::getLoggedInUserName()) { + if (NetworkService::get().getLoggedInUserName()) { changeTitle("Upload " + BrowserDataTypeToLowerString.at(resourceType)); _resourceType = resourceType; _folder = folder; diff --git a/source/Network/NetworkService.cpp b/source/Network/NetworkService.cpp index be3a5c258..2c8d311fb 100644 --- a/source/Network/NetworkService.cpp +++ b/source/Network/NetworkService.cpp @@ -67,12 +67,6 @@ namespace } } -std::string NetworkService::_serverAddress; -std::optional NetworkService::_loggedInUserName; -std::optional NetworkService::_password; -std::optional NetworkService::_lastRefreshTime; -Cache NetworkService::_downloadCache; - void NetworkService::init() { _serverAddress = GlobalSettings::get().getString("settings.server", "alien-project.org"); diff --git a/source/Network/NetworkService.h b/source/Network/NetworkService.h index 77640932c..254e0bd9f 100644 --- a/source/Network/NetworkService.h +++ b/source/Network/NetworkService.h @@ -6,6 +6,7 @@ #include "NetworkResourceRawTO.h" #include "UserTO.h" #include "Definitions.h" +#include "Base/Singleton.h" using LoginErrorCode = int; enum LoginErrorCode_ @@ -21,34 +22,34 @@ struct UserInfo class NetworkService { -public: - NetworkService() = delete; + MAKE_SINGLETON(NetworkService); - static void init(); - static void shutdown(); +public: + void init(); + void shutdown(); - static std::string getServerAddress(); - static void setServerAddress(std::string const& value); - static std::optional getLoggedInUserName(); - static std::optional getPassword(); + std::string getServerAddress(); + void setServerAddress(std::string const& value); + std::optional getLoggedInUserName(); + std::optional getPassword(); - static bool createUser(std::string const& userName, std::string const& password, std::string const& email); - static bool activateUser(std::string const& userName, std::string const& password, UserInfo const& userInfo, std::string const& confirmationCode); + bool createUser(std::string const& userName, std::string const& password, std::string const& email); + bool activateUser(std::string const& userName, std::string const& password, UserInfo const& userInfo, std::string const& confirmationCode); - static bool login(LoginErrorCode& errorCode, std::string const& userName, std::string const& password, UserInfo const& userInfo); - static bool logout(); - static void refreshLogin(); - static bool deleteUser(); - static bool resetPassword(std::string const& userName, std::string const& email); - static bool setNewPassword(std::string const& userName, std::string const& newPassword, std::string const& confirmationCode); + bool login(LoginErrorCode& errorCode, std::string const& userName, std::string const& password, UserInfo const& userInfo); + bool logout(); + void refreshLogin(); + bool deleteUser(); + bool resetPassword(std::string const& userName, std::string const& email); + bool setNewPassword(std::string const& userName, std::string const& newPassword, std::string const& confirmationCode); - static bool getNetworkResources(std::vector& result, bool withRetry); - static bool getUserList(std::vector& result, bool withRetry); - static bool getEmojiTypeByResourceId(std::unordered_map& result); - static bool getUserNamesForResourceAndEmojiType(std::set& result, std::string const& simId, int likeType); - static bool toggleReactToResource(std::string const& simId, int likeType); + bool getNetworkResources(std::vector& result, bool withRetry); + bool getUserList(std::vector& result, bool withRetry); + bool getEmojiTypeByResourceId(std::unordered_map& result); + bool getUserNamesForResourceAndEmojiType(std::set& result, std::string const& simId, int likeType); + bool toggleReactToResource(std::string const& simId, int likeType); - static bool uploadResource( + bool uploadResource( std::string& resourceId, std::string const& resourceName, std::string const& description, @@ -59,26 +60,26 @@ class NetworkService std::string const& statistics, NetworkResourceType resourceType, WorkspaceType workspaceType); - static bool replaceResource( + bool replaceResource( std::string const& resourceId, IntVector2D const& worldSize, int numParticles, std::string const& data, std::string const& settings, std::string const& statistics); - static bool downloadResource(std::string& mainData, std::string& auxiliaryData, std::string& statistics, std::string const& simId); - static void incDownloadCounter(std::string const& simId); - static bool editResource(std::string const& simId, std::string const& newName, std::string const& newDescription); - static bool moveResource(std::string const& simId, WorkspaceType targetWorkspace); - static bool deleteResource(std::string const& simId); + bool downloadResource(std::string& mainData, std::string& auxiliaryData, std::string& statistics, std::string const& simId); + void incDownloadCounter(std::string const& simId); + bool editResource(std::string const& simId, std::string const& newName, std::string const& newDescription); + bool moveResource(std::string const& simId, WorkspaceType targetWorkspace); + bool deleteResource(std::string const& simId); private: - static bool appendResourceData(std::string const& resourceId, std::string const& data, int chunkIndex); + bool appendResourceData(std::string const& resourceId, std::string const& data, int chunkIndex); - static std::string _serverAddress; - static std::optional _loggedInUserName; - static std::optional _password; - static std::optional _lastRefreshTime; + std::string _serverAddress; + std::optional _loggedInUserName; + std::optional _password; + std::optional _lastRefreshTime; struct ResourceData { @@ -86,5 +87,5 @@ class NetworkService std::string auxiliaryData; std::string statistics; }; - static Cache _downloadCache; + Cache _downloadCache; }; diff --git a/source/PersisterImpl/PersisterWorker.cpp b/source/PersisterImpl/PersisterWorker.cpp index 58ade6ebe..472f298c9 100644 --- a/source/PersisterImpl/PersisterWorker.cpp +++ b/source/PersisterImpl/PersisterWorker.cpp @@ -256,7 +256,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest auto const& requestData = request->getData(); LoginErrorCode errorCode; - if (!NetworkService::login(errorCode, requestData.userName, requestData.password, requestData.userInfo)) { + if (!NetworkService::get().login(errorCode, requestData.userName, requestData.password, requestData.userInfo)) { if (errorCode != LoginErrorCode_UnknownUser) { return std::make_shared<_PersisterRequestError>( request->getRequestId(), @@ -274,17 +274,17 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest { UnlockGuard unlockGuard(lock); - NetworkService::refreshLogin(); + NetworkService::get().refreshLogin(); GetNetworkResourcesResultData data; auto withRetry = true; - bool success = NetworkService::getNetworkResources(data.resourceTOs, withRetry); + bool success = NetworkService::get().getNetworkResources(data.resourceTOs, withRetry); if (success) { - success &= NetworkService::getUserList(data.userTOs, withRetry); + success &= NetworkService::get().getUserList(data.userTOs, withRetry); } - if (success && NetworkService::getLoggedInUserName()) { - success &= NetworkService::getEmojiTypeByResourceId(data.emojiTypeByResourceId); + if (success && NetworkService::get().getLoggedInUserName()) { + success &= NetworkService::get().getEmojiTypeByResourceId(data.emojiTypeByResourceId); } if (!success) { @@ -316,7 +316,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest } SerializedSimulation serializedSim; if (!cachedSimulation.has_value()) { - if (!NetworkService::downloadResource(serializedSim.mainData, serializedSim.auxiliaryData, serializedSim.statistics, requestData.resourceId)) { + if (!NetworkService::get().downloadResource(serializedSim.mainData, serializedSim.auxiliaryData, serializedSim.statistics, requestData.resourceId)) { return std::make_shared<_PersisterRequestError>( request->getRequestId(), request->getSenderInfo().senderId, PersisterErrorInfo{"Failed to download " + dataTypeString + "."}); } @@ -335,7 +335,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest } else { log(Priority::Important, "browser: get resource with id=" + requestData.resourceId + " from simulation cache"); std::swap(deserializedSimulation, *cachedSimulation); - NetworkService::incDownloadCounter(requestData.resourceId); + NetworkService::get().incDownloadCounter(requestData.resourceId); } resultData.resourceData.emplace(std::move(deserializedSimulation)); } else { @@ -416,7 +416,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest } std::string resourceId; - if (!NetworkService::uploadResource( + if (!NetworkService::get().uploadResource( resourceId, requestData.folderName + requestData.resourceWithoutFolderName, requestData.resourceDescription, @@ -503,7 +503,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest } } - if (!NetworkService::replaceResource(requestData.resourceId, worldSize, numObjects, mainData, settings, statistics)) { + if (!NetworkService::get().replaceResource(requestData.resourceId, worldSize, numObjects, mainData, settings, statistics)) { std::string dataTypeString = resourceType == NetworkResourceType_Simulation ? "simulation" : "genome"; return std::make_shared<_PersisterRequestError>( @@ -529,7 +529,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest GetUserNamesForEmojiResultData resultData; resultData.resourceId = requestData.resourceId; resultData.emojiType = requestData.emojiType; - if (!NetworkService::getUserNamesForResourceAndEmojiType(resultData.userNames, requestData.resourceId, requestData.emojiType)) { + if (!NetworkService::get().getUserNamesForResourceAndEmojiType(resultData.userNames, requestData.resourceId, requestData.emojiType)) { return std::make_shared<_PersisterRequestError>( request->getRequestId(), request->getSenderInfo().senderId, PersisterErrorInfo{"Could not load user names."}); } @@ -545,7 +545,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest auto const& requestData = request->getData(); - if (!NetworkService::deleteResource(requestData.resourceId)) { + if (!NetworkService::get().deleteResource(requestData.resourceId)) { return std::make_shared<_PersisterRequestError>( request->getRequestId(), request->getSenderInfo().senderId, PersisterErrorInfo{"Failed to delete item. Please try again later."}); }