-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathCSyncQueue.cpp
148 lines (133 loc) · 3.81 KB
/
CSyncQueue.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "CSyncQueue.h"
#include <windows.h>
CSyncQueue::CSyncQueue()
{
InitializeCriticalSection(&this->cSection);
qwQueueFilesizeSum = 0;
qwNewFileAcc = 0;
bThreadDone = true;
bThreadSuspended = false;
dwCountOK = dwCountNotOK = dwCountNoCrcFound = dwCountNotFound = dwCountErrors = dwCountTotal = dwCountDone = 0;
}
CSyncQueue::~CSyncQueue()
{
clearQueue();
clearList();
DeleteCriticalSection(&this->cSection);
}
void CSyncQueue::addToList(lFILEINFO *fInfoGroup)
{
EnterCriticalSection(&this->cSection);
doneList.push_back(fInfoGroup);
LeaveCriticalSection(&this->cSection);
}
void CSyncQueue::deleteFromListById(int i)
{
list<lFILEINFO*>::iterator it;
int id;
EnterCriticalSection(&this->cSection);
for(id=0,it = doneList.begin();it!=doneList.end();id++,it++)
if(id==i) {
list<FILEINFO>::iterator itr;
for(itr = (*it)->fInfos.begin();itr!=(*it)->fInfos.end();itr++) {
adjustErrorCounters(&(*itr),-1);
}
dwCountTotal -= (DWORD)(*it)->fInfos.size();
doneList.erase(it);
break;
}
LeaveCriticalSection(&this->cSection);
}
void CSyncQueue::deleteFromList(lFILEINFO *rList)
{
EnterCriticalSection(&this->cSection);
doneList.remove(rList);
list<FILEINFO>::iterator it;
for(it = rList->fInfos.begin();it!=rList->fInfos.end();it++) {
adjustErrorCounters(&(*it),-1);
}
dwCountTotal -= (DWORD)rList->fInfos.size();
LeaveCriticalSection(&this->cSection);
}
void CSyncQueue::pushQueue(lFILEINFO *fInfoGroup)
{
EnterCriticalSection(&this->cSection);
workQueue.push(fInfoGroup);
qwQueueFilesizeSum += fInfoGroup->qwFilesizeSum;
qwNewFileAcc += fInfoGroup->qwFilesizeSum;
dwCountTotal += (DWORD)fInfoGroup->fInfos.size();
LeaveCriticalSection(&this->cSection);
}
lFILEINFO *CSyncQueue::popQueue()
{
lFILEINFO *ret=NULL;
EnterCriticalSection(&this->cSection);
if(!workQueue.empty()) {
ret = workQueue.front();
workQueue.pop();
qwQueueFilesizeSum -= ret->qwFilesizeSum;
}
LeaveCriticalSection(&this->cSection);
return ret;
}
bool CSyncQueue::isQueueEmpty()
{
return workQueue.empty();
}
void CSyncQueue::clearList()
{
EnterCriticalSection(&this->cSection);
for(list<lFILEINFO*>::iterator it=doneList.begin();it!=doneList.end();it++)
delete (*it);
doneList.clear();
dwCountOK = dwCountNotOK = dwCountNoCrcFound = dwCountNotFound = dwCountErrors = dwCountTotal = dwCountDone = 0;
LeaveCriticalSection(&this->cSection);
}
void CSyncQueue::clearQueue()
{
EnterCriticalSection(&this->cSection);
while(!workQueue.empty()) {
dwCountTotal -= (DWORD)workQueue.front()->fInfos.size();
delete workQueue.front();
workQueue.pop();
}
LeaveCriticalSection(&this->cSection);
}
list<lFILEINFO*> *CSyncQueue::getDoneList()
{
EnterCriticalSection(&this->cSection);
return &doneList;
}
void CSyncQueue::releaseDoneList()
{
LeaveCriticalSection(&this->cSection);
}
void CSyncQueue::setFileAccForCalc()
{
EnterCriticalSection(&this->cSection);
qwNewFileAcc = qwQueueFilesizeSum;
LeaveCriticalSection(&this->cSection);
}
void CSyncQueue::adjustErrorCounters(FILEINFO *pFileinfo, DWORD amount)
{
switch(pFileinfo->status) {
case STATUS_OK:
dwCountOK += amount;
break;
case STATUS_NOT_OK:
dwCountNotOK += amount;
break;
case STATUS_NO_CRC:
dwCountNoCrcFound += amount;
break;
case STATUS_ERROR:
if(pFileinfo->dwError == ERROR_FILE_NOT_FOUND || pFileinfo->dwError == ERROR_PATH_NOT_FOUND)
dwCountNotFound += amount;
else
dwCountErrors += amount;
break;
default: dwCountNoCrcFound += amount;
}
dwCountDone += amount;
}
CSyncQueue SyncQueue;