blob: 561e6c7bb59b8b99c15829c89f2f98e015eff1ca [file] [log] [blame]
#pragma once
#include "interface.hpp"
#include "updatehelper.hpp"
#include <fstream>
#include <memory>
#include <string>
class UploadManager
{
public:
UploadManager(std::ifstream&& image, std::ifstream&& hash,
int32_t imageSize, int32_t hashSize,
UpdateHelperInterface* helper, DataInterface* dintf) :
imageStream(std::move(image)),
hashStream(std::move(hash)), imageSize(imageSize), hashSize(hashSize),
helper(helper), dintf(dintf)
{
}
/**
* Instantiate an UploadManager if the parameters check out.
*
* @param[in] image - path to the firmware image.
* @param[in] hash - path to the image's hash.
* @param[in] helper - pointer to an UpdateHelperInterface.
* @param[in] dintf - pointer to the data interface to use.
* @return UploadManager if valid or nullptr if invalid.
*/
static std::unique_ptr<UploadManager>
BuildUploadMgr(const std::string& image, const std::string& hash,
UpdateHelperInterface* helper, DataInterface* dintf);
/**
* Try to update the BMC flash image over IPMI through BT.
*/
void UpdateBMC();
private:
std::ifstream imageStream;
std::ifstream hashStream;
int32_t imageSize;
int32_t hashSize;
UpdateHelperInterface* helper;
DataInterface* dintf;
};
// Main entry point for the update command.
// Update uploads and verifies the image.
// throws exception on errors.
void UpdaterMain(const std::string& interface, const std::string& image,
const std::string& signature);