-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueFilter.cpp
112 lines (104 loc) · 2.58 KB
/
QueueFilter.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
#include"QueueFilter.h"
#include "Inotify.h"
#include"main.h"
using namespace std;
#define MAX_SEARCH_LENGTH 10
QueueFilter::QueueFilter( )
{
}
Event QueueFilter::pop( )
{
boost::mutex::scoped_lock lock(queue_mutex);
Event event = que.back();
que.pop_back();
return event;
}
bool QueueFilter::empty( )
{
boost::mutex::scoped_lock lock(queue_mutex);
return que.empty();
}
int QueueFilter::push( Event event )
{
boost::mutex::scoped_lock lock(queue_mutex);
if( !filter(event) )
{
que.push_front(event);
return 1;
}
return 0;
}
int QueueFilter::filter( Event event )
{
int searchDistance = 0;
if( event->dir == true && event->operation == 0 )
{
std::deque<Event>::iterator i = que.begin();
string dirPath = event->path + "/"; //in case this path name is the prefix of other file name
while( i < que.end() )
{
if(((*i)->path).empty()){
++i;
continue;
}
string temp = ((*i)->path).substr(0, dirPath.length());
if( ((*i)->path).substr(0, dirPath.length()) == dirPath )
{
if( debug_level & SUB_CLASS )
{
cout << "erase now" << "\t" << (*i)->path << endl;
}
i = que.erase(i);
continue;
}
i++;
}
}
searchDistance = 0;
std::deque<Event>::iterator i = que.begin();
while( i < que.end() && searchDistance <= MAX_SEARCH_LENGTH )
{
if( (*i)->path == event->path )
{
(*i)->operation = event->operation;
break;
}
i++;
searchDistance++;
}
if( i != que.end() && searchDistance < MAX_SEARCH_LENGTH )
{
return 1;
}
return 0;
}
void QueueFilter::printdeque( )
{
boost::mutex::scoped_lock lock(queue_mutex);
int cre = 0;
int del = 0;
for( std::deque<Event>::iterator itrt = que.begin(); itrt < que.end(); itrt++ )
{
std::cout << "queue filter" << (*itrt)->path << "\t";
cout << (*itrt)->operation << endl;
if( (*itrt)->operation == 1 )
{
cre++;
}
if( (*itrt)->operation == 0 )
{
del++;
}
}
if( que.empty() )
{
cout << "empty Filter Queue" << endl;
}else
{
cout << "Queue Filter" << "\t";
cout << "amount: " << que.size() << "\t";
cout << "create: " << cre << "\t";
cout << "delete: " << del << "\t";
std::cout << endl << endl << "\t";
}
}