blob: 59c07f25ed77f02023cf3c655186248d758122e2 [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 !=
43 convertForMessage(server::Version::VersionPurpose::BMC))
Gunnar Mills2ce7da22017-05-04 15:37:56 -050044 {
Patrick Williamse75d10f2017-05-30 16:56:32 -050045 return;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050046 }
47 }
48 }
49 }
50
51 // Version id is the last item in the path
52 auto pos = path.rfind("/");
53 if (pos == std::string::npos)
54 {
55 log<level::ERR>("No version id found in object path",
56 entry("OBJPATH=%s", path));
Patrick Williamse75d10f2017-05-30 16:56:32 -050057 return;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050058 }
59
60 auto versionId = path.substr(pos + 1);
61
Patrick Williamse75d10f2017-05-30 16:56:32 -050062 if (activations.find(versionId) == activations.end())
Gunnar Mills2ce7da22017-05-04 15:37:56 -050063 {
64 // For now set all BMC code versions to active
Patrick Williamse75d10f2017-05-30 16:56:32 -050065 constexpr auto activationState =
66 server::Activation::Activations::Active;
Gunnar Mills2ce7da22017-05-04 15:37:56 -050067
Patrick Williamse75d10f2017-05-30 16:56:32 -050068 activations.insert(
69 std::make_pair(
70 versionId,
71 std::make_unique<Activation>(
72 bus, path, versionId, activationState)));
Gunnar Mills2ce7da22017-05-04 15:37:56 -050073 }
Patrick Williamse75d10f2017-05-30 16:56:32 -050074 return;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050075}
76
77} // namespace updater
78} // namespace software
79} // namespace phosphor