-
Notifications
You must be signed in to change notification settings - Fork 34
/
instance_environment.hpp
55 lines (45 loc) · 1.63 KB
/
instance_environment.hpp
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
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <functional>
#include <memory>
namespace kagome::host_api {
class HostApi;
}
namespace kagome::runtime {
class TrieStorageProvider;
class MemoryProvider;
struct InstanceEnvironment {
InstanceEnvironment(const InstanceEnvironment &) = delete;
InstanceEnvironment &operator=(const InstanceEnvironment &) = delete;
InstanceEnvironment(
std::shared_ptr<MemoryProvider> memory_provider,
std::shared_ptr<TrieStorageProvider> storage_provider,
std::shared_ptr<host_api::HostApi> host_api,
std::function<void(InstanceEnvironment &)> on_destruction)
: memory_provider(std::move(memory_provider)),
storage_provider(std::move(storage_provider)),
host_api(std::move(host_api)),
on_destruction(std::move(on_destruction)) {}
InstanceEnvironment(InstanceEnvironment &&e) noexcept
: memory_provider(std::move(e.memory_provider)),
storage_provider(std::move(e.storage_provider)),
host_api(std::move(e.host_api)),
on_destruction(std::move(e.on_destruction)) {
e.on_destruction = {};
}
InstanceEnvironment &operator=(InstanceEnvironment &&) = default;
~InstanceEnvironment() {
if (on_destruction) {
on_destruction(*this);
}
}
std::shared_ptr<MemoryProvider> memory_provider;
std::shared_ptr<TrieStorageProvider> storage_provider;
std::shared_ptr<host_api::HostApi> host_api;
std::function<void(InstanceEnvironment &)> on_destruction;
};
} // namespace kagome::runtime