-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (51 loc) · 1.68 KB
/
main.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
#include <iostream>
#include <vector>
#include <thread>
#include <mutex>
#include "include/httptools.h"
#include "include/configuraton.h"
std::mutex access_mutex;
void processUrl(std::string url)
{
HttpTools* httpTools = new HttpTools();
//std::string requestStatusCode {""};
std::string html = httpTools->getHTML(url);
std::cout << "response status code -\t"
<< httpTools->getLastResponseStatusCode() << "\n";
//std::cout << html << "\n";
std::string cleanedHtml = httpTools->getCleanedText(html);
//split in words:
std::vector<std::string> words = httpTools->getNormalisedWordsEng(cleanedHtml);
//printing vector:
//httpTools->printVector(words);
//After insertion to SQL:
//ToDo: place to SQL;
words.clear();
}
int main()
{
std::cout << "Search engine 1.0.1 by oldscripter\n";
std::vector<std::thread> urlProcessingThreads;
//Read configuration:
Configuration::getInstance();
//Start new thread"
std::string url {""};
std::forward_list<std::string> urls = *Configuration::getInstance()->getStartUrlSet();
for (auto url : urls)
{
std::thread urlProcessing (processUrl, url);
std::cout << urlProcessing.get_id() << ": thread is started.\n";
access_mutex.lock();
urlProcessingThreads.push_back(std::move(urlProcessing));
std::cout << urlProcessing.get_id() << ": thread is pushed to threads list.\n";
access_mutex.unlock();
}
access_mutex.lock();
for (std::thread& t : urlProcessingThreads)
{
std::cout << t.get_id() << ": is finishing\n";
if (t.joinable()) t.join();
}
access_mutex.unlock();
return 0;
}