-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.h
More file actions
71 lines (46 loc) · 1.3 KB
/
Task.h
File metadata and controls
71 lines (46 loc) · 1.3 KB
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
/*
* Copyright (C) 2021 Ilya Entin
*/
#pragma once
#include <atomic>
#include <future>
#include <memory>
#include <tuple>
#include <boost/core/noncopyable.hpp>
#include "Header.h"
using SIZETUPLE = std::tuple<unsigned, unsigned>;
using Response = std::vector<std::string>;
using PreprocessRequest = SIZETUPLE (*)(std::string_view);
using ServerWeakPtr = std::weak_ptr<class Server>;
struct Request {
Request() = default;
~Request() = default;
Request& operator=(std::string_view value) {
_value = value;
return *this;
}
SIZETUPLE _sizeKey;
std::string_view _value;
};
class Task : private boost::noncopyable {
std::vector<Request> _requests;
std::size_t _size = 0;
std::vector<unsigned> _sortedIndices;
Response _response;
std::promise<void> _promise;
std::atomic<unsigned> _index = 0;
bool _diagnostics;
ServerWeakPtr _server;
public:
explicit Task (ServerWeakPtr server = ServerWeakPtr());
~Task() = default;
const Response& getResponse() const { return _response; }
void update(const HEADER& header, std::string_view request);
void sortIndices();
void resetIndex() { _index = 0; }
std::promise<void>& getPromise() { return _promise; }
bool preprocessNext();
bool processNext();
void finish();
static PreprocessRequest _preprocessRequest;
};