Fixups and renamespacing

This commit is contained in:
Cyberboss
2018-07-04 14:09:17 -04:00
parent ec248029ba
commit 4fb1019d30
14 changed files with 95 additions and 98 deletions
+7
View File
@@ -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
@@ -1,15 +0,0 @@
namespace Tgstation.Server.Host.Components
{
static class DreamDaemonParameters
{
/// <summary>
/// Host version. Do not change to keep forwards/backwards api compatibility
/// </summary>
public const string HostVersion = "server_service_version";
/// <summary>
/// Path to <see cref="Models.InteropInfo"/> json
/// </summary>
public const string InfoJsonPath = "tgs_json";
}
}
@@ -1,16 +0,0 @@
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models.Internal;
namespace Tgstation.Server.Host.Components
{
/// <summary>
/// Factory for <see cref="IDreamDaemonControl"/>s
/// </summary>
interface IDreamDaemonFactory
{
IDreamDaemonControl LaunchNew(DreamDaemonLaunchParameters launchParameters);
Task<IDreamDaemonControl> Reattach(DreamDaemonReattachInformation reattachInformation, CancellationToken cancellationToken);
}
}
@@ -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
{
/// <inheritdoc />
sealed class DreamDaemonExecutor : IDreamDaemonExecutor
sealed class Executor : IExecutor
{
/// <summary>
/// Change a given <paramref name="securityLevel"/> into the appropriate DreamDaemon command line word
@@ -30,10 +30,10 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public IDreamDaemonSession AttachToDreamDaemon(int processId) => new DreamDaemonSession(Process.GetProcessById(processId));
public ISession AttachToDreamDaemon(int processId) => new Session(Process.GetProcessById(processId));
/// <inheritdoc />
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
{
@@ -1,11 +1,11 @@
using Tgstation.Server.Api.Models.Internal;
namespace Tgstation.Server.Host.Components
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// For creating <see cref="IDreamDaemonSession"/>s
/// For creating <see cref="ISession"/>s
/// </summary>
interface IDreamDaemonExecutor
interface IExecutor
{
/// <summary>
/// Run a dream daemon instance
@@ -16,14 +16,14 @@ namespace Tgstation.Server.Host.Components
/// <param name="dmbProvider">The <see cref="IDmbProvider"/> for the .dmb to run</param>
/// <param name="parameters">The value of the -params command line option</param>
/// <param name="useSecondaryPort">If the <see cref="DreamDaemonLaunchParameters.SecondaryPort"/> field of <paramref name="launchParameters"/> should be used</param>
/// <returns>A new <see cref="IDreamDaemonSession"/></returns>
IDreamDaemonSession RunDreamDaemon(DreamDaemonLaunchParameters launchParameters, string dreamDaemonPath, IDmbProvider dmbProvider, string parameters, bool useSecondaryPort, bool useSecondaryDirectory);
/// <returns>A new <see cref="ISession"/></returns>
ISession RunDreamDaemon(DreamDaemonLaunchParameters launchParameters, string dreamDaemonPath, IDmbProvider dmbProvider, string parameters, bool useSecondaryPort, bool useSecondaryDirectory);
/// <summary>
/// Attach to a running instance of DreamDaemon
/// </summary>
/// <param name="processId">The <see cref="IDreamDaemonSession.ProcessId"/></param>
/// <returns>A new <see cref="IDreamDaemonSession"/></returns>
IDreamDaemonSession AttachToDreamDaemon(int processId);
/// <param name="processId">The <see cref="ISession.ProcessId"/></param>
/// <returns>A new <see cref="ISession"/></returns>
ISession AttachToDreamDaemon(int processId);
}
}
@@ -1,12 +1,12 @@
using System;
using System.Threading.Tasks;
namespace Tgstation.Server.Host.Components
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// Represents a dream daemon process
/// </summary>
interface IDreamDaemonSession : IDisposable
interface ISession : IDisposable
{
/// <summary>
/// The <see cref="System.Diagnostics.Process.Id"/>
@@ -2,12 +2,12 @@
using System.Threading;
using System.Threading.Tasks;
namespace Tgstation.Server.Host.Components
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// Handles communication with a <see cref="IDreamDaemonSession"/>
/// Handles communication with a <see cref="ISession"/>
/// </summary>
interface IDreamDaemonControl : IDisposable
interface ISessionManager : IDisposable
{
/// <summary>
/// If the <see cref="IDmbProvider.PrimaryDirectory"/> of <see cref="Dmb"/> is being used
@@ -22,18 +22,18 @@ namespace Tgstation.Server.Host.Components
/// <summary>
/// The current port DreamDaemon is listening on
/// </summary>
ushort Port { get; }
ushort? Port { get; }
/// <summary>
/// The current <see cref="DreamDaemonRebootState"/>
/// The current <see cref="RebootState"/>
/// </summary>
DreamDaemonRebootState RebootState { get; }
RebootState RebootState { get; }
/// <summary>
/// Releases the <see cref="IDreamDaemonSession"/> without terminating it. Also calls <see cref="IDisposable.Dispose"/>
/// Releases the <see cref="ISession"/> without terminating it. Also calls <see cref="IDisposable.Dispose"/>
/// </summary>
/// <returns><see cref="DreamDaemonReattachInformation"/> which can be used to create a new <see cref="IDreamDaemonControl"/> similar to this one</returns>
DreamDaemonReattachInformation Release();
/// <returns><see cref="ReattachInformation"/> which can be used to create a new <see cref="ISessionManager"/> similar to this one</returns>
ReattachInformation Release();
/// <summary>
/// Sends a command to DreamDaemon through /world/Topic()
@@ -59,9 +59,9 @@ namespace Tgstation.Server.Host.Components
/// <summary>
/// Attempts to change the current <see cref="RebootState"/> to <paramref name="newRebootState"/>
/// </summary>
/// <param name="newRebootState">The new <see cref="DreamDaemonRebootState"/></param>
/// <param name="newRebootState">The new <see cref="RebootState"/></param>
/// <param name="cancellatonToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if the operation succeeded, <see langword="false"/> otherwise</returns>
Task<bool> SetRebootState(DreamDaemonRebootState newRebootState, CancellationToken cancellationToken);
Task<bool> SetRebootState(RebootState newRebootState, CancellationToken cancellationToken);
}
}
@@ -0,0 +1,16 @@
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models.Internal;
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// Factory for <see cref="ISessionManager"/>s
/// </summary>
interface ISessionManagerFactory
{
ISessionManager LaunchNew(DreamDaemonLaunchParameters launchParameters);
Task<ISessionManager> Reattach(ReattachInformation reattachInformation, CancellationToken cancellationToken);
}
}
@@ -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
{
@@ -1,11 +1,11 @@
using System;
namespace Tgstation.Server.Host.Components
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// Parameters necessary for duplicating a <see cref="IDreamDaemonControl"/> session
/// Parameters necessary for duplicating a <see cref="ISessionManager"/> session
/// </summary>
sealed class DreamDaemonReattachInformation
sealed class ReattachInformation
{
/// <summary>
/// Used to identify and authenticate the DreamDaemon instance
@@ -30,7 +30,7 @@ namespace Tgstation.Server.Host.Components
/// <summary>
/// The current DreamDaemon reboot state
/// </summary>
public DreamDaemonRebootState RebootState { get; set; }
public RebootState RebootState { get; set; }
/// <summary>
/// The <see cref="IDmbProvider"/> used by DreamDaemon
@@ -1,21 +1,21 @@
namespace Tgstation.Server.Host.Components
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// Represents the action to take when /world/Reboot() is called
/// </summary>
enum DreamDaemonRebootState
enum RebootState : int
{
/// <summary>
/// Run DreamDaemon's normal reboot process
/// </summary>
Normal,
Normal = 0,
/// <summary>
/// Shutdown DreamDaemon
/// </summary>
Shutdown,
Shutdown = 1,
/// <summary>
/// Restart the DreamDaemon process
/// </summary>
Restart
Restart = 2
}
}
@@ -2,10 +2,10 @@
using System.Diagnostics;
using System.Threading.Tasks;
namespace Tgstation.Server.Host.Components
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <inheritdoc />
sealed class DreamDaemonSession : IDreamDaemonSession
sealed class Session : ISession
{
/// <inheritdoc />
public int ProcessId => process.Id;
@@ -26,10 +26,10 @@ namespace Tgstation.Server.Host.Components
readonly TaskCompletionSource<int> lifetimeTask;
/// <summary>
/// Construct a <see cref="DreamDaemonSession"/>
/// Construct a <see cref="Session"/>
/// </summary>
/// <param name="process">The value of <see cref="process"/></param>
public DreamDaemonSession(Process process)
public Session(Process process)
{
this.process = process ?? throw new ArgumentNullException(nameof(process));
@@ -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
{
/// <inheritdoc />
sealed class DreamDaemonControl : IDreamDaemonControl, IInteropConsumer
sealed class SessionManager : ISessionManager, IInteropConsumer
{
/// <summary>
/// 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";
/// <inheritdoc />
public bool IsPrimary
@@ -48,17 +50,19 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public ushort Port
public ushort? Port
{
get
{
CheckDisposed();
if (portClosed)
return null;
return reattachInformation.Port;
}
}
/// <inheritdoc />
public DreamDaemonRebootState RebootState
public RebootState RebootState
{
get
{
@@ -68,24 +72,24 @@ namespace Tgstation.Server.Host.Components
}
/// <summary>
/// The up to date <see cref="DreamDaemonReattachInformation"/>
/// The up to date <see cref="ReattachInformation"/>
/// </summary>
readonly DreamDaemonReattachInformation reattachInformation;
readonly ReattachInformation reattachInformation;
/// <summary>
/// The <see cref="IByondTopicSender"/> for the <see cref="DreamDaemonControl"/>
/// The <see cref="IByondTopicSender"/> for the <see cref="SessionManager"/>
/// </summary>
readonly IByondTopicSender byondTopicSender;
/// <summary>
/// The <see cref="IInteropContext"/> for the <see cref="DreamDaemonControl"/>
/// The <see cref="IInteropContext"/> for the <see cref="SessionManager"/>
/// </summary>
readonly IInteropContext interopContext;
/// <summary>
/// The <see cref="IDreamDaemonSession"/> for the <see cref="DreamDaemonControl"/>
/// The <see cref="ISession"/> for the <see cref="SessionManager"/>
/// </summary>
readonly IDreamDaemonSession session;
readonly ISession session;
/// <summary>
/// The <see cref="TaskCompletionSource{TResult}"/> <see cref="SetPortImpl(ushort, CancellationToken)"/> waits on when DreamDaemon currently has it's ports closed
@@ -101,18 +105,18 @@ namespace Tgstation.Server.Host.Components
/// </summary>
bool portClosed;
/// <summary>
/// If the <see cref="DreamDaemonControl"/> has been disposed
/// If the <see cref="SessionManager"/> has been disposed
/// </summary>
bool disposed;
/// <summary>
/// Construct a <see cref="DreamDaemonControl"/>
/// Construct a <see cref="SessionManager"/>
/// </summary>
/// <param name="reattachInformation">The value of <see cref="reattachInformation"/></param>
/// <param name="session">The value of <see cref="session"/></param>
/// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
/// <param name="interopRegistrar">The <see cref="IInteropRegistrar"/> used to construct <see cref="interopContext"/></param>
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;
}
}
/// <inheritdoc />
@@ -164,11 +169,11 @@ namespace Tgstation.Server.Host.Components
void CheckDisposed()
{
if (disposed)
throw new ObjectDisposedException(nameof(DreamDaemonControl));
throw new ObjectDisposedException(nameof(SessionManager));
}
/// <inheritdoc />
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
}
/// <inheritdoc />
public async Task<bool> SetRebootState(DreamDaemonRebootState newRebootState, CancellationToken cancellationToken)
public async Task<bool> 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;
}
}
}
@@ -1,6 +1,6 @@
using Tgstation.Server.Api.Models.Internal;
namespace Tgstation.Server.Host.Components.Models
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// This model mirrors /datum/tgs_revision_information/test_merge