| #include "tlbmc/hal/fru_scanner_gpio.h" |
| |
| #include <memory> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "bus_topology.pb.h" |
| #include "absl/log/log.h" |
| #include "absl/memory/memory.h" |
| #include "absl/status/status.h" |
| #include "absl/status/statusor.h" |
| #include "g3/macros.h" |
| #include "tlbmc/collector/gpio_collector.h" |
| #include "gpio_config.pb.h" |
| #include "gpio_fru_config.pb.h" |
| #include "tlbmc/hal/fru_scanner.h" |
| #include "status.pb.h" |
| |
| namespace milotic_tlbmc { |
| |
| absl::StatusOr<std::unique_ptr<FruScannerGpio>> FruScannerGpio::Create( |
| const Options& options) { |
| if (options.gpio_collector == nullptr) { |
| return absl::InvalidArgumentError( |
| "FruScannerGpio::Create: GpioCollector cannot be null"); |
| } |
| return absl::WrapUnique( |
| new FruScannerGpio(options.components, options.gpio_collector)); |
| } |
| |
| absl::StatusOr<std::vector<std::unique_ptr<GpioFruInfo>>> |
| FruScannerGpio::ScanAllGpioFrus() const { |
| if (gpio_collector_ == nullptr) { |
| return absl::InternalError( |
| "FruScannerGpio::ScanAllGpioFrus: GpioCollector is null"); |
| } |
| |
| std::vector<std::unique_ptr<GpioFruInfo>> gpio_frus; |
| for (const auto& component : gpio_components_) { |
| if (component.gpio_line_name().empty()) { |
| continue; |
| } |
| auto gpio_fru = std::make_unique<GpioFruInfo>(); |
| gpio_fru->expected_barepath = component.barepath(); |
| ECCLESIA_ASSIGN_OR_RETURN( |
| bool is_active, gpio_collector_->IsActive(component.gpio_line_name())); |
| |
| if (is_active) { |
| gpio_fru->presence_status = PresenceStatus::PRESENCE_STATUS_PRESENT; |
| } else { |
| gpio_fru->presence_status = PresenceStatus::PRESENCE_STATUS_NOT_FOUND; |
| } |
| gpio_frus.push_back(std::move(gpio_fru)); |
| } |
| return gpio_frus; |
| } |
| |
| } // namespace milotic_tlbmc |