Skip to content

Commit

Permalink
Add UnknownActivityAborted session
Browse files Browse the repository at this point in the history
The new type is a session-wrapper for activities that should be aborted, but for which the session is unknown for a cell. It can be created and uses a new session context.
  • Loading branch information
1nf0rmagician committed Dec 2, 2024
1 parent 3863ffb commit 1f8a5b6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Moryx.ControlSystem/Activities/ActivityClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace Moryx.ControlSystem.Activities
[Flags]
public enum ActivityClassification
{
/// <summary>
/// Use in case the activity classification is unkown
/// </summary>
Unknown = 0x00,

/// <summary>
/// Default classification is production
/// </summary>
Expand All @@ -33,6 +38,6 @@ public enum ActivityClassification
/// <summary>
/// Activity performs a preparation, for example for a <see cref="Production"/> activity
/// </summary>
Preparation = 0x08
Preparation = 0x08,
}
}
3 changes: 0 additions & 3 deletions src/Moryx.ControlSystem/Cells/ActivityCompleted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace Moryx.ControlSystem.Cells
/// </summary>
public class ActivityCompleted : Session, ICompletableSession
{
/// <summary>
/// Initialize a new resource request for a certain resource
/// </summary>
internal ActivityCompleted(IActivity completed, Session currentSession)
: base(currentSession)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Moryx.ControlSystem/Cells/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ public static ReadyToWork StartSession(ActivityClassification classification, Re
return CreateSession(classification, type, ProcessReference.InstanceIdentity(identity), constraints);
}


/// <summary>
/// Creates a new <see cref="Session"/> for the <paramref name="unknown"/> activity
/// with a new session context and marks the activity as failed.
/// </summary>
/// <param name="unknown"></param>
public static UnknownActivityAborted WrapUnknownActivity(IActivity unknown)
{
unknown.Fail();
var wrapper = StartSession(ActivityClassification.Unknown, ReadyToWorkType.Unset, unknown.Process.Id)
.CompleteSequence(null, false, new long[] { });
return new UnknownActivityAborted(unknown, wrapper);
}

private static ReadyToWork CreateSession(ActivityClassification classification, ReadyToWorkType type, ProcessReference reference, IConstraint[] constraints)
{
if (constraints == null)
Expand Down
26 changes: 26 additions & 0 deletions src/Moryx.ControlSystem/Cells/UnknownActivityAborted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using Moryx.AbstractionLayer;

namespace Moryx.ControlSystem.Cells
{
/// <summary>
/// Message send by the resource managment when it aborted an activity for an
/// unkown session.
/// </summary>
public class UnknownActivityAborted : ActivityCompleted
{
internal UnknownActivityAborted(IActivity aborted, Session wrapper)
: base(aborted, wrapper)
{
aborted.Fail();
AbortedActivity = aborted;
}

/// <summary>
/// Activity that was aborted
/// </summary>
public IActivity AbortedActivity { get; }
}
}

0 comments on commit 1f8a5b6

Please sign in to comment.