blob: 95dc4cdbb855827f161dbd15c5d40f91b52ee6ab [file] [log] [blame]
Brad Bishop825e31e2017-06-14 16:38:22 -04001/**
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 Bishop825e31e2017-06-14 16:38:22 -040016#include "fan.hpp"
Matthew Barth2d2caa32020-05-26 11:07:24 -050017
Brad Bishop825e31e2017-06-14 16:38:22 -040018#include "sdbusplus.hpp"
19
Matthew Barth2d2caa32020-05-26 11:07:24 -050020#include <sdbusplus/message.hpp>
21
22#include <map>
23#include <string>
24
Brad Bishop825e31e2017-06-14 16:38:22 -040025namespace phosphor
26{
27namespace fan
28{
29namespace presence
30{
31
32using namespace std::literals::string_literals;
33
Brad Bishop825e31e2017-06-14 16:38:22 -040034static const auto itemIface = "xyz.openbmc_project.Inventory.Item"s;
35static const auto invMgrIface = "xyz.openbmc_project.Inventory.Manager"s;
Anthony Wilsond9a580a2019-04-30 17:05:53 -050036static const auto fanIface = "xyz.openbmc_project.Inventory.Item.Fan"s;
Brad Bishop825e31e2017-06-14 16:38:22 -040037
38void setPresence(const Fan& fan, bool newState)
39{
40 using namespace sdbusplus::message;
41
Matthew Barth9dd65ad2020-06-03 12:49:27 -050042 using Properties = std::map<std::string, std::variant<std::string, bool>>;
Brad Bishop825e31e2017-06-14 16:38:22 -040043 using Interfaces = std::map<std::string, Properties>;
44
Matthew Barth2d2caa32020-05-26 11:07:24 -050045 std::map<object_path, Interfaces> obj = {{
Brad Bishop825e31e2017-06-14 16:38:22 -040046 std::get<1>(fan),
Matthew Barth2d2caa32020-05-26 11:07:24 -050047 {{itemIface,
48 {
49 {"Present"s, newState},
50 {"PrettyName"s, std::get<0>(fan)},
51 }},
52 {fanIface, {}}},
Brad Bishop825e31e2017-06-14 16:38:22 -040053 }};
54
Matthew Barth2d2caa32020-05-26 11:07:24 -050055 util::SDBusPlus::lookupAndCallMethod(invNamespace, invMgrIface, "Notify"s,
56 obj);
Brad Bishop825e31e2017-06-14 16:38:22 -040057}
58
59bool getPresence(const Fan& fan)
60{
Matt Spinler0dc85ee2020-09-24 14:07:02 -050061 return util::SDBusPlus::getProperty<bool>(invNamespace + std::get<1>(fan),
62 itemIface, "Present"s);
Brad Bishop825e31e2017-06-14 16:38:22 -040063}
64
65} // namespace presence
66} // namespace fan
67} // namespace phosphor