diff options
Diffstat (limited to 'protocols/Weather/src')
-rw-r--r-- | protocols/Weather/src/proto.h | 8 | ||||
-rw-r--r-- | protocols/Weather/src/stdafx.h | 2 | ||||
-rw-r--r-- | protocols/Weather/src/weather_addstn.cpp | 2 | ||||
-rw-r--r-- | protocols/Weather/src/weather_update.cpp | 39 |
4 files changed, 11 insertions, 40 deletions
diff --git a/protocols/Weather/src/proto.h b/protocols/Weather/src/proto.h index 3a42f47e5d..271504f665 100644 --- a/protocols/Weather/src/proto.h +++ b/protocols/Weather/src/proto.h @@ -1,11 +1,5 @@ #pragma once -struct UPDATELIST -{ - MCONTACT hContact; - UPDATELIST *next; -}; - struct WEATHERINFO { MCONTACT hContact; @@ -191,7 +185,7 @@ class CWeatherProto : public PROTO<CWeatherProto> void __cdecl BasicSearchThread(void *); // update weather - UPDATELIST *UpdateListHead = nullptr, *UpdateListTail = nullptr; + std::vector<MCONTACT> m_updateList; // check if weather is currently updating bool m_bThreadRunning; diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h index ebfb15e6f6..583e564abc 100644 --- a/protocols/Weather/src/stdafx.h +++ b/protocols/Weather/src/stdafx.h @@ -31,6 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <richedit.h>
#include <malloc.h>
+#include <vector>
+
#include <newpluginapi.h>
#include <m_acc.h>
#include <m_avatars.h>
diff --git a/protocols/Weather/src/weather_addstn.cpp b/protocols/Weather/src/weather_addstn.cpp index 1dcf9004a9..0ad5e1bbc8 100644 --- a/protocols/Weather/src/weather_addstn.cpp +++ b/protocols/Weather/src/weather_addstn.cpp @@ -113,7 +113,7 @@ MCONTACT CWeatherProto::AddToList(int, PROTOSEARCHRESULT *psr) bool CWeatherProto::CheckSearch() { - if (UpdateListHead != nullptr) { + if (!m_updateList.empty()) { MessageBox(nullptr, TranslateT("Please try again after weather update is completed."), TranslateT("Weather Protocol"), MB_OK | MB_ICONERROR); return false; } diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp index 7c90f73fcf..d0bd575629 100644 --- a/protocols/Weather/src/weather_update.cpp +++ b/protocols/Weather/src/weather_update.cpp @@ -221,16 +221,8 @@ int CWeatherProto::UpdateWeather(MCONTACT hContact) void CWeatherProto::UpdateListAdd(MCONTACT hContact) { - UPDATELIST *newItem = (UPDATELIST*)mir_alloc(sizeof(UPDATELIST)); - newItem->hContact = hContact; - newItem->next = nullptr; - mir_cslock lck(m_csUpdate); - if (UpdateListTail == nullptr) - UpdateListHead = newItem; - else - UpdateListTail->next = newItem; - UpdateListTail = newItem; + m_updateList.push_back(hContact); } // get the first item from the update queue and remove it from the queue @@ -238,35 +230,19 @@ void CWeatherProto::UpdateListAdd(MCONTACT hContact) MCONTACT CWeatherProto::UpdateGetFirst() { mir_cslock lck(m_csUpdate); - if (UpdateListHead == nullptr) + if (m_updateList.empty()) return 0; - UPDATELIST *Item = UpdateListHead; - - MCONTACT hContact = Item->hContact; - UpdateListHead = Item->next; - mir_free(Item); - - if (UpdateListHead == nullptr) - UpdateListTail = nullptr; - + auto it = m_updateList.begin(); + MCONTACT hContact = *it; + m_updateList.erase(it); return hContact; } void CWeatherProto::DestroyUpdateList(void) { mir_cslock lck(m_csUpdate); - - // free the list one by one - UPDATELIST *temp = UpdateListHead; - while (temp != nullptr) { - UpdateListHead = temp->next; - mir_free(temp); - temp = UpdateListHead; - } - - // make sure the entire list is clear - UpdateListTail = nullptr; + m_updateList.clear(); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -283,7 +259,7 @@ void CWeatherProto::UpdateThread(void *) } // update weather by getting the first station from the queue until the queue is empty - while (UpdateListHead != nullptr && !Miranda_IsTerminated()) + while (!m_updateList.empty() && !Miranda_IsTerminated()) UpdateWeather(UpdateGetFirst()); // exit the update thread @@ -389,7 +365,6 @@ int CWeatherProto::GetWeatherData(MCONTACT hContact) if (Svc[0] == 0) return INVALID_SVC; uint16_t cond = NA; - char loc[256]; // download the html file from the internet wchar_t *szData = nullptr; |