From 4cb3383c4a1b18494055df80f0d3a1132edf0799 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 1 Dec 2019 01:19:51 +0800 Subject: [PATCH] Remove the unneeded manage memory option in request --- src/achievements/achievements_status.cpp | 2 +- src/addons/addons_manager.cpp | 2 +- src/config/hardware_stats.cpp | 2 +- src/network/protocols/server_lobby.cpp | 2 +- src/network/servers_manager.cpp | 5 ++--- src/online/http_request.cpp | 18 ++++++------------ src/online/http_request.hpp | 8 +++----- src/online/online_player_profile.cpp | 6 +++--- src/online/online_profile.cpp | 4 ++-- src/online/request.cpp | 6 ++---- src/online/request.hpp | 19 +------------------ src/online/request_manager.cpp | 3 +-- src/online/xml_request.cpp | 6 ++---- src/online/xml_request.hpp | 2 +- src/states_screens/dialogs/addons_loading.cpp | 2 +- src/states_screens/dialogs/addons_pack.cpp | 4 +--- .../dialogs/download_assets.cpp | 2 +- .../dialogs/ranking_callback.hpp | 2 +- 18 files changed, 31 insertions(+), 64 deletions(-) diff --git a/src/achievements/achievements_status.cpp b/src/achievements/achievements_status.cpp index 12240e4eb..e5bde1e9a 100644 --- a/src/achievements/achievements_status.cpp +++ b/src/achievements/achievements_status.cpp @@ -370,7 +370,7 @@ void AchievementsStatus::sync(const std::vector & achieved_ids) ids = ids.substr(0, ids.size() - 1); // delete the last "," in the string Log::info("Achievements", "Synching achievement %s to server.", ids.c_str()); - auto request = std::make_shared(true, 2); + auto request = std::make_shared(/*priority*/2); PlayerManager::setUserDetails(request, "achieving"); request->addParameter("achievementid", ids); request->queue(); diff --git a/src/addons/addons_manager.cpp b/src/addons/addons_manager.cpp index aa029a53c..78e82d986 100644 --- a/src/addons/addons_manager.cpp +++ b/src/addons/addons_manager.cpp @@ -396,7 +396,7 @@ void AddonsManager::downloadIcons() public: IconRequest(const std::string &filename, const std::string &url, - Addon *addon ) : HTTPRequest(filename, true, 1) + Addon *addon ) : HTTPRequest(filename,/*priority*/1) { m_addon = addon; setURL(url); } // IconRequest diff --git a/src/config/hardware_stats.cpp b/src/config/hardware_stats.cpp index b8e7712e7..9389e6066 100644 --- a/src/config/hardware_stats.cpp +++ b/src/config/hardware_stats.cpp @@ -370,7 +370,7 @@ void reportHardwareStats() /** Version number of the hw report. */ int m_version; public: - HWReportRequest(int version) : Online::HTTPRequest(/*manage memory*/true, 1) + HWReportRequest(int version) : Online::HTTPRequest(/*priority*/1) , m_version(version) {} // -------------------------------------------------------------------- diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index d93b8df1d..777257862 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -2461,7 +2461,7 @@ void ServerLobby::checkIncomingConnectionRequests() } public: PollServerRequest(std::shared_ptr sl) - : XMLRequest(true), m_server_lobby(sl) + : XMLRequest(), m_server_lobby(sl) { m_disable_sending_log = true; } diff --git a/src/network/servers_manager.cpp b/src/network/servers_manager.cpp index 8e53b3437..d62555918 100644 --- a/src/network/servers_manager.cpp +++ b/src/network/servers_manager.cpp @@ -85,8 +85,7 @@ std::shared_ptr ServersManager::getWANRefreshRequest() const class WANRefreshRequest : public Online::XMLRequest { public: - WANRefreshRequest() : Online::XMLRequest(/*manage_memory*/true, - /*priority*/100) {} + WANRefreshRequest() : Online::XMLRequest(/*priority*/100) {} // -------------------------------------------------------------------- virtual void afterOperation() OVERRIDE { @@ -120,7 +119,7 @@ std::shared_ptr ServersManager::getLANRefreshRequest() const public: /** High priority for this request. */ - LANRefreshRequest() : XMLRequest(true, 100) {m_success = false;} + LANRefreshRequest() : XMLRequest(/*priority*/100) {m_success = false;} // -------------------------------------------------------------------- virtual ~LANRefreshRequest() {} // -------------------------------------------------------------------- diff --git a/src/online/http_request.cpp b/src/online/http_request.cpp index 475ab693a..b339d885b 100644 --- a/src/online/http_request.cpp +++ b/src/online/http_request.cpp @@ -38,13 +38,11 @@ namespace Online /** Creates a HTTP(S) request that will have a raw string as result. (Can * of course be used if the result doesn't matter.) - * \param manage_memory whether or not the RequestManager should take care of - * deleting the object after all callbacks have been done. * \param priority by what priority should the RequestManager take care of * this request. */ - HTTPRequest::HTTPRequest(bool manage_memory, int priority) - : Request(manage_memory, priority, 0) + HTTPRequest::HTTPRequest(int priority) + : Request(priority, 0) { init(); } // HTTPRequest @@ -52,14 +50,11 @@ namespace Online // ------------------------------------------------------------------------ /** This constructor configures this request to save the data in a flie. * \param filename Name of the file to save the data to. - * \param manage_memory whether or not the RequestManager should take care of - * deleting the object after all callbacks have been done. * \param priority by what priority should the RequestManager take care of * this request. */ - HTTPRequest::HTTPRequest(const std::string &filename, bool manage_memory, - int priority) - : Request(manage_memory, priority, 0) + HTTPRequest::HTTPRequest(const std::string &filename, int priority) + : Request(priority, 0) { // A http request should not even be created when internet is disabled assert(UserConfigParams::m_internet_status == @@ -74,9 +69,8 @@ namespace Online /** Char * needs a separate constructor, otherwise it will be considered * to be the no-filename constructor (char* -> bool). */ - HTTPRequest::HTTPRequest(const char* const filename, bool manage_memory, - int priority) - : Request(manage_memory, priority, 0) + HTTPRequest::HTTPRequest(const char* const filename, int priority) + : Request(priority, 0) { // A http request should not even be created when internet is disabled assert(UserConfigParams::m_internet_status == diff --git a/src/online/http_request.hpp b/src/online/http_request.hpp index c1e66fa56..699e5906e 100644 --- a/src/online/http_request.hpp +++ b/src/online/http_request.hpp @@ -91,11 +91,9 @@ namespace Online void init(); public : - HTTPRequest(bool manage_memory = false, int priority = 1); - HTTPRequest(const std::string &filename, bool manage_memory = false, - int priority = 1); - HTTPRequest(const char * const filename, bool manage_memory = false, - int priority = 1); + HTTPRequest(int priority = 1); + HTTPRequest(const std::string &filename, int priority = 1); + HTTPRequest(const char * const filename, int priority = 1); virtual ~HTTPRequest() { if (m_http_header) diff --git a/src/online/online_player_profile.cpp b/src/online/online_player_profile.cpp index b6ca14239..cdcb5bcb2 100644 --- a/src/online/online_player_profile.cpp +++ b/src/online/online_player_profile.cpp @@ -54,7 +54,7 @@ namespace Online virtual void callback(); public: SignInRequest() - : XMLRequest(true/*manage_memory*/, /*priority*/10) {} + : XMLRequest(/*priority*/10) {} }; // SignInRequest // ---------------------------------------------------------------- @@ -298,7 +298,7 @@ namespace Online * happens before a following logout. */ SignOutRequest(PlayerProfile *player) - : XMLRequest(true,/*priority*/RequestManager::HTTP_MAX_PRIORITY) + : XMLRequest(/*priority*/RequestManager::HTTP_MAX_PRIORITY) { m_player = player; setAbortable(false); @@ -366,7 +366,7 @@ namespace Online // ------------------------------------------------------------------------ PrivateRequest::PollRequest::PollRequest() - : XMLRequest(true) + : XMLRequest() { } // PollRequest diff --git a/src/online/online_profile.cpp b/src/online/online_profile.cpp index d8be45c3d..454b072b7 100644 --- a/src/online/online_profile.cpp +++ b/src/online/online_profile.cpp @@ -142,7 +142,7 @@ void OnlineProfile::fetchAchievements() class AchievementsRequest : public XMLRequest { public: - AchievementsRequest() : XMLRequest(true, true) {} + AchievementsRequest() : XMLRequest() {} virtual void callback() { uint32_t user_id = 0; @@ -195,7 +195,7 @@ void OnlineProfile::fetchFriends() class FriendsListRequest : public XMLRequest { public: - FriendsListRequest() : XMLRequest(true, true) {} + FriendsListRequest() : XMLRequest() {} virtual void callback() { uint32_t user_id = 0; diff --git a/src/online/request.cpp b/src/online/request.cpp index 0b91fbafd..885bf65ac 100644 --- a/src/online/request.cpp +++ b/src/online/request.cpp @@ -30,15 +30,13 @@ namespace Online // ======================================================================== /** * Creates a request that can be handled by the RequestManager - * \param manage_memory whether or not the RequestManager should take care of - * deleting the object after all callbacks have been done * \param priority by what priority should the RequestManager take care of * this request * \param type indicates whether the request has a special task for the * RequestManager */ - Request::Request(bool manage_memory, int priority, int type) - : m_type(type), m_manage_memory(manage_memory), m_priority(priority) + Request::Request(int priority, int type) + : m_type(type), m_priority(priority) { m_cancel.setAtomic(false); m_state.setAtomic(S_PREPARING); diff --git a/src/online/request.hpp b/src/online/request.hpp index d7a071ace..826019e8c 100644 --- a/src/online/request.hpp +++ b/src/online/request.hpp @@ -64,12 +64,6 @@ namespace Online /** Type of the request. Has 0 as default value. */ const int m_type; - /** True if the memory for this Request should be managed by - * http connector (i.e. this object is freed once the request - * is handled). Otherwise the memory is not freed, so it must - * be freed by the calling function. */ - bool m_manage_memory; - /** The priority of this request. The higher the value the more important this request is. */ const int m_priority; @@ -130,7 +124,7 @@ namespace Online RT_QUIT = 1 }; - Request(bool manage_memory, int priority, int type); + Request(int priority, int type); virtual ~Request() {} void execute(); void executeNow(); @@ -144,17 +138,6 @@ namespace Online /** Returns the type of the request. */ int getType() const { return m_type; } - // -------------------------------------------------------------------- - /** Returns if the memory for this object should be managed by - * by network_http (i.e. freed once the request is handled). */ - bool manageMemory() const { return m_manage_memory; } - - // -------------------------------------------------------------------- - /** Sets the memory management flag of this request. This function - * must only be called by the main thread, since it is only tested by - * the main thread. */ - void setManageMemory(bool m) { m_manage_memory = m; } - // -------------------------------------------------------------------- /** Returns the priority of this request. */ int getPriority() const { return m_priority; } diff --git a/src/online/request_manager.cpp b/src/online/request_manager.cpp index ac8221f55..dd594366c 100644 --- a/src/online/request_manager.cpp +++ b/src/online/request_manager.cpp @@ -145,8 +145,7 @@ namespace Online // quit request). // Required for std::make_shared as it takes reference int priority = HTTP_MAX_PRIORITY; - auto quit = std::make_shared(true, priority, - Request::RT_QUIT); + auto quit = std::make_shared(priority, Request::RT_QUIT); quit->setAbortable(false); addRequest(quit); diff --git a/src/online/xml_request.cpp b/src/online/xml_request.cpp index 1a626e67f..fb1080ca5 100644 --- a/src/online/xml_request.cpp +++ b/src/online/xml_request.cpp @@ -34,13 +34,11 @@ namespace Online { /** Creates a HTTP(S) request that will automatically parse the answer into * a XML structure. - * \param manage_memory whether or not the RequestManager should take care of - * deleting the object after all callbacks have been done. * \param priority by what priority should the RequestManager take care of * this request. */ - XMLRequest::XMLRequest(bool manage_memory, int priority) - : HTTPRequest(manage_memory, priority) + XMLRequest::XMLRequest(int priority) + : HTTPRequest(priority) { m_info = ""; m_success = false; diff --git a/src/online/xml_request.hpp b/src/online/xml_request.hpp index 984232952..b2b5b81d8 100644 --- a/src/online/xml_request.hpp +++ b/src/online/xml_request.hpp @@ -54,7 +54,7 @@ namespace Online virtual void afterOperation() OVERRIDE; public : - XMLRequest(bool manage_memory = false, int priority = 1); + XMLRequest(int priority = 1); virtual ~XMLRequest(); // ------------------------------------------------------------------------ diff --git a/src/states_screens/dialogs/addons_loading.cpp b/src/states_screens/dialogs/addons_loading.cpp index 1ae0d37cf..7a8391af9 100644 --- a/src/states_screens/dialogs/addons_loading.cpp +++ b/src/states_screens/dialogs/addons_loading.cpp @@ -345,7 +345,7 @@ void AddonsLoading::startDownload() std::string save = "tmp/" + StringUtils::getBasename(m_addon.getZipFileName()); m_download_request = std::make_shared( - save, /*manage mem*/false, /*priority*/5); + save, /*priority*/5); m_download_request->setURL(m_addon.getZipFileName()); m_download_request->queue(); #endif diff --git a/src/states_screens/dialogs/addons_pack.cpp b/src/states_screens/dialogs/addons_pack.cpp index 5490e644b..88fef7fbf 100644 --- a/src/states_screens/dialogs/addons_pack.cpp +++ b/src/states_screens/dialogs/addons_pack.cpp @@ -62,8 +62,7 @@ private: } public: AddonsPackRequest(const std::string& url) - : HTTPRequest(StringUtils::getBasename(url), /*manage mem*/false, - /*priority*/5) + : HTTPRequest(StringUtils::getBasename(url), /*priority*/5) { m_extraction_error = true; if (url.find("https://") != std::string::npos || @@ -166,7 +165,6 @@ void AddonsPack::onUpdate(float delta) { // Avoid displaying '-100%' in case of an error. m_progress->setVisible(false); - m_download_request->setManageMemory(true); dismiss(); new MessageDialog(_("Sorry, downloading the add-on failed")); return; diff --git a/src/states_screens/dialogs/download_assets.cpp b/src/states_screens/dialogs/download_assets.cpp index b3e949942..6766db97f 100644 --- a/src/states_screens/dialogs/download_assets.cpp +++ b/src/states_screens/dialogs/download_assets.cpp @@ -49,7 +49,7 @@ private: } public: DownloadAssetsRequest() - : HTTPRequest("stk-assets.zip", /*manage mem*/false, /*priority*/5) + : HTTPRequest("stk-assets.zip", /*priority*/5) { m_extraction_error = true; std::string download_url = stk_config->m_assets_download_url; diff --git a/src/states_screens/dialogs/ranking_callback.hpp b/src/states_screens/dialogs/ranking_callback.hpp index 8e9dc77f3..b9f203d4d 100644 --- a/src/states_screens/dialogs/ranking_callback.hpp +++ b/src/states_screens/dialogs/ranking_callback.hpp @@ -81,7 +81,7 @@ protected: uint32_t online_id, GUIEngine::LabelWidget* info, std::shared_ptr done) - : XMLRequest(true) + : XMLRequest() { m_name = name; m_info = info;