blob: 570171288aa1cf0ca575daebc904f3063cc49678 [file] [log] [blame]
Jennifer Leec5d03ff2019-03-08 15:42:58 -08001/*
2// Copyright (c) 2019 Intel 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#ifndef BMCWEB_ENABLE_REDFISH_ONE_CHASSIS
17#pragma once
18
19#include <node.hpp>
20
21namespace redfish
22{
23
24template <typename CallbackFunc>
25void getMainChassisId(std::shared_ptr<AsyncResp> asyncResp,
26 CallbackFunc&& callback)
27{
28 // Find managed chassis
29 crow::connections::systemBus->async_method_call(
30 [callback,
31 asyncResp](const boost::system::error_code ec,
32 const crow::openbmc_mapper::GetSubTreeType& subtree) {
33 if (ec)
34 {
35 BMCWEB_LOG_ERROR << ec;
36 return;
37 }
38 if (subtree.size() == 0)
39 {
40 BMCWEB_LOG_DEBUG << "Can't find chassis!";
41 return;
42 }
43
44 std::size_t idPos = subtree[0].first.rfind("/");
45 if (idPos == std::string::npos ||
46 (idPos + 1) >= subtree[0].first.size())
47 {
48 messages::internalError(asyncResp->res);
49 BMCWEB_LOG_DEBUG << "Can't parse chassis ID!";
50 return;
51 }
52 std::string chassisId = subtree[0].first.substr(idPos + 1);
53 BMCWEB_LOG_DEBUG << "chassisId = " << chassisId;
54 callback(chassisId, asyncResp);
55 },
56 "xyz.openbmc_project.ObjectMapper",
57 "/xyz/openbmc_project/object_mapper",
58 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
59 "/xyz/openbmc_project/inventory", 0,
AppaRao Pulif857e9a2020-03-12 14:28:03 +053060 std::array<const char*, 2>{
61 "xyz.openbmc_project.Inventory.Item.Board",
Jennifer Leec5d03ff2019-03-08 15:42:58 -080062 "xyz.openbmc_project.Inventory.Item.Chassis"});
63}
64} // namespace redfish
65#endif