/*** Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: LSIOHandle.cpp Date: 2023-9-16 Author: Reece ***/ #include #include "Loop.hpp" #include "LSIOHandle.hpp" #if defined(AURORA_IS_MODERNNT_DERIVED) #include #include #endif namespace Aurora::IO::Loop { LSIOHandle::LSIOHandle() { } LSIOHandle::LSIOHandle(const AuSPtr &pHandle) : pHandle(pHandle) { } bool LSIOHandle::OnTrigger(AuUInt handle) { return true; } const AuList &LSIOHandle::GetHandles() { static AuList kDummyArray; return kDummyArray; } #if defined(AURORA_IS_POSIX_DERIVED) const AuList &LSIOHandle::GetWriteHandles() { static AuList 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 NewLSIOHandle(const AuSPtr &pHandle) { if (!pHandle) { SysPushErrorArg(); return {}; } #if defined(AURORA_IS_MODERNNT_DERIVED) if (pHandle->IsPipe()) { if (auto pIPCPipe = AuStaticCast(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(pHandle); } }