start-update-interface: implement update manager
Implement the update manager module for the new daemon inheriting from
the Update D-Bus interface. Link with new interface APIs from
item_updater and software utils. New daemon will continue to exist at
runtime alongwith old flow, until old flow is deprecated and removed.
This change is based on -
https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/65738
https://gerrit.openbmc.org/c/openbmc/docs/+/65739
Change-Id: I0ecbbb8fc5340de7f66f8870ae389b405a2debee
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/update_manager.hpp b/update_manager.hpp
new file mode 100644
index 0000000..5214335
--- /dev/null
+++ b/update_manager.hpp
@@ -0,0 +1,76 @@
+#pragma once
+
+#include "config.h"
+
+#include <sdbusplus/async.hpp>
+#include <xyz/openbmc_project/Software/Update/server.hpp>
+
+#include <random>
+#include <string>
+#include <tuple>
+
+namespace phosphor::software::updater
+{
+class ItemUpdater;
+}
+
+namespace phosphor::software::update
+{
+
+using UpdateIntf = sdbusplus::server::object_t<
+ sdbusplus::xyz::openbmc_project::Software::server::Update>;
+using ItemUpdaterIntf = phosphor::software::updater::ItemUpdater;
+
+using ApplyTimeIntf =
+ sdbusplus::common::xyz::openbmc_project::software::ApplyTime;
+
+/** @class Manager
+ * @brief Processes the image file from update D-Bus interface.
+ * @details The update manager class handles software updates and manages
+ * software info through version and activation objects.
+ */
+class Manager : public UpdateIntf
+{
+ public:
+ /** @brief Constructs Manager Class
+ *
+ * @param[in] bus - The Dbus bus object
+ */
+ explicit Manager(sdbusplus::async::context& ctx, const std::string& path,
+ ItemUpdaterIntf& itemUpdater) :
+ UpdateIntf(ctx.get_bus(), path.c_str(), UpdateIntf::action::defer_emit),
+ ctx(ctx), itemUpdater(itemUpdater)
+ {
+ emit_object_added();
+ }
+
+ private:
+ /** @brief Implementation for StartUpdate
+ * Start a firware update to be performed asynchronously.
+ */
+ sdbusplus::message::object_path
+ startUpdate(sdbusplus::message::unix_fd image,
+ ApplyTimeIntf::RequestedApplyTimes applyTime) override;
+
+ /* @brief Process the image supplied via image fd */
+ auto processImage(sdbusplus::message::unix_fd image,
+ ApplyTimeIntf::RequestedApplyTimes applyTime,
+ std::string id,
+ std::string objPath) -> sdbusplus::async::task<>;
+
+ /* @brief The handler for the image processing failure */
+ void processImageFailed(sdbusplus::message::unix_fd image, std::string& id);
+
+ /** @brief The random generator for the software id */
+ std::mt19937 randomGen{static_cast<unsigned>(
+ std::chrono::system_clock::now().time_since_epoch().count())};
+
+ /** @brief D-Bus context */
+ sdbusplus::async::context& ctx;
+ /** @brief item_updater reference */
+ ItemUpdaterIntf& itemUpdater;
+ /** @brief State whether update is in progress */
+ bool updateInProgress = false;
+};
+
+} // namespace phosphor::software::update