2022-06-11 23:01:27 +00:00
/***
Copyright ( C ) 2022 J Reece Wilson ( a / k / a " Reece " ) . All rights reserved .
File : IIOProcessor . hpp
Date : 2022 - 6 - 6
Author : Reece
* * */
# pragma once
2022-08-02 04:58:00 +00:00
namespace Aurora : : IO : : Loop
{
struct ILoopQueue ;
struct ILoopSource ;
}
2022-06-11 23:01:27 +00:00
namespace Aurora : : IO
{
struct IIOProcessor
{
2022-12-06 22:53:37 +00:00
// Local thread:
// note: IOProcessors running over an AuAsync runner or is getting pumped by an external loop queue (NewIOProcessor(...), NewIOProcessorOnThread(...)) need not use the following apis:
2022-06-28 14:57:29 +00:00
virtual AuUInt32 TryTick ( ) = 0 ;
virtual AuUInt32 RunTick ( ) = 0 ;
2022-12-06 22:53:37 +00:00
virtual AuUInt32 RunTickEx ( AuUInt32 dwTimeout ) = 0 ;
virtual AuUInt32 TickFor ( const AuSPtr < IIOProcessorItem > & pIoEvent ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief force a tick
*/
2022-06-28 14:57:29 +00:00
virtual AuUInt32 ManualTick ( ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief to be used with bTickOnly primarily . wakes up the thread at a set frequency .
*/
2022-06-28 14:57:29 +00:00
virtual AuUInt64 SetRefreshRate ( AuUInt64 ns ) = 0 ;
2022-12-06 22:53:37 +00:00
/**
* @ brief to be used with bTickOnly primarily . wakes up the thread at a set frequency .
*/
2022-06-28 14:57:29 +00:00
virtual bool HasRefreshRate ( ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief returns the aurora threadid of the intended caller ( see : AuThreads : : GetThreadId ( ) )
*/
2022-06-28 14:57:29 +00:00
virtual AuUInt64 GetOwnedThreadId ( ) = 0 ;
2022-12-06 22:53:37 +00:00
// The following apis are thread safe:
/**
* @ brief Used to poll if there are any items worth [ try / blocking ] ticking over .
* @ return returns true if there are callbacks , watches , or other registered work available .
* @ note you can use me as a while ( AuIsThreadRunning ( ) & & pIoProcessor - > [ IsAlive / HasItems ] ( ) ) { pIoProcessor - > [ RunTickEx ( uTimeout ) ; }
*/
virtual bool HasItems ( ) = 0 ;
// the following are apis used to register triggers (usually loop sources) on the thread/processor/loop queue/whatever
/**
* @ brief low level wait api
*/
virtual AuSPtr < IIOProcessorItem > StartIOWatch ( const AuSPtr < IIOWaitableItem > & pSource , const AuSPtr < IIOEventListener > & pEventListener ) = 0 ;
/**
* @ brief low level wait api
*/
virtual AuSPtr < IIOProcessorItem > StartIOWatchEx ( const AuSPtr < IIOWaitableItem > & pSource , const AuSPtr < IIOEventListener > & pEventListener , bool bSingleshot ) = 0 ;
2022-06-28 14:57:29 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief low level wait api with simple callback
*/
virtual AuSPtr < IIOProcessorItem > StartSimpleIOWatch ( const AuSPtr < IIOWaitableItem > & pSource , const AuSPtr < IIOSimpleEventListener > & pEventListener ) = 0 ;
2022-06-28 14:57:29 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief low level wait api with simple callback
*/
virtual AuSPtr < IIOProcessorItem > StartSimpleIOWatchEx ( const AuSPtr < IIOWaitableItem > & pSource , const AuSPtr < IIOSimpleEventListener > & pEventListener , bool bSingleshot ) = 0 ;
2022-06-28 14:57:29 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief Registers a callback given a loopsource ( multi - trigger )
* @ param pSource
* @ param pEventListener
* @ return
*/
virtual AuSPtr < IIOProcessorItem > StartSimpleLSWatch ( const AuSPtr < Loop : : ILoopSource > & pSource , const AuSPtr < IIOSimpleEventListener > & pEventListener ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief Registers an optionally singleshot callback given a loopsource
* @ param pSource
* @ param pEventListener
* @ param dwMsTimeout optional timeout
* @ return
*/
virtual AuSPtr < IIOProcessorItem > StartSimpleLSWatchEx ( const AuSPtr < Loop : : ILoopSource > & pSource , const AuSPtr < IIOSimpleEventListener > & pEventListener , bool bSingleshot , AuUInt32 dwMsTimeout = 0 ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
// general purpose work callbacks
/**
* @ brief Dispatches an abortable callback to the processor thread
* @ param pWork
* @ return
*/
virtual bool SubmitIOWorkItem ( const AuSPtr < IIOProcessorWorkUnit > & pWork ) = 0 ;
// wake up
/**
* @ brief you almost certainly will not need me . so far i ' ve come across one legitmate use case for glib - io interop and thats about it .
*/
2022-11-28 16:01:08 +00:00
virtual void WakeupThread ( ) = 0 ;
2022-12-06 22:53:37 +00:00
// io sequence callbacks
/**
* @ brief Register an inter - frame callback indicating point of execution throughout the [ START ] ( optional [ yield ] ) [ IO ] [ IO TICK ] [ WORK ITEMS ] [ EPILOGUE ] [ END OF FRAME ] frame
* @ param eventListener
* @ return
*/
virtual bool AddEventListener ( const AuSPtr < IIOProcessorEventListener > & pEventListener ) = 0 ;
/**
* @ brief Deregisters an inter - frame callback listener
* @ param pEventListener
*/
virtual void RemoveEventListener ( const AuSPtr < IIOProcessorEventListener > & pEventListener ) = 0 ;
2022-06-21 04:49:36 +00:00
2022-12-06 22:53:37 +00:00
// factories backed by this processor to provide additional functionality
/**
* @ brief provides an IO pipe processor for creating pipe requests
* @ return
*/
2022-08-02 04:58:00 +00:00
virtual AuSPtr < IIOPipeProcessor > ToPipeProcessor ( ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
// internal and utility apis
/**
* @ brief Utility proprety access to the underlying IO wait surface : a loop queue
* @ return
* @ warning Do not use me unless you know what you ' re doing .
* There is very little reason to pull the underlying loop queue from here .
* You are probably doing something wrong . IOProcessors are meant to sit on top of
* queues as an abstraction layer for intelligent work dispatch , global stream processing
* and dispatch of io work callbacks . pulling a loopqueue from such a layer of abstraction
* would be like pulling the state of an upcoming WaitMultipleObjects call ; it makes no sense .
*
* [ note to future deadbeat maintainers : that doesnt mean you should remove it either ]
*/
2022-08-02 04:58:00 +00:00
virtual AuSPtr < Loop : : ILoopQueue > ToQueue ( ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
virtual bool MultiplexRefreshRateWithIOEvents ( ) = 0 ;
2022-06-11 23:01:27 +00:00
2022-12-06 22:53:37 +00:00
/**
* @ brief resets the io processors footprint in : : ToQueue ( )
*/
virtual void ReleaseAllWatches ( ) = 0 ;
2023-07-27 15:31:47 +00:00
/**
* @ warning : do not use me . this is a niche hack for nested ui modal loops .
*/
virtual bool ConfigureNoDeferredTicks ( bool bOption ) = 0 ;
2022-06-11 23:01:27 +00:00
} ;
2022-08-29 15:46:46 +00:00
/**
* @ brief Creates an IOProcessor to execute tasks on a given loop queue
* @ param bTickOnly True if kernel yielding on IO objects is disabled in favor of forced TPS .
* Do note that the throughput of a tick will differ per platform . Accept rate ,
* throughput , etc may need tweaking , if you wish to drive an IIOProcessor using
* a timer or the manual tick functions .
* @ param pQueue
* @ return
*/
AUKN_SYM AuSPtr < IIOProcessor > NewIOProcessor ( bool bTickOnly , const AuSPtr < Loop : : ILoopQueue > & pQueue ) ;
/**
* @ brief Creates an IOProcessor to execute tasks on the loop queue of a given AuAsync thread id
* @ param bTickOnly True if kernel yielding on IO objects is disabled in favor of forced TPS .
* Do note that the throughput of a tick will differ per platform . Accept rate ,
* throughput , etc may need tweaking , if you wish to drive an IIOProcessor using
* a timer or the manual tick functions .
* @ param pQueue
* @ return
*/
AUKN_SYM AuSPtr < IIOProcessor > NewIOProcessorOnThread ( bool bTickOnly , Async : : WorkerPId_t id ) ;
AUKN_SYM AuSPtr < IIOProcessor > NewIOProcessorNoQueue ( bool bTickOnly ) ;
2022-06-11 23:01:27 +00:00
}