Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 1 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 2 | #include "config.h" |
| 3 | #include "item_updater.hpp" |
| 4 | |
| 5 | namespace openpower |
| 6 | { |
| 7 | namespace software |
| 8 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame^] | 9 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 10 | { |
| 11 | |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 12 | using namespace phosphor::logging; |
| 13 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 14 | int ItemUpdater::createActivation(sd_bus_message* msg, |
| 15 | void* userData, |
| 16 | sd_bus_error* retErr) |
| 17 | { |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 18 | auto* updater = static_cast<ItemUpdater*>(userData); |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 19 | auto mapper = updater->busItem.new_method_call( |
| 20 | MAPPER_BUSNAME, |
| 21 | MAPPER_PATH, |
| 22 | MAPPER_INTERFACE, |
| 23 | "GetSubTreePaths"); |
| 24 | mapper.append(SOFTWARE_OBJPATH, |
| 25 | 1, // Depth |
| 26 | std::vector<std::string>({VERSION_IFACE})); |
| 27 | |
| 28 | auto mapperResponseMsg = updater->busItem.call(mapper); |
| 29 | if (mapperResponseMsg.is_method_error()) |
| 30 | { |
| 31 | log<level::ERR>("Error in mapper call", |
| 32 | entry("PATH=%s", SOFTWARE_OBJPATH), |
| 33 | entry("INTERFACE=%s", VERSION_IFACE)); |
| 34 | return -1; |
| 35 | } |
| 36 | |
| 37 | std::vector<std::string> mapperResponse; |
| 38 | mapperResponseMsg.read(mapperResponse); |
| 39 | if (mapperResponse.empty()) |
| 40 | { |
| 41 | log<level::ERR>("Error reading mapper response", |
| 42 | entry("PATH=%s", SOFTWARE_OBJPATH), |
| 43 | entry("INTERFACE=%s", VERSION_IFACE)); |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | for (const auto& resp : mapperResponse) |
| 48 | { |
| 49 | // Version id is the last item in the path |
| 50 | auto pos = resp.rfind("/"); |
| 51 | if (pos == std::string::npos) |
| 52 | { |
| 53 | log<level::ERR>("No version id found in object path", |
| 54 | entry("OBJPATH=%s", resp)); |
| 55 | return -1; |
| 56 | } |
| 57 | |
Adriana Kobylak | 268616b | 2017-04-05 15:23:30 -0500 | [diff] [blame] | 58 | auto versionId = resp.substr(pos + 1); |
Adriana Kobylak | b66ac3a | 2017-03-28 13:33:20 -0500 | [diff] [blame] | 59 | if (updater->activations.find(versionId) == updater->activations.end()) |
| 60 | { |
| 61 | updater->activations.insert(std::make_pair( |
| 62 | versionId, |
| 63 | std::make_unique<Activation>( |
| 64 | updater->busItem, |
| 65 | resp))); |
| 66 | } |
| 67 | } |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame^] | 71 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 72 | } // namespace software |
| 73 | } // namespace openpower |
| 74 | |