xref: /openbmc/telemetry/src/main.cpp (revision 3a1c297a)
1*64b75a5bSKrzysztof Grobelny #include "telemetry.hpp"
2*64b75a5bSKrzysztof Grobelny 
3*64b75a5bSKrzysztof Grobelny #include <boost/asio/io_context.hpp>
4*64b75a5bSKrzysztof Grobelny #include <boost/asio/signal_set.hpp>
5*64b75a5bSKrzysztof Grobelny #include <phosphor-logging/log.hpp>
6*64b75a5bSKrzysztof Grobelny #include <sdbusplus/asio/connection.hpp>
7*64b75a5bSKrzysztof Grobelny 
8*64b75a5bSKrzysztof Grobelny #include <memory>
9*64b75a5bSKrzysztof Grobelny #include <stdexcept>
10*64b75a5bSKrzysztof Grobelny 
main()11*64b75a5bSKrzysztof Grobelny int main()
12*64b75a5bSKrzysztof Grobelny {
13*64b75a5bSKrzysztof Grobelny     boost::asio::io_context ioc;
14*64b75a5bSKrzysztof Grobelny     boost::asio::signal_set signals(ioc, SIGINT, SIGTERM);
15*64b75a5bSKrzysztof Grobelny 
16*64b75a5bSKrzysztof Grobelny     auto bus = std::make_shared<sdbusplus::asio::connection>(ioc);
17*64b75a5bSKrzysztof Grobelny 
18*64b75a5bSKrzysztof Grobelny     constexpr const char* serviceName = "xyz.openbmc_project.Telemetry";
19*64b75a5bSKrzysztof Grobelny     bus->request_name(serviceName);
20*64b75a5bSKrzysztof Grobelny 
21*64b75a5bSKrzysztof Grobelny     signals.async_wait(
22*64b75a5bSKrzysztof Grobelny         [&ioc](const boost::system::error_code ec, const int& sig) {
23*64b75a5bSKrzysztof Grobelny         if (ec)
24*64b75a5bSKrzysztof Grobelny         {
25*64b75a5bSKrzysztof Grobelny             throw std::runtime_error("Signal should not be canceled");
26*64b75a5bSKrzysztof Grobelny         }
27*64b75a5bSKrzysztof Grobelny 
28*64b75a5bSKrzysztof Grobelny         ioc.stop();
29*64b75a5bSKrzysztof Grobelny     });
30*64b75a5bSKrzysztof Grobelny 
31*64b75a5bSKrzysztof Grobelny     phosphor::logging::log<phosphor::logging::level::INFO>(
32*64b75a5bSKrzysztof Grobelny         "Telemetry starting");
33*64b75a5bSKrzysztof Grobelny     Telemetry app(bus);
34*64b75a5bSKrzysztof Grobelny     ioc.run();
35*64b75a5bSKrzysztof Grobelny 
36*64b75a5bSKrzysztof Grobelny     return 0;
37*64b75a5bSKrzysztof Grobelny }
38