Skip to content
Snippets Groups Projects
Commit 8913b68c authored by Tobias's avatar Tobias
Browse files

Added Suspending and Unsuspending to ConfigOpMode,

IsUsable Checks IsSet in OrderOutput
parent 5fdb4703
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ namespace ControlComponents.Core
protected override void Selected()
{
if (AllNeededOutputsAreSet())
if (AllNeededOutputsArePresent())
{
ConfigureOutputsAtExternalCC();
// By selecting the ConfigOperationMode, simply the same OperationMode is selected on the external cc
......@@ -47,9 +47,9 @@ namespace ControlComponents.Core
}
}
private bool AllNeededOutputsAreSet()
private bool AllNeededOutputsArePresent()
{
return _externalCC.Roles.All(role => this.outputs.Keys.Contains(role) && this.outputs[role].IsSet);
return _externalCC.Roles.All(role => this.outputs.Keys.Contains(role));
}
private void ConfigureOutputsAtExternalCC()
......@@ -94,6 +94,26 @@ namespace ControlComponents.Core
await base.Completing(token);
}
protected override async Task Suspending(CancellationToken token)
{
if(_externalCC.OpModeName != "NONE" && _externalCC.EXST != ExecutionState.SUSPENDING)
{
_externalCC.Suspend(base.execution.ComponentName);
}
await MirrorState(token);
await base.Suspending(token);
}
protected override async Task Unsuspending(CancellationToken token)
{
if(_externalCC.OpModeName != "NONE" && _externalCC.EXST != ExecutionState.UNSUSPENDING)
{
_externalCC.Unsuspend(base.execution.ComponentName);
}
await MirrorState(token);
await base.Unsuspending(token);
}
protected override async Task Stopping(CancellationToken token)
{
if(_externalCC.OpModeName != "NONE")
......
......@@ -117,6 +117,24 @@ namespace ControlComponents.Core
}
}
public static async Task UnsuspendAndWaitForExecute(this IControlComponent cc, string occupier)
{
if (cc.EXST == ExecutionState.SUSPENDED || cc.EXST == ExecutionState.UNSUSPENDING)
{
StateWaiter waiter = new StateWaiter();
cc.ExecutionStateChanged += waiter.EventHandler;
cc.Unsuspend(occupier);
await waiter.Execute();
cc.ExecutionStateChanged -= waiter.EventHandler;
}
else
{
logger.Warn($"{cc.ComponentName} is in state {cc.EXST}, but must be in SUSPENDED OR UNSUSPENDING");
}
}
public static async Task HoldAndWaitForHeld(this IControlComponent cc, string occupier)
{
if (cc.EXST == ExecutionState.EXECUTE || cc.EXST == ExecutionState.HOLDING)
......
......@@ -49,8 +49,7 @@ namespace ControlComponents.Core
public void Free(string sender) => controlComponent.CallMethod<string>(Role, nameof(Free), sender);
public bool IsOccupied() => controlComponent.CallMethod<bool>(Role, nameof(IsOccupied));
public bool IsFree() => controlComponent.CallMethod<bool>(Role, nameof(IsFree));
// TODO use IsSet as well
public bool IsUsableBy(string id) => controlComponent.CallMethod<string, bool>(Role, nameof(IsUsableBy), id);
public bool IsUsableBy(string id) => IsSet && controlComponent.CallMethod<string, bool>(Role, nameof(IsUsableBy), id);
private void OnExecutionStateChanged(object sender, ExecutionStateEventArgs e) => ExecutionStateChanged?.Invoke(this.Role, e);
private void OnExecutionModeChanged(object sender, ExecutionModeEventArgs e) => ExecutionModeChanged?.Invoke(this.Role, e);
......@@ -79,7 +78,10 @@ namespace ControlComponents.Core
public Task DeselectOperationMode()
{
return controlComponent.CallMethod<Task>(Role, nameof(DeselectOperationMode));
if(IsSet)
return controlComponent.CallMethod<Task>(Role, nameof(DeselectOperationMode));
else
return Task.CompletedTask;
}
public void Reset(string sender)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment