-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThreadManager.h
70 lines (56 loc) · 2.1 KB
/
ThreadManager.h
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
#ifndef THREADMANAGER_H
#define THREADMANAGER_H
#include "Crawler.h"
#include "CurlThread.h"
#include "SearcherThread.h"
#include "ThreadSafeQueue.h"
#include "ThreadSafeSet.h"
#include "CurlInteractionStructs.h"
#include <atomic>
#include <iostream>
#include <queue>
#include <string>
#include <thread>
#include <unordered_set>
class ThreadManager {
public:
/**
* ThreadManager constructor
*
* The construction of this object automatically initiates the crawling and searching process.
* This process manages all threads and waits for the user to submit a '\n' input before exiting.
*
* @param iQueue the initial crawler queue.
* @param eDomains the domains excluded from both the crawler and the searcher.
*/
ThreadManager(ThreadSafeQueue<std::string>* iQueue, std::unordered_set<std::string> eDomains);
private:
Config config;
TermMatcher validator;
curlIO crawlerCurlIO;
CurlThread crawlerCurl;
std::thread crawlerCurlThread;
ThreadSafeQueue<std::string> crawlerInitialQueue;
std::thread crawlerThread;
Crawler crawler;
curlIO searcherCurlIO;
CurlThread searcherCurl;
std::thread searcherCurlThread;
SearcherThread searcher;
std::thread searcherThread;
ThreadSafeQueue<std::string> extractedDomains;
ThreadSafeSet<std::string> checkedDomains;
std::unordered_set<std::string> searchTerms;
std::unordered_set<std::string> excludedDomains;
std::atomic<int> killSwitch;
/**
* verboseOutputThread contains logic for verbose output.
*
* This output prints the input and output queues for the crawler's CURL thread and
* the searcher's CURL thread. The output is written every 100ms until the kill switch is thrown.
*
* @param verbose the killswitch for verbose output
*/
void verboseOutputThread(std::atomic<bool>* verbose);
};
#endif