1ec1b41c4SGunnar Mills #include <string> 22ce7da29SGunnar Mills #include <phosphor-logging/log.hpp> 3ec1b41c4SGunnar Mills #include "config.h" 42ce7da29SGunnar Mills #include "item_updater.hpp" 52ce7da29SGunnar Mills #include "xyz/openbmc_project/Software/Version/server.hpp" 6ec1b41c4SGunnar Mills 7ec1b41c4SGunnar Mills namespace phosphor 8ec1b41c4SGunnar Mills { 9ec1b41c4SGunnar Mills namespace software 10ec1b41c4SGunnar Mills { 11ec1b41c4SGunnar Mills namespace updater 12ec1b41c4SGunnar Mills { 13ec1b41c4SGunnar Mills 142ce7da29SGunnar Mills // When you see server:: you know we're referencing our base class 152ce7da29SGunnar Mills namespace server = sdbusplus::xyz::openbmc_project::Software::server; 162ce7da29SGunnar Mills 172ce7da29SGunnar Mills using namespace phosphor::logging; 182ce7da29SGunnar Mills 19*e75d10f5SPatrick Williams void ItemUpdater::createActivation(sdbusplus::message::message& msg) 20ec1b41c4SGunnar Mills { 212ce7da29SGunnar Mills sdbusplus::message::object_path objPath; 222ce7da29SGunnar Mills std::map<std::string, 232ce7da29SGunnar Mills std::map<std::string, 242ce7da29SGunnar Mills sdbusplus::message::variant<std::string>>> interfaces; 25*e75d10f5SPatrick Williams msg.read(objPath, interfaces); 262ce7da29SGunnar Mills std::string path(std::move(objPath)); 272ce7da29SGunnar Mills 282ce7da29SGunnar Mills for (const auto& intf : interfaces) 292ce7da29SGunnar Mills { 302ce7da29SGunnar Mills if (intf.first.compare(VERSION_IFACE)) 312ce7da29SGunnar Mills { 322ce7da29SGunnar Mills continue; 332ce7da29SGunnar Mills } 342ce7da29SGunnar Mills 352ce7da29SGunnar Mills for (const auto& property : intf.second) 362ce7da29SGunnar Mills { 372ce7da29SGunnar Mills if (!property.first.compare("Purpose")) 382ce7da29SGunnar Mills { 392ce7da29SGunnar Mills // Only process the BMC images 40*e75d10f5SPatrick Williams auto value = sdbusplus::message::variant_ns::get<std::string>( 41*e75d10f5SPatrick Williams property.second); 42*e75d10f5SPatrick Williams if (value != 43*e75d10f5SPatrick Williams convertForMessage(server::Version::VersionPurpose::BMC)) 442ce7da29SGunnar Mills { 45*e75d10f5SPatrick Williams return; 462ce7da29SGunnar Mills } 472ce7da29SGunnar Mills } 482ce7da29SGunnar Mills } 492ce7da29SGunnar Mills } 502ce7da29SGunnar Mills 512ce7da29SGunnar Mills // Version id is the last item in the path 522ce7da29SGunnar Mills auto pos = path.rfind("/"); 532ce7da29SGunnar Mills if (pos == std::string::npos) 542ce7da29SGunnar Mills { 552ce7da29SGunnar Mills log<level::ERR>("No version id found in object path", 562ce7da29SGunnar Mills entry("OBJPATH=%s", path)); 57*e75d10f5SPatrick Williams return; 582ce7da29SGunnar Mills } 592ce7da29SGunnar Mills 602ce7da29SGunnar Mills auto versionId = path.substr(pos + 1); 612ce7da29SGunnar Mills 62*e75d10f5SPatrick Williams if (activations.find(versionId) == activations.end()) 632ce7da29SGunnar Mills { 642ce7da29SGunnar Mills // For now set all BMC code versions to active 65*e75d10f5SPatrick Williams constexpr auto activationState = 66*e75d10f5SPatrick Williams server::Activation::Activations::Active; 672ce7da29SGunnar Mills 68*e75d10f5SPatrick Williams activations.insert( 69*e75d10f5SPatrick Williams std::make_pair( 702ce7da29SGunnar Mills versionId, 71ec1b41c4SGunnar Mills std::make_unique<Activation>( 72*e75d10f5SPatrick Williams bus, path, versionId, activationState))); 732ce7da29SGunnar Mills } 74*e75d10f5SPatrick Williams return; 75ec1b41c4SGunnar Mills } 76ec1b41c4SGunnar Mills 77ec1b41c4SGunnar Mills } // namespace updater 78ec1b41c4SGunnar Mills } // namespace software 79ec1b41c4SGunnar Mills } // namespace phosphor 80