-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.h
More file actions
63 lines (52 loc) · 1.52 KB
/
Session.h
File metadata and controls
63 lines (52 loc) · 1.52 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
/*
* Copyright (C) 2021 Ilya Entin
*/
#pragma once
#include <memory>
#include <boost/core/noncopyable.hpp>
#include "EncryptorTemplates.h"
#include "IOUtility.h"
using namespace encryptortemplates;
using ServerWeakPtr = std::weak_ptr<class Server>;
using TaskPtr = std::shared_ptr<class Task>;
class Session : private boost::noncopyable {
protected:
std::size_t _clientId = 0;
HEADER _header;
std::string _request;
TaskPtr _task;
std::string _responseData;
std::string _buffer;
ServerWeakPtr _server;
ENCRYPTORCONTAINER _encryptorContainer;
Session(ServerWeakPtr server,
std::string_view primarySignatureWithKey,
std::string_view primaryPubKeyAes);
virtual ~Session() = default;
std::pair<HEADER, std::string_view>
buildReply(std::atomic<STATUS>& status);
bool processTask();
template <typename L>
void sendStatusToClient(L& lambda, STATUS status) {
if (auto server = _server.lock()) {
std::string clientIdStr;
clientIdStr = ioutility::toCharsBoost(_clientId);
HEADER header;
std::string encodedPubKeyAes;
sendStatusToClientImpl(_encryptorContainer,
clientIdStr,
status,
header,
encodedPubKeyAes);
lambda(header, clientIdStr, encodedPubKeyAes);
}
}
void displayCapacityCheck(std::string_view type,
unsigned totalNumberObjects,
unsigned numberObjects,
unsigned numberRunningByType,
unsigned maxNumberRunningByType,
STATUS status);
public:
std::size_t getId() const { return _clientId; }
};