blob: db8871282269af3e115d131e1778824b9cae2528 [file] [log] [blame]
Brandon Wyman5914f652017-03-16 18:17:07 -05001/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <string>
17#include "utility.hpp"
18
19namespace phosphor
20{
21namespace fan
22{
23namespace presence
24{
25
26//TODO Should get these from phosphor-objmgr config.h
27constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
28constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
29constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
30
31//TODO Should get these from phosphor-inventory-manager config.h
32constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory";
33constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager";
34
35std::string getInvService(sdbusplus::bus::bus& bus)
36{
37 auto mapperCall = bus.new_method_call(MAPPER_BUSNAME,
38 MAPPER_PATH,
39 MAPPER_INTERFACE,
40 "GetObject");
41
42 mapperCall.append(INVENTORY_PATH);
43 mapperCall.append(std::vector<std::string>({INVENTORY_INTF}));
44
45 auto mapperResponseMsg = bus.call(mapperCall);
46 if (mapperResponseMsg.is_method_error())
47 {
48 throw std::runtime_error(
49 "Error in mapper call to get inventory service name");
50 }
51
52 std::map<std::string, std::vector<std::string>> mapperResponse;
53 mapperResponseMsg.read(mapperResponse);
54
55 if (mapperResponse.empty())
56 {
57 throw std::runtime_error(
58 "Error in mapper response for inventory service name");
59 }
60
61 return mapperResponse.begin()->first;
62}
63
64}
65}
66}