AuroraRuntime/Source/IO/Loop/LSIOHandle.cpp

96 lines
2.2 KiB
C++
Raw Normal View History

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSIOHandle.cpp
Date: 2023-9-16
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Loop.hpp"
#include "LSIOHandle.hpp"
#if defined(AURORA_IS_MODERNNT_DERIVED)
#include <Source/IO/AuIOHandle.hpp>
#include <Source/IO/IPC/AuIPCPipe.NT.hpp>
#endif
namespace Aurora::IO::Loop
{
LSIOHandle::LSIOHandle()
{ }
LSIOHandle::LSIOHandle(const AuSPtr<IIOHandle> &pHandle) : pHandle(pHandle)
{ }
bool LSIOHandle::OnTrigger(AuUInt handle)
{
return true;
}
const AuList<AuUInt> &LSIOHandle::GetHandles()
{
static AuList<AuUInt> kDummyArray;
return kDummyArray;
}
#if defined(AURORA_IS_POSIX_DERIVED)
const AuList<AuUInt> &LSIOHandle::GetWriteHandles()
{
static AuList<AuUInt> kDummyArray;
return kDummyArray;
}
AuUInt LSIOHandle::GetWriteHandle()
{
return this->pHandle->GetOSWriteHandleSafe().ValueOr(-1);
}
#endif
AuUInt LSIOHandle::GetHandle()
{
return this->pHandle->GetOSReadHandleSafe().ValueOr(-1);
}
bool LSIOHandle::Singular()
{
return true;
}
ELoopSource LSIOHandle::GetType()
{
return ELoopSource::eSourceHandle;
}
AUKN_SYM AuSPtr<ILoopSource> NewLSIOHandle(const AuSPtr<IIOHandle> &pHandle)
{
if (!pHandle)
{
SysPushErrorArg();
return {};
}
#if defined(AURORA_IS_MODERNNT_DERIVED)
if (pHandle->IsPipe())
{
if (auto pIPCPipe = AuStaticCast<AFileHandle>(pHandle)->pIPCPipe)
{
return pIPCPipe->AsReadChannelHasData();
}
else
{
SysPushErrorResourceInvalid("Use the loop source provided by the IPC pipe class.");
return {};
}
}
if (pHandle->IsTTY())
{
SysPushErrorResourceInvalid("Use the loop source provided by AuConsole::StdInBufferLoopSource() or AuLoop::NewStdIn(). If this is a PTY, you're out of luck.");
return {};
}
#endif
return AuMakeShared<LSIOHandle>(pHandle);
}
}