dbuswrite: Add another write() form to WriteInterface

Adding another form of the write() call,
which takes 3 arguments instead of 1,
providing an alternate interface for caller to use.

A compatibility function is provided,
which simply calls write(), so no API breakage.

The additional arguments to write() allow caller
to force the write to happen even if old value same,
and/or to learn the actual raw value written.

Adding boilerplate to Sensor and PluggableSensor,
to also pass the 3-argument write() through.

Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: Iaf35f674ef9ce38b56017f6cb0f821df6c789649
diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp
index 288cb1a..fce95ae 100644
--- a/dbus/dbuswrite.cpp
+++ b/dbus/dbuswrite.cpp
@@ -54,6 +54,11 @@
 
 void DbusWritePercent::write(double value)
 {
+    return write(value, false, nullptr);
+}
+
+void DbusWritePercent::write(double value, bool force, int64_t* written)
+{
     double minimum = getMin();
     double maximum = getMax();
 
@@ -63,7 +68,14 @@
 
     if (oldValue == static_cast<int64_t>(ovalue))
     {
-        return;
+        if (!force)
+        {
+            if (written)
+            {
+                *written = oldValue;
+            }
+            return;
+        }
     }
     auto writeBus = sdbusplus::bus::new_default();
     auto mesg =
@@ -84,6 +96,10 @@
     }
 
     oldValue = static_cast<int64_t>(ovalue);
+    if (written)
+    {
+        *written = oldValue;
+    }
     return;
 }
 
@@ -108,9 +124,21 @@
 
 void DbusWrite::write(double value)
 {
+    return write(value, false, nullptr);
+}
+
+void DbusWrite::write(double value, bool force, int64_t* written)
+{
     if (oldValue == static_cast<int64_t>(value))
     {
-        return;
+        if (!force)
+        {
+            if (written)
+            {
+                *written = oldValue;
+            }
+            return;
+        }
     }
     auto writeBus = sdbusplus::bus::new_default();
     auto mesg =
@@ -131,6 +159,10 @@
     }
 
     oldValue = static_cast<int64_t>(value);
+    if (written)
+    {
+        *written = oldValue;
+    }
     return;
 }
 
diff --git a/dbus/dbuswrite.hpp b/dbus/dbuswrite.hpp
index f890781..1beac27 100644
--- a/dbus/dbuswrite.hpp
+++ b/dbus/dbuswrite.hpp
@@ -42,6 +42,7 @@
     {}
 
     void write(double value) override;
+    void write(double value, bool force, int64_t* written) override;
 
   private:
     std::string path;
@@ -63,6 +64,7 @@
     {}
 
     void write(double value) override;
+    void write(double value, bool needRedundant, int64_t* rawWritten) override;
 
   private:
     std::string path;
diff --git a/interfaces.hpp b/interfaces.hpp
index b4b236b..8ec474b 100644
--- a/interfaces.hpp
+++ b/interfaces.hpp
@@ -53,6 +53,18 @@
     virtual void write(double value) = 0;
 
     /*
+     * A wrapper around write(), with additional parameters.
+     * force = true to perform redundant write, even if raw value unchanged.
+     * written = non-null to be filled in with the actual raw value written.
+     */
+    virtual void write(double value, bool force, int64_t* written)
+    {
+        (void)force;
+        (void)written;
+        return write(value);
+    }
+
+    /*
      * All WriteInterfaces have min/max available in case they want to error
      * check.
      */
diff --git a/sensors/pluggable.cpp b/sensors/pluggable.cpp
index 07d3d0e..530737d 100644
--- a/sensors/pluggable.cpp
+++ b/sensors/pluggable.cpp
@@ -29,6 +29,11 @@
     _writer->write(value);
 }
 
+void PluggableSensor::write(double value, bool force, int64_t* written)
+{
+    _writer->write(value, force, written);
+}
+
 bool PluggableSensor::getFailed(void)
 {
     return _reader->getFailed();
diff --git a/sensors/pluggable.hpp b/sensors/pluggable.hpp
index 23aea99..0dc1c71 100644
--- a/sensors/pluggable.hpp
+++ b/sensors/pluggable.hpp
@@ -24,6 +24,7 @@
 
     ReadReturn read(void) override;
     void write(double value) override;
+    void write(double value, bool force, int64_t* written) override;
     bool getFailed(void) override;
 
   private:
diff --git a/sensors/sensor.hpp b/sensors/sensor.hpp
index 8258b7b..f5f01c2 100644
--- a/sensors/sensor.hpp
+++ b/sensors/sensor.hpp
@@ -36,6 +36,14 @@
 
     virtual ReadReturn read(void) = 0;
     virtual void write(double value) = 0;
+
+    virtual void write(double value, bool force, int64_t* written)
+    {
+        (void)force;
+        (void)written;
+        return write(value);
+    }
+
     virtual bool getFailed(void)
     {
         return false;