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