From cd9e109fef2e1a2cc44fd54a856117245ff47e4d Mon Sep 17 00:00:00 2001 From: James Feist Date: Mon, 8 Oct 2018 13:06:41 -0700 Subject: [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 --- dbus/dbuswrite.cpp | 12 +++++++++++- dbus/dbuswrite.hpp | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) 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 @@ void DbusWritePercent::write(double value) float range = maximum - minimum; float offset = range * value; float ovalue = offset + minimum; + + if (oldValue == static_cast(ovalue)) + { + return; + } initBus(); auto mesg = writeBus->new_method_call(connectionName.c_str(), path.c_str(), @@ -52,11 +57,16 @@ void DbusWritePercent::write(double value) { std::cerr << "Error sending message to " << path << "\n"; } + oldValue = static_cast(ovalue); return; } void DbusWrite::write(double value) { + if (oldValue == static_cast(value)) + { + return; + } initBus(); auto mesg = writeBus->new_method_call(connectionName.c_str(), path.c_str(), @@ -68,6 +78,6 @@ void DbusWrite::write(double value) { std::cerr << "Error sending message to " << path << "\n"; } - + oldValue = static_cast(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 @@ class DbusWritePercent : public WriteInterface private: std::string path; std::string connectionName; + int64_t oldValue = -1; }; class DbusWrite : public WriteInterface @@ -60,4 +61,5 @@ class DbusWrite : public WriteInterface private: std::string path; std::string connectionName; + int64_t oldValue = -1; }; -- cgit v1.2.3