Reset OCC on error condition

After detecting the error in the OCC, invokes OccReset command
in Host Control dbus object with the sensor ID of the failing OCC

Fixes openbmc/openbmc#1363

Change-Id: I608dbbb943d3b39d0709d6f350ab799e771a13e9
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/utils.cpp b/utils.cpp
new file mode 100644
index 0000000..1dfdcef
--- /dev/null
+++ b/utils.cpp
@@ -0,0 +1,53 @@
+#include <string>
+#include <sdbusplus/bus.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+namespace open_power
+{
+namespace occ
+{
+
+// For throwing exceptions
+using namespace phosphor::logging;
+using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
+                            Error::InternalFailure;
+
+std::string getService(sdbusplus::bus::bus& bus,
+                       const std::string& intf,
+                       const std::string& path)
+{
+    auto mapperCall = bus.new_method_call("xyz.openbmc_project.ObjectMapper",
+                                          "/xyz/openbmc_project/object_mapper",
+                                          "xyz.openbmc_project.ObjectMapper",
+                                          "GetObject");
+
+    mapperCall.append(path);
+    mapperCall.append(std::vector<std::string>({intf}));
+
+    auto mapperResponseMsg = bus.call(mapperCall);
+
+    if (mapperResponseMsg.is_method_error())
+    {
+        log<level::ERR>("ERROR in getting service",
+                entry("PATH=%s",path.c_str()),
+                entry("INTERFACE=%s",intf.c_str()));
+
+        elog<InternalFailure>();
+    }
+
+    std::map<std::string, std::vector<std::string>> mapperResponse;
+    mapperResponseMsg.read(mapperResponse);
+
+    if (mapperResponse.begin() == mapperResponse.end())
+    {
+        log<level::ERR>("ERROR reading mapper response",
+                entry("PATH=%s",path.c_str()),
+                entry("INTERFACE=%s",intf.c_str()));
+
+        elog<InternalFailure>();
+    }
+    return mapperResponse.begin()->first;
+}
+
+} // namespace occ
+} // namespace open_power