-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loop.hpp
111 lines (84 loc) · 3.08 KB
/
Loop.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
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
/************************************************************************
* Copyright(c) 2023, One Unified. All rights reserved. *
* email: [email protected] *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
/*
* File: Loop.hpp
* Author: [email protected]
* Project: Mqtt2Telegram
* Created: October 23, 2023 13:43:38
*/
#include <chrono>
#include <memory>
#include <string>
#include <unordered_map>
#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/executor_work_guard.hpp>
namespace config {
class Values;
}
namespace ou {
class Mqtt;
namespace telegram {
class Bot;
}
}
namespace asio = boost::asio; // from <boost/asio/context.hpp>
class Loop {
public:
Loop( const config::Values&, asio::io_context& );
~Loop();
protected:
private:
const config::Values& m_choices;
asio::io_context& m_io_context;
std::string m_sMqttId;
std::unique_ptr<ou::Mqtt> m_pMqtt;
std::unique_ptr<ou::telegram::Bot> m_telegram_bot;
using time_point = std::chrono::time_point<std::chrono::system_clock>;
struct ups_state_t {
std::string sStatus_basic; // OL vs OB
std::string sStatus_full; //
std::string sRunTime;
time_point tpLastSeen;
ups_state_t( const std::string& sStatus_basic_ )
: sStatus_basic( sStatus_basic_ )
{}
//ups_state_t( const std::string& sStatus_basic_
// , const std::string& sStatus_full_
// , const std::string& sRunTime_
// , time_point tpLastSeen_
// )
//: sStatus_basic( sStatus_basic_ )
//, sStatus_full( sStatus_full_ )
//, sRunTime( sRunTime_ )
//, tpLastSeen( tpLastSeen_ )
//{}
ups_state_t( ups_state_t&& state )
: sStatus_basic( std::move( state.sStatus_basic ) )
, sStatus_full( std::move( state.sStatus_full ) )
, sRunTime( std::move( state.sRunTime ) )
, tpLastSeen( state.tpLastSeen )
{}
};
using umapStatus_t = std::unordered_map<std::string,ups_state_t>;
umapStatus_t m_umapStatus;
using work_guard_t = asio::executor_work_guard<asio::io_context::executor_type>;
using pWorkGuard_t = std::unique_ptr<work_guard_t>;
pWorkGuard_t m_pWorkGuard;
asio::signal_set m_signals;
void Signals( const boost::system::error_code&, int );
void Telegram_GetMe();
void Telegram_SendMessage();
};