mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-20 04:48:53 +00:00
made a simple staging system
This commit is contained in:
parent
2fc752f3f5
commit
4fa2a3baef
4 changed files with 100 additions and 3 deletions
|
|
@ -67,9 +67,9 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FileSystem\Ext2.Structs.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Staging\" />
|
||||
<Compile Include="Staging\DefaultStageQueue.cs" />
|
||||
<Compile Include="Staging\IStage.cs" />
|
||||
<Compile Include="Staging\StageQueue.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
11
source/Cosmos/Cosmos.Kernel/Staging/DefaultStageQueue.cs
Normal file
11
source/Cosmos/Cosmos.Kernel/Staging/DefaultStageQueue.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.Kernel.Staging {
|
||||
public class DefaultStageQueue : StageQueue {
|
||||
public DefaultStageQueue() : base() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
27
source/Cosmos/Cosmos.Kernel/Staging/IStage.cs
Normal file
27
source/Cosmos/Cosmos.Kernel/Staging/IStage.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.Kernel.Staging {
|
||||
/// <summary>
|
||||
/// Represents a kernel stage.
|
||||
/// </summary>
|
||||
public interface IStage {
|
||||
/// <summary>
|
||||
/// Gets the name of the stage.
|
||||
/// </summary>
|
||||
string Name {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the stage.
|
||||
/// </summary>
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Tears the stage down.
|
||||
/// </summary>
|
||||
void Teardown();
|
||||
}
|
||||
}
|
||||
59
source/Cosmos/Cosmos.Kernel/Staging/StageQueue.cs
Normal file
59
source/Cosmos/Cosmos.Kernel/Staging/StageQueue.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.Kernel.Staging {
|
||||
/// <summary>
|
||||
/// Represents a stage queue.
|
||||
/// </summary>
|
||||
public class StageQueue {
|
||||
/// <summary>
|
||||
/// The list of initialize stages.
|
||||
/// </summary>
|
||||
private Queue<IStage> _initialize = new Queue<IStage> ();
|
||||
|
||||
/// <summary>
|
||||
/// The list of teardown stages.
|
||||
/// </summary>
|
||||
private Queue<IStage> _teardown = new Queue<IStage> ();
|
||||
|
||||
private IStage _current;
|
||||
/// <summary>
|
||||
/// Gets the current kernel stage.
|
||||
/// </summary>
|
||||
public IStage Current {
|
||||
get {
|
||||
return _current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues a stage.
|
||||
/// </summary>
|
||||
/// <param name="stage"></param>
|
||||
public void Enqueue(IStage stage) {
|
||||
_initialize.Enqueue (stage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the tasks.
|
||||
/// </summary>
|
||||
public void Run() {
|
||||
while (_initialize.Count != 0) {
|
||||
_current = _initialize.Dequeue ();
|
||||
_current.Initialize ();
|
||||
_teardown.Enqueue (_current);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the teardown.
|
||||
/// </summary>
|
||||
public void Teardown() {
|
||||
while (_teardown.Count != 0) {
|
||||
_current = _teardown.Dequeue ();
|
||||
_current.Teardown ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue