unique_ptr'ing things and removing some XECLEANUP.

This commit is contained in:
Ben Vanik
2014-08-20 23:26:46 -07:00
parent 244e8a8745
commit c59d053404
43 changed files with 271 additions and 347 deletions

View File

@@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_FS_DEVICE_H_
#define XENIA_KERNEL_FS_DEVICE_H_
#include <memory>
#include <string>
#include <xenia/core.h>
@@ -26,7 +27,7 @@ class Device {
const std::string& path() const { return path_; }
virtual Entry* ResolvePath(const char* path) = 0;
virtual std::unique_ptr<Entry> ResolvePath(const char* path) = 0;
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) = 0;
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,

View File

@@ -42,7 +42,7 @@ int DiscImageDevice::Init() {
return 0;
}
Entry* DiscImageDevice::ResolvePath(const char* path) {
std::unique_ptr<Entry> DiscImageDevice::ResolvePath(const char* path) {
// The filesystem will have stripped our prefix off already, so the path will
// be in the form:
// some\PATH.foo
@@ -64,7 +64,8 @@ Entry* DiscImageDevice::ResolvePath(const char* path) {
Entry::Type type = gdfx_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY
? Entry::Type::DIRECTORY
: Entry::Type::FILE;
return new DiscImageEntry(type, this, path, mmap_.get(), gdfx_entry);
return std::make_unique<DiscImageEntry>(type, this, path, mmap_.get(),
gdfx_entry);
}
X_STATUS DiscImageDevice::QueryVolume(XVolumeInfo* out_info, size_t length) {

View File

@@ -31,7 +31,7 @@ class DiscImageDevice : public Device {
int Init();
Entry* ResolvePath(const char* path) override;
std::unique_ptr<Entry> ResolvePath(const char* path) override;
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,

View File

@@ -96,23 +96,22 @@ X_STATUS DiscImageEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length,
return X_STATUS_SUCCESS;
}
MemoryMapping* DiscImageEntry::CreateMemoryMapping(Mode map_mode,
const size_t offset,
const size_t length) {
std::unique_ptr<MemoryMapping> DiscImageEntry::CreateMemoryMapping(
Mode map_mode, const size_t offset, const size_t length) {
if (map_mode != Mode::READ) {
// Only allow reads.
return NULL;
return nullptr;
}
size_t real_offset = gdfx_entry_->offset + offset;
size_t real_length =
length ? std::min(length, gdfx_entry_->size) : gdfx_entry_->size;
return new DiscImageMemoryMapping(mmap_->data() + real_offset, real_length,
mmap_);
return std::make_unique<DiscImageMemoryMapping>(mmap_->data() + real_offset,
real_length, mmap_);
}
X_STATUS DiscImageEntry::Open(KernelState* kernel_state, Mode mode,
bool async, XFile** out_file) {
X_STATUS DiscImageEntry::Open(KernelState* kernel_state, Mode mode, bool async,
XFile** out_file) {
*out_file = new DiscImageFile(kernel_state, mode, this);
return X_STATUS_SUCCESS;
}

View File

@@ -37,11 +37,11 @@ class DiscImageEntry : public Entry {
const char* file_name, bool restart);
virtual bool can_map() { return true; }
virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset,
const size_t length);
virtual std::unique_ptr<MemoryMapping> CreateMemoryMapping(
Mode map_mode, const size_t offset, const size_t length);
virtual X_STATUS Open(KernelState* kernel_state, Mode mode,
bool async, XFile** out_file);
virtual X_STATUS Open(KernelState* kernel_state, Mode mode, bool async,
XFile** out_file);
private:
poly::MappedMemory* mmap_;

View File

@@ -22,7 +22,7 @@ HostPathDevice::HostPathDevice(const std::string& path,
HostPathDevice::~HostPathDevice() {}
Entry* HostPathDevice::ResolvePath(const char* path) {
std::unique_ptr<Entry> HostPathDevice::ResolvePath(const char* path) {
// The filesystem will have stripped our prefix off already, so the path will
// be in the form:
// some\PATH.foo
@@ -38,8 +38,7 @@ Entry* HostPathDevice::ResolvePath(const char* path) {
// TODO(benvanik): switch based on type
auto type = Entry::Type::FILE;
HostPathEntry* entry = new HostPathEntry(type, this, path, full_path);
return entry;
return std::make_unique<HostPathEntry>(type, this, path, full_path);
}
// TODO(gibbed): call into HostPathDevice?

View File

@@ -25,7 +25,7 @@ class HostPathDevice : public Device {
HostPathDevice(const std::string& path, const std::wstring& local_path);
~HostPathDevice() override;
Entry* ResolvePath(const char* path) override;
std::unique_ptr<Entry> ResolvePath(const char* path) override;
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,

View File

@@ -121,9 +121,8 @@ X_STATUS HostPathEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length,
return X_STATUS_SUCCESS;
}
MemoryMapping* HostPathEntry::CreateMemoryMapping(Mode map_mode,
const size_t offset,
const size_t length) {
std::unique_ptr<MemoryMapping> HostPathEntry::CreateMemoryMapping(
Mode map_mode, const size_t offset, const size_t length) {
auto mmap = poly::MappedMemory::Open(
local_path_,
map_mode == Mode::READ ? poly::MappedMemory::Mode::READ
@@ -133,13 +132,11 @@ MemoryMapping* HostPathEntry::CreateMemoryMapping(Mode map_mode,
return nullptr;
}
HostPathMemoryMapping* lfmm = new HostPathMemoryMapping(std::move(mmap));
return lfmm;
return std::make_unique<HostPathMemoryMapping>(std::move(mmap));
}
X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode,
bool async, XFile** out_file) {
X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode, bool async,
XFile** out_file) {
DWORD desired_access =
mode == Mode::READ ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
DWORD share_mode = FILE_SHARE_READ;

View File

@@ -31,8 +31,8 @@ class HostPathEntry : public Entry {
const char* file_name, bool restart);
virtual bool can_map() { return true; }
virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset,
const size_t length);
virtual std::unique_ptr<MemoryMapping> CreateMemoryMapping(
Mode map_mode, const size_t offset, const size_t length);
virtual X_STATUS Open(KernelState* kernel_state, Mode mode, bool async,
XFile** out_file);

View File

@@ -42,7 +42,7 @@ int STFSContainerDevice::Init() {
return 0;
}
Entry* STFSContainerDevice::ResolvePath(const char* path) {
std::unique_ptr<Entry> STFSContainerDevice::ResolvePath(const char* path) {
// The filesystem will have stripped our prefix off already, so the path will
// be in the form:
// some\PATH.foo
@@ -64,7 +64,8 @@ Entry* STFSContainerDevice::ResolvePath(const char* path) {
Entry::Type type = stfs_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY
? Entry::Type::DIRECTORY
: Entry::Type::FILE;
return new STFSContainerEntry(type, this, path, mmap_.get(), stfs_entry);
return std::make_unique<STFSContainerEntry>(type, this, path, mmap_.get(),
stfs_entry);
}
X_STATUS STFSContainerDevice::QueryVolume(XVolumeInfo* out_info,

View File

@@ -31,7 +31,7 @@ class STFSContainerDevice : public Device {
int Init();
Entry* ResolvePath(const char* path) override;
std::unique_ptr<Entry> ResolvePath(const char* path) override;
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,

View File

@@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_FS_ENTRY_H_
#define XENIA_KERNEL_FS_ENTRY_H_
#include <memory>
#include <string>
#include <xenia/core.h>
@@ -72,8 +73,8 @@ class Entry {
virtual bool can_map() { return false; }
virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset,
const size_t length) {
virtual std::unique_ptr<MemoryMapping> CreateMemoryMapping(
Mode map_mode, const size_t offset, const size_t length) {
return NULL;
}

View File

@@ -142,7 +142,7 @@ int FileSystem::DeleteSymbolicLink(const std::string& path) {
return 0;
}
Entry* FileSystem::ResolvePath(const std::string& path) {
std::unique_ptr<Entry> FileSystem::ResolvePath(const std::string& path) {
// Strip off prefix and pass to device.
// e.g., d:\some\PATH.foo -> some\PATH.foo
// Support both symlinks and device specifiers, like:
@@ -173,7 +173,7 @@ Entry* FileSystem::ResolvePath(const std::string& path) {
}
XELOGE("ResolvePath(%s) failed - no root found", path.c_str());
return NULL;
return nullptr;
}
} // namespace fs

View File

@@ -10,6 +10,7 @@
#ifndef XENIA_KERNEL_FS_FILESYSTEM_H_
#define XENIA_KERNEL_FS_FILESYSTEM_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
@@ -50,7 +51,7 @@ class FileSystem {
int CreateSymbolicLink(const std::string& path, const std::string& target);
int DeleteSymbolicLink(const std::string& path);
Entry* ResolvePath(const std::string& path);
std::unique_ptr<Entry> ResolvePath(const std::string& path);
private:
std::vector<Device*> devices_;