Newer
Older
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
#include <vereign/test/service_context.hh>
#include <vereign/kvstore/sqlite_storage.hh>
#include <vereign/kvstore/crypto_storage.hh>
#include <vereign/restapi/client.hh>
#include <vereign/restapi/client_session.hh>
#include <vereign/identity/provider.hh>
#include <vereign/core/temp.hh>
#include <boost/filesystem/operations.hpp>
namespace vereign::test {
ServiceContext::ServiceContext(
const std::string& vereign_host,
const std::string& vereign_port,
boost::filesystem::path storage_path
) : work_guard_{boost::asio::make_work_guard(ioc_)},
ssl_context_{boost::asio::ssl::context::tlsv12_client},
client_{std::make_unique<restapi::Client>(
ioc_, ssl_context_, vereign_host, vereign_port
)},
client_session_{std::make_unique<restapi::ClientSession>(*client_)},
storage_path_{std::move(storage_path)},
sqlite_storage_{std::make_unique<kvstore::SqliteStorage>(storage_path_.string())},
storage_{std::make_unique<kvstore::CryptoStorage>(*sqlite_storage_)},
identity_provider_{std::make_unique<identity::Provider>(*storage_)}
{
service_thread_ = std::thread([this]() {
ioc_.run();
});
}
auto ServiceContext::IdentityProvider() -> identity::Provider& {
return *identity_provider_;
}
auto ServiceContext::ClientSession() -> restapi::ClientSession& {
return *client_session_;
}
auto ServiceContext::StoragePath() const -> const boost::filesystem::path& {
return storage_path_;
}
void ServiceContext::Shutdown() {
client_session_->Close();
work_guard_.reset();
if (service_thread_.joinable()) {
service_thread_.join();
}
}
ServiceContext::~ServiceContext() {
Shutdown();
}
}