From 5914f657e6f7e84d12cb4ef736db522e0fced6c6 Mon Sep 17 00:00:00 2001 From: Brandon Wyman Date: Thu, 16 Mar 2017 18:17:07 -0500 Subject: Move getInvService() into utility function. Resolves openbmc/openbmc#1299 Change-Id: I61f511dcc15e67393a47bd0395b752d2e6f17f11 Signed-off-by: Brandon Wyman --- Makefile.am | 3 ++- fan_enclosure.cpp | 38 ++------------------------------ fan_enclosure.hpp | 8 +------ utility.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ utility.hpp | 21 ++++++++++++++++++ 5 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 utility.cpp create mode 100644 utility.hpp diff --git a/Makefile.am b/Makefile.am index 610e543..30223d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,8 @@ sbin_PROGRAMS = \ phosphor_fan_presence_tach_SOURCES = \ fan_enclosure.cpp \ tach_sensor.cpp \ - tach_detect.cpp + tach_detect.cpp \ + utility.cpp nodist_phosphor_fan_presence_tach_SOURCES = \ fan_detect_defs.cpp diff --git a/fan_enclosure.cpp b/fan_enclosure.cpp index cb0c423..262876e 100644 --- a/fan_enclosure.cpp +++ b/fan_enclosure.cpp @@ -16,7 +16,7 @@ #include #include #include "fan_enclosure.hpp" - +#include "utility.hpp" namespace phosphor { @@ -27,11 +27,6 @@ namespace presence using namespace phosphor::logging; -//TODO Should get these from phosphor-objmgr config.h -constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; -constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; -constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; - //TODO Should get these from phosphor-inventory-manager config.h constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory"; constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"; @@ -62,35 +57,6 @@ FanEnclosure::ObjectMap FanEnclosure::getObjectMap(const bool curPresState) return invObj; } -std::string FanEnclosure::getInvService() -{ - auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, - MAPPER_PATH, - MAPPER_INTERFACE, - "GetObject"); - - mapperCall.append(INVENTORY_PATH); - mapperCall.append(std::vector({INVENTORY_INTF})); - - auto mapperResponseMsg = bus.call(mapperCall); - if (mapperResponseMsg.is_method_error()) - { - throw std::runtime_error( - "Error in mapper call to get inventory service name"); - } - - std::map> mapperResponse; - mapperResponseMsg.read(mapperResponse); - - if (mapperResponse.empty()) - { - throw std::runtime_error( - "Error in mapper response for inventory service name"); - } - - return mapperResponse.begin()->first; -} - void FanEnclosure::updInventory() { auto curPresState = getCurPresState(); @@ -103,7 +69,7 @@ void FanEnclosure::updInventory() std::string invService; try { - invService = getInvService(); + invService = getInvService(bus); } catch (const std::runtime_error& err) { diff --git a/fan_enclosure.hpp b/fan_enclosure.hpp index 1c8d241..8f5cfdf 100644 --- a/fan_enclosure.hpp +++ b/fan_enclosure.hpp @@ -97,13 +97,7 @@ class FanEnclosure * @return Current presence state determined from all sensors */ presenceState getCurPresState(); - //TODO openbmc/openbmc#1299 - Move getInvService() to a utility file - /** - * @brief Get the inventory service name from the mapper object - * - * @return The inventory manager service name - */ - std::string getInvService(); + /** * @brief Construct the inventory object map * diff --git a/utility.cpp b/utility.cpp new file mode 100644 index 0000000..db88712 --- /dev/null +++ b/utility.cpp @@ -0,0 +1,66 @@ +/** + * Copyright © 2017 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "utility.hpp" + +namespace phosphor +{ +namespace fan +{ +namespace presence +{ + +//TODO Should get these from phosphor-objmgr config.h +constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; +constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; +constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; + +//TODO Should get these from phosphor-inventory-manager config.h +constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory"; +constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"; + +std::string getInvService(sdbusplus::bus::bus& bus) +{ + auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, + MAPPER_PATH, + MAPPER_INTERFACE, + "GetObject"); + + mapperCall.append(INVENTORY_PATH); + mapperCall.append(std::vector({INVENTORY_INTF})); + + auto mapperResponseMsg = bus.call(mapperCall); + if (mapperResponseMsg.is_method_error()) + { + throw std::runtime_error( + "Error in mapper call to get inventory service name"); + } + + std::map> mapperResponse; + mapperResponseMsg.read(mapperResponse); + + if (mapperResponse.empty()) + { + throw std::runtime_error( + "Error in mapper response for inventory service name"); + } + + return mapperResponse.begin()->first; +} + +} +} +} diff --git a/utility.hpp b/utility.hpp new file mode 100644 index 0000000..d45fa02 --- /dev/null +++ b/utility.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace phosphor +{ +namespace fan +{ +namespace presence +{ + +/** + * @brief Get the inventory service name from the mapper object + * + * @return The inventory manager service name + */ +std::string getInvService(sdbusplus::bus::bus& bus); + +} +} +} -- cgit v1.2.1