From c07d5a69635494e1bcd39890df8f929fb7353709 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 2 Jan 2019 15:57:48 +0100 Subject: [PATCH] Remove unused PowerManagement It isn't up to the application to prevent the system from going to sleep --- .../ApplicationHost.cs | 5 -- .../EntryPoints/KeepServerAwake.cs | 65 ------------------- .../LiveTv/EmbyTV/EmbyTV.cs | 20 +++++- .../LiveTv/EmbyTV/TimerManager.cs | 30 ++------- Jellyfin.Server/CoreAppHost.cs | 4 +- Jellyfin.Server/PowerManagement.cs | 23 ------- Jellyfin.Server/Program.cs | 4 +- MediaBrowser.Model/System/IPowerManagement.cs | 11 ---- 8 files changed, 26 insertions(+), 136 deletions(-) delete mode 100644 Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs delete mode 100644 Jellyfin.Server/PowerManagement.cs delete mode 100644 MediaBrowser.Model/System/IPowerManagement.cs diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 9b9c6146f..950ae10c7 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -369,7 +369,6 @@ namespace Emby.Server.Implementations public StartupOptions StartupOptions { get; private set; } - internal IPowerManagement PowerManagement { get; private set; } internal IImageEncoder ImageEncoder { get; private set; } protected IProcessFactory ProcessFactory { get; private set; } @@ -391,7 +390,6 @@ namespace Emby.Server.Implementations ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, - IPowerManagement powerManagement, IEnvironmentInfo environmentInfo, IImageEncoder imageEncoder, ISystemEvents systemEvents, @@ -417,7 +415,6 @@ namespace Emby.Server.Implementations Logger = LoggerFactory.CreateLogger("App"); StartupOptions = options; - PowerManagement = powerManagement; ImageEncoder = imageEncoder; @@ -857,8 +854,6 @@ namespace Emby.Server.Implementations SocketFactory = new SocketFactory(LoggerFactory.CreateLogger("SocketFactory")); RegisterSingleInstance(SocketFactory); - RegisterSingleInstance(PowerManagement); - SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LoggerFactory, FileSystemManager, CryptographyProvider); RegisterSingleInstance(SecurityManager); diff --git a/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs b/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs deleted file mode 100644 index a6dadcef0..000000000 --- a/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs +++ /dev/null @@ -1,65 +0,0 @@ -using MediaBrowser.Controller; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Controller.Session; -using Microsoft.Extensions.Logging; -using System; -using System.Linq; -using MediaBrowser.Model.System; -using MediaBrowser.Model.Threading; - -namespace Emby.Server.Implementations.EntryPoints -{ - public class KeepServerAwake : IServerEntryPoint - { - private readonly ISessionManager _sessionManager; - private readonly ILogger _logger; - private ITimer _timer; - private readonly IServerApplicationHost _appHost; - private readonly ITimerFactory _timerFactory; - private readonly IPowerManagement _powerManagement; - - public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost, ITimerFactory timerFactory, IPowerManagement powerManagement) - { - _sessionManager = sessionManager; - _logger = logger; - _appHost = appHost; - _timerFactory = timerFactory; - _powerManagement = powerManagement; - } - - public void Run() - { - _timer = _timerFactory.Create(OnTimerCallback, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); - } - - private void OnTimerCallback(object state) - { - var now = DateTime.UtcNow; - - try - { - if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15)) - { - _powerManagement.PreventSystemStandby(); - } - else - { - _powerManagement.AllowSystemStandby(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Error resetting system standby timer"); - } - } - - public void Dispose() - { - if (_timer != null) - { - _timer.Dispose(); - _timer = null; - } - } - } -} diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 59f9fe86f..81a47bfea 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -75,7 +75,23 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV private readonly IStreamHelper _streamHelper; - public EmbyTV(IServerApplicationHost appHost, IStreamHelper streamHelper, IMediaSourceManager mediaSourceManager, IAssemblyInfo assemblyInfo, ILogger logger, IJsonSerializer jsonSerializer, IPowerManagement powerManagement, IHttpClient httpClient, IServerConfigurationManager config, ILiveTvManager liveTvManager, IFileSystem fileSystem, ILibraryManager libraryManager, ILibraryMonitor libraryMonitor, IProviderManager providerManager, IMediaEncoder mediaEncoder, ITimerFactory timerFactory, IProcessFactory processFactory, ISystemEvents systemEvents) + public EmbyTV(IServerApplicationHost appHost, + IStreamHelper streamHelper, + IMediaSourceManager mediaSourceManager, + IAssemblyInfo assemblyInfo, + ILogger logger, + IJsonSerializer jsonSerializer, + IHttpClient httpClient, + IServerConfigurationManager config, + ILiveTvManager liveTvManager, + IFileSystem fileSystem, + ILibraryManager libraryManager, + ILibraryMonitor libraryMonitor, + IProviderManager providerManager, + IMediaEncoder mediaEncoder, + ITimerFactory timerFactory, + IProcessFactory processFactory, + ISystemEvents systemEvents) { Current = this; @@ -97,7 +113,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _streamHelper = streamHelper; _seriesTimerProvider = new SeriesTimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers")); - _timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers"), _logger, timerFactory, powerManagement); + _timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers"), _logger, timerFactory); _timerProvider.TimerFired += _timerProvider_TimerFired; _config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated; diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs index 76a044c02..e4ab34770 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs @@ -9,7 +9,6 @@ using MediaBrowser.Model.Serialization; using MediaBrowser.Model.IO; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Threading; -using MediaBrowser.Model.System; namespace Emby.Server.Implementations.LiveTv.EmbyTV { @@ -20,14 +19,12 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV public event EventHandler> TimerFired; private readonly ITimerFactory _timerFactory; - private readonly IPowerManagement _powerManagement; - public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, ILogger logger1, ITimerFactory timerFactory, IPowerManagement powerManagement) + public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, ILogger logger1, ITimerFactory timerFactory) : base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)) { _logger = logger1; _timerFactory = timerFactory; - _powerManagement = powerManagement; } public void RestartTimers() @@ -36,7 +33,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV foreach (var item in GetAll().ToList()) { - AddOrUpdateSystemTimer(item, false); + AddOrUpdateSystemTimer(item); } } @@ -59,7 +56,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV public override void Update(TimerInfo item) { base.Update(item); - AddOrUpdateSystemTimer(item, false); + AddOrUpdateSystemTimer(item); } public void AddOrUpdate(TimerInfo item, bool resetTimer) @@ -90,7 +87,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV } base.Add(item); - AddOrUpdateSystemTimer(item, true); + AddOrUpdateSystemTimer(item); } private bool ShouldStartTimer(TimerInfo item) @@ -104,7 +101,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV return true; } - private void AddOrUpdateSystemTimer(TimerInfo item, bool scheduleSystemWakeTimer) + private void AddOrUpdateSystemTimer(TimerInfo item) { StopTimer(item); @@ -124,23 +121,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV var dueTime = startDate - now; StartTimer(item, dueTime); - - if (scheduleSystemWakeTimer && dueTime >= TimeSpan.FromMinutes(15)) - { - ScheduleSystemWakeTimer(startDate, item.Name); - } - } - - private void ScheduleSystemWakeTimer(DateTime startDate, string displayName) - { - try - { - _powerManagement.ScheduleWake(startDate.AddMinutes(-5), displayName); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error scheduling wake timer"); - } } private void StartTimer(TimerInfo item, TimeSpan dueTime) diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index b54634387..64e03f22e 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -11,8 +11,8 @@ namespace Jellyfin.Server { public class CoreAppHost : ApplicationHost { - public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager) - : base(applicationPaths, loggerFactory, options, fileSystem, powerManagement, environmentInfo, imageEncoder, systemEvents, networkManager) + public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager) + : base(applicationPaths, loggerFactory, options, fileSystem, environmentInfo, imageEncoder, systemEvents, networkManager) { } diff --git a/Jellyfin.Server/PowerManagement.cs b/Jellyfin.Server/PowerManagement.cs deleted file mode 100644 index c27c51893..000000000 --- a/Jellyfin.Server/PowerManagement.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using MediaBrowser.Model.System; - -namespace Jellyfin.Server.Native -{ - public class PowerManagement : IPowerManagement - { - public void PreventSystemStandby() - { - - } - - public void AllowSystemStandby() - { - - } - - public void ScheduleWake(DateTime wakeTimeUtc, string displayName) - { - - } - } -} diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 03fdacb26..e9f4708c8 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -13,7 +13,6 @@ using Emby.Server.Implementations; using Emby.Server.Implementations.EnvironmentInfo; using Emby.Server.Implementations.IO; using Emby.Server.Implementations.Networking; -using Jellyfin.Server.Native; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Drawing; @@ -71,7 +70,6 @@ namespace Jellyfin.Server _loggerFactory, options, fileSystem, - new PowerManagement(), environmentInfo, new NullImageEncoder(), new SystemEvents(_loggerFactory.CreateLogger("SystemEvents")), @@ -274,7 +272,7 @@ namespace Jellyfin.Server } } - public static void Shutdown() + public static void Shutdown() { ApplicationTaskCompletionSource.SetResult(true); } diff --git a/MediaBrowser.Model/System/IPowerManagement.cs b/MediaBrowser.Model/System/IPowerManagement.cs deleted file mode 100644 index 03907568c..000000000 --- a/MediaBrowser.Model/System/IPowerManagement.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace MediaBrowser.Model.System -{ - public interface IPowerManagement - { - void PreventSystemStandby(); - void AllowSystemStandby(); - void ScheduleWake(DateTime wakeTimeUtc, string displayName); - } -}