From 4fb1019d30abe7f46b50ee846cc0922e0f9dafc8 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 4 Jul 2018 14:09:17 -0400 Subject: [PATCH] Fixups and renamespacing --- src/DMAPI/tgs.dm | 7 +++ .../Components/DreamDaemonParameters.cs | 15 ----- .../Components/IDreamDaemonFactory.cs | 16 ------ .../Executor.cs} | 10 ++-- .../IExecutor.cs} | 16 +++--- .../ISession.cs} | 4 +- .../ISessionManager.cs} | 22 +++---- .../Watchdog/ISessionManagerFactory.cs | 16 ++++++ .../{Models => Watchdog}/InteropInfo.cs | 2 +- .../ReattachInformation.cs} | 8 +-- .../RebootState.cs} | 10 ++-- .../Session.cs} | 8 +-- .../SessionManager.cs} | 57 ++++++++++--------- .../{Models => Watchdog}/TestMerge.cs | 2 +- 14 files changed, 95 insertions(+), 98 deletions(-) delete mode 100644 src/Tgstation.Server.Host/Components/DreamDaemonParameters.cs delete mode 100644 src/Tgstation.Server.Host/Components/IDreamDaemonFactory.cs rename src/Tgstation.Server.Host/Components/{DreamDaemonExecutor.cs => Watchdog/Executor.cs} (81%) rename src/Tgstation.Server.Host/Components/{IDreamDaemonExecutor.cs => Watchdog/IExecutor.cs} (60%) rename src/Tgstation.Server.Host/Components/{IDreamDaemonSession.cs => Watchdog/ISession.cs} (89%) rename src/Tgstation.Server.Host/Components/{IDreamDaemonControl.cs => Watchdog/ISessionManager.cs} (72%) create mode 100644 src/Tgstation.Server.Host/Components/Watchdog/ISessionManagerFactory.cs rename src/Tgstation.Server.Host/Components/{Models => Watchdog}/InteropInfo.cs (92%) rename src/Tgstation.Server.Host/Components/{DreamDaemonReattachInformation.cs => Watchdog/ReattachInformation.cs} (77%) rename src/Tgstation.Server.Host/Components/{DreamDaemonRebootState.cs => Watchdog/RebootState.cs} (71%) rename src/Tgstation.Server.Host/Components/{DreamDaemonSession.cs => Watchdog/Session.cs} (87%) rename src/Tgstation.Server.Host/Components/{DreamDaemonControl.cs => Watchdog/SessionManager.cs} (77%) rename src/Tgstation.Server.Host/Components/{Models => Watchdog}/TestMerge.cs (90%) diff --git a/src/DMAPI/tgs.dm b/src/DMAPI/tgs.dm index e68bfa9b61..eee991a8aa 100644 --- a/src/DMAPI/tgs.dm +++ b/src/DMAPI/tgs.dm @@ -45,6 +45,13 @@ //EVENT CODES #define TGS_EVENT_PORT_SWAP 1 //before a port change is about to happen, extra parameter is new port +#define TGS_EVENT_REBOOT_MODE_CHANGE 2 //before a reboot mode change, extras parameters are the current and new reboot mode enums + +//OTHER ENUMS + +#define TGS_REBOOT_MODE_NORMAL 0 +#define TGS_REBOOT_MODE_SHUTDOWN 1 +#define TGS_REBOOT_MODE_RESTART 2 //TODO diff --git a/src/Tgstation.Server.Host/Components/DreamDaemonParameters.cs b/src/Tgstation.Server.Host/Components/DreamDaemonParameters.cs deleted file mode 100644 index c4306bca80..0000000000 --- a/src/Tgstation.Server.Host/Components/DreamDaemonParameters.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Tgstation.Server.Host.Components -{ - static class DreamDaemonParameters - { - /// - /// Host version. Do not change to keep forwards/backwards api compatibility - /// - public const string HostVersion = "server_service_version"; - - /// - /// Path to json - /// - public const string InfoJsonPath = "tgs_json"; - } -} diff --git a/src/Tgstation.Server.Host/Components/IDreamDaemonFactory.cs b/src/Tgstation.Server.Host/Components/IDreamDaemonFactory.cs deleted file mode 100644 index 76ae5ce3f4..0000000000 --- a/src/Tgstation.Server.Host/Components/IDreamDaemonFactory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using Tgstation.Server.Api.Models.Internal; - -namespace Tgstation.Server.Host.Components -{ - /// - /// Factory for s - /// - interface IDreamDaemonFactory - { - IDreamDaemonControl LaunchNew(DreamDaemonLaunchParameters launchParameters); - - Task Reattach(DreamDaemonReattachInformation reattachInformation, CancellationToken cancellationToken); - } -} diff --git a/src/Tgstation.Server.Host/Components/DreamDaemonExecutor.cs b/src/Tgstation.Server.Host/Components/Watchdog/Executor.cs similarity index 81% rename from src/Tgstation.Server.Host/Components/DreamDaemonExecutor.cs rename to src/Tgstation.Server.Host/Components/Watchdog/Executor.cs index 6c08cf40ac..718b459917 100644 --- a/src/Tgstation.Server.Host/Components/DreamDaemonExecutor.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/Executor.cs @@ -4,10 +4,10 @@ using System.Globalization; using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Models.Internal; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// - sealed class DreamDaemonExecutor : IDreamDaemonExecutor + sealed class Executor : IExecutor { /// /// Change a given into the appropriate DreamDaemon command line word @@ -30,10 +30,10 @@ namespace Tgstation.Server.Host.Components } /// - public IDreamDaemonSession AttachToDreamDaemon(int processId) => new DreamDaemonSession(Process.GetProcessById(processId)); + public ISession AttachToDreamDaemon(int processId) => new Session(Process.GetProcessById(processId)); /// - public IDreamDaemonSession RunDreamDaemon(DreamDaemonLaunchParameters launchParameters, string dreamDaemonPath, IDmbProvider dmbProvider, string parameters, bool useSecondaryPort, bool useSecondaryDirectory) + public ISession RunDreamDaemon(DreamDaemonLaunchParameters launchParameters, string dreamDaemonPath, IDmbProvider dmbProvider, string parameters, bool useSecondaryPort, bool useSecondaryDirectory) { if (launchParameters == null) throw new ArgumentNullException(nameof(launchParameters)); @@ -60,7 +60,7 @@ namespace Tgstation.Server.Host.Components proc.Start(); - return new DreamDaemonSession(proc); + return new Session(proc); } catch { diff --git a/src/Tgstation.Server.Host/Components/IDreamDaemonExecutor.cs b/src/Tgstation.Server.Host/Components/Watchdog/IExecutor.cs similarity index 60% rename from src/Tgstation.Server.Host/Components/IDreamDaemonExecutor.cs rename to src/Tgstation.Server.Host/Components/Watchdog/IExecutor.cs index b4cbe33837..5555d24030 100644 --- a/src/Tgstation.Server.Host/Components/IDreamDaemonExecutor.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/IExecutor.cs @@ -1,11 +1,11 @@ using Tgstation.Server.Api.Models.Internal; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// - /// For creating s + /// For creating s /// - interface IDreamDaemonExecutor + interface IExecutor { /// /// Run a dream daemon instance @@ -16,14 +16,14 @@ namespace Tgstation.Server.Host.Components /// The for the .dmb to run /// The value of the -params command line option /// If the field of should be used - /// A new - IDreamDaemonSession RunDreamDaemon(DreamDaemonLaunchParameters launchParameters, string dreamDaemonPath, IDmbProvider dmbProvider, string parameters, bool useSecondaryPort, bool useSecondaryDirectory); + /// A new + ISession RunDreamDaemon(DreamDaemonLaunchParameters launchParameters, string dreamDaemonPath, IDmbProvider dmbProvider, string parameters, bool useSecondaryPort, bool useSecondaryDirectory); /// /// Attach to a running instance of DreamDaemon /// - /// The - /// A new - IDreamDaemonSession AttachToDreamDaemon(int processId); + /// The + /// A new + ISession AttachToDreamDaemon(int processId); } } diff --git a/src/Tgstation.Server.Host/Components/IDreamDaemonSession.cs b/src/Tgstation.Server.Host/Components/Watchdog/ISession.cs similarity index 89% rename from src/Tgstation.Server.Host/Components/IDreamDaemonSession.cs rename to src/Tgstation.Server.Host/Components/Watchdog/ISession.cs index 0adbc8b8d2..5404306202 100644 --- a/src/Tgstation.Server.Host/Components/IDreamDaemonSession.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ISession.cs @@ -1,12 +1,12 @@ using System; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// /// Represents a dream daemon process /// - interface IDreamDaemonSession : IDisposable + interface ISession : IDisposable { /// /// The diff --git a/src/Tgstation.Server.Host/Components/IDreamDaemonControl.cs b/src/Tgstation.Server.Host/Components/Watchdog/ISessionManager.cs similarity index 72% rename from src/Tgstation.Server.Host/Components/IDreamDaemonControl.cs rename to src/Tgstation.Server.Host/Components/Watchdog/ISessionManager.cs index 81454a6047..613009b02b 100644 --- a/src/Tgstation.Server.Host/Components/IDreamDaemonControl.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ISessionManager.cs @@ -2,12 +2,12 @@ using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// - /// Handles communication with a + /// Handles communication with a /// - interface IDreamDaemonControl : IDisposable + interface ISessionManager : IDisposable { /// /// If the of is being used @@ -22,18 +22,18 @@ namespace Tgstation.Server.Host.Components /// /// The current port DreamDaemon is listening on /// - ushort Port { get; } + ushort? Port { get; } /// - /// The current + /// The current /// - DreamDaemonRebootState RebootState { get; } + RebootState RebootState { get; } /// - /// Releases the without terminating it. Also calls + /// Releases the without terminating it. Also calls /// - /// which can be used to create a new similar to this one - DreamDaemonReattachInformation Release(); + /// which can be used to create a new similar to this one + ReattachInformation Release(); /// /// Sends a command to DreamDaemon through /world/Topic() @@ -59,9 +59,9 @@ namespace Tgstation.Server.Host.Components /// /// Attempts to change the current to /// - /// The new + /// The new /// The for the operation /// A resulting in if the operation succeeded, otherwise - Task SetRebootState(DreamDaemonRebootState newRebootState, CancellationToken cancellationToken); + Task SetRebootState(RebootState newRebootState, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ISessionManagerFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/ISessionManagerFactory.cs new file mode 100644 index 0000000000..0dfa13b376 --- /dev/null +++ b/src/Tgstation.Server.Host/Components/Watchdog/ISessionManagerFactory.cs @@ -0,0 +1,16 @@ +using System.Threading; +using System.Threading.Tasks; +using Tgstation.Server.Api.Models.Internal; + +namespace Tgstation.Server.Host.Components.Watchdog +{ + /// + /// Factory for s + /// + interface ISessionManagerFactory + { + ISessionManager LaunchNew(DreamDaemonLaunchParameters launchParameters); + + Task Reattach(ReattachInformation reattachInformation, CancellationToken cancellationToken); + } +} diff --git a/src/Tgstation.Server.Host/Components/Models/InteropInfo.cs b/src/Tgstation.Server.Host/Components/Watchdog/InteropInfo.cs similarity index 92% rename from src/Tgstation.Server.Host/Components/Models/InteropInfo.cs rename to src/Tgstation.Server.Host/Components/Watchdog/InteropInfo.cs index 152d65d11a..a68aaa5bf0 100644 --- a/src/Tgstation.Server.Host/Components/Models/InteropInfo.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/InteropInfo.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Tgstation.Server.Api.Models.Internal; -namespace Tgstation.Server.Host.Components.Models +namespace Tgstation.Server.Host.Components.Watchdog { sealed class InteropInfo { diff --git a/src/Tgstation.Server.Host/Components/DreamDaemonReattachInformation.cs b/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs similarity index 77% rename from src/Tgstation.Server.Host/Components/DreamDaemonReattachInformation.cs rename to src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs index 5c24f46e21..cc852a69fd 100644 --- a/src/Tgstation.Server.Host/Components/DreamDaemonReattachInformation.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ReattachInformation.cs @@ -1,11 +1,11 @@ using System; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// - /// Parameters necessary for duplicating a session + /// Parameters necessary for duplicating a session /// - sealed class DreamDaemonReattachInformation + sealed class ReattachInformation { /// /// Used to identify and authenticate the DreamDaemon instance @@ -30,7 +30,7 @@ namespace Tgstation.Server.Host.Components /// /// The current DreamDaemon reboot state /// - public DreamDaemonRebootState RebootState { get; set; } + public RebootState RebootState { get; set; } /// /// The used by DreamDaemon diff --git a/src/Tgstation.Server.Host/Components/DreamDaemonRebootState.cs b/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs similarity index 71% rename from src/Tgstation.Server.Host/Components/DreamDaemonRebootState.cs rename to src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs index 8608ab6005..b1fc80317a 100644 --- a/src/Tgstation.Server.Host/Components/DreamDaemonRebootState.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs @@ -1,21 +1,21 @@ -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// /// Represents the action to take when /world/Reboot() is called /// - enum DreamDaemonRebootState + enum RebootState : int { /// /// Run DreamDaemon's normal reboot process /// - Normal, + Normal = 0, /// /// Shutdown DreamDaemon /// - Shutdown, + Shutdown = 1, /// /// Restart the DreamDaemon process /// - Restart + Restart = 2 } } diff --git a/src/Tgstation.Server.Host/Components/DreamDaemonSession.cs b/src/Tgstation.Server.Host/Components/Watchdog/Session.cs similarity index 87% rename from src/Tgstation.Server.Host/Components/DreamDaemonSession.cs rename to src/Tgstation.Server.Host/Components/Watchdog/Session.cs index 7420c43ce7..138be06b17 100644 --- a/src/Tgstation.Server.Host/Components/DreamDaemonSession.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/Session.cs @@ -2,10 +2,10 @@ using System.Diagnostics; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// - sealed class DreamDaemonSession : IDreamDaemonSession + sealed class Session : ISession { /// public int ProcessId => process.Id; @@ -26,10 +26,10 @@ namespace Tgstation.Server.Host.Components readonly TaskCompletionSource lifetimeTask; /// - /// Construct a + /// Construct a /// /// The value of - public DreamDaemonSession(Process process) + public Session(Process process) { this.process = process ?? throw new ArgumentNullException(nameof(process)); diff --git a/src/Tgstation.Server.Host/Components/DreamDaemonControl.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionManager.cs similarity index 77% rename from src/Tgstation.Server.Host/Components/DreamDaemonControl.cs rename to src/Tgstation.Server.Host/Components/Watchdog/SessionManager.cs index 272cf23d69..b2012b7873 100644 --- a/src/Tgstation.Server.Host/Components/DreamDaemonControl.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionManager.cs @@ -6,10 +6,10 @@ using System.Net; using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components.Watchdog { /// - sealed class DreamDaemonControl : IDreamDaemonControl, IInteropConsumer + sealed class SessionManager : ISessionManager, IInteropConsumer { /// /// Generic OK response @@ -24,8 +24,10 @@ namespace Tgstation.Server.Host.Components const string DMParameterAccessIdentifier = "access"; const string DMParameterCommand = "command"; const string DMParameterNewPort = "new_port"; + const string DMParameterNewRebootMode = "new_reboot_mode"; const string DMCommandChangePort = "change_port"; + const string DMCommandChangeReboot = "change_reboot"; /// public bool IsPrimary @@ -48,17 +50,19 @@ namespace Tgstation.Server.Host.Components } /// - public ushort Port + public ushort? Port { get { CheckDisposed(); + if (portClosed) + return null; return reattachInformation.Port; } } /// - public DreamDaemonRebootState RebootState + public RebootState RebootState { get { @@ -68,24 +72,24 @@ namespace Tgstation.Server.Host.Components } /// - /// The up to date + /// The up to date /// - readonly DreamDaemonReattachInformation reattachInformation; + readonly ReattachInformation reattachInformation; /// - /// The for the + /// The for the /// readonly IByondTopicSender byondTopicSender; /// - /// The for the + /// The for the /// readonly IInteropContext interopContext; /// - /// The for the + /// The for the /// - readonly IDreamDaemonSession session; + readonly ISession session; /// /// The waits on when DreamDaemon currently has it's ports closed @@ -101,18 +105,18 @@ namespace Tgstation.Server.Host.Components /// bool portClosed; /// - /// If the has been disposed + /// If the has been disposed /// bool disposed; /// - /// Construct a + /// Construct a /// /// The value of /// The value of /// The value of /// The used to construct - public DreamDaemonControl(DreamDaemonReattachInformation reattachInformation, IDreamDaemonSession session, IByondTopicSender byondTopicSender, IInteropRegistrar interopRegistrar) + public SessionManager(ReattachInformation reattachInformation, ISession session, IByondTopicSender byondTopicSender, IInteropRegistrar interopRegistrar) { this.reattachInformation = reattachInformation ?? throw new ArgumentNullException(nameof(reattachInformation)); this.byondTopicSender = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender)); @@ -130,13 +134,14 @@ namespace Tgstation.Server.Host.Components public void Dispose() { lock (this) - if (!disposed) - { - session.Dispose(); - interopContext.Dispose(); - Dmb?.Dispose(); //will be null when released - disposed = true; - } + { + if (disposed) + return; + session.Dispose(); + interopContext.Dispose(); + Dmb?.Dispose(); //will be null when released + disposed = true; + } } /// @@ -164,11 +169,11 @@ namespace Tgstation.Server.Host.Components void CheckDisposed() { if (disposed) - throw new ObjectDisposedException(nameof(DreamDaemonControl)); + throw new ObjectDisposedException(nameof(SessionManager)); } /// - public DreamDaemonReattachInformation Release() + public ReattachInformation Release() { CheckDisposed(); //we still don't want to dispose the dmb yet, even though we're keeping it alive @@ -221,12 +226,12 @@ namespace Tgstation.Server.Host.Components } /// - public async Task SetRebootState(DreamDaemonRebootState newRebootState, CancellationToken cancellationToken) + public async Task SetRebootState(RebootState newRebootState, CancellationToken cancellationToken) { - var oldActive = RebootState != DreamDaemonRebootState.Normal; - var newActive = RebootState != DreamDaemonRebootState.Normal; - if (oldActive == newActive) + if (RebootState == newRebootState) return true; + + return await SendCommand(String.Format(CultureInfo.InvariantCulture, "{0}&{1}={2}", DMCommandChangeReboot, DMParameterNewRebootMode, (int)newRebootState), cancellationToken).ConfigureAwait(false) == DMResponseOKGeneric; } } } diff --git a/src/Tgstation.Server.Host/Components/Models/TestMerge.cs b/src/Tgstation.Server.Host/Components/Watchdog/TestMerge.cs similarity index 90% rename from src/Tgstation.Server.Host/Components/Models/TestMerge.cs rename to src/Tgstation.Server.Host/Components/Watchdog/TestMerge.cs index cda4aaa5ea..7a55e739fe 100644 --- a/src/Tgstation.Server.Host/Components/Models/TestMerge.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/TestMerge.cs @@ -1,6 +1,6 @@ using Tgstation.Server.Api.Models.Internal; -namespace Tgstation.Server.Host.Components.Models +namespace Tgstation.Server.Host.Components.Watchdog { /// /// This model mirrors /datum/tgs_revision_information/test_merge