phosphor-fan-presence elog error exception.

Implemented elog exception for phosphor fan presence,
replacing runtime_errors.

Change-Id: I70465060838b2cbaeadccf84ed5924e222ac59e3
Signed-off-by: Dinesh Chinari <chinari@us.ibm.com>
diff --git a/control/Makefile.am b/control/Makefile.am
index 7599977..7a970ea 100644
--- a/control/Makefile.am
+++ b/control/Makefile.am
@@ -17,11 +17,13 @@
 phosphor_fan_control_LDADD = \
 	$(top_builddir)/libfan.la \
 	$(SDBUSPLUS_LIBS) \
-	$(PHOSPHOR_LOGGING_LIBS)
+	$(PHOSPHOR_LOGGING_LIBS) \
+	${PHOSPHOR_DBUS_INTERFACES_LIBS}
 
 phosphor_fan_control_CXXFLAGS = \
 	$(SDBUSPLUS_CFLAGS) \
-	$(PHOSPHOR_LOGGING_CFLAGS)
+	$(PHOSPHOR_LOGGING_CFLAGS) \
+	${PHOSPHOR_DBUS_INTERFACES_CFLAGS}
 
 BUILT_SOURCES = fan_zone_defs.cpp
 
diff --git a/control/fan.cpp b/control/fan.cpp
index 550d34a..fcbf4f8 100644
--- a/control/fan.cpp
+++ b/control/fan.cpp
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 #include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
 #include <string>
 #include "fan.hpp"
 #include "utility.hpp"
@@ -25,6 +28,11 @@
 namespace control
 {
 
+// For throwing exception
+using namespace phosphor::logging;
+using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
+                            Error::InternalFailure;
+
 constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
 constexpr auto FAN_SENSOR_PATH = "/xyz/openbmc_project/sensors/fan_tach/";
 constexpr auto FAN_SENSOR_CONTROL_INTF = "xyz.openbmc_project.Control.FanSpeed";
@@ -60,27 +68,20 @@
 
     for (auto& sensor : _sensors)
     {
-        try
-        {
-            auto service = getService(sensor);
+        auto service = getService(sensor);
 
-            auto method = _bus.new_method_call(service.c_str(),
+        auto method = _bus.new_method_call(service.c_str(),
                                                sensor.c_str(),
                                                PROPERTY_INTERFACE,
                                                "Set");
-            method.append(FAN_SENSOR_CONTROL_INTF, property, value);
+        method.append(FAN_SENSOR_CONTROL_INTF, property, value);
 
-            auto response = _bus.call(method);
-            if (response.is_method_error())
-            {
-                throw std::runtime_error(
-                    "Failed call to set fan speed on " + sensor);
-            }
-        }
-        catch (std::exception& e)
+        auto response = _bus.call(method);
+        if (response.is_method_error())
         {
-            //Other applications will handle reporting errors for this
-            phosphor::logging::log<phosphor::logging::level::INFO>(e.what());
+            log<level::ERR>(
+                "Failed call to set fan speed ", entry("SENSOR=%s", sensor));
+            elog<InternalFailure>();
         }
     }
 }
diff --git a/control/manager.cpp b/control/manager.cpp
index c3c1226..bbd0f5e 100644
--- a/control/manager.cpp
+++ b/control/manager.cpp
@@ -15,6 +15,9 @@
  */
 #include <algorithm>
 #include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
 #include <unistd.h>
 #include "manager.hpp"
 #include "utility.hpp"
@@ -69,8 +72,8 @@
 
     if (reply.is_method_error())
     {
-        throw std::runtime_error(
-            "Error in call response for retrieving property");
+        log<level::ERR>("Error in call response for retrieving property");
+        elog<InternalFailure>();
     }
     reply.read(property);
     value = sdbusplus::message::variant_ns::get<T>(property);
@@ -179,9 +182,8 @@
     auto response = _bus.call(method);
     if (response.is_method_error())
     {
-        //TODO openbmc/openbmc#1555 create an elog
         log<level::ERR>("Failed to start fan control ready target");
-        throw std::runtime_error("Failed to start fan control ready target");
+        elog<InternalFailure>();
     }
 }
 
diff --git a/control/zone.cpp b/control/zone.cpp
index 14bd9d2..67e22d9 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -13,7 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <phosphor-logging/log.hpp>
 #include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
 #include "zone.hpp"
 #include "utility.hpp"
 
@@ -25,6 +28,8 @@
 {
 
 using namespace phosphor::logging;
+using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
+                             Error::InternalFailure;
 
 Zone::Zone(Mode mode,
            sdbusplus::bus::bus& bus,
@@ -141,8 +146,8 @@
     auto hostResponseMsg = bus.call(hostCall);
     if (hostResponseMsg.is_method_error())
     {
-        throw std::runtime_error(
-            "Error in host call response for retrieving property");
+        log<level::ERR>("Error in host call response for retrieving property");
+        elog<InternalFailure>();
     }
     hostResponseMsg.read(value);
 }