diff options
| author | James Feist <james.feist@linux.intel.com> | 2018-10-08 13:06:41 -0700 |
|---|---|---|
| committer | James Feist <james.feist@linux.intel.com> | 2018-10-08 20:10:04 +0000 |
| commit | cd9e109fef2e1a2cc44fd54a856117245ff47e4d (patch) | |
| tree | 4811acfd86c1762badd1bdd635cde104ba68bad9 | |
| parent | 50fdfe39889126fe6201436162cc2bba78f5b049 (diff) | |
| download | phosphor-pid-control-cd9e109fef2e1a2cc44fd54a856117245ff47e4d.tar.gz phosphor-pid-control-cd9e109fef2e1a2cc44fd54a856117245ff47e4d.zip | |
[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>
| -rw-r--r-- | dbus/dbuswrite.cpp | 12 | ||||
| -rw-r--r-- | dbus/dbuswrite.hpp | 2 |
2 files changed, 13 insertions, 1 deletions
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<int64_t>(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<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 @@ void DbusWrite::write(double value) { 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 @@ 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; }; |

