AuroraRuntime/Source/IO/IOProcessorItem.cpp
2022-08-08 16:32:45 +01:00

108 lines
2.5 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOProcessorItem.cpp
Date: 2022-6-6
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include "IOProcessorItem.hpp"
#include "IOProcessor.hpp"
namespace Aurora::IO
{
bool IOProcessorItem::StopWatch()
{
if (this->parent->CheckThread() &&
this->parent->bFrameStart)
{
this->parent->ClearProcessor(AuSharedFromThis(), false);
return true;
}
return this->parent->items.ScheduleFinish(AuSharedFromThis(), false);
}
bool IOProcessorItem::FailWatch()
{
if (this->parent->CheckThread() &&
this->parent->bFrameStart)
{
this->parent->ClearProcessor(AuSharedFromThis(), true);
return false;
}
return this->parent->items.ScheduleFinish(AuSharedFromThis(), true);
}
bool IOProcessorItem::OnFinished(const AuSPtr<AuLoop::ILoopSource>& source, AuUInt8 pos)
{
if (this->singleshot)
{
if (AuExchange(this->triggered, true))
{
StopWatch();
return false;
}
}
IOAlert(false);
return this->singleshot;
}
void IOProcessorItem::OnTimeout(const AuSPtr<AuLoop::ILoopSource>& source)
{
SysPushErrorIO("IO Timeout");
this->FailWatch();
}
void IOProcessorItem::InvokeManualTick()
{
IOAlert(true);
}
void IOProcessorItem::IOAlert(bool force)
{
if (!this->parent->IsTickOnly())
{
if (!this->parent->bFrameStart)
{
if (force)
{
this->parent->TickFor(AuSharedFromThis());
}
else
{
this->parent->TickForHack(AuSharedFromThis());
}
}
else
{
this->parent->TickForRegister(AuSharedFromThis());
}
}
else if (force) // manual tick
{
if (this->parent->CheckThread())
{
this->parent->TickFor(AuSharedFromThis());
}
else if (parent->IsAsync())
{
// TODO:
}
else
{
SysPanic("Missing");
}
}
if (this->singleshot)
{
StopWatch();
}
}
}