summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: 6bb165f054e8d270ce6dafc9cb78eab9c7da447e (plain)
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
// SPDX-License-Identifier: Apache-2.0

#include <iostream>
#include <iomanip>
#include <boost/asio/signal_set.hpp>
#include <boost/bind.hpp>
#include "hvac-service.hpp"

using work_guard_type = boost::asio::executor_work_guard<boost::asio::io_context::executor_type>;

int main(int argc, char** argv)
{
	// The io_context is required for all I/O
	net::io_context ioc;

	// Register to stop I/O context on SIGINT and SIGTERM
	net::signal_set signals(ioc, SIGINT, SIGTERM);
	signals.async_wait(boost::bind(&net::io_context::stop, &ioc));

	// The SSL context is required, and holds certificates
	ssl::context ctx{ssl::context::tlsv12_client};

	// Launch the asynchronous operation
	VisConfig config("agl-service-hvac");
	std::make_shared<HvacService>(config, ioc, ctx)->run();

	// Ensure I/O context continues running even if there's no work
	work_guard_type work_guard(ioc.get_executor());

	// Run the I/O context
	ioc.run();

	return 0;
}