blob: 5494a238382ebbd2d5cf865f76771dc7b23444e2 [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
Jennifer Leec5d03ff2019-03-08 15:42:58 -080019namespace redfish
20{
21
22template <typename CallbackFunc>
zhanghch058d1b46d2021-04-01 11:18:24 +080023void getMainChassisId(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Jennifer Leec5d03ff2019-03-08 15:42:58 -080024 CallbackFunc&& callback)
25{
26 // Find managed chassis
27 crow::connections::systemBus->async_method_call(
28 [callback,
29 asyncResp](const boost::system::error_code ec,
30 const crow::openbmc_mapper::GetSubTreeType& subtree) {
31 if (ec)
32 {
33 BMCWEB_LOG_ERROR << ec;
34 return;
35 }
36 if (subtree.size() == 0)
37 {
38 BMCWEB_LOG_DEBUG << "Can't find chassis!";
39 return;
40 }
41
Ed Tanousf23b7292020-10-15 09:41:17 -070042 std::size_t idPos = subtree[0].first.rfind('/');
Jennifer Leec5d03ff2019-03-08 15:42:58 -080043 if (idPos == std::string::npos ||
44 (idPos + 1) >= subtree[0].first.size())
45 {
46 messages::internalError(asyncResp->res);
47 BMCWEB_LOG_DEBUG << "Can't parse chassis ID!";
48 return;
49 }
50 std::string chassisId = subtree[0].first.substr(idPos + 1);
51 BMCWEB_LOG_DEBUG << "chassisId = " << chassisId;
52 callback(chassisId, asyncResp);
53 },
54 "xyz.openbmc_project.ObjectMapper",
55 "/xyz/openbmc_project/object_mapper",
56 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
57 "/xyz/openbmc_project/inventory", 0,
AppaRao Pulif857e9a2020-03-12 14:28:03 +053058 std::array<const char*, 2>{
59 "xyz.openbmc_project.Inventory.Item.Board",
Jennifer Leec5d03ff2019-03-08 15:42:58 -080060 "xyz.openbmc_project.Inventory.Item.Chassis"});
61}
62} // namespace redfish
63#endif