RASCSI/cpp/disk_image/disk_image_handle_factory.cpp

49 lines
1.6 KiB
C++
Raw Normal View History

2023-01-09 02:04:49 +00:00
//---------------------------------------------------------------------------
//
// SCSI Target Emulator RaSCSI (*^..^*)
// for Raspberry Pi
//
2023-01-11 03:08:22 +00:00
// Copyright (C) 2022-2023 akuker
2023-01-09 02:04:49 +00:00
//
// Factory class for creating DiskImageHandles
//
// [ DiskImageHandleFactory ]
//
//---------------------------------------------------------------------------
#include "disk_image/disk_image_handle_factory.h"
2023-01-09 03:39:07 +00:00
#include "shared/log.h"
2023-01-09 02:04:49 +00:00
#include "disk_image/disk_track_cache.h"
#include "disk_image/mmap_file_handle.h"
#include "disk_image/posix_file_handle.h"
DiskImageHandleType DiskImageHandleFactory::current_access_type = DiskImageHandleType::ePosixFile;
2023-01-09 03:39:07 +00:00
unique_ptr<DiskImageHandle> DiskImageHandleFactory::CreateDiskImageHandle(const string &path, int size, uint32_t blocks, off_t imgoff)
2023-01-09 02:04:49 +00:00
{
2023-01-09 03:39:07 +00:00
unique_ptr<DiskImageHandle> result = nullptr;
2023-01-09 02:04:49 +00:00
if (current_access_type == DiskImageHandleType::eMmapFile)
{
2023-01-09 03:39:07 +00:00
LOGINFO("%s Creating MmapFileAccess %s", __PRETTY_FUNCTION__, path.c_str())
result = make_unique<MmapFileHandle>(path, size, blocks, imgoff);
2023-01-09 02:04:49 +00:00
}
else if (current_access_type == DiskImageHandleType::eRamCache)
{
2023-01-09 03:39:07 +00:00
LOGINFO("%s Creating DiskCache %s", __PRETTY_FUNCTION__, path.c_str())
result = make_unique<DiskCache>(path, size, blocks, imgoff);
2023-01-09 02:04:49 +00:00
}
else if (current_access_type == DiskImageHandleType::ePosixFile)
{
2023-01-09 03:39:07 +00:00
LOGINFO("%s Creating PosixFileHandle %s", __PRETTY_FUNCTION__, path.c_str())
result = make_unique<PosixFileHandle>(path, size, blocks, imgoff);
2023-01-09 02:04:49 +00:00
}
2023-01-09 03:39:07 +00:00
if (result == nullptr)
2023-01-09 02:04:49 +00:00
{
2023-01-11 03:08:22 +00:00
LOGWARN("%s Unable to create the File Access", __PRETTY_FUNCTION__)
2023-01-09 02:04:49 +00:00
}
return result;
}