-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBridge.cpp
84 lines (66 loc) · 2.08 KB
/
Bridge.cpp
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
//============================================================================
// Name : Bridge.cpp
// Created on : 08.06.2020
// Author : Tokmakov Andrey
// Version : 1.0
// Copyright : Your copyright notice
// Description : Bridge tests
//============================================================================
#define _CRT_SECURE_NO_WARNINGS
#include "Bridge.h"
#include <chrono>
#include <iostream>
#include <string>
#include <string_view>
#include <thread>
namespace Bridge {
LockupAlarmClock::LockupAlarmClock(std::unique_ptr<AlarmClockImpl> bridgeImpl,
int hour, int minutes) {
// this->bridge.reset(bridgeImpl.release());
this->bridge = std::move(bridgeImpl);
this->waitForWake = false;
this->hourAlarm = hour;
this->minutesAlarm = minutes;
}
void LockupAlarmClock::toWake() {
this->bridge->notify();
this->bridge->ring();
}
void LockupAlarmClock::start() noexcept {
time_t rawtime;
tm* timeinfo;
std::cout << "ArarmClock stared" << std::endl;
waitForWake = true;
while (waitForWake) {
time(&rawtime);
timeinfo = localtime(&rawtime);
if (timeinfo->tm_hour == this->hourAlarm && timeinfo->tm_min == this->minutesAlarm) {
waitForWake = false;
} else {
std::cout << "Dont need to Ring" << std::endl;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
toWake();
}
void LockupAlarmClock::stop() noexcept {
// stop lockup process
waitForWake = false;
}
ShellMP3AlarmClock::ShellMP3AlarmClock(const std::string& cmd) {
this->cmdplay = cmd;
}
void ShellMP3AlarmClock::ring() noexcept {
// run command
// system(cmdplay.c_str());
std::cout << cmdplay.c_str() << std::endl;
}
void ShellMP3AlarmClock::notify() noexcept {
std::cout << "ALARMING!" << std::endl;
}
}
void Bridge::TEST_ALL() {
std::unique_ptr<AlarmClockImpl> clockImpl = std::make_unique< ShellMP3AlarmClock>("DING DING DING");
std::shared_ptr<AlarmClock> clock = std::make_shared< LockupAlarmClock>(std::move(clockImpl), 9, 46);
clock->start();
}