Remove unused PowerManagement

It isn't up to the application to prevent the system from going to sleep
This commit is contained in:
Bond_009 2019-01-02 15:57:48 +01:00
parent b27315bc08
commit c07d5a6963
8 changed files with 26 additions and 136 deletions

View File

@ -369,7 +369,6 @@ namespace Emby.Server.Implementations
public StartupOptions StartupOptions { get; private set; } public StartupOptions StartupOptions { get; private set; }
internal IPowerManagement PowerManagement { get; private set; }
internal IImageEncoder ImageEncoder { get; private set; } internal IImageEncoder ImageEncoder { get; private set; }
protected IProcessFactory ProcessFactory { get; private set; } protected IProcessFactory ProcessFactory { get; private set; }
@ -391,7 +390,6 @@ namespace Emby.Server.Implementations
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
StartupOptions options, StartupOptions options,
IFileSystem fileSystem, IFileSystem fileSystem,
IPowerManagement powerManagement,
IEnvironmentInfo environmentInfo, IEnvironmentInfo environmentInfo,
IImageEncoder imageEncoder, IImageEncoder imageEncoder,
ISystemEvents systemEvents, ISystemEvents systemEvents,
@ -417,7 +415,6 @@ namespace Emby.Server.Implementations
Logger = LoggerFactory.CreateLogger("App"); Logger = LoggerFactory.CreateLogger("App");
StartupOptions = options; StartupOptions = options;
PowerManagement = powerManagement;
ImageEncoder = imageEncoder; ImageEncoder = imageEncoder;
@ -857,8 +854,6 @@ namespace Emby.Server.Implementations
SocketFactory = new SocketFactory(LoggerFactory.CreateLogger("SocketFactory")); SocketFactory = new SocketFactory(LoggerFactory.CreateLogger("SocketFactory"));
RegisterSingleInstance(SocketFactory); RegisterSingleInstance(SocketFactory);
RegisterSingleInstance(PowerManagement);
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LoggerFactory, FileSystemManager, CryptographyProvider); SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LoggerFactory, FileSystemManager, CryptographyProvider);
RegisterSingleInstance(SecurityManager); RegisterSingleInstance(SecurityManager);

View File

@ -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;
}
}
}
}

View File

@ -75,7 +75,23 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private readonly IStreamHelper _streamHelper; 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; Current = this;
@ -97,7 +113,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_streamHelper = streamHelper; _streamHelper = streamHelper;
_seriesTimerProvider = new SeriesTimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers")); _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; _timerProvider.TimerFired += _timerProvider_TimerFired;
_config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated; _config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated;

View File

@ -9,7 +9,6 @@ using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Threading; using MediaBrowser.Model.Threading;
using MediaBrowser.Model.System;
namespace Emby.Server.Implementations.LiveTv.EmbyTV namespace Emby.Server.Implementations.LiveTv.EmbyTV
{ {
@ -20,14 +19,12 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
public event EventHandler<GenericEventArgs<TimerInfo>> TimerFired; public event EventHandler<GenericEventArgs<TimerInfo>> TimerFired;
private readonly ITimerFactory _timerFactory; 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)) : base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase))
{ {
_logger = logger1; _logger = logger1;
_timerFactory = timerFactory; _timerFactory = timerFactory;
_powerManagement = powerManagement;
} }
public void RestartTimers() public void RestartTimers()
@ -36,7 +33,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
foreach (var item in GetAll().ToList()) 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) public override void Update(TimerInfo item)
{ {
base.Update(item); base.Update(item);
AddOrUpdateSystemTimer(item, false); AddOrUpdateSystemTimer(item);
} }
public void AddOrUpdate(TimerInfo item, bool resetTimer) public void AddOrUpdate(TimerInfo item, bool resetTimer)
@ -90,7 +87,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
} }
base.Add(item); base.Add(item);
AddOrUpdateSystemTimer(item, true); AddOrUpdateSystemTimer(item);
} }
private bool ShouldStartTimer(TimerInfo item) private bool ShouldStartTimer(TimerInfo item)
@ -104,7 +101,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
return true; return true;
} }
private void AddOrUpdateSystemTimer(TimerInfo item, bool scheduleSystemWakeTimer) private void AddOrUpdateSystemTimer(TimerInfo item)
{ {
StopTimer(item); StopTimer(item);
@ -124,23 +121,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var dueTime = startDate - now; var dueTime = startDate - now;
StartTimer(item, dueTime); 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) private void StartTimer(TimerInfo item, TimeSpan dueTime)

View File

@ -11,8 +11,8 @@ namespace Jellyfin.Server
{ {
public class CoreAppHost : ApplicationHost 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) 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, powerManagement, environmentInfo, imageEncoder, systemEvents, networkManager) : base(applicationPaths, loggerFactory, options, fileSystem, environmentInfo, imageEncoder, systemEvents, networkManager)
{ {
} }

View File

@ -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)
{
}
}
}

View File

@ -13,7 +13,6 @@ using Emby.Server.Implementations;
using Emby.Server.Implementations.EnvironmentInfo; using Emby.Server.Implementations.EnvironmentInfo;
using Emby.Server.Implementations.IO; using Emby.Server.Implementations.IO;
using Emby.Server.Implementations.Networking; using Emby.Server.Implementations.Networking;
using Jellyfin.Server.Native;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
@ -71,7 +70,6 @@ namespace Jellyfin.Server
_loggerFactory, _loggerFactory,
options, options,
fileSystem, fileSystem,
new PowerManagement(),
environmentInfo, environmentInfo,
new NullImageEncoder(), new NullImageEncoder(),
new SystemEvents(_loggerFactory.CreateLogger("SystemEvents")), new SystemEvents(_loggerFactory.CreateLogger("SystemEvents")),

View File

@ -1,11 +0,0 @@
using System;
namespace MediaBrowser.Model.System
{
public interface IPowerManagement
{
void PreventSystemStandby();
void AllowSystemStandby();
void ScheduleWake(DateTime wakeTimeUtc, string displayName);
}
}