blob: 81afd6db0b25576ee4caf8fd274ca9c005abe984 [file] [log] [blame]
Gunnar Millsec1b41c2017-05-02 12:20:36 -05001#include <string>
Gunnar Mills2ce7da22017-05-04 15:37:56 -05002#include <phosphor-logging/log.hpp>
Gunnar Millsec1b41c2017-05-02 12:20:36 -05003#include "config.h"
Gunnar Mills2ce7da22017-05-04 15:37:56 -05004#include "item_updater.hpp"
5#include "xyz/openbmc_project/Software/Version/server.hpp"
Gunnar Millsec1b41c2017-05-02 12:20:36 -05006
7namespace phosphor
8{
9namespace software
10{
11namespace updater
12{
13
Gunnar Mills2ce7da22017-05-04 15:37:56 -050014// When you see server:: you know we're referencing our base class
15namespace server = sdbusplus::xyz::openbmc_project::Software::server;
16
17using namespace phosphor::logging;
18
Patrick Williamse75d10f2017-05-30 16:56:32 -050019void ItemUpdater::createActivation(sdbusplus::message::message& msg)
Gunnar Millsec1b41c2017-05-02 12:20:36 -050020{
Gunnar Mills2ce7da22017-05-04 15:37:56 -050021 sdbusplus::message::object_path objPath;
22 std::map<std::string,
Patrick Williamse75d10f2017-05-30 16:56:32 -050023 std::map<std::string,
24 sdbusplus::message::variant<std::string>>> interfaces;
25 msg.read(objPath, interfaces);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050026 std::string path(std::move(objPath));
27
28 for (const auto& intf : interfaces)
29 {
30 if (intf.first.compare(VERSION_IFACE))
31 {
32 continue;
33 }
34
35 for (const auto& property : intf.second)
36 {
37 if (!property.first.compare("Purpose"))
38 {
39 // Only process the BMC images
Patrick Williamse75d10f2017-05-30 16:56:32 -050040 auto value = sdbusplus::message::variant_ns::get<std::string>(
41 property.second);
42 if (value !=
Patrick Williams9f357142017-05-30 16:58:30 -050043 convertForMessage(server::Version::VersionPurpose::BMC) &&
44 value !=
45 convertForMessage(server::Version::VersionPurpose::System))
Gunnar Mills2ce7da22017-05-04 15:37:56 -050046 {
Patrick Williamse75d10f2017-05-30 16:56:32 -050047 return;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050048 }
49 }
50 }
51 }
52
53 // Version id is the last item in the path
54 auto pos = path.rfind("/");
55 if (pos == std::string::npos)
56 {
57 log<level::ERR>("No version id found in object path",
58 entry("OBJPATH=%s", path));
Patrick Williamse75d10f2017-05-30 16:56:32 -050059 return;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050060 }
61
62 auto versionId = path.substr(pos + 1);
63
Patrick Williamse75d10f2017-05-30 16:56:32 -050064 if (activations.find(versionId) == activations.end())
Gunnar Mills2ce7da22017-05-04 15:37:56 -050065 {
66 // For now set all BMC code versions to active
Patrick Williamse75d10f2017-05-30 16:56:32 -050067 constexpr auto activationState =
68 server::Activation::Activations::Active;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050069
Patrick Williamse75d10f2017-05-30 16:56:32 -050070 activations.insert(
71 std::make_pair(
72 versionId,
73 std::make_unique<Activation>(
74 bus, path, versionId, activationState)));
Gunnar Mills2ce7da22017-05-04 15:37:56 -050075 }
Patrick Williamse75d10f2017-05-30 16:56:32 -050076 return;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050077}
78
79} // namespace updater
80} // namespace software
81} // namespace phosphor