2022-06-11 23:01:27 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-12-17 20:14:19 +00:00
|
|
|
File: AuIOProcessorItem.cpp
|
2022-06-11 23:01:27 +00:00
|
|
|
Date: 2022-6-6
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include <Aurora/IO/IOExperimental.hpp>
|
2022-12-17 20:14:19 +00:00
|
|
|
#include "AuIOProcessorItem.hpp"
|
|
|
|
#include "AuIOProcessor.hpp"
|
2022-06-11 23:01:27 +00:00
|
|
|
|
|
|
|
namespace Aurora::IO
|
|
|
|
{
|
|
|
|
bool IOProcessorItem::StopWatch()
|
|
|
|
{
|
2023-12-11 20:18:36 +00:00
|
|
|
if (!this->pParent)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
if (this->pParent->CheckThread() &&
|
|
|
|
this->pParent->bFrameStart)
|
2022-06-11 23:01:27 +00:00
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
this->pParent->ClearProcessor(AuSharedFromThis(), false);
|
2022-08-08 15:32:45 +00:00
|
|
|
return true;
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
return this->pParent->items.ScheduleFinish(AuSharedFromThis(), false);
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IOProcessorItem::FailWatch()
|
|
|
|
{
|
2023-12-11 20:18:36 +00:00
|
|
|
if (!this->pParent)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
if (this->pParent->CheckThread() &&
|
|
|
|
this->pParent->bFrameStart)
|
2022-06-11 23:01:27 +00:00
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
this->pParent->ClearProcessor(AuSharedFromThis(), true);
|
2022-06-11 23:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
return this->pParent->items.ScheduleFinish(AuSharedFromThis(), true);
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 14:57:29 +00:00
|
|
|
bool IOProcessorItem::OnFinished(const AuSPtr<AuLoop::ILoopSource>& source, AuUInt8 pos)
|
2022-06-11 23:01:27 +00:00
|
|
|
{
|
2023-12-11 20:18:36 +00:00
|
|
|
if (!this->pParent)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
if (this->bSingleshot)
|
2022-06-28 14:57:29 +00:00
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
if (AuExchange(this->bTriggered, true))
|
2022-06-28 14:57:29 +00:00
|
|
|
{
|
|
|
|
StopWatch();
|
2022-07-05 19:35:40 +00:00
|
|
|
return false;
|
2022-06-28 14:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
IOAlert(false);
|
2022-08-29 15:46:46 +00:00
|
|
|
return this->bSingleshot;
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 14:57:29 +00:00
|
|
|
void IOProcessorItem::OnTimeout(const AuSPtr<AuLoop::ILoopSource>& source)
|
|
|
|
{
|
|
|
|
SysPushErrorIO("IO Timeout");
|
|
|
|
this->FailWatch();
|
|
|
|
}
|
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
void IOProcessorItem::InvokeManualTick()
|
|
|
|
{
|
|
|
|
IOAlert(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IOProcessorItem::IOAlert(bool force)
|
|
|
|
{
|
2023-12-11 20:18:36 +00:00
|
|
|
if (!this->pParent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
if (!this->pParent->IsTickOnly())
|
2022-06-11 23:01:27 +00:00
|
|
|
{
|
2023-07-27 15:31:47 +00:00
|
|
|
bool bForceTick {};
|
|
|
|
if (!this->pParent->bFrameStart ||
|
|
|
|
(bForceTick = this->pParent->bNoDeferredTick))
|
2022-06-21 06:12:11 +00:00
|
|
|
{
|
2023-07-27 15:31:47 +00:00
|
|
|
if (force || bForceTick)
|
2022-07-06 02:40:09 +00:00
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
this->pParent->TickFor(AuSharedFromThis());
|
2022-07-06 02:40:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
this->pParent->TickForHack(AuSharedFromThis());
|
2022-07-06 02:40:09 +00:00
|
|
|
}
|
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
|
|
|
}
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|
|
|
|
else if (force) // manual tick
|
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
if (this->pParent->CheckThread())
|
2022-06-11 23:01:27 +00:00
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
this->pParent->TickFor(AuSharedFromThis());
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|
2022-08-29 15:46:46 +00:00
|
|
|
else if (this->pParent->IsAsync())
|
2022-06-11 23:01:27 +00:00
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SysPanic("Missing");
|
|
|
|
}
|
|
|
|
}
|
2022-07-05 19:35:40 +00:00
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
if (this->bSingleshot)
|
2022-07-05 19:35:40 +00:00
|
|
|
{
|
|
|
|
StopWatch();
|
|
|
|
}
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|
2024-01-06 04:18:13 +00:00
|
|
|
|
|
|
|
void IOProcessorItem::Finalize()
|
|
|
|
{
|
|
|
|
AuResetMember(this->pItem);
|
|
|
|
AuResetMember(this->pListener);
|
|
|
|
}
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|