Remove the unneeded manage memory option in request

This commit is contained in:
Benau 2019-12-01 01:19:51 +08:00
parent 89d35f09fa
commit 4cb3383c4a
18 changed files with 31 additions and 64 deletions

View File

@ -370,7 +370,7 @@ void AchievementsStatus::sync(const std::vector<uint32_t> & 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<Online::HTTPRequest>(true, 2);
auto request = std::make_shared<Online::HTTPRequest>(/*priority*/2);
PlayerManager::setUserDetails(request, "achieving");
request->addParameter("achievementid", ids);
request->queue();

View File

@ -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

View File

@ -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)
{}
// --------------------------------------------------------------------

View File

@ -2461,7 +2461,7 @@ void ServerLobby::checkIncomingConnectionRequests()
}
public:
PollServerRequest(std::shared_ptr<ServerLobby> sl)
: XMLRequest(true), m_server_lobby(sl)
: XMLRequest(), m_server_lobby(sl)
{
m_disable_sending_log = true;
}

View File

@ -85,8 +85,7 @@ std::shared_ptr<Online::XMLRequest> 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<Online::XMLRequest> 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() {}
// --------------------------------------------------------------------

View File

@ -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 ==

View File

@ -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)

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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; }

View File

@ -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<Request>(true, priority,
Request::RT_QUIT);
auto quit = std::make_shared<Request>(priority, Request::RT_QUIT);
quit->setAbortable(false);
addRequest(quit);

View File

@ -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;

View File

@ -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();
// ------------------------------------------------------------------------

View File

@ -345,7 +345,7 @@ void AddonsLoading::startDownload()
std::string save = "tmp/"
+ StringUtils::getBasename(m_addon.getZipFileName());
m_download_request = std::make_shared<Online::HTTPRequest>(
save, /*manage mem*/false, /*priority*/5);
save, /*priority*/5);
m_download_request->setURL(m_addon.getZipFileName());
m_download_request->queue();
#endif

View File

@ -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;

View File

@ -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;

View File

@ -81,7 +81,7 @@ protected:
uint32_t online_id,
GUIEngine::LabelWidget* info,
std::shared_ptr<bool> done)
: XMLRequest(true)
: XMLRequest()
{
m_name = name;
m_info = info;