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 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 19 | int ItemUpdater::createActivation(sd_bus_message* msg, |
| 20 | void* userData, |
| 21 | sd_bus_error* retErr) |
| 22 | { |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 23 | auto* updater = static_cast<ItemUpdater*>(userData); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 24 | 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 Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | } // namespace updater |
| 85 | } // namespace software |
| 86 | } // namespace phosphor |