diff options
author | Tobias Weimer <wishmaster51@googlemail.com> | 2016-04-05 18:55:38 +0000 |
---|---|---|
committer | Tobias Weimer <wishmaster51@googlemail.com> | 2016-04-05 18:55:38 +0000 |
commit | ab2852015641c9aa9aa2588fb21617e31b7da546 (patch) | |
tree | d364084fadc2ef4b3787b61695c8323ecf0a0214 /plugins/Weather/src/weather_update.cpp | |
parent | ce08c537a294e306a01981f3f02c4757cd130c92 (diff) |
Weather: - cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@16589 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Weather/src/weather_update.cpp')
-rw-r--r-- | plugins/Weather/src/weather_update.cpp | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp index b2d2928896..be95d9e56e 100644 --- a/plugins/Weather/src/weather_update.cpp +++ b/plugins/Weather/src/weather_update.cpp @@ -26,12 +26,10 @@ menu items). #include "stdafx.h"
-UPDATELIST *UpdateListHead;
-UPDATELIST *UpdateListTail;
-
+UPDATELIST *UpdateListHead, *UpdateListTail;
//============ RETRIEVE NEW WEATHER ============
-
+//
// retrieve weather info and display / log them
// hContact = current contact
int UpdateWeather(MCONTACT hContact)
@@ -219,7 +217,7 @@ int UpdateWeather(MCONTACT hContact) }
//============ UPDATE LIST ============
-
+//
// a linked list queue for updating weather station
// this function add a weather contact to the end of queue for update
// hContact = current contact
@@ -279,8 +277,30 @@ void DestroyUpdateList(void) ReleaseMutex(hUpdateMutex);
}
-//============ UPDATE WEATHER ============
+// update all weather thread
+// this thread update each weather station from the queue
+static void UpdateThreadProc(void *)
+{
+ WaitForSingleObject(hUpdateMutex, INFINITE);
+ if (ThreadRunning) {
+ ReleaseMutex(hUpdateMutex);
+ return;
+ }
+ ThreadRunning = TRUE; // prevent 2 instance of this thread running
+ ReleaseMutex(hUpdateMutex);
+
+ // update weather by getting the first station from the queue until the queue is empty
+ while (UpdateListHead != NULL && !Miranda_Terminated())
+ UpdateWeather(UpdateGetFirst());
+
+ NetlibHttpDisconnect();
+
+ // exit the update thread
+ ThreadRunning = FALSE;
+}
+//============ UPDATE WEATHER ============
+//
// update all weather station
// AutoUpdate = true if it is from automatic update using timer
// false if it is from update by clicking the main menu
@@ -290,14 +310,14 @@ void UpdateAll(BOOL AutoUpdate, BOOL RemoveData) for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME))
if (!db_get_b(hContact, WEATHERPROTONAME, "AutoUpdate", FALSE) || !AutoUpdate) {
if (RemoveData)
- DBDataManage((MCONTACT)hContact, WDBM_REMOVE, 0, 0);
+ DBDataManage(hContact, WDBM_REMOVE, 0, 0);
UpdateListAdd(hContact);
}
// if it is not updating, then start the update thread process
// if it is updating, the stations just added to the queue will get updated by the already-running process
if (!ThreadRunning)
- mir_forkthread(UpdateThreadProc, NULL);
+ mir_forkthread(UpdateThreadProc);
}
// update a single station
@@ -312,7 +332,7 @@ INT_PTR UpdateSingleStation(WPARAM wParam, LPARAM) // if it is updating, the stations just added to the queue will get
// updated by the already-running process
if (!ThreadRunning)
- mir_forkthread(UpdateThreadProc, NULL);
+ mir_forkthread(UpdateThreadProc);
}
return 0;
@@ -330,34 +350,12 @@ INT_PTR UpdateSingleRemove(WPARAM wParam, LPARAM) // if it is not updating, then start the update thread process
// if it is updating, the stations just added to the queue will get updated by the already-running process
if (!ThreadRunning)
- mir_forkthread(UpdateThreadProc, NULL);
+ mir_forkthread(UpdateThreadProc);
}
return 0;
}
-// update all weather thread
-// this thread update each weather station from the queue
-void UpdateThreadProc(LPVOID)
-{
- WaitForSingleObject(hUpdateMutex, INFINITE);
- if (ThreadRunning) {
- ReleaseMutex(hUpdateMutex);
- return;
- }
- ThreadRunning = TRUE; // prevent 2 instance of this thread running
- ReleaseMutex(hUpdateMutex);
-
- // update weather by getting the first station from the queue until the queue is empty
- while (UpdateListHead != NULL && !Miranda_Terminated())
- UpdateWeather(UpdateGetFirst());
-
- NetlibHttpDisconnect();
-
- // exit the update thread
- ThreadRunning = FALSE;
-}
-
// the "Update All" menu item in main menu
INT_PTR UpdateAllInfo(WPARAM, LPARAM)
{
@@ -375,12 +373,12 @@ INT_PTR UpdateAllRemove(WPARAM, LPARAM) }
//============ GETTING WEATHER DATA ============
-
+//
// getting weather data and save them into the database
// hContact = the contact to get the data
int GetWeatherData(MCONTACT hContact)
{
- // get eacnh part of the id's
+ // get each part of the id's
TCHAR id[256];
GetStationID(hContact, id, _countof(id));
@@ -585,7 +583,7 @@ int GetWeatherData(MCONTACT hContact) }
//============ UPDATE TIMERS ============
-
+//
// main auto-update timer
void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
{
|