blob: 9427414fef30fdfd2da900916ae2cb4a9f41bd2e [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
Gunnar Millsec1b41c2017-05-02 12:20:36 -050019int ItemUpdater::createActivation(sd_bus_message* msg,
20 void* userData,
21 sd_bus_error* retErr)
22{
Gunnar Millsec1b41c2017-05-02 12:20:36 -050023 auto* updater = static_cast<ItemUpdater*>(userData);
Gunnar Mills2ce7da22017-05-04 15:37:56 -050024 auto m = sdbusplus::message::message(msg);
25
26 sdbusplus::message::object_path objPath;
27 std::map<std::string,
28 std::map<std::string,
29 sdbusplus::message::variant<std::string>>> interfaces;
30 m.read(objPath, interfaces);
31 std::string path(std::move(objPath));
32
33 for (const auto& intf : interfaces)
34 {
35 if (intf.first.compare(VERSION_IFACE))
36 {
37 continue;
38 }
39
40 for (const auto& property : intf.second)
41 {
42 if (!property.first.compare("Purpose"))
43 {
44 // Only process the BMC images
45 std::string value = sdbusplus::message::variant_ns::get <
46 std::string > (property.second);
47 if (value.compare(convertForMessage(server::Version::
48 VersionPurpose::
49 BMC).c_str()))
50 {
51 return 0;
52 }
53 }
54 }
55 }
56
57 // Version id is the last item in the path
58 auto pos = path.rfind("/");
59 if (pos == std::string::npos)
60 {
61 log<level::ERR>("No version id found in object path",
62 entry("OBJPATH=%s", path));
63 return -1;
64 }
65
66 auto versionId = path.substr(pos + 1);
67
68 if (updater->activations.find(versionId) == updater->activations.end())
69 {
70 // For now set all BMC code versions to active
71 auto activationState = server::Activation::Activations::Active;
72
73 updater->activations.insert(std::make_pair(
74 versionId,
75 std::make_unique<Activation>(
76 updater->bus,
77 path,
78 versionId,
79 activationState)));
80 }
Gunnar Millsec1b41c2017-05-02 12:20:36 -050081 return 0;
82}
83
84} // namespace updater
85} // namespace software
86} // namespace phosphor