xref: /openbmc/phosphor-ipmi-flash/tools/handler.hpp (revision 9b37b09541d468a616d586bf533b684a3751c0f7)
101123b2aSPatrick Venture #pragma once
201123b2aSPatrick Venture 
301123b2aSPatrick Venture #include "interface.hpp"
401123b2aSPatrick Venture 
501123b2aSPatrick Venture #include <ipmiblob/blob_interface.hpp>
6*9b37b095SPatrick Venture 
701123b2aSPatrick Venture #include <string>
801123b2aSPatrick Venture 
901123b2aSPatrick Venture namespace host_tool
1001123b2aSPatrick Venture {
1101123b2aSPatrick Venture 
1201123b2aSPatrick Venture class UpdateHandlerInterface
1301123b2aSPatrick Venture {
1401123b2aSPatrick Venture   public:
1501123b2aSPatrick Venture     virtual ~UpdateHandlerInterface() = default;
1601123b2aSPatrick Venture 
1701123b2aSPatrick Venture     /**
1801123b2aSPatrick Venture      * Check if the goal firmware is listed in the blob_list and that the
1901123b2aSPatrick Venture      * handler's supported data type is available.
2001123b2aSPatrick Venture      *
2101123b2aSPatrick Venture      * @param[in] goalFirmware - the firmware to check /flash/image
2201123b2aSPatrick Venture      * /flash/tarball, etc.
2301123b2aSPatrick Venture      */
2401123b2aSPatrick Venture     virtual bool checkAvailable(const std::string& goalFirmware) = 0;
2501123b2aSPatrick Venture 
2601123b2aSPatrick Venture     /**
2701123b2aSPatrick Venture      * Send the file contents at path to the blob id, target.
2801123b2aSPatrick Venture      *
2901123b2aSPatrick Venture      * @param[in] target - the blob id
3001123b2aSPatrick Venture      * @param[in] path - the source file path
3101123b2aSPatrick Venture      */
3201123b2aSPatrick Venture     virtual void sendFile(const std::string& target,
3301123b2aSPatrick Venture                           const std::string& path) = 0;
3401123b2aSPatrick Venture 
3501123b2aSPatrick Venture     /**
3601123b2aSPatrick Venture      * Trigger verification.
3701123b2aSPatrick Venture      *
3801123b2aSPatrick Venture      * @param[in] target - the verification blob id (may support multiple in the
3901123b2aSPatrick Venture      * future.
406749ba1cSBrandon Kim      * @param[in] ignoreStatus - determines whether to ignore the verification
416749ba1cSBrandon Kim      * status.
4201123b2aSPatrick Venture      * @return true if verified, false if verification errors.
4301123b2aSPatrick Venture      */
446749ba1cSBrandon Kim     virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0;
4501123b2aSPatrick Venture 
4601123b2aSPatrick Venture     /**
4701123b2aSPatrick Venture      * Cleanup the artifacts by triggering this action.
4801123b2aSPatrick Venture      */
4901123b2aSPatrick Venture     virtual void cleanArtifacts() = 0;
5001123b2aSPatrick Venture };
5101123b2aSPatrick Venture 
5201123b2aSPatrick Venture /** Object that actually handles the update itself. */
5301123b2aSPatrick Venture class UpdateHandler : public UpdateHandlerInterface
5401123b2aSPatrick Venture {
5501123b2aSPatrick Venture   public:
5601123b2aSPatrick Venture     UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) :
5701123b2aSPatrick Venture         blob(blob), handler(handler)
58*9b37b095SPatrick Venture     {}
5901123b2aSPatrick Venture 
6001123b2aSPatrick Venture     ~UpdateHandler() = default;
6101123b2aSPatrick Venture 
6201123b2aSPatrick Venture     bool checkAvailable(const std::string& goalFirmware) override;
6301123b2aSPatrick Venture 
6401123b2aSPatrick Venture     /**
6501123b2aSPatrick Venture      * @throw ToolException on failure.
6601123b2aSPatrick Venture      */
6701123b2aSPatrick Venture     void sendFile(const std::string& target, const std::string& path) override;
6801123b2aSPatrick Venture 
6901123b2aSPatrick Venture     /**
7001123b2aSPatrick Venture      * @throw ToolException on failure (TODO: throw on timeout.)
7101123b2aSPatrick Venture      */
726749ba1cSBrandon Kim     bool verifyFile(const std::string& target, bool ignoreStatus) override;
7301123b2aSPatrick Venture 
7401123b2aSPatrick Venture     void cleanArtifacts() override;
7501123b2aSPatrick Venture 
7601123b2aSPatrick Venture   private:
7701123b2aSPatrick Venture     ipmiblob::BlobInterface* blob;
7801123b2aSPatrick Venture     DataInterface* handler;
7901123b2aSPatrick Venture };
8001123b2aSPatrick Venture 
8101123b2aSPatrick Venture } // namespace host_tool
82