Create Activation dbus object
Monitor the creation of new software version dbus objects and
create an activation dbus object SOFTWARE_OBJPATH/<ID>.
Save them in a persistent map with the corresponding version id,
add the real version id number to the map and to the dbus
object path once that's available.
Change-Id: I35c2f211bbefc44a066aafa1760f725399215e69
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/.gitignore b/.gitignore
index 43f2f95..b7a0bd8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@
/config.log
/config.status
/openpower-version-host-software-manager
+/openpower-update-manager
Makefile
.deps
*-libtool
diff --git a/Makefile.am b/Makefile.am
index 7d8aa90..d686971 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,12 +1,17 @@
AM_DEFAULT_SOURCE_EXT = .cpp
sbin_PROGRAMS = \
- openpower-version-host-software-manager
+ openpower-version-host-software-manager \
+ openpower-update-manager
openpower_version_host_software_manager_SOURCES = \
version_host_software_manager.cpp \
version_host_software_manager_main.cpp
+openpower_update_manager_SOURCES = \
+ item_updater.cpp \
+ item_updater_main.cpp
+
generic_cxxflags = \
$(SYSTEMD_CFLAGS) \
$(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
@@ -18,4 +23,6 @@
openpower_version_host_software_manager_CXXFLAGS = $(generic_cxxflags)
openpower_version_host_software_manager_LDFLAGS = $(generic_ldflags)
+openpower_update_manager_CXXFLAGS = $(generic_cxxflags)
+openpower_update_manager_LDFLAGS = $(generic_ldflags)
diff --git a/activation.hpp b/activation.hpp
new file mode 100755
index 0000000..34191bc
--- /dev/null
+++ b/activation.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include <xyz/openbmc_project/Software/Activation/server.hpp>
+
+namespace openpower
+{
+namespace software
+{
+namespace manager
+{
+
+using ActivationInherit = sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Software::server::Activation>;
+
+/** @class Activation
+ * @brief OpenBMC activation software management implementation.
+ * @details A concrete implementation for
+ * xyz.openbmc_project.Software.Activation DBus API.
+ */
+class Activation : public ActivationInherit
+{
+ public:
+ /** @brief Constructs Activation Software Manager
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] path - The Dbus object path
+ */
+ Activation(sdbusplus::bus::bus& bus, const std::string& path) :
+ ActivationInherit(bus, path.c_str()) {};
+};
+
+} // namespace manager
+} // namespace software
+} // namespace openpower
+
diff --git a/configure.ac b/configure.ac
index eaf171f..d51ad37 100755
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,9 @@
AS_IF([test "x$SOFTWARE_OBJPATH" == "x"], [SOFTWARE_OBJPATH="/xyz/openbmc_project/software"])
AC_DEFINE_UNQUOTED([SOFTWARE_OBJPATH], ["$SOFTWARE_OBJPATH"], [The software manager Dbus root])
+AC_DEFINE(BUSNAME_UPDATER, "org.open_power.Software.Host.Updater",
+ [The item updater DBus busname to own.])
+
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
diff --git a/item_updater.cpp b/item_updater.cpp
new file mode 100755
index 0000000..9614f50
--- /dev/null
+++ b/item_updater.cpp
@@ -0,0 +1,28 @@
+#include "config.h"
+#include "item_updater.hpp"
+
+namespace openpower
+{
+namespace software
+{
+namespace manager
+{
+
+int ItemUpdater::createActivation(sd_bus_message* msg,
+ void* userData,
+ sd_bus_error* retErr)
+{
+ auto versionId = 1;
+ auto* updater = static_cast<ItemUpdater*>(userData);
+ updater->activations.insert(std::make_pair(
+ versionId,
+ std::make_unique<Activation>(
+ updater->busItem,
+ SOFTWARE_OBJPATH)));
+ return 0;
+}
+
+} // namespace manager
+} // namespace software
+} // namespace openpower
+
diff --git a/item_updater.hpp b/item_updater.hpp
new file mode 100755
index 0000000..a854a62
--- /dev/null
+++ b/item_updater.hpp
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <sdbusplus/server.hpp>
+#include "activation.hpp"
+
+namespace openpower
+{
+namespace software
+{
+namespace manager
+{
+
+/** @class ItemUpdater
+ * @brief Manages the activation of the version items.
+ */
+class ItemUpdater
+{
+ public:
+ ItemUpdater() = delete;
+ ~ItemUpdater() = default;
+ ItemUpdater(const ItemUpdater&) = delete;
+ ItemUpdater& operator=(const ItemUpdater&) = delete;
+ ItemUpdater(ItemUpdater&&) = delete;
+ ItemUpdater& operator=(ItemUpdater&&) = delete;
+
+ /** @brief Constructs ItemUpdater
+ *
+ * @param[in] bus - The Dbus bus object
+ */
+ ItemUpdater(sdbusplus::bus::bus& bus) :
+ busItem(bus),
+ versionMatch(
+ bus,
+ "type='signal',"
+ "member='InterfacesAdded',"
+ "path='/xyz/openbmc_project/software',"
+ "interface='org.freedesktop.DBus.ObjectManager'",
+ createActivation,
+ this)
+ {
+ }
+
+ private:
+ /** @brief Callback function for Software.Version match.
+ * @details Creates an Activation dbus object.
+ *
+ * @param[in] msg - Data associated with subscribed signal
+ * @param[in] userData - Pointer to this object instance
+ * @param[out] retError - Required param
+ */
+ static int createActivation(sd_bus_message* msg,
+ void* userData,
+ sd_bus_error* retError);
+
+ /** @brief Persistent sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus& busItem;
+
+ /** @brief Persistent map of Activation dbus objects and their
+ * version id */
+ std::map<uint32_t, std::unique_ptr<Activation>> activations;
+
+ /** @brief sdbusplus signal match for Software.Version */
+ sdbusplus::server::match::match versionMatch;
+};
+
+} // namespace manager
+} // namespace software
+} // namespace openpower
+
diff --git a/item_updater_main.cpp b/item_updater_main.cpp
new file mode 100755
index 0000000..b4ff177
--- /dev/null
+++ b/item_updater_main.cpp
@@ -0,0 +1,23 @@
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/manager.hpp>
+#include "config.h"
+#include "item_updater.hpp"
+
+int main(int argc, char* argv[])
+{
+ auto bus = sdbusplus::bus::new_default();
+
+ // Add sdbusplus ObjectManager.
+ sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
+
+ openpower::software::manager::ItemUpdater updater(bus);
+
+ bus.request_name(BUSNAME_UPDATER);
+
+ while (true)
+ {
+ bus.process_discard();
+ bus.wait();
+ }
+ return 0;
+}