From 49f7160974f661c7e3350f971bf400bb0ed49d04 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 5 Sep 2020 17:18:23 +1000 Subject: [PATCH] Http_GetCurrent only returns request ID --- src/Http.c | 13 ++++--------- src/Http.h | 2 +- src/LScreens.c | 11 +++++------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Http.c b/src/Http.c index f612616a1..35b44fa58 100644 --- a/src/Http.c +++ b/src/Http.c @@ -1054,24 +1054,19 @@ cc_bool Http_GetResult(int reqID, struct HttpRequest* item) { return i >= 0; } -cc_bool Http_GetCurrent(struct HttpRequest* request, int* progress) { +cc_bool Http_GetCurrent(int* reqID, int* progress) { Mutex_Lock(curRequestMutex); { - *request = http_curRequest; + *reqID = http_curRequest.id; *progress = http_curProgress; } Mutex_Unlock(curRequestMutex); - return request->id != 0; + return *reqID != 0; } int Http_CheckProgress(int reqID) { int curReqID, progress; - Mutex_Lock(curRequestMutex); - { - curReqID = http_curRequest.id; - progress = http_curProgress; - } - Mutex_Unlock(curRequestMutex); + Http_GetCurrent(&curReqID, &progress); if (reqID != curReqID) progress = HTTP_PROGRESS_NOT_WORKING_ON; return progress; diff --git a/src/Http.h b/src/Http.h index f330c72e9..1b235f69b 100644 --- a/src/Http.h +++ b/src/Http.h @@ -72,7 +72,7 @@ cc_bool Http_DescribeError(cc_result res, String* dst); /* (Data may still be non NULL even on error, e.g. on a http 404 error) */ cc_bool Http_GetResult(int reqID, struct HttpRequest* item); /* Retrieves information about the request currently being processed. */ -cc_bool Http_GetCurrent(struct HttpRequest* request, int* progress); +cc_bool Http_GetCurrent(int* reqID, int* progress); /* Retrieves information about the download progress of the given request. */ /* NOTE: This may return HTTP_PROGRESS_NOT_WORKING_ON if download has finished. */ /* As such, this method should always be paired with a call to Http_GetResult. */ diff --git a/src/LScreens.c b/src/LScreens.c index 4a196872d..b08888a63 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -1098,13 +1098,13 @@ static void ResourcesScreen_SetStatus(const String* str) { LWidget_Draw(w); } -static void ResourcesScreen_UpdateStatus(struct HttpRequest* req) { +static void ResourcesScreen_UpdateStatus(int reqID) { String str; char strBuffer[STRING_SIZE]; const char* name; struct LLabel* w = &ResourcesScreen_Instance.lblStatus; int count; - name = Fetcher_RequestName(req->id); + name = Fetcher_RequestName(reqID); if (!name) return; String_InitArray(str, strBuffer); @@ -1116,11 +1116,10 @@ static void ResourcesScreen_UpdateStatus(struct HttpRequest* req) { } static void ResourcesScreen_UpdateProgress(struct ResourcesScreen* s) { - struct HttpRequest req; - int progress; + int reqID, progress; - if (!Http_GetCurrent(&req, &progress)) return; - ResourcesScreen_UpdateStatus(&req); + if (!Http_GetCurrent(&reqID, &progress)) return; + ResourcesScreen_UpdateStatus(reqID); /* making request still, haven't started download yet */ if (progress < 0 || progress > 100) return;