Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 1 | /* |
| 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 Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 19 | namespace redfish |
| 20 | { |
| 21 | |
| 22 | template <typename CallbackFunc> |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 23 | void getMainChassisId(std::shared_ptr<bmcweb::AsyncResp> asyncResp, |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 24 | 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 Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 42 | std::size_t idPos = subtree[0].first.rfind('/'); |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 43 | 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 Puli | f857e9a | 2020-03-12 14:28:03 +0530 | [diff] [blame] | 58 | std::array<const char*, 2>{ |
| 59 | "xyz.openbmc_project.Inventory.Item.Board", |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 60 | "xyz.openbmc_project.Inventory.Item.Chassis"}); |
| 61 | } |
| 62 | } // namespace redfish |
| 63 | #endif |