Class CodeProcessor
- Namespace
- DuetControlServer.Codes
- Assembly
- DuetControlServer.dll
Main class delegating parallel G/M/T-code execution
[DiagnosticsPriority(0)]
public sealed class CodeProcessor : IDiagnostics
- Inheritance
-
CodeProcessor
- Implements
- Inherited Members
Constructors
CodeProcessor(Expressions, ObjectModel, IHostApplicationLifetime, IServiceProvider)
Main class delegating parallel G/M/T-code execution
public CodeProcessor(Expressions expressions, ObjectModel model, IHostApplicationLifetime lifetime, IServiceProvider serviceProvider)
Parameters
expressionsExpressionsExpression parser
modelObjectModelObject model
lifetimeIHostApplicationLifetimeApplication lifetime
serviceProviderIServiceProviderService provider
Fields
CancellationTokenSources
List of cancellation tokens to cancel pending codes while they are waiting for their execution
public readonly CancellationTokenSource[] CancellationTokenSources
Field Value
Remarks
While it may appear nicer to move the cancellation functionality to the code pipeline itself, this coule lead to performance issues or unexpected behaviour due to intercepted codes. So leave it here for now
FileLocks
Lock around the files being written
public readonly AsyncLock[] FileLocks
Field Value
- AsyncLock[]
FilesBeingWritten
Current stream writer of the files being written to (M28/M29)
public readonly StreamWriter?[] FilesBeingWritten
Field Value
Processors
Processors per code channel
public readonly Lazy<ChannelProcessor[]> Processors
Field Value
Methods
CancelCode(Code, Exception?)
Cancel a given code
public void CancelCode(Code code, Exception? e = null)
Parameters
CancelPending(CodeChannel)
Cancel pending codes of the given channel
public void CancelPending(CodeChannel channel)
Parameters
channelCodeChannelChannel to cancel codes from
CodeCompleted(Code)
Execute a given code on a given pipeline stage
public void CodeCompleted(Code code)
Parameters
codeCodeCode to enqueue
DoSyncAsync(Code, CancellationToken)
Synchronize the File and File2 code streams, may only be called when a job is live
public Task<bool> DoSyncAsync(Code code, CancellationToken cancellationToken = default)
Parameters
codeCodeCode to synchronize at
cancellationTokenCancellationTokenOptional cancellation token
Returns
Remarks
This must be called while the Job class is NOT locked and it must be called from the same code on File AND File2, else the sync request is never resolved (or at least not before the file is cancelled)
FlushAsync(CodeChannel, bool, CancellationToken)
Wait for all pending codes to finish
public Task<bool> FlushAsync(CodeChannel channel, bool flushAll = false, CancellationToken cancellationToken = default)
Parameters
channelCodeChannelCode channel to wait for
flushAllboolFlush all codes on all stack levels
cancellationTokenCancellationTokenOptional cancellation token
Returns
FlushAsync(Code, bool, bool, bool, bool, CancellationToken)
Wait for all pending codes on the same stack level as the given code to finish. By default this replaces all expressions as well for convenient parsing by the code processors.
public Task<bool> FlushAsync(Code code, bool evaluateExpressions = true, bool evaluateAll = true, bool syncFileStreams = false, bool ifExecuting = true, CancellationToken cancellationToken = default)
Parameters
codeCodeCode waiting for the flush
evaluateExpressionsboolEvaluate all expressions when pending codes have been flushed
evaluateAllboolEvaluate the expressions or only SBC fields if evaluateExpressions is set to true
syncFileStreamsboolWhether the file streams are supposed to be synchronized (if applicable)
ifExecutingboolReturn true only if the corresponding code input is actually active (ignored if syncFileStreams is true)
cancellationTokenCancellationTokenOptional cancellation token
Returns
FlushAsync(CodeFile, CancellationToken)
Wait for all pending codes of the given file to finish
public Task<bool> FlushAsync(CodeFile file, CancellationToken cancellationToken = default)
Parameters
fileCodeFileCode file
cancellationTokenCancellationTokenOptional cancellation token
Returns
GetFirmwareState(CodeChannel)
Get the pipeline state of the firmware stage from a given channel
public PipelineStackItem GetFirmwareState(CodeChannel channel)
Parameters
channelCodeChannel
Returns
Pop(CodeChannel)
Push a new state on the stack of a given pipeline. Only to be used by the SPI channel processor!
public void Pop(CodeChannel channel)
Parameters
channelCodeChannelCode channel
PrintDiagnostics(StringBuilder)
Get diagnostics from every channel processor
public void PrintDiagnostics(StringBuilder builder)
Parameters
builderStringBuilderString builder to write to
PurgeSyncRequestsFor(CodeFile)
Resolve all sync requests for a given file
public void PurgeSyncRequestsFor(CodeFile file)
Parameters
fileCodeFileFile
Push(CodeChannel, CodeFile?)
Push a new state on the stack of a given channel procesor. Only to be used by the SPI channel processor!
public PipelineStackItem Push(CodeChannel channel, CodeFile? file = null)
Parameters
channelCodeChannelCode channel
fileCodeFileOptional file
Returns
- PipelineStackItem
Pipeline state
ResolveSyncRequestsAfter(long)
Resolve all sync requests that are after the given file position
public void ResolveSyncRequestsAfter(long filePosition)
Parameters
filePositionlongFile position
SetJobFile(CodeChannel, CodeFile?)
Assign the job file to the given channel. Only used by the job tasks!
public void SetJobFile(CodeChannel channel, CodeFile? file)
Parameters
channelCodeChannelCode channel
fileCodeFileJob file
StartCodeAsync(Code)
Start the execution of a given code
public ValueTask StartCodeAsync(Code code)
Parameters
codeCodeCode to enqueue
Returns
- ValueTask
Asynchronous task