blob: eb96b13213aab751bebf510d4f8a5e4af804c137 [file] [log] [blame]
Kuiying Wanga9d39e32018-08-14 13:47:32 +08001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
Kuiying Wanga9d39e32018-08-14 13:47:32 +080017#include "id_button.hpp"
Patrick Venture0d9377d2018-11-01 19:34:59 -070018#include "power_button.hpp"
19#include "reset_button.hpp"
Kuiying Wanga9d39e32018-08-14 13:47:32 +080020
21int main(int argc, char* argv[])
22{
23 int ret = 0;
24
25 phosphor::logging::log<phosphor::logging::level::INFO>(
26 "Start power button service...");
27
28 sd_event* event = nullptr;
29 ret = sd_event_default(&event);
30 if (ret < 0)
31 {
32 phosphor::logging::log<phosphor::logging::level::ERR>(
33 "Error creating a default sd_event handler");
34 return ret;
35 }
36 EventPtr eventP{event};
37 event = nullptr;
38
39 sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
40 sdbusplus::server::manager::manager objManager{
41 bus, "/xyz/openbmc_project/Chassis/Buttons"};
42
43 bus.request_name("xyz.openbmc_project.Chassis.Buttons");
44
Matt Spinler8605bdf2018-11-05 14:55:46 -060045 std::unique_ptr<PowerButton> pb;
46 if (hasGpio<PowerButton>())
47 {
48 pb = std::make_unique<PowerButton>(bus, POWER_DBUS_OBJECT_NAME, eventP);
49 }
Kuiying Wanga9d39e32018-08-14 13:47:32 +080050
Matt Spinler8605bdf2018-11-05 14:55:46 -060051 std::unique_ptr<ResetButton> rb;
52 if (hasGpio<ResetButton>())
53 {
54 rb = std::make_unique<ResetButton>(bus, RESET_DBUS_OBJECT_NAME, eventP);
55 }
Kuiying Wanga9d39e32018-08-14 13:47:32 +080056
Matt Spinler8605bdf2018-11-05 14:55:46 -060057 std::unique_ptr<IDButton> ib;
58 if (hasGpio<IDButton>())
59 {
60 ib = std::make_unique<IDButton>(bus, ID_DBUS_OBJECT_NAME, eventP);
61 }
Kuiying Wanga9d39e32018-08-14 13:47:32 +080062
63 try
64 {
65 bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
66 ret = sd_event_loop(eventP.get());
67 if (ret < 0)
68 {
69 phosphor::logging::log<phosphor::logging::level::ERR>(
70 "Error occurred during the sd_event_loop",
71 phosphor::logging::entry("RET=%d", ret));
72 }
73 }
74 catch (std::exception& e)
75 {
76 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
77 ret = -1;
78 }
79 return ret;
80}