xref: /openbmc/phosphor-bmc-code-mgmt/bmc/update_manager.hpp (revision eae5ec9e28d8e0586eae116802e1f0c173040df7)
1cab87e9cSJagpal Singh Gill #pragma once
2cab87e9cSJagpal Singh Gill 
3cab87e9cSJagpal Singh Gill #include "config.h"
4cab87e9cSJagpal Singh Gill 
5cab87e9cSJagpal Singh Gill #include <sdbusplus/async.hpp>
6cab87e9cSJagpal Singh Gill #include <xyz/openbmc_project/Software/Update/server.hpp>
7cab87e9cSJagpal Singh Gill 
8cab87e9cSJagpal Singh Gill #include <random>
9cab87e9cSJagpal Singh Gill #include <string>
10cab87e9cSJagpal Singh Gill #include <tuple>
11cab87e9cSJagpal Singh Gill 
12cab87e9cSJagpal Singh Gill namespace phosphor::software::updater
13cab87e9cSJagpal Singh Gill {
14cab87e9cSJagpal Singh Gill class ItemUpdater;
15cab87e9cSJagpal Singh Gill }
16cab87e9cSJagpal Singh Gill 
17cab87e9cSJagpal Singh Gill namespace phosphor::software::update
18cab87e9cSJagpal Singh Gill {
19cab87e9cSJagpal Singh Gill 
20cab87e9cSJagpal Singh Gill using UpdateIntf = sdbusplus::server::object_t<
21cab87e9cSJagpal Singh Gill     sdbusplus::xyz::openbmc_project::Software::server::Update>;
22cab87e9cSJagpal Singh Gill using ItemUpdaterIntf = phosphor::software::updater::ItemUpdater;
23cab87e9cSJagpal Singh Gill 
24cab87e9cSJagpal Singh Gill using ApplyTimeIntf =
25cab87e9cSJagpal Singh Gill     sdbusplus::common::xyz::openbmc_project::software::ApplyTime;
26cab87e9cSJagpal Singh Gill 
27cab87e9cSJagpal Singh Gill /** @class Manager
28cab87e9cSJagpal Singh Gill  *  @brief Processes the image file from update D-Bus interface.
29cab87e9cSJagpal Singh Gill  *  @details The update manager class handles software updates and manages
30cab87e9cSJagpal Singh Gill  * software info through version and activation objects.
31cab87e9cSJagpal Singh Gill  */
32cab87e9cSJagpal Singh Gill class Manager : public UpdateIntf
33cab87e9cSJagpal Singh Gill {
34cab87e9cSJagpal Singh Gill   public:
35cab87e9cSJagpal Singh Gill     /** @brief Constructs Manager Class
36cab87e9cSJagpal Singh Gill      *
37cab87e9cSJagpal Singh Gill      * @param[in] bus - The Dbus bus object
38cab87e9cSJagpal Singh Gill      */
Manager(sdbusplus::async::context & ctx,const std::string & path,ItemUpdaterIntf & itemUpdater)39cab87e9cSJagpal Singh Gill     explicit Manager(sdbusplus::async::context& ctx, const std::string& path,
40cab87e9cSJagpal Singh Gill                      ItemUpdaterIntf& itemUpdater) :
41cab87e9cSJagpal Singh Gill         UpdateIntf(ctx.get_bus(), path.c_str(), UpdateIntf::action::defer_emit),
42cab87e9cSJagpal Singh Gill         ctx(ctx), itemUpdater(itemUpdater)
43cab87e9cSJagpal Singh Gill     {
44cab87e9cSJagpal Singh Gill         emit_object_added();
45cab87e9cSJagpal Singh Gill     }
46cab87e9cSJagpal Singh Gill 
47cab87e9cSJagpal Singh Gill   private:
48cab87e9cSJagpal Singh Gill     /** @brief Implementation for StartUpdate
49cab87e9cSJagpal Singh Gill      *  Start a firware update to be performed asynchronously.
50cab87e9cSJagpal Singh Gill      */
51*eae5ec9eSPatrick Williams     sdbusplus::message::object_path startUpdate(
52*eae5ec9eSPatrick Williams         sdbusplus::message::unix_fd image,
53cab87e9cSJagpal Singh Gill         ApplyTimeIntf::RequestedApplyTimes applyTime) override;
54cab87e9cSJagpal Singh Gill 
55cab87e9cSJagpal Singh Gill     /* @brief Process the image supplied via image fd */
56cab87e9cSJagpal Singh Gill     auto processImage(sdbusplus::message::unix_fd image,
57cab87e9cSJagpal Singh Gill                       ApplyTimeIntf::RequestedApplyTimes applyTime,
58cab87e9cSJagpal Singh Gill                       std::string id, std::string objPath)
59cab87e9cSJagpal Singh Gill         -> sdbusplus::async::task<>;
60cab87e9cSJagpal Singh Gill 
61cab87e9cSJagpal Singh Gill     /* @brief The handler for the image processing failure  */
62cab87e9cSJagpal Singh Gill     void processImageFailed(sdbusplus::message::unix_fd image, std::string& id);
63cab87e9cSJagpal Singh Gill 
64cab87e9cSJagpal Singh Gill     /** @brief The random generator for the software id */
65cab87e9cSJagpal Singh Gill     std::mt19937 randomGen{static_cast<unsigned>(
66cab87e9cSJagpal Singh Gill         std::chrono::system_clock::now().time_since_epoch().count())};
67cab87e9cSJagpal Singh Gill 
68cab87e9cSJagpal Singh Gill     /** @brief D-Bus context */
69cab87e9cSJagpal Singh Gill     sdbusplus::async::context& ctx;
70cab87e9cSJagpal Singh Gill     /** @brief item_updater reference */
71cab87e9cSJagpal Singh Gill     ItemUpdaterIntf& itemUpdater;
72cab87e9cSJagpal Singh Gill     /** @brief State whether update is in progress */
73cab87e9cSJagpal Singh Gill     bool updateInProgress = false;
74cab87e9cSJagpal Singh Gill };
75cab87e9cSJagpal Singh Gill 
76cab87e9cSJagpal Singh Gill } // namespace phosphor::software::update
77