AuroraRuntime/Source/IO/AuIOProcessorItem.cpp

134 lines
3.0 KiB
C++
Raw Normal View History

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOProcessorItem.cpp
Date: 2022-6-6
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include "AuIOProcessorItem.hpp"
#include "AuIOProcessor.hpp"
namespace Aurora::IO
{
bool IOProcessorItem::StopWatch()
{
if (!this->pParent)
{
return false;
}
2022-08-29 15:46:46 +00:00
if (this->pParent->CheckThread() &&
this->pParent->bFrameStart)
{
2022-08-29 15:46:46 +00:00
this->pParent->ClearProcessor(AuSharedFromThis(), false);
return true;
}
2022-08-29 15:46:46 +00:00
return this->pParent->items.ScheduleFinish(AuSharedFromThis(), false);
}
bool IOProcessorItem::FailWatch()
{
if (!this->pParent)
{
return false;
}
2022-08-29 15:46:46 +00:00
if (this->pParent->CheckThread() &&
this->pParent->bFrameStart)
{
2022-08-29 15:46:46 +00:00
this->pParent->ClearProcessor(AuSharedFromThis(), true);
return false;
}
2022-08-29 15:46:46 +00:00
return this->pParent->items.ScheduleFinish(AuSharedFromThis(), true);
}
bool IOProcessorItem::OnFinished(const AuSPtr<AuLoop::ILoopSource>& source, AuUInt8 pos)
{
if (!this->pParent)
{
return true;
}
2022-08-29 15:46:46 +00:00
if (this->bSingleshot)
{
2022-08-29 15:46:46 +00:00
if (AuExchange(this->bTriggered, true))
{
StopWatch();
return false;
}
}
IOAlert(false);
2022-08-29 15:46:46 +00:00
return this->bSingleshot;
}
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->pParent)
{
return;
}
2022-08-29 15:46:46 +00:00
if (!this->pParent->IsTickOnly())
{
bool bForceTick {};
if (!this->pParent->bFrameStart ||
(bForceTick = this->pParent->bNoDeferredTick))
2022-06-21 06:12:11 +00:00
{
if (force || bForceTick)
{
2022-08-29 15:46:46 +00:00
this->pParent->TickFor(AuSharedFromThis());
}
else
{
2022-08-29 15:46:46 +00:00
this->pParent->TickForHack(AuSharedFromThis());
}
2022-06-21 06:12:11 +00:00
}
else
{
2022-08-29 15:46:46 +00:00
this->pParent->TickForRegister(AuSharedFromThis());
2022-06-21 06:12:11 +00:00
}
}
else if (force) // manual tick
{
2022-08-29 15:46:46 +00:00
if (this->pParent->CheckThread())
{
2022-08-29 15:46:46 +00:00
this->pParent->TickFor(AuSharedFromThis());
}
2022-08-29 15:46:46 +00:00
else if (this->pParent->IsAsync())
{
// TODO:
}
else
{
SysPanic("Missing");
}
}
2022-08-29 15:46:46 +00:00
if (this->bSingleshot)
{
StopWatch();
}
}
void IOProcessorItem::Finalize()
{
AuResetMember(this->pItem);
AuResetMember(this->pListener);
}
}