blob: 823de2938f2a60dd3759140597212d18bebb1df6 [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 */
16#include <map>
17#include <sdbusplus/message.hpp>
18#include <string>
19#include "fan.hpp"
20#include "sdbusplus.hpp"
21
22namespace phosphor
23{
24namespace fan
25{
26namespace presence
27{
28
29using namespace std::literals::string_literals;
30
31static const auto invNamespace = "/xyz/openbmc_project/inventory"s;
32static const auto itemIface = "xyz.openbmc_project.Inventory.Item"s;
33static const auto invMgrIface = "xyz.openbmc_project.Inventory.Manager"s;
Anthony Wilsond9a580a2019-04-30 17:05:53 -050034static const auto fanIface = "xyz.openbmc_project.Inventory.Item.Fan"s;
Brad Bishop825e31e2017-06-14 16:38:22 -040035
36void setPresence(const Fan& fan, bool newState)
37{
38 using namespace sdbusplus::message;
39
40 using Properties = std::map<std::string, variant<std::string, bool>>;
41 using Interfaces = std::map<std::string, Properties>;
42
43 std::map<object_path, Interfaces> obj =
44 {{
45 std::get<1>(fan),
46 {{
47 itemIface,
48 {
49 {"Present"s, newState},
50 {"PrettyName"s, std::get<0>(fan)},
51 }
Anthony Wilsond9a580a2019-04-30 17:05:53 -050052 },
53 {
54 fanIface, {}
55 }},
Brad Bishop825e31e2017-06-14 16:38:22 -040056 }};
57
58 util::SDBusPlus::lookupAndCallMethod(
59 invNamespace,
60 invMgrIface,
61 "Notify"s,
62 obj);
63}
64
65bool getPresence(const Fan& fan)
66{
67 return util::SDBusPlus::getProperty<bool>(
68 std::get<1>(fan),
69 itemIface,
70 "Present"s);
71}
72
73} // namespace presence
74} // namespace fan
75} // namespace phosphor