[dbus-writer] limit d-bus traffic

Limit d-bus traffic by only sending updates, instead
of every value.

Tested-by: used d-bus monitor and noticed significantly
reduced messages.

Change-Id: Ie677feaedab4e9ebb14950392b9588d4d82c0058
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp
index b26b96e..714580b 100644
--- a/dbus/dbuswrite.cpp
+++ b/dbus/dbuswrite.cpp
@@ -41,6 +41,11 @@
     float range = maximum - minimum;
     float offset = range * value;
     float ovalue = offset + minimum;
+
+    if (oldValue == static_cast<int64_t>(ovalue))
+    {
+        return;
+    }
     initBus();
     auto mesg =
         writeBus->new_method_call(connectionName.c_str(), path.c_str(),
@@ -52,11 +57,16 @@
     {
         std::cerr << "Error sending message to " << path << "\n";
     }
+    oldValue = static_cast<int64_t>(ovalue);
     return;
 }
 
 void DbusWrite::write(double value)
 {
+    if (oldValue == static_cast<int64_t>(value))
+    {
+        return;
+    }
     initBus();
     auto mesg =
         writeBus->new_method_call(connectionName.c_str(), path.c_str(),
@@ -68,6 +78,6 @@
     {
         std::cerr << "Error sending message to " << path << "\n";
     }
-
+    oldValue = static_cast<int64_t>(value);
     return;
 }
diff --git a/dbus/dbuswrite.hpp b/dbus/dbuswrite.hpp
index 0bdcde9..6a70fe9 100644
--- a/dbus/dbuswrite.hpp
+++ b/dbus/dbuswrite.hpp
@@ -41,6 +41,7 @@
   private:
     std::string path;
     std::string connectionName;
+    int64_t oldValue = -1;
 };
 
 class DbusWrite : public WriteInterface
@@ -60,4 +61,5 @@
   private:
     std::string path;
     std::string connectionName;
+    int64_t oldValue = -1;
 };