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