Create activation interface on BMC version dbus creation
Create an activation interface on BMC version dbus creation.
For now, set all versions with a purpose of "BMC" to Active.
Resolves openbmc/openbmc#1532
Change-Id: Ia253c5744bf7808191f2f1814734dab426edc1a5
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index f35a9a0..9427414 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -1,6 +1,8 @@
#include <string>
-#include "item_updater.hpp"
+#include <phosphor-logging/log.hpp>
#include "config.h"
+#include "item_updater.hpp"
+#include "xyz/openbmc_project/Software/Version/server.hpp"
namespace phosphor
{
@@ -9,17 +11,73 @@
namespace updater
{
+// When you see server:: you know we're referencing our base class
+namespace server = sdbusplus::xyz::openbmc_project::Software::server;
+
+using namespace phosphor::logging;
+
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(
- std::to_string(versionId),
- std::make_unique<Activation>(
- updater->bus,
- SOFTWARE_OBJPATH)));
+ auto m = sdbusplus::message::message(msg);
+
+ sdbusplus::message::object_path objPath;
+ std::map<std::string,
+ std::map<std::string,
+ sdbusplus::message::variant<std::string>>> interfaces;
+ m.read(objPath, interfaces);
+ std::string path(std::move(objPath));
+
+ for (const auto& intf : interfaces)
+ {
+ if (intf.first.compare(VERSION_IFACE))
+ {
+ continue;
+ }
+
+ for (const auto& property : intf.second)
+ {
+ if (!property.first.compare("Purpose"))
+ {
+ // Only process the BMC images
+ std::string value = sdbusplus::message::variant_ns::get <
+ std::string > (property.second);
+ if (value.compare(convertForMessage(server::Version::
+ VersionPurpose::
+ BMC).c_str()))
+ {
+ return 0;
+ }
+ }
+ }
+ }
+
+ // Version id is the last item in the path
+ auto pos = path.rfind("/");
+ if (pos == std::string::npos)
+ {
+ log<level::ERR>("No version id found in object path",
+ entry("OBJPATH=%s", path));
+ return -1;
+ }
+
+ auto versionId = path.substr(pos + 1);
+
+ if (updater->activations.find(versionId) == updater->activations.end())
+ {
+ // For now set all BMC code versions to active
+ auto activationState = server::Activation::Activations::Active;
+
+ updater->activations.insert(std::make_pair(
+ versionId,
+ std::make_unique<Activation>(
+ updater->bus,
+ path,
+ versionId,
+ activationState)));
+ }
return 0;
}