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 19 namespace redfish 20 { 21 22 template <typename CallbackFunc> 23 void getMainChassisId(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 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 42 std::size_t idPos = subtree[0].first.rfind('/'); 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, 58 std::array<const char*, 2>{ 59 "xyz.openbmc_project.Inventory.Item.Board", 60 "xyz.openbmc_project.Inventory.Item.Chassis"}); 61 } 62 } // namespace redfish 63 #endif 64