Patrick Venture | 7dc4670 | 2018-08-08 09:43:33 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "interface.hpp" |
| 4 | #include "updatehelper.hpp" |
| 5 | |
| 6 | #include <fstream> |
| 7 | #include <memory> |
| 8 | #include <string> |
| 9 | |
| 10 | class UploadManager |
| 11 | { |
| 12 | public: |
| 13 | UploadManager(std::ifstream&& image, std::ifstream&& hash, |
| 14 | int32_t imageSize, int32_t hashSize, |
| 15 | UpdateHelperInterface* helper, DataInterface* dintf) : |
| 16 | imageStream(std::move(image)), |
| 17 | hashStream(std::move(hash)), imageSize(imageSize), hashSize(hashSize), |
| 18 | helper(helper), dintf(dintf) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Instantiate an UploadManager if the parameters check out. |
| 24 | * |
| 25 | * @param[in] image - path to the firmware image. |
| 26 | * @param[in] hash - path to the image's hash. |
| 27 | * @param[in] helper - pointer to an UpdateHelperInterface. |
| 28 | * @param[in] dintf - pointer to the data interface to use. |
| 29 | * @return UploadManager if valid or nullptr if invalid. |
| 30 | */ |
| 31 | static std::unique_ptr<UploadManager> |
| 32 | BuildUploadMgr(const std::string& image, const std::string& hash, |
| 33 | UpdateHelperInterface* helper, DataInterface* dintf); |
| 34 | |
| 35 | /** |
| 36 | * Try to update the BMC flash image over IPMI through BT. |
| 37 | */ |
| 38 | void UpdateBMC(); |
| 39 | |
| 40 | private: |
| 41 | std::ifstream imageStream; |
| 42 | std::ifstream hashStream; |
| 43 | int32_t imageSize; |
| 44 | int32_t hashSize; |
| 45 | UpdateHelperInterface* helper; |
| 46 | DataInterface* dintf; |
| 47 | }; |
| 48 | |
| 49 | // Main entry point for the update command. |
| 50 | // Update uploads and verifies the image. |
| 51 | // throws exception on errors. |
| 52 | void UpdaterMain(const std::string& interface, const std::string& image, |
| 53 | const std::string& signature); |