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