blob: 77dfe1ca102d39435a733ea729844276edc5d940 [file] [log] [blame]
Adriana Kobylakb66ac3a2017-03-28 13:33:20 -05001#include <phosphor-logging/log.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05002#include "config.h"
3#include "item_updater.hpp"
4
5namespace openpower
6{
7namespace software
8{
9namespace manager
10{
11
Adriana Kobylakb66ac3a2017-03-28 13:33:20 -050012using namespace phosphor::logging;
13
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050014int ItemUpdater::createActivation(sd_bus_message* msg,
15 void* userData,
16 sd_bus_error* retErr)
17{
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050018 auto* updater = static_cast<ItemUpdater*>(userData);
Adriana Kobylakb66ac3a2017-03-28 13:33:20 -050019 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
58 auto versionId = std::stoi(resp.substr(pos + 1), nullptr, 16);
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 Kobylak2d8fa222017-03-15 12:34:32 -050068 return 0;
69}
70
71} // namespace manager
72} // namespace software
73} // namespace openpower
74