handler: Support more retry logic

Add retry logic for more methods that may fail due to unstable
ipmi interfaces. Also added one seconds sleep in between retries to
allow some time for the interface to be initialized.

Tested: Updated BMC firmware with the new tool and didn't have any
regression.

Change-Id: Ifc4155dd895f1a654da9e03f17e4c1e8613c9133
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/tools/handler.hpp b/tools/handler.hpp
index 4d2fe50..25dc2f5 100644
--- a/tools/handler.hpp
+++ b/tools/handler.hpp
@@ -3,6 +3,7 @@
 #include "interface.hpp"
 
 #include <ipmiblob/blob_interface.hpp>
+#include <stdplus/function_view.hpp>
 
 #include <string>
 
@@ -76,11 +77,6 @@
     void sendFile(const std::string& target, const std::string& path) override;
 
     /**
-     * @throw ToolException on failure.
-     */
-    void retrySendFile(const std::string& target, const std::string& path);
-
-    /**
      * @throw ToolException on failure (TODO: throw on timeout.)
      */
     bool verifyFile(const std::string& target, bool ignoreStatus) override;
@@ -92,6 +88,27 @@
   private:
     ipmiblob::BlobInterface* blob;
     DataInterface* handler;
+
+    /**
+     * @throw ToolException on failure.
+     */
+    void retrySendFile(const std::string& target, const std::string& path);
+
+    /**
+     * @throw ToolException on failure (TODO: throw on timeout.)
+     */
+    void retryVerifyFile(const std::string& target, bool ignoreStatus);
+
+    /**
+     * @throw ToolException on failure.
+     */
+    std::vector<uint8_t> retryReadVersion(const std::string& versionBlob);
+
+    /**
+     * @throw ToolException on failure.
+     */
+    std::vector<uint8_t>
+        retryIfFailed(stdplus::function_view<std::vector<uint8_t>()> callback);
 };
 
 } // namespace host_tool