-
Notifications
You must be signed in to change notification settings - Fork 8
/
PowerController.hpp
52 lines (42 loc) · 1.24 KB
/
PowerController.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
#ifndef CPP_REFACTORING_FOR_TESTABILITY_POWERCONTROLLER_HPP
#define CPP_REFACTORING_FOR_TESTABILITY_POWERCONTROLLER_HPP
#include "AsynchronousTimer.hpp"
#include "InterruptManager.hpp"
#include "PinManager.hpp"
#include "TimeKeeper.hpp"
#include <atomic>
#include <condition_variable>
#include <mutex>
namespace before
{
struct PowerController
{
PowerController(PinManager& pinManager, InterruptManager& interruptManager);
bool turnOn();
private:
PinManager& mPinManager;
std::condition_variable mConditionVariable;
std::atomic<bool> mPulseReceived{false};
std::mutex mRunnerMutex;
};
} // namespace before
namespace after
{
struct PowerController
{
PowerController(PinManager& pinManager,
InterruptManager& interruptManager,
AsynchronousTimer& asynchronousTimer,
TimeKeeper& timeKeeper);
bool turnOn();
private:
PinManager& mPinManager;
AsynchronousTimer& mAsynchronousTimer;
TimeKeeper& mTimeKeeper;
std::condition_variable mConditionVariable;
std::atomic<bool> mPulseReceived{false};
std::atomic<bool> mPulseTimedOut{false};
std::mutex mRunnerMutex;
};
} // namespace after
#endif // CPP_REFACTORING_FOR_TESTABILITY_POWERCONTROLLER_HPP