ExternalSensor: Further refinements

Further refinements, learned after more testing.

Moved the writeHook lambda out of the ExternalSensor constructor,
and into separate initWriteHook() function, to reduce the bloat of
an already extremely large argument list to the constructor,
and solve a nasty gotcha regarding enable_shared_from_this usage:

https://stackoverflow.com/a/63579750/3063879

Adding a few more useful debugging messages, to be printed when
debugging is enabled (set the "debug" constants to true).

Tested: Interrupted external source of data, values changed to NaN
as expected. Resumed external source, values changed from NaN to the
correctly updated values. Timer durations appear correct. Also sent
many configuration change messages, forcing sensor objects to be
reconstructed. No errors noted during processing, even when messages
sent quickly, and also with random delays, and left to run a while.

To check sensor data value:

busctl --no-pager introspect xyz.openbmc_project.ExternalSensor \
 /xyz/openbmc_project/sensors/temperature/mysensor \
 xyz.openbmc_project.Sensor.Value

To send a configuration change message:

dbus-send --system \
/xyz/openbmc_project/inventory/system/board/myboard/mysensor \
x.x.x.PropertiesChanged \
string:xyz.openbmc_project.Configuration.ExternalSensor

Change-Id: I7bd515fed8ddf391df3fabadab61321a446c1b9f
Signed-off-by: Josh Lehan <krellan@google.com>
diff --git a/include/ExternalSensor.hpp b/include/ExternalSensor.hpp
index 02110fe..a8b48e5 100644
--- a/include/ExternalSensor.hpp
+++ b/include/ExternalSensor.hpp
@@ -14,17 +14,21 @@
     public std::enable_shared_from_this<ExternalSensor>
 {
   public:
-    ExternalSensor(
-        const std::string& objectType,
-        sdbusplus::asio::object_server& objectServer,
-        std::shared_ptr<sdbusplus::asio::connection>& conn,
-        const std::string& sensorName, const std::string& sensorMeasure,
-        std::vector<thresholds::Threshold>&& thresholdsIn,
-        const std::string& sensorConfiguration, double maxReading,
-        double minReading, double timeoutSecs, const PowerState& powerState,
+    ExternalSensor(const std::string& objectType,
+                   sdbusplus::asio::object_server& objectServer,
+                   std::shared_ptr<sdbusplus::asio::connection>& conn,
+                   const std::string& sensorName,
+                   const std::string& sensorMeasure,
+                   std::vector<thresholds::Threshold>&& thresholdsIn,
+                   const std::string& sensorConfiguration, double maxReading,
+                   double minReading, double timeoutSecs,
+                   const PowerState& powerState);
+    virtual ~ExternalSensor();
+
+    // Call this immediately after calling the constructor
+    void initWriteHook(
         std::function<void(std::chrono::steady_clock::time_point now)>&&
             writeHookIn);
-    virtual ~ExternalSensor();
 
     // Returns true if sensor has external Value that is subject to timeout
     bool isAliveAndPerishable(void) const;