Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 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 | */ |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 16 | #include "fan.hpp" |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 17 | |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 18 | #include "sdbusplus.hpp" |
| 19 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 20 | #include <sdbusplus/message.hpp> |
| 21 | |
| 22 | #include <map> |
| 23 | #include <string> |
| 24 | |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 25 | namespace phosphor |
| 26 | { |
| 27 | namespace fan |
| 28 | { |
| 29 | namespace presence |
| 30 | { |
| 31 | |
| 32 | using namespace std::literals::string_literals; |
| 33 | |
| 34 | static const auto invNamespace = "/xyz/openbmc_project/inventory"s; |
| 35 | static const auto itemIface = "xyz.openbmc_project.Inventory.Item"s; |
| 36 | static const auto invMgrIface = "xyz.openbmc_project.Inventory.Manager"s; |
Anthony Wilson | d9a580a | 2019-04-30 17:05:53 -0500 | [diff] [blame] | 37 | static const auto fanIface = "xyz.openbmc_project.Inventory.Item.Fan"s; |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 38 | |
| 39 | void setPresence(const Fan& fan, bool newState) |
| 40 | { |
| 41 | using namespace sdbusplus::message; |
| 42 | |
Matthew Barth | 9dd65ad | 2020-06-03 12:49:27 -0500 | [diff] [blame^] | 43 | using Properties = std::map<std::string, std::variant<std::string, bool>>; |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 44 | using Interfaces = std::map<std::string, Properties>; |
| 45 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 46 | std::map<object_path, Interfaces> obj = {{ |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 47 | std::get<1>(fan), |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 48 | {{itemIface, |
| 49 | { |
| 50 | {"Present"s, newState}, |
| 51 | {"PrettyName"s, std::get<0>(fan)}, |
| 52 | }}, |
| 53 | {fanIface, {}}}, |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 54 | }}; |
| 55 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 56 | util::SDBusPlus::lookupAndCallMethod(invNamespace, invMgrIface, "Notify"s, |
| 57 | obj); |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | bool getPresence(const Fan& fan) |
| 61 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 62 | return util::SDBusPlus::getProperty<bool>(std::get<1>(fan), itemIface, |
| 63 | "Present"s); |
Brad Bishop | 825e31e | 2017-06-14 16:38:22 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace presence |
| 67 | } // namespace fan |
| 68 | } // namespace phosphor |