summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-10-30 18:39:50 -0700
committerPatrick Venture <venture@google.com>2018-10-30 18:42:16 -0700
commit76ce5d775c2bb31dc8214dc110c593b9ca0abd22 (patch)
tree3ff5682e1d8e4693233bba548ff6ec8b95e50f1c
parente725286473cf6a522f50b7bfe69fcd56248028bc (diff)
downloadphosphor-pid-control-76ce5d775c2bb31dc8214dc110c593b9ca0abd22.tar.gz
phosphor-pid-control-76ce5d775c2bb31dc8214dc110c593b9ca0abd22.zip
dbus: dbuswrite: add try/catch block on calls
The dbus calls can now except, therefore add try/catch blocks and report the errors. Change-Id: I8cae2576922fa9316065ef048e674beb48a58e88 Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--dbus/dbuswrite.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp
index b691b66..fab9b4a 100644
--- a/dbus/dbuswrite.cpp
+++ b/dbus/dbuswrite.cpp
@@ -18,11 +18,14 @@
#include <iostream>
#include <memory>
+#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <string>
constexpr const char* pwmInterface = "xyz.openbmc_project.Control.FanPwm";
+using namespace phosphor::logging;
+
// this bus object is treated as a singleton because the class is constructed in
// a different thread than it is used, and as bus objects are relatively
// expensive we'd prefer to only have one
@@ -75,11 +78,18 @@ void DbusWritePercent::write(double value)
"org.freedesktop.DBus.Properties", "Set");
mesg.append(pwmInterface, "Target",
sdbusplus::message::variant<uint64_t>(ovalue));
- auto resp = writeBus->call(mesg);
- if (resp.is_method_error())
+
+ try
{
- std::cerr << "Error sending message to " << path << "\n";
+ // TODO: if we don't use the reply, call_noreply()
+ auto resp = writeBus->call(mesg);
}
+ catch (const sdbusplus::exception::SdBusError& ex)
+ {
+ log<level::ERR>("Dbus Call Failure", entry("PATH=%s", path.c_str()),
+ entry("WHAT=%s", ex.what()));
+ }
+
oldValue = static_cast<int64_t>(ovalue);
return;
}
@@ -115,11 +125,18 @@ void DbusWrite::write(double value)
"org.freedesktop.DBus.Properties", "Set");
mesg.append(pwmInterface, "Target",
sdbusplus::message::variant<uint64_t>(value));
- auto resp = writeBus->call(mesg);
- if (resp.is_method_error())
+
+ try
{
- std::cerr << "Error sending message to " << path << "\n";
+ // TODO: consider call_noreplly
+ auto resp = writeBus->call(mesg);
}
+ catch (const sdbusplus::exception::SdBusError& ex)
+ {
+ log<level::ERR>("Dbus Call Failure", entry("PATH=%s", path.c_str()),
+ entry("WHAT=%s", ex.what()));
+ }
+
oldValue = static_cast<int64_t>(value);
return;
}
OpenPOWER on IntegriCloud