summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Wyman <bjwyman@gmail.com>2017-03-16 18:17:07 -0500
committerBrandon Wyman <bjwyman@gmail.com>2017-03-20 16:54:25 -0500
commit5914f657e6f7e84d12cb4ef736db522e0fced6c6 (patch)
treec5c23f370a6fddc580f570b066ce2bdf7b20e3a0
parent6d9b18d5e51b269d741c13120a35a7b780ac8928 (diff)
downloadphosphor-fan-presence-5914f657e6f7e84d12cb4ef736db522e0fced6c6.tar.gz
phosphor-fan-presence-5914f657e6f7e84d12cb4ef736db522e0fced6c6.zip
Move getInvService() into utility function.
Resolves openbmc/openbmc#1299 Change-Id: I61f511dcc15e67393a47bd0395b752d2e6f17f11 Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
-rw-r--r--Makefile.am3
-rw-r--r--fan_enclosure.cpp38
-rw-r--r--fan_enclosure.hpp8
-rw-r--r--utility.cpp66
-rw-r--r--utility.hpp21
5 files changed, 92 insertions, 44 deletions
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 <algorithm>
#include <phosphor-logging/log.hpp>
#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<std::string>({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<std::string, std::vector<std::string>> 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 <string>
+#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<std::string>({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<std::string, std::vector<std::string>> 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 <sdbusplus/bus.hpp>
+
+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);
+
+}
+}
+}
OpenPOWER on IntegriCloud