1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #pragma once 15 16 #include <cstdint> 17 #include <functional> 18 #include <optional> 19 #include <string> 20 #include <string_view> 21 #include <unordered_map> 22 #include <vector> 23 24 namespace google 25 { 26 namespace ipmi 27 { 28 29 class BifurcationInterface 30 { 31 public: 32 virtual ~BifurcationInterface() = default; 33 34 /** 35 * Get the Bifurcation of the device at the i2c bus 36 * 37 * @param[in] bus - I2C bus of the device 38 * @return the bifurcation at the i2c bus 39 */ 40 virtual std::optional<std::vector<uint8_t>> 41 getBifurcation(uint8_t bus) noexcept = 0; 42 }; 43 44 class BifurcationStatic : public BifurcationInterface 45 { 46 public: createBifurcation()47 static std::reference_wrapper<BifurcationInterface> createBifurcation() 48 { 49 static BifurcationStatic bifurcationStatic; 50 51 return std::ref(bifurcationStatic); 52 } 53 54 BifurcationStatic(std::string_view bifurcationFile); 55 56 std::optional<std::vector<uint8_t>> 57 getBifurcation(uint8_t index) noexcept override; 58 59 protected: 60 BifurcationStatic(); 61 62 private: 63 std::string bifurcationFile; 64 }; 65 66 } // namespace ipmi 67 } // namespace google 68