Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 1 | #include <algorithm> |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 2 | #include "fan_enclosure.hpp" |
| 3 | |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace fan |
| 8 | { |
| 9 | namespace presence |
| 10 | { |
| 11 | |
Matthew Barth | 736d143 | 2017-02-20 16:09:21 -0600 | [diff] [blame] | 12 | //TODO Should get these from phosphor-objmgr config.h |
| 13 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 14 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/ObjectMapper"; |
| 15 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 16 | |
| 17 | //TODO Should get these from phosphor-inventory-manager config.h |
| 18 | constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory"; |
| 19 | constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"; |
| 20 | |
Matthew Barth | 1562ac7 | 2017-02-20 16:01:21 -0600 | [diff] [blame] | 21 | FanEnclosure::ObjectMap FanEnclosure::getObjectMap() |
| 22 | { |
| 23 | ObjectMap invObj; |
| 24 | InterfaceMap invIntf; |
| 25 | PropertyMap invProp; |
| 26 | auto presPred = [](auto const& s) {return s->isPresent();}; |
| 27 | // Determine if all sensors show fan is not present |
| 28 | auto isPresent = std::any_of(sensors.begin(), |
| 29 | sensors.end(), |
| 30 | presPred); |
| 31 | invProp.emplace("Present", isPresent); |
| 32 | invProp.emplace("PrettyName", fanDesc); |
| 33 | invIntf.emplace("xyz.openbmc_project.Inventory.Item", std::move(invProp)); |
| 34 | Object fanInvPath = invPath; |
| 35 | invObj.emplace(std::move(fanInvPath), std::move(invIntf)); |
| 36 | |
| 37 | return invObj; |
| 38 | } |
| 39 | |
Matthew Barth | 736d143 | 2017-02-20 16:09:21 -0600 | [diff] [blame] | 40 | std::string FanEnclosure::getInvService() |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 41 | { |
Matthew Barth | 736d143 | 2017-02-20 16:09:21 -0600 | [diff] [blame] | 42 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, |
| 43 | MAPPER_PATH, |
| 44 | MAPPER_INTERFACE, |
| 45 | "GetObject"); |
| 46 | |
| 47 | mapperCall.append(INVENTORY_PATH); |
| 48 | mapperCall.append(std::vector<std::string>({INVENTORY_INTF})); |
| 49 | |
| 50 | auto mapperResponseMsg = bus.call(mapperCall); |
| 51 | if (mapperResponseMsg.is_method_error()) |
| 52 | { |
| 53 | //TODO Retry or throw exception/log error? |
| 54 | } |
| 55 | |
| 56 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 57 | mapperResponseMsg.read(mapperResponse); |
| 58 | |
| 59 | if (mapperResponse.empty()) |
| 60 | { |
| 61 | //TODO Nothing found, throw exception/log error? |
| 62 | } |
| 63 | |
| 64 | return mapperResponse.begin()->first; |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 65 | } |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 66 | |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 67 | void FanEnclosure::updInventory() |
| 68 | { |
Matthew Barth | 1562ac7 | 2017-02-20 16:01:21 -0600 | [diff] [blame] | 69 | //Get inventory object for this fan |
| 70 | ObjectMap invObj = getObjectMap(); |
Matthew Barth | 736d143 | 2017-02-20 16:09:21 -0600 | [diff] [blame] | 71 | //Get inventory manager service name from mapper |
| 72 | std::string invService = getInvService(); |
Matthew Barth | 398257a | 2017-02-20 16:15:00 -0600 | [diff] [blame^] | 73 | // Update inventory for this fan |
| 74 | auto invMsg = bus.new_method_call(invService.c_str(), |
| 75 | INVENTORY_PATH, |
| 76 | INVENTORY_INTF, |
| 77 | "Notify"); |
| 78 | invMsg.append(std::move(invObj)); |
| 79 | auto invMgrResponseMsg = bus.call(invMsg); |
| 80 | if (invMgrResponseMsg.is_method_error()) |
| 81 | { |
| 82 | //TODO Handle error in notify call |
| 83 | } |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 84 | } |
| 85 | |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 86 | void FanEnclosure::addSensor( |
| 87 | std::unique_ptr<Sensor>&& sensor) |
| 88 | { |
| 89 | FanEnclosure::sensors.push_back(std::move(sensor)); |
| 90 | } |
| 91 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 92 | } // namespace presence |
| 93 | } // namespace fan |
| 94 | } // namespace phosphor |