Repository navigation
Expand file tree
/
Copy pathairlock.cpp
More file actions
119 lines (91 loc) · 3.37 KB
/
Copy pathairlock.cpp
File metadata and controls
119 lines (91 loc) · 3.37 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "airlock.hpp"
#include <dzn/locator.hh>
#include <dzn/runtime.hh>
#include <dzn/pump.hh>
#include "dzn-gen/AirlockSystem.hh"
#include "glue/GlueDoor.hpp"
#include "glue/GlueVacuum.hpp"
#include "glue/injected/ErrorHelper.hpp"
#include "glue/injected/Logging.hpp"
#include "glue/custom-dzn-logging.hpp"
namespace example {
class AirlockImpl
{
public:
explicit AirlockImpl(AirlockDependencies dependencies, ILogger& logger)
: m_doorInside{m_dzn_pump, dependencies.doorInside},
m_doorOutside{m_dzn_pump, dependencies.doorOutside},
m_vacuum{m_dzn_pump, dependencies.vacuum},
m_logging{logger},
m_dznLogging{[&logger](const std::string& m) { logger.Debug(m); }}
{
// Add runtime and pump to locator
m_dzn_locator.set(m_dzn_runtime);
m_dzn_locator.set(m_dzn_pump);
m_dzn_locator.set<std::ostream>(m_dznLogging);
// Add injected glue to locator
m_dzn_locator.set(m_errorHelper.port());
m_dzn_locator.set(m_logging.port());
// Construct dezyne system
m_system = std::make_unique<dezyne::AirlockSystem>(m_dzn_locator);
// Connect glue objects to our dezyne system
m_doorInside.ConnectWith(m_system->doorInside);
m_doorOutside.ConnectWith(m_system->doorOutside);
m_vacuum.ConnectWith(m_system->vacuum);
dzn::check_bindings(*m_system);
}
std::future<std::expected<void, std::string>> TransitionToInsideOpen()
{
std::shared_future<dezyne::utils::PromiseFC::PromiseResult> future;
dzn::shell(m_dzn_pump, [this, &future]() {
m_system->api.in.TransitionToInsideOpen(future);
});
return std::async(std::launch::async, [future = std::move(future)] -> std::expected<void, std::string> {
auto r = future.get();
if (r.has_value()) {
return {};
} else {
return std::unexpected{r.error().ToString()};
}
});
}
std::future<std::expected<void, std::string>> TransitionToOutsideOpen()
{
std::shared_future<dezyne::utils::PromiseFC::PromiseResult> future;
dzn::shell(m_dzn_pump, [this, &future]()
{ m_system->api.in.TransitionToOutsideOpen(future); });
return std::async(std::launch::async, [future = std::move(future)] -> std::expected<void, std::string> {
auto r = future.get();
if (r.has_value()) {
return {};
} else {
return std::unexpected{r.error().ToString()};
}
});
}
private:
dzn::locator m_dzn_locator;
dzn::runtime m_dzn_runtime;
dzn::pump m_dzn_pump;
std::unique_ptr<dezyne::AirlockSystem> m_system;
glue::GlueDoor m_doorInside;
glue::GlueDoor m_doorOutside;
glue::GlueVacuum m_vacuum;
glue::injected::ErrorHelper m_errorHelper;
glue::injected::Logging m_logging;
CustomDznLogging m_dznLogging;
};
MyAirlock::MyAirlock(AirlockDependencies dependencies, ILogger& logger)
: impl{std::make_unique<AirlockImpl>(dependencies, logger)}
{
}
MyAirlock::~MyAirlock() = default;
std::future<std::expected<void, std::string>> MyAirlock::TransitionToInsideOpen()
{
return impl->TransitionToInsideOpen();
}
std::future<std::expected<void, std::string>> MyAirlock::TransitionToOutsideOpen()
{
return impl->TransitionToOutsideOpen();
}
}