Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 1 | #include <string> |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 2 | #include <phosphor-logging/log.hpp> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 3 | #include "config.h" |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 4 | #include "item_updater.hpp" |
| 5 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace software |
| 10 | { |
| 11 | namespace updater |
| 12 | { |
| 13 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 14 | // When you see server:: you know we're referencing our base class |
| 15 | namespace server = sdbusplus::xyz::openbmc_project::Software::server; |
| 16 | |
| 17 | using namespace phosphor::logging; |
| 18 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 19 | void ItemUpdater::createActivation(sdbusplus::message::message& msg) |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 20 | { |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 21 | sdbusplus::message::object_path objPath; |
| 22 | std::map<std::string, |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 23 | std::map<std::string, |
| 24 | sdbusplus::message::variant<std::string>>> interfaces; |
| 25 | msg.read(objPath, interfaces); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 26 | 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 Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 40 | auto value = sdbusplus::message::variant_ns::get<std::string>( |
| 41 | property.second); |
| 42 | if (value != |
| 43 | convertForMessage(server::Version::VersionPurpose::BMC)) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 44 | { |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 45 | return; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 46 | } |
| 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 Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 57 | return; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | auto versionId = path.substr(pos + 1); |
| 61 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 62 | if (activations.find(versionId) == activations.end()) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 63 | { |
| 64 | // For now set all BMC code versions to active |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 65 | constexpr auto activationState = |
| 66 | server::Activation::Activations::Active; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 67 | |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 68 | activations.insert( |
| 69 | std::make_pair( |
| 70 | versionId, |
| 71 | std::make_unique<Activation>( |
| 72 | bus, path, versionId, activationState))); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 73 | } |
Patrick Williams | e75d10f | 2017-05-30 16:56:32 -0500 | [diff] [blame^] | 74 | return; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | } // namespace updater |
| 78 | } // namespace software |
| 79 | } // namespace phosphor |