RASCSI/cpp/hal/gpiobus_factory.cpp
Uwe Seimet 43088ab3bc
Remove non-working Banana Pi code (#1252)
* Remove non-working Banana Pi code

* Remove SonarQube suppressions which can be resolved by a code update

* Update device detection
2023-10-22 17:29:26 +02:00

49 lines
1.2 KiB
C++

//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
// Copyright (C) 2023 Uwe Seimet
//
//---------------------------------------------------------------------------
#include <memory>
#include "hal/gpiobus_factory.h"
#include "hal/gpiobus_raspberry.h"
#include "hal/gpiobus_virtual.h"
#include "hal/sbc_version.h"
#include <unistd.h>
#include <spdlog/spdlog.h>
using namespace std;
unique_ptr<BUS> GPIOBUS_Factory::Create(BUS::mode_e mode)
{
unique_ptr<BUS> bus;
try {
SBC_Version::Init();
if (SBC_Version::IsRaspberryPi()) {
if (getuid()) {
spdlog::error("GPIO bus access requires root permissions. Are you running as root?");
return nullptr;
}
bus = make_unique<GPIOBUS_Raspberry>();
} else {
bus = make_unique<GPIOBUS_Virtual>();
}
if (bus->Init(mode)) {
bus->Reset();
}
} catch (const invalid_argument& e) {
spdlog::error(string("Exception while trying to initialize GPIO bus: ") + e.what());
return nullptr;
}
return bus;
}