regulators: Add toString() method to Action class

Add a toString() method to the Action class and all child classes.

This method returns a string description of the action.  The description
will be used in journal entries and error logs when an action fails
(such as due to an I2C error).

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I083496d23bf9c3df5be1b082650a9def24be1b00
diff --git a/phosphor-regulators/src/actions/action.hpp b/phosphor-regulators/src/actions/action.hpp
index 4cbe76d..81b7b4d 100644
--- a/phosphor-regulators/src/actions/action.hpp
+++ b/phosphor-regulators/src/actions/action.hpp
@@ -17,6 +17,8 @@
 
 #include "action_environment.hpp"
 
+#include <string>
+
 namespace phosphor::power::regulators
 {
 
@@ -54,6 +56,18 @@
      *         indicate if the action was successfully executed.
      */
     virtual bool execute(ActionEnvironment& environment) = 0;
+
+    /**
+     * Returns a string description of this action.
+     *
+     * The description should include the action name, properties, and property
+     * values.
+     *
+     * The description is used in journal entries and error logs.
+     *
+     * @return description of action
+     */
+    virtual std::string toString() const = 0;
 };
 
 } // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/src/actions/and_action.hpp b/phosphor-regulators/src/actions/and_action.hpp
index cb934b4..f4c3fca 100644
--- a/phosphor-regulators/src/actions/and_action.hpp
+++ b/phosphor-regulators/src/actions/and_action.hpp
@@ -19,6 +19,7 @@
 #include "action_environment.hpp"
 
 #include <memory>
+#include <string>
 #include <utility>
 #include <vector>
 
@@ -93,6 +94,16 @@
         return actions;
     }
 
+    /**
+     * Returns a string description of this action.
+     *
+     * @return description of action
+     */
+    virtual std::string toString() const override
+    {
+        return "and: [ ... ]";
+    }
+
   private:
     /**
      * Actions to execute.
diff --git a/phosphor-regulators/src/actions/if_action.hpp b/phosphor-regulators/src/actions/if_action.hpp
index 13b9860..10b2f5b 100644
--- a/phosphor-regulators/src/actions/if_action.hpp
+++ b/phosphor-regulators/src/actions/if_action.hpp
@@ -19,6 +19,7 @@
 #include "action_environment.hpp"
 
 #include <memory>
+#include <string>
 #include <utility>
 #include <vector>
 
@@ -126,6 +127,22 @@
         return elseActions;
     }
 
+    /**
+     * Returns a string description of this action.
+     *
+     * @return description of action
+     */
+    virtual std::string toString() const override
+    {
+        std::string description{"if: { condition: { ... }, then: [ ... ]"};
+        if (elseActions.size() > 0)
+        {
+            description += ", else: [ ... ]";
+        }
+        description += " }";
+        return description;
+    }
+
   private:
     /**
      * Action that tests whether the condition is true.
diff --git a/phosphor-regulators/src/actions/not_action.hpp b/phosphor-regulators/src/actions/not_action.hpp
index 824a763..762f5b5 100644
--- a/phosphor-regulators/src/actions/not_action.hpp
+++ b/phosphor-regulators/src/actions/not_action.hpp
@@ -19,6 +19,7 @@
 #include "action_environment.hpp"
 
 #include <memory>
+#include <string>
 #include <utility>
 
 namespace phosphor::power::regulators
@@ -79,6 +80,16 @@
         return action;
     }
 
+    /**
+     * Returns a string description of this action.
+     *
+     * @return description of action
+     */
+    virtual std::string toString() const override
+    {
+        return "not: { ... }";
+    }
+
   private:
     /**
      * Action to execute.
diff --git a/phosphor-regulators/src/actions/or_action.hpp b/phosphor-regulators/src/actions/or_action.hpp
index 7adcc6f..5dcff7a 100644
--- a/phosphor-regulators/src/actions/or_action.hpp
+++ b/phosphor-regulators/src/actions/or_action.hpp
@@ -19,6 +19,7 @@
 #include "action_environment.hpp"
 
 #include <memory>
+#include <string>
 #include <utility>
 #include <vector>
 
@@ -93,6 +94,16 @@
         return actions;
     }
 
+    /**
+     * Returns a string description of this action.
+     *
+     * @return description of action
+     */
+    virtual std::string toString() const override
+    {
+        return "or: [ ... ]";
+    }
+
   private:
     /**
      * Actions to execute.
diff --git a/phosphor-regulators/src/actions/run_rule_action.hpp b/phosphor-regulators/src/actions/run_rule_action.hpp
index 8e84a89..6cf63ac 100644
--- a/phosphor-regulators/src/actions/run_rule_action.hpp
+++ b/phosphor-regulators/src/actions/run_rule_action.hpp
@@ -89,6 +89,16 @@
         return ruleID;
     }
 
+    /**
+     * Returns a string description of this action.
+     *
+     * @return description of action
+     */
+    virtual std::string toString() const override
+    {
+        return "run_rule: " + ruleID;
+    }
+
   private:
     /**
      * Rule ID.
diff --git a/phosphor-regulators/src/actions/set_device_action.hpp b/phosphor-regulators/src/actions/set_device_action.hpp
index 7942840..955891e 100644
--- a/phosphor-regulators/src/actions/set_device_action.hpp
+++ b/phosphor-regulators/src/actions/set_device_action.hpp
@@ -75,6 +75,16 @@
         return deviceID;
     }
 
+    /**
+     * Returns a string description of this action.
+     *
+     * @return description of action
+     */
+    virtual std::string toString() const override
+    {
+        return "set_device: " + deviceID;
+    }
+
   private:
     /**
      * Device ID.