| Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 1 | /** | 
 | 2 |  * Copyright © 2020 IBM 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 | #include "power_interface.hpp" | 
 | 17 |  | 
| Mike Capps | 477b13b | 2022-07-11 10:45:46 -0400 | [diff] [blame] | 18 | #include "logging.hpp" | 
| Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 19 | #include "sdbusplus.hpp" | 
 | 20 |  | 
 | 21 | namespace phosphor::fan::monitor | 
 | 22 | { | 
 | 23 |  | 
 | 24 | constexpr auto systemdService = "org.freedesktop.systemd1"; | 
 | 25 | constexpr auto systemdPath = "/org/freedesktop/systemd1"; | 
 | 26 | constexpr auto systemdMgrIface = "org.freedesktop.systemd1.Manager"; | 
 | 27 |  | 
 | 28 | void PowerInterface::softPowerOff() | 
 | 29 | { | 
 | 30 |     util::SDBusPlus::callMethod(systemdService, systemdPath, systemdMgrIface, | 
 | 31 |                                 "StartUnit", "obmc-host-shutdown@0.target", | 
 | 32 |                                 "replace"); | 
 | 33 | } | 
 | 34 |  | 
| Matt Spinler | bb449c1 | 2021-06-14 11:45:28 -0600 | [diff] [blame] | 35 | void PowerInterface::executeHardPowerOff() | 
| Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 36 | { | 
 | 37 |     util::SDBusPlus::callMethod( | 
 | 38 |         systemdService, systemdPath, systemdMgrIface, "StartUnit", | 
 | 39 |         "obmc-chassis-hard-poweroff@0.target", "replace"); | 
| Mike Capps | 683a96c | 2022-04-27 16:46:06 -0400 | [diff] [blame] | 40 |  | 
 | 41 |     try | 
 | 42 |     { | 
 | 43 |         util::SDBusPlus::callMethod( | 
 | 44 |             "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump/bmc", | 
 | 45 |             "xyz.openbmc_project.Dump.Create", "CreateDump", | 
 | 46 |             std::vector< | 
 | 47 |                 std::pair<std::string, std::variant<std::string, uint64_t>>>()); | 
 | 48 |     } | 
| Mike Capps | 477b13b | 2022-07-11 10:45:46 -0400 | [diff] [blame] | 49 |     catch (const std::exception& e) | 
 | 50 |     { | 
 | 51 |         getLogger().log( | 
| Patrick Williams | fbf4703 | 2023-07-17 12:27:34 -0500 | [diff] [blame] | 52 |             std::format("Caught exception while creating BMC dump: {}", | 
| Mike Capps | 477b13b | 2022-07-11 10:45:46 -0400 | [diff] [blame] | 53 |                         e.what()), | 
 | 54 |             Logger::error); | 
 | 55 |     } | 
| Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 56 | } | 
 | 57 |  | 
| Matt Spinler | bb449c1 | 2021-06-14 11:45:28 -0600 | [diff] [blame] | 58 | void PowerInterface::hardPowerOff() | 
 | 59 | { | 
 | 60 |     executeHardPowerOff(); | 
 | 61 | } | 
 | 62 |  | 
| Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 63 | } // namespace phosphor::fan::monitor |