Kuiying Wang | a9d39e3 | 2018-08-14 13:47:32 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #include "reset_button.hpp" |
| 18 | #include "power_button.hpp" |
| 19 | #include "id_button.hpp" |
| 20 | |
| 21 | int 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 | |
| 45 | PowerButton powerButton{bus, POWER_DBUS_OBJECT_NAME, eventP}; |
| 46 | |
| 47 | ResetButton resetButton{bus, RESET_DBUS_OBJECT_NAME, eventP}; |
| 48 | |
| 49 | IDButton idButton{bus, ID_DBUS_OBJECT_NAME, eventP}; |
| 50 | |
| 51 | try |
| 52 | { |
| 53 | bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); |
| 54 | ret = sd_event_loop(eventP.get()); |
| 55 | if (ret < 0) |
| 56 | { |
| 57 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 58 | "Error occurred during the sd_event_loop", |
| 59 | phosphor::logging::entry("RET=%d", ret)); |
| 60 | } |
| 61 | } |
| 62 | catch (std::exception& e) |
| 63 | { |
| 64 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 65 | ret = -1; |
| 66 | } |
| 67 | return ret; |
| 68 | } |