forked from NOVACProject/NOVACProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CombinerThread.cpp
95 lines (76 loc) · 2.75 KB
/
CombinerThread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "stdafx.h"
#include "NovacMasterProgram.h"
#include "CombinerThread.h"
#include <math.h>
// --------------------------------------------------------
// ----------------- CEvalLogFile -------------------------
// --------------------------------------------------------
CCombinerThread::CEvalLogFile::CEvalLogFile(){
}
CCombinerThread::CEvalLogFile::~CEvalLogFile(){
}
// --------------------------------------------------------
// --------------- CCombinerThread ------------------------
// --------------------------------------------------------
CCombinerThread::CCombinerThread()
{
}
CCombinerThread::~CCombinerThread()
{
m_evalLogs.RemoveAll();
}
BOOL CCombinerThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
void CCombinerThread::OnQuit(WPARAM wp, LPARAM lp){
m_evalLogs.RemoveAll();
}
/** Called when the message queue is empty */
BOOL CCombinerThread::OnIdle(LONG lCount){
return CWinThread::OnIdle(lCount);
}
BEGIN_MESSAGE_MAP(CCombinerThread, CWinThread)
END_MESSAGE_MAP()
// CCombinerThread message handlers
/** Inserts the given evaluation log into the correct position into the list. */
void CCombinerThread::InsertIntoList(const CString &evalLog, int volcanoIndex){
CEvalLogFile newLog;
// 1. Create a novel CEvalLogFile object to insert into the list
newLog.arrived.SetToNow();
newLog.fileName.Format(evalLog);
newLog.volcanoIndex = volcanoIndex;
newLog.matched = 0;
// 2. Insert the scan-result
m_evalLogs.AddHead(newLog);
}
/** Performs a cleaning of the list of evaluation-logs. Wind-speed
calculations can only be performed using two or more evaluation-logs
together. The files are stored in the list, waiting for matching log-files
to arrive. When long enough time has passed, the files are removed from
the list. */
void CCombinerThread::CleanEvalLogList(){
CDateTime now;
// 1. Get the time now;
now.SetToNow();
// 2. Go through the list and remove all items which are too old
POSITION pos = m_evalLogs.GetTailPosition();
while(pos != NULL){
// 2a. get a reference to the arrival-time
CDateTime &arrived = m_evalLogs.GetAt(pos).arrived;
// 2b. Calculate the amount of time that has elapsed since the file arrived
double secondsPassed = fabs(CDateTime::Difference(arrived, now));
// 2c. If the time is longer than the maximum allowed time, remove
// the rest of the list
if(secondsPassed > MAX_RESIDENCE_TIME){
m_evalLogs.GetPrev(pos);
m_evalLogs.RemoveTail();
}else{
// if this item has been less than 'MAX_RESIDENCE_TIME'
// in the list, then the previous items in the list
// have been there shorter time, no need to even look at them...
return;
}
}
}