36 s =
new std::set<ScanResult *, ScanResultComperator>();
40 pthread_mutex_init(&
mutex, NULL);
51 std::set<ScanResult *, ScanResultComperator>::iterator it;
52 std::pair < std::set<ScanResult *, ScanResultComperator>::iterator,
bool> pair;
55 if (0 == cacheMaxSize) {
60 scr->
dev = stat->st_dev;
61 scr->
ino = stat->st_ino;
62 scr->
mtime = stat->st_mtime;
66 pthread_mutex_lock(&
mutex);
70 (*it)->left->right = (*it)->right;
71 (*it)->right->left = (*it)->left;
74 }
else while (
s->size() >= cacheMaxSize) {
79 (*it)->left->right = (*it)->right;
80 (*it)->right->left = (*it)->left;
87 pair =
s->insert(scr);
98 pthread_mutex_unlock(&
mutex);
105 pthread_mutex_lock(&
mutex);
106 std::set<ScanResult *, ScanResultComperator>::iterator pos;
107 for (pos =
s->begin(); pos !=
s->end(); ++pos) {
115 pthread_mutex_unlock(&
mutex);
125 std::set<ScanResult *, ScanResultComperator>::iterator it;
127 scr->
dev = stat->st_dev;
128 scr->
ino = stat->st_ino;
130 pthread_mutex_lock(&
mutex);
133 if (it ==
s->end()) {
139 if (scr->
mtime == stat->st_mtime) {
152 (*it)->left->right = (*it)->right;
153 (*it)->right->left = (*it)->left;
160 pthread_mutex_unlock(&
mutex);
169 std::set<ScanResult *, ScanResultComperator>::iterator it;
171 scr->
dev = stat->st_dev;
172 scr->
ino = stat->st_ino;
174 pthread_mutex_lock(&
mutex);
176 if (it !=
s->end()) {
178 (*it)->left->right = (*it)->right;
179 (*it)->right->left = (*it)->left;
183 pthread_mutex_unlock(&
mutex);
188 std::stringstream msg;
189 msg <<
"Cache size " <<
s->size() <<
190 ", cache hits " <<
hits <<
", cache misses " <<
misses <<
".";
192 pthread_mutex_destroy(&
mutex);
unsigned int response
Result of scan.
void remove(const struct stat *)
Remove scan result from cache.
std::set< ScanResult *, ScanResultComperator > * s
ScanResult * left
Left neighbour in double linked list.
ScanResult root
Root for double linked list.
time_t age
Time when this record entered the cache.
void clear()
Removes all entries from the cache.
Result of scanning a file for viruses.
Information, e.g. access scanning has started.
static void message(const enum Level, const std::string &)
Sends message.
void add(const struct stat *, const unsigned int)
Adds scan result to cache.
time_t mtime
Time of last modification.
unsigned long long misses
Number of cache misses.
Cache for virus scanning results.
dev_t dev
ID of device containing file.
ScanResult * right
Right neighbour in double linked list.
static const unsigned int CACHE_MISS
No matching element found in cache.
Environment * e
Environment.
Debugging information only to be shown in the console.
The environment holds variables that are shared by instances of multiple classes. ...
int get(const struct stat *)
Adds scan result to cache.
pthread_mutex_t mutex
Mutex used when reading from or writing to the cache.
unsigned long long hits
Number of cache hits.
unsigned int getCacheMaxSize()
Gets the maximum number of entries in the cache with scan results.