Removes FileIOBus
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -16,33 +16,6 @@ namespace AZ
|
||||
{
|
||||
namespace IO
|
||||
{
|
||||
/**
|
||||
* File IO interface. All events return true if we executed the
|
||||
* specific operation and no other code will be executed. If we return false
|
||||
* the normal code for the specific event will be executed.
|
||||
* IMPORTANT: We support multiple listeners with the idea that many systems can listen
|
||||
* for event. This interface allows to actually perform the operations, in such cases make
|
||||
* sure only one of the listeners provides this service (otherwise depending on registration
|
||||
* order service providers may change)
|
||||
* IMPORTANT: We don't provide any sync for the FileIOBus. We do that for a couple of reasons.
|
||||
* 1. If you will handle file IO youself or keeptrack of statistics you code will most likely already do that
|
||||
* 2. It is NOT safe to BusConnect/BusDisconnect while the FileIO is in use (this is why you should connect in advance)
|
||||
* otherwise if you provide service you can end up connecting in a middle of reads/writes/etc.
|
||||
*/
|
||||
class FileIO
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
virtual ~FileIO() {}
|
||||
virtual bool OnOpen(SystemFile& file, const char* fileName, int mode, int platformFlags, bool& isFileOpened) = 0;
|
||||
virtual bool OnClose(SystemFile& file) = 0;
|
||||
virtual bool OnSeek(SystemFile& file, SystemFile::SizeType offset, SystemFile::SeekMode mode) = 0;
|
||||
virtual bool OnRead(SystemFile& file, SystemFile::SizeType byteSize, void* buffer, SystemFile::SizeType& numRead) = 0;
|
||||
virtual bool OnWrite(SystemFile& file, const void* buffer, SystemFile::SizeType byteSize, SystemFile::SizeType& numWritten) = 0;
|
||||
};
|
||||
|
||||
typedef AZ::EBus<FileIO> FileIOBus;
|
||||
|
||||
/**
|
||||
* Interface for handling file io events. All events are syncronized
|
||||
*/
|
||||
|
||||
@@ -109,17 +109,6 @@ bool SystemFile::Open(const char* fileName, int mode, int platformFlags)
|
||||
m_fileName = fileName;
|
||||
}
|
||||
|
||||
if (FileIOBus::HasHandlers())
|
||||
{
|
||||
bool isOpen = false;
|
||||
bool isHandled = false;
|
||||
EBUS_EVENT_RESULT(isHandled, FileIOBus, OnOpen, *this, m_fileName.c_str(), mode, platformFlags, isOpen);
|
||||
if (isHandled)
|
||||
{
|
||||
return isOpen;
|
||||
}
|
||||
}
|
||||
|
||||
AZ_Assert(!IsOpen(), "This file (%s) is already open!", m_fileName.c_str());
|
||||
|
||||
return PlatformOpen(mode, platformFlags);
|
||||
@@ -133,31 +122,11 @@ bool SystemFile::ReOpen(int mode, int platformFlags)
|
||||
|
||||
void SystemFile::Close()
|
||||
{
|
||||
if (FileIOBus::HasHandlers())
|
||||
{
|
||||
bool isHandled = false;
|
||||
EBUS_EVENT_RESULT(isHandled, FileIOBus, OnClose, *this);
|
||||
if (isHandled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PlatformClose();
|
||||
}
|
||||
|
||||
void SystemFile::Seek(SeekSizeType offset, SeekMode mode)
|
||||
{
|
||||
if (FileIOBus::HasHandlers())
|
||||
{
|
||||
bool isHandled = false;
|
||||
EBUS_EVENT_RESULT(isHandled, FileIOBus, OnSeek, *this, offset, mode);
|
||||
if (isHandled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Platform::Seek(m_handle, this, offset, mode);
|
||||
}
|
||||
|
||||
@@ -178,33 +147,11 @@ AZ::u64 SystemFile::ModificationTime()
|
||||
|
||||
SystemFile::SizeType SystemFile::Read(SizeType byteSize, void* buffer)
|
||||
{
|
||||
if (FileIOBus::HasHandlers())
|
||||
{
|
||||
SizeType numRead = 0;
|
||||
bool isHandled = false;
|
||||
EBUS_EVENT_RESULT(isHandled, FileIOBus, OnRead, *this, byteSize, buffer, numRead);
|
||||
if (isHandled)
|
||||
{
|
||||
return numRead;
|
||||
}
|
||||
}
|
||||
|
||||
return Platform::Read(m_handle, this, byteSize, buffer);
|
||||
}
|
||||
|
||||
SystemFile::SizeType SystemFile::Write(const void* buffer, SizeType byteSize)
|
||||
{
|
||||
if (FileIOBus::HasHandlers())
|
||||
{
|
||||
SizeType numWritten = 0;
|
||||
bool isHandled = false;
|
||||
EBUS_EVENT_RESULT(isHandled, FileIOBus, OnWrite, *this, buffer, byteSize, numWritten);
|
||||
if (isHandled)
|
||||
{
|
||||
return numWritten;
|
||||
}
|
||||
}
|
||||
|
||||
return Platform::Write(m_handle, this, buffer, byteSize);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user