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
18 #include "logging.hpp"
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
softPowerOff()28 void PowerInterface::softPowerOff()
29 {
30 util::SDBusPlus::callMethod(systemdService, systemdPath, systemdMgrIface,
31 "StartUnit", "obmc-host-shutdown@0.target",
32 "replace");
33 }
34
executeHardPowerOff()35 void PowerInterface::executeHardPowerOff()
36 {
37 util::SDBusPlus::callMethod(
38 systemdService, systemdPath, systemdMgrIface, "StartUnit",
39 "obmc-chassis-hard-poweroff@0.target", "replace");
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 }
49 catch (const std::exception& e)
50 {
51 getLogger().log(
52 std::format("Caught exception while creating BMC dump: {}",
53 e.what()),
54 Logger::error);
55 }
56 }
57
hardPowerOff()58 void PowerInterface::hardPowerOff()
59 {
60 executeHardPowerOff();
61 }
62
63 } // namespace phosphor::fan::monitor
64