mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-22 15:30:09 +00:00
08194af424
- Moved C++ code to cpp/ from src/raspberrypi - Related updates to Makefile, easyinstall.sh, and the github build rules - Removed the native X68k C code in src/x68k from the repo
92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "devices/device_factory.h"
|
|
#include "devices/primary_device.h"
|
|
#include "scsi_controller.h"
|
|
#include "controller_manager.h"
|
|
|
|
using namespace std;
|
|
|
|
bool ControllerManager::AttachToScsiController(int id, shared_ptr<PrimaryDevice> device)
|
|
{
|
|
auto controller = FindController(id);
|
|
if (controller != nullptr) {
|
|
return controller->AddDevice(device);
|
|
}
|
|
|
|
// If there is no LUN yet the first LUN must be LUN 0
|
|
if (device->GetLun() == 0) {
|
|
controller = make_shared<ScsiController>(bus, id);
|
|
|
|
if (controller->AddDevice(device)) {
|
|
controllers[id] = controller;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool ControllerManager::DeleteController(shared_ptr<AbstractController> controller)
|
|
{
|
|
return controllers.erase(controller->GetTargetId()) == 1;
|
|
}
|
|
|
|
shared_ptr<AbstractController> ControllerManager::IdentifyController(int data) const
|
|
{
|
|
for (const auto& [id, controller] : controllers) {
|
|
if (data & (1 << controller->GetTargetId())) {
|
|
return controller;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
shared_ptr<AbstractController> ControllerManager::FindController(int target_id) const
|
|
{
|
|
const auto& it = controllers.find(target_id);
|
|
return it == controllers.end() ? nullptr : it->second;
|
|
}
|
|
|
|
unordered_set<shared_ptr<PrimaryDevice>> ControllerManager::GetAllDevices() const
|
|
{
|
|
unordered_set<shared_ptr<PrimaryDevice>> devices;
|
|
|
|
for (const auto& [id, controller] : controllers) {
|
|
const auto& d = controller->GetDevices();
|
|
devices.insert(d.begin(), d.end());
|
|
}
|
|
|
|
return devices;
|
|
}
|
|
|
|
void ControllerManager::DeleteAllControllers()
|
|
{
|
|
controllers.clear();
|
|
}
|
|
|
|
void ControllerManager::ResetAllControllers() const
|
|
{
|
|
for (const auto& [id, controller] : controllers) {
|
|
controller->Reset();
|
|
}
|
|
}
|
|
|
|
shared_ptr<PrimaryDevice> ControllerManager::GetDeviceByIdAndLun(int id, int lun) const
|
|
{
|
|
if (const auto& controller = FindController(id); controller != nullptr) {
|
|
return controller->GetDeviceForLun(lun);
|
|
}
|
|
|
|
return nullptr;
|
|
}
|