From: <mic...@us...> - 2011-10-21 18:58:17
|
Revision: 4313 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4313&view=rev Author: michael-t Date: 2011-10-21 18:58:08 +0000 (Fri, 21 Oct 2011) Log Message: ----------- New experimental alpha version 1.2.5.1 for MP 1.2.1 FINAL Modified Paths: -------------- trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IEpgHandler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerScheduler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerSettings.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IStandbyHandler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerManager.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerScheduler.Interfaces.csproj trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerSettings.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/MPEI/PowerScheduler++.xmp2 trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/RemoteClientStandbyHandler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/XmlTvImportWakeupHandler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerScheduler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerScheduler.csproj trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerSchedulerFactory.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerSchedulerMasterSetup.Designer.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerSchedulerMasterSetup.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerSchedulerMasterSetup.resx trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Properties/AssemblyInfo.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/SelectShareForm.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/VersionInfo.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/Handlers/WakeableStandbyHandler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/Handlers/WakeableWakeupHandler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/PowerScheduler.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/PowerSchedulerClientPlugin.csproj trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/PowerSchedulerClientSetup.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/PowerSchedulerClientSetup.designer.cs trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/PowerSchedulerClientSetup.resx trunk/plugins/PowerScheduler++/Test/1.2.5.1/mediaportal/PowerSchedulerClientPlugin/Properties/AssemblyInfo.cs Added Paths: ----------- trunk/plugins/PowerScheduler++/Test/1.2.5.1/ Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IEpgHandler.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IEpgHandler.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IEpgHandler.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -29,8 +29,7 @@ public delegate void EPGScheduleHandler(); /// <summary> - /// Provides access to PowerScheduler's EPG interface for - /// EPG plugins. + /// Provides access to PowerScheduler's EPG interface for EPG plugins. /// </summary> public interface IEpgHandler { Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerScheduler.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerScheduler.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerScheduler.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -27,7 +27,7 @@ namespace TvEngine.PowerScheduler.Interfaces { /// <summary> - /// EvenHandler delegate for PowerScheduler events + /// EventHandler delegate for PowerScheduler events /// </summary> /// <param name="args"></param> public delegate void PowerSchedulerEventHandler(PowerSchedulerEventArgs args); @@ -114,7 +114,6 @@ void GetCurrentState(bool refresh, out bool unattended, out bool disAllowShutdown, out String disAllowShutdownHandler, out DateTime nextWakeupTime, out String nextWakeupHandler); - /// <summary> /// Checks if a suspend request is in progress /// </summary> Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerSettings.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerSettings.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IPowerSettings.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -25,6 +25,27 @@ namespace TvEngine.PowerScheduler.Interfaces { /// <summary> + /// PowerScheduler shutdown mode enumeration + /// </summary> + public enum ShutdownMode + { + Sleep, + Hibernate, + StayOn, + ShutDown + } + + /// <summary> + /// PowerScheduler++ standby mode enumeration + /// </summary> + public enum StandbyMode + { + StandbyAllowed, + StandbyPrevented, + AwayModeRequested + } + + /// <summary> /// Provides access to PowerScheduler's settings /// </summary> public interface IPowerSettings @@ -73,9 +94,9 @@ int CheckInterval { get; } /// <summary> - /// How should put the system into standby? suspend/hibernate/stayon - /// suspend uses S3, hibernate uses S4, stayon is for debugging purposes and - /// doesn't put the system into standby at all + /// <summary> + /// How should put the system into standby? suspend/hibernate/stayon/shutdown + /// suspend uses S3, hibernate uses S4, stayon doesn't do anyting, shutdown uses S5 (soft power off) /// </summary> ShutdownMode ShutdownMode { get; } } Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IStandbyHandler.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IStandbyHandler.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/Interfaces/IStandbyHandler.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -24,6 +24,9 @@ namespace TvEngine.PowerScheduler.Interfaces { + /// <summary> + /// StandbyHandler interface for PowerScheduler + /// </summary> public interface IStandbyHandler { /// <summary> @@ -43,14 +46,13 @@ } /// <summary> - /// Extension to the IStandbyHandler interface for away mode + /// Extension to the IStandbyHandler interface for PowerScheduler++ /// </summary> public interface IStandbyHandlerEx : IStandbyHandler { /// <summary> - /// Indicator whether away mode is required by standby handler or not + /// Indicator which standby mode is requested by the handler /// </summary> - bool RequireAwayMode { get; } + StandbyMode StandbyMode { get; } } - } \ No newline at end of file Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerManager.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerManager.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerManager.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -21,64 +21,21 @@ #region Usings using System; +using System.Net; using System.Runtime.InteropServices; -using System.Threading; #endregion namespace TvEngine.PowerScheduler.Interfaces { /// <summary> - /// Provides methods for handling system power events + /// Provides static methods for managing system power states, events and settings /// </summary> - public class PowerManager + public static class PowerManager { - #region Variables + #region System power constants and enumerations /// <summary> - /// Enable / disable away mode - /// </summary> - private bool _awayMode; - - /// <summary> - /// Thread for calling SetThreadExecutionState() - /// </summary> - private Thread _awayModeThread; - - #endregion - - #region Constructor/Destructor - - /// <summary> - /// Constructor starts the thread for away mode and inits PowerSettings array - /// </summary> - unsafe public PowerManager() - { - if (Environment.OSVersion.Version.Major >= 6) - { - // Start the thread to enable/disable away mode - _awayModeThread = new Thread(AwayModeThread); - _awayModeThread.Name = "ExecutionStateThread"; - _awayModeThread.IsBackground = true; - _awayModeThread.Start(); - } - } - - ~PowerManager() - { - if (_awayModeThread != null) - { - _awayModeThread.Abort(); - _awayModeThread.Join(100); - _awayModeThread = null; - } - } - - #endregion - - #region External power management methods and enumerations - - /// <summary> /// The thread's execution requirements /// </summary> [Flags] @@ -117,128 +74,306 @@ } /// <summary> - /// Enables an application to inform the system that it is in use, thereby preventing the system - /// from entering sleep or turning off the display while the application is running. + /// Flags to register for power setting change notification /// </summary> - /// <param name="esFlags">The thread's execution requirements - /// /// </param> - /// <returns> - /// If the function succeeds, the return value is the previous thread execution state. - /// If the function fails, the return value is NULL. - /// </returns> - [DllImport("kernel32.dll", SetLastError = true, EntryPoint = "SetThreadExecutionState")] - private static extern ExecutionState SetThreadExecutionState(ExecutionState esFlags); + private const int DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000; + private const int DEVICE_NOTIFY_SERVICE_HANDLE = 0x00000001; - #endregion + /// <summary> + /// Constants for power notifications + /// </summary> + public const int WM_POWERBROADCAST = 0x0218; + public const int PBT_APMQUERYSUSPEND = 0x0000; + public const int PBT_APMQUERYSUSPENDFAILED = 0x0002; + public const int PBT_APMSUSPEND = 0x0004; + public const int PBT_APMRESUMECRITICAL = 0x0006; + public const int PBT_APMRESUMESUSPEND = 0x0007; + public const int PBT_APMRESUMEAUTOMATIC = 0x0012; + public const int PBT_POWERSETTINGCHANGE = 0x8013; + public const int BROADCAST_QUERY_DENY = 0x424D5144; - #region Power management wrapper methods + /// <summary> + /// This structure is sent when the PBT_POWERSETTINGSCHANGE message is sent. + /// It describes the power setting that has changed and contains data about the change + /// </summary> + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct POWERBROADCAST_SETTING + { + public Guid PowerSetting; + public uint DataLength; + public byte Data; + } /// <summary> - /// Set the PowerManager to allow standby + /// Handle to unregister for power setting change notification /// </summary> - /// <returns>bool indicating whether or not standby is allowed</returns> - public bool AllowStandby() + private static IntPtr _hAwayMode = (IntPtr)null; + + /// <summary> + /// Guid to register for power setting change notification + /// </summary> + public static Guid GUID_SYSTEM_AWAYMODE = new Guid("98a7f580-01f7-48aa-9c0f-44352c29e5C0"); + + /// <summary> + /// System power setting guids + /// </summary> + private static Guid NO_SUBGROUP_GUID = new Guid("fea3413e-7e05-4911-9a71-700331f1c294"); + private static Guid GUID_LOCK_CONSOLE_ON_WAKE = new Guid("0e796bdb-100d-47d6-a2d5-f7d2daa51f51"); + private static Guid GUID_SUB_SLEEP = new Guid("238c9fa8-0aad-41ed-83f4-97be242c8f20"); + private static Guid GUID_ALLOW_AWAY_MODE = new Guid("25dfa149-5dd1-4736-b5ab-e8a37b5b8187"); + private static Guid GUID_SLEEP_AFTER = new Guid("29f6c1db-86da-48c5-9fdb-f2b67b1f44da"); + private static Guid GUID_ALLOW_HYBRID_SLEEP = new Guid("94ac6d29-73ce-41a6-809f-6363ba21b47e"); + private static Guid GUID_HIBERNATE_AFTER = new Guid("9d7815a6-7ee4-497e-8888-515a05f02364"); + private static Guid GUID_ALLOW_RTC_WAKE = new Guid("bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d"); + private static Guid GUID_SUB_POWER_BUTTONS_AND_LID = new Guid("4f971e89-eebd-4455-a8de-9e59040e7347"); + private static Guid GUID_LID_CLOSE_ACTION = new Guid("5ca83367-6e45-459f-a27b-476b1d01c936"); + private static Guid GUID_POWER_BUTTON_ACTION = new Guid("7648efa3-dd9c-4e3e-b566-50f929386280"); + private static Guid GUID_SLEEP_BUTTON_ACTION = new Guid("96996bc0-ad50-47ec-923b-6f41874dd9eb"); + private static Guid GUID_SUB_MULTIMEDIA = new Guid("9596fb26-9850-41fd-ac3e-f7c3c00afd4b"); + private static Guid GUID_WHEN_SHARING_MEDIA = new Guid("03680956-93bc-4294-bba6-4e0f09bb717f"); + + /// <summary> + /// System power setting structure + /// </summary> + private struct SystemPowerSetting { - return true; + public Guid settingGuid; + public Guid subgroupGuid; } /// <summary> - /// Set the PowerManager to prevent standby + /// Array of system power settings (index is SystemPowerSettingsType) /// </summary> + static SystemPowerSetting[] SystemPowerSettings = new SystemPowerSetting[] + { + new SystemPowerSetting // LOCK_CONSOLE_ON_WAKE + { + settingGuid = GUID_LOCK_CONSOLE_ON_WAKE, + subgroupGuid = NO_SUBGROUP_GUID, + }, + new SystemPowerSetting // ALLOW_AWAY_MODE + { + settingGuid = GUID_ALLOW_AWAY_MODE, + subgroupGuid = GUID_SUB_SLEEP, + }, + new SystemPowerSetting // SLEEP_AFTER + { + settingGuid = GUID_SLEEP_AFTER, + subgroupGuid = GUID_SUB_SLEEP, + }, + new SystemPowerSetting // ALLOW_HYBRID_SLEEP + { + settingGuid = GUID_ALLOW_HYBRID_SLEEP, + subgroupGuid = GUID_SUB_SLEEP, + }, + new SystemPowerSetting // HIBERNATE_AFTER + { + settingGuid = GUID_HIBERNATE_AFTER, + subgroupGuid = GUID_SUB_SLEEP, + }, + new SystemPowerSetting // ALLOW_RTC_WAKE + { + settingGuid = GUID_ALLOW_RTC_WAKE, + subgroupGuid = GUID_SUB_SLEEP, + }, + new SystemPowerSetting // LID_CLOSE_ACTION + { + settingGuid = GUID_LID_CLOSE_ACTION, + subgroupGuid = GUID_SUB_POWER_BUTTONS_AND_LID, + }, + new SystemPowerSetting // POWER_BUTTON_ACTION + { + settingGuid = GUID_POWER_BUTTON_ACTION, + subgroupGuid = GUID_SUB_POWER_BUTTONS_AND_LID, + }, + new SystemPowerSetting // SLEEP_BUTTON_ACTION + { + settingGuid = GUID_SLEEP_BUTTON_ACTION, + subgroupGuid = GUID_SUB_POWER_BUTTONS_AND_LID, + }, + new SystemPowerSetting // WHEN_SHARING_MEDIA + { + settingGuid = GUID_WHEN_SHARING_MEDIA, + subgroupGuid = GUID_SUB_MULTIMEDIA, + }, + }; + + /// <summary> + /// Power setting type (index to PowerSettings) + /// </summary> + public enum SystemPowerSettingType + { + LOCK_CONSOLE_ON_WAKE, + ALLOW_AWAY_MODE, + STANDBYIDLE, + ALLOW_HYBRID_SLEEP, + HIBERNATE_AFTER, + ALLOW_RTC_WAKE, + LID_CLOSE_ACTION, + POWER_BUTTON_ACTION, + SLEEP_BUTTON_ACTION, + WHEN_SHARING_MEDIA + } + + #endregion + + #region Public power management methods + + /// <summary> + /// Reset the system idle timeout to prevent standby + /// </summary> /// <returns>bool indicating whether or not standby is prevented</returns> - public bool PreventStandby() + public static void ResetIdleTimer() { - lock (this) - { - ExecutionState result = SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED); - //Log.Debug("PowerManager.PreventStandBy: SetThreadExecutionState() returned: {0}", result.ToString()); - if (result == ExecutionState.Error) - { - return false; - } - return true; - } + // ES_SYSTEM_REQUIRED without ES_CONTINUOS resets the idle timeout + SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED); } /// <summary> - /// Sets AwayModeRequired execution state; triggers AwayModeThread to do the real work + /// Sets thread execution state to allow / prevent standby (always must be called by one and the same thread) /// </summary> /// <param name="awayModeRequired">Enable/disable away mode</param> - public void SetAwayModeRequired(bool awayModeRequired) + public static void SetStandbyMode(StandbyMode standbyMode) { - if (Environment.OSVersion.Version.Major >= 6) + switch (standbyMode) { - Monitor.Enter(_awayModeThread); - _awayMode = awayModeRequired; - Monitor.Pulse(_awayModeThread); - Monitor.Exit(_awayModeThread); + case StandbyMode.StandbyAllowed: + SetThreadExecutionState(ExecutionState.ES_CONTINUOUS); + break; + case StandbyMode.StandbyPrevented: + SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED | ExecutionState.ES_CONTINUOUS); + break; + case StandbyMode.AwayModeRequested: + if (Environment.OSVersion.Version.Major >= 6) + SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED | ExecutionState.ES_AWAYMODE_REQUIRED | ExecutionState.ES_CONTINUOUS); + else + SetThreadExecutionState(ExecutionState.ES_SYSTEM_REQUIRED | ExecutionState.ES_CONTINUOUS); + break; } } /// <summary> - /// Gets triggered by SetAwayMode and sets the execution state to the desired value - /// /// </summary> - private void AwayModeThread() + /// Register for away mode notifications + /// </summary> + /// <param name="hRecipient">Window handle (e.g. GUIGraphicsContext.ActiveForm)</param> + public static void RegisterAwayModeNotification(IntPtr hRecipient) { - while (true) - { - Monitor.Enter(_awayModeThread); - Monitor.Wait(_awayModeThread); - if (_awayMode) - SetThreadExecutionState(ExecutionState.ES_AWAYMODE_REQUIRED | ExecutionState.ES_CONTINUOUS); - else - SetThreadExecutionState(ExecutionState.ES_CONTINUOUS); - Monitor.Exit(_awayModeThread); - } + if (Environment.OSVersion.Version.Major >= 6 && _hAwayMode == (IntPtr)null) + _hAwayMode = RegisterPowerSettingNotification(hRecipient, ref GUID_SYSTEM_AWAYMODE, DEVICE_NOTIFY_WINDOW_HANDLE); } - #endregion + /// <summary> + /// Unregister for away mode notifications + /// </summary> + public static void UnregisterAwayModeNotification() + { + if (Environment.OSVersion.Version.Major >= 6 && _hAwayMode != (IntPtr)null) + UnregisterPowerSettingNotification(_hAwayMode); + _hAwayMode = (IntPtr)null; + } - #region External power setting change notification methods and enumerations - /// <summary> - /// Flags to register for power setting change notification + /// Retrieves guid of active power scheme /// </summary> - private const int DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000; - private const int DEVICE_NOTIFY_SERVICE_HANDLE = 0x00000001; + /// <returns>Active power scheme guid</returns> + public static Guid GetActivePowerScheme() + { + try + { + IntPtr ptr = IntPtr.Zero; + PowerGetActiveScheme(IntPtr.Zero, ref ptr); + Guid activePowerScheme = (Guid)Marshal.PtrToStructure(ptr, typeof(Guid)); + return activePowerScheme; + } + catch (Exception) { } + return Guid.Empty; + } + /// <summary> - /// Handle to unregister for power setting change notification + /// Get system power setting /// </summary> - private IntPtr hAwayMode; + /// <param name="scheme"></param> + /// <param name="settingType"></param> + /// <returns>System power setting AC value</returns> + public static UInt32 GetSystemPowerSetting(Guid scheme, SystemPowerSettingType settingType) + { + UInt32 systemPowerSetting = 0; + try + { + SystemPowerSetting ps = SystemPowerSettings[(int)settingType]; + systemPowerSetting = ReadACPowerValueIndex(scheme, ps.subgroupGuid, ps.settingGuid); + } + catch (Exception) { } + + return systemPowerSetting; + } + /// <summary> - /// Constants for power notifications + /// Set system power setting AC and DC value /// </summary> - public const int WM_POWERBROADCAST = 0x0218; - public const int PBT_APMQUERYSUSPEND = 0x0000; - public const int PBT_APMQUERYSUSPENDFAILED = 0x0002; - public const int PBT_APMSUSPEND = 0x0004; - public const int PBT_APMRESUMECRITICAL = 0x0006; - public const int PBT_APMRESUMESUSPEND = 0x0007; - public const int PBT_APMRESUMEAUTOMATIC = 0x0012; - public const int PBT_POWERSETTINGCHANGE = 0x8013; - public const int BROADCAST_QUERY_DENY = 0x424D5144; + /// <param name="scheme"></param> + /// <param name="settingType"></param> + /// <param name="value"></param> + public static void SetSystemPowerSetting(Guid scheme, SystemPowerSettingType settingType, UInt32 value) + { + UInt32 systemPowerSetting; + try + { + SystemPowerSetting ps = SystemPowerSettings[(int)settingType]; + systemPowerSetting = ReadACPowerValueIndex(scheme, ps.subgroupGuid, ps.settingGuid); + if (systemPowerSetting != value) + WriteACPowerValueIndex(scheme, ps.subgroupGuid, ps.settingGuid, value); + systemPowerSetting = ReadDCPowerValueIndex(scheme, ps.subgroupGuid, ps.settingGuid); + if (systemPowerSetting != value) + WriteDCPowerValueIndex(scheme, ps.subgroupGuid, ps.settingGuid, value); + } + catch (Exception) { } + + } + /// <summary> - /// This structure is sent when the PBT_POWERSETTINGSCHANGE message is sent. - /// It describes the power setting that has changed and contains data about the change + /// Checks if the given hostname/IP address is the local host /// </summary> - [StructLayout(LayoutKind.Sequential, Pack = 4)] - public struct POWERBROADCAST_SETTING + /// <param name="serverName">hostname/IP address to check</param> + /// <returns>is this name/address local?</returns> + public static bool IsLocal(string serverName) { - public Guid PowerSetting; - public uint DataLength; - public byte Data; - } + foreach (string name in new string[] { "localhost", "127.0.0.1", Dns.GetHostName() }) + { + if (serverName.Equals(name, StringComparison.CurrentCultureIgnoreCase)) + return true; + } + IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); + foreach (IPAddress address in hostEntry.AddressList) + { + if (address.ToString().Equals(serverName, StringComparison.CurrentCultureIgnoreCase)) + return true; + } + return false; + } + #endregion + + #region System power management functions imports + /// <summary> - /// Guid to register for power setting change notification + /// Enables an application to inform the system that it is in use, thereby preventing the system + /// from entering sleep or turning off the display while the application is running. /// </summary> - public static Guid GUID_SYSTEM_AWAYMODE = new Guid("98a7f580-01f7-48aa-9c0f-44352c29e5C0"); + /// <param name="esFlags">The thread's execution requirements + /// /// </param> + /// <returns> + /// If the function succeeds, the return value is the previous thread execution state. + /// If the function fails, the return value is NULL. + /// </returns> + [DllImport("kernel32.dll", SetLastError = true, EntryPoint = "SetThreadExecutionState")] + private static extern ExecutionState SetThreadExecutionState(ExecutionState esFlags); /// <summary> - /// + /// Registers the application to receive power setting notifications for the specific power setting event /// </summary> /// <param name="hRecipient"></param> /// <param name="PowerSettingGuid"></param> @@ -248,36 +383,149 @@ private static extern IntPtr RegisterPowerSettingNotification(IntPtr hRecipient, ref Guid PowerSettingGuid, Int32 Flags); /// <summary> - /// + /// Unregisters the power setting notification /// </summary> /// <param name="handle"></param> /// <returns></returns> [DllImport(@"User32", SetLastError = true, EntryPoint = "UnregisterPowerSettingNotification", CallingConvention = CallingConvention.StdCall)] private static extern bool UnregisterPowerSettingNotification(IntPtr handle); + /// <summary> + /// Retrieves the active power scheme and returns a GUID that identifies the scheme. + /// </summary> + /// <param name="userRootPowerKey"></param> + /// <param name="activePolicyGuid"></param> + /// <returns></returns> + [DllImport("powrprof.dll", SetLastError = true)] + private static extern UInt32 PowerGetActiveScheme(IntPtr RootPowerKey, ref IntPtr activePolicyGuid); + + /// <summary> + /// Retrieves the AC index of the specified power setting. + /// </summary> + /// <param name="rootPowerKey"></param> + /// <param name="schemeGuid"></param> + /// <param name="subgroupOfPowerSettingsGuid"></param> + /// <param name="powerSettingGuid"></param> + /// <param name="valueIndex"></param> + /// <returns></returns> + [DllImport("powrprof.dll", SetLastError = true)] + private static extern UInt32 PowerReadACValueIndex(IntPtr RootPowerKey, ref Guid SchemeGuid, + ref Guid SubGroupOfPowerSettingsGuid, ref Guid PowerSettingGuid, ref UInt32 AcValueIndex); + + /// <summary> + /// Writes the AC index of the specified power setting. + /// </summary> + /// <param name="rootPowerKey"></param> + /// <param name="schemeGuid"></param> + /// <param name="subgroupOfPowerSettingsGuid"></param> + /// <param name="powerSettingGuid"></param> + /// <param name="valueIndex"></param> + /// <returns></returns> + [DllImport("powrprof.dll", SetLastError = true)] + private static extern UInt32 PowerWriteACValueIndex(IntPtr RootPowerKey, ref Guid SchemeGuid, + ref Guid SubGroupOfPowerSettingsGuid, ref Guid PowerSettingGuid, UInt32 AcValueIndex); + + /// <summary> + /// Retrieves the DC index of the specified power setting. + /// </summary> + /// <param name="rootPowerKey"></param> + /// <param name="schemeGuid"></param> + /// <param name="subgroupOfPowerSettingsGuid"></param> + /// <param name="powerSettingGuid"></param> + /// <param name="valueIndex"></param> + /// <returns></returns> + [DllImport("powrprof.dll", SetLastError = true)] + private static extern UInt32 PowerReadDCValueIndex(IntPtr RootPowerKey, ref Guid SchemeGuid, + ref Guid SubGroupOfPowerSettingsGuid, ref Guid PowerSettingGuid, ref UInt32 DcValueIndex); + + /// <summary> + /// Writes the DC index of the specified power setting. + /// </summary> + /// <param name="rootPowerKey"></param> + /// <param name="schemeGuid"></param> + /// <param name="subgroupOfPowerSettingsGuid"></param> + /// <param name="powerSettingGuid"></param> + /// <param name="valueIndex"></param> + /// <returns></returns> + [DllImport("powrprof.dll", SetLastError = true)] + private static extern UInt32 PowerWriteDCValueIndex(IntPtr RootPowerKey, ref Guid SchemeGuid, + ref Guid SubGroupOfPowerSettingsGuid, ref Guid PowerSettingGuid, UInt32 DcValueIndex); + #endregion - #region Power setting change notification wrapper methods + #region Private power management wrapper methods /// <summary> - /// Register for away mode notifications + /// Wrapper for PowerReadACValueIndex /// </summary> - /// <param name="hRecipient">Window handle (e.g. GUIGraphicsContext.ActiveForm)</param> - public void RegisterAwayModeNotification(IntPtr hRecipient) + /// <param name="schemeGuid"></param> + /// <param name="subgroupGuid"></param> + /// <param name="settingGuid"></param> + /// <returns></returns> + private static UInt32 ReadACPowerValueIndex(Guid schemeGuid, Guid subgroupGuid, Guid settingGuid) { - if (Environment.OSVersion.Version.Major >= 6) - hAwayMode = RegisterPowerSettingNotification(hRecipient, ref GUID_SYSTEM_AWAYMODE, DEVICE_NOTIFY_WINDOW_HANDLE); + UInt32 value = 0; + try + { + PowerReadACValueIndex(IntPtr.Zero, ref schemeGuid, ref subgroupGuid, ref settingGuid, ref value); + } + catch (Exception) { } + + return value; } /// <summary> - /// Unregister for away mode notifications + /// Wrapper for PowerWriteACValueIndex /// </summary> - public void UnregisterAwayModeNotification() + /// <param name="schemeGuid"></param> + /// <param name="subgroupGuid"></param> + /// <param name="settingGuid"></param> + /// <param name="value"></param> + private static void WriteACPowerValueIndex(Guid schemeGuid, Guid subgroupGuid, Guid settingGuid, UInt32 value) { - if (Environment.OSVersion.Version.Major >= 6) - UnregisterPowerSettingNotification(hAwayMode); + try + { + PowerWriteACValueIndex(IntPtr.Zero, ref schemeGuid, ref subgroupGuid, ref settingGuid, value); + } + catch (Exception) { } } + /// <summary> + /// Wrapper for PowerReadDCValueIndex + /// </summary> + /// <param name="schemeGuid"></param> + /// <param name="subgroupGuid"></param> + /// <param name="settingGuid"></param> + /// <returns></returns> + private static UInt32 ReadDCPowerValueIndex(Guid schemeGuid, Guid subgroupGuid, Guid settingGuid) + { + UInt32 value = 0; + try + { + PowerReadDCValueIndex(IntPtr.Zero, ref schemeGuid, ref subgroupGuid, ref settingGuid, ref value); + } + catch (Exception) { } + + return value; + } + + /// <summary> + /// Wrapper for PowerWriteDCValueIndex + /// </summary> + /// <param name="schemeGuid"></param> + /// <param name="subgroupGuid"></param> + /// <param name="settingGuid"></param> + /// <param name="value"></param> + private static void WriteDCPowerValueIndex(Guid schemeGuid, Guid subgroupGuid, Guid settingGuid, UInt32 value) + { + try + { + PowerWriteDCValueIndex(IntPtr.Zero, ref schemeGuid, ref subgroupGuid, ref settingGuid, value); + } + catch (Exception) { } + } + #endregion + } } \ No newline at end of file Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerScheduler.Interfaces.csproj =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerScheduler.Interfaces.csproj 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerScheduler.Interfaces.csproj 2011-10-21 18:58:08 UTC (rev 4313) @@ -92,5 +92,8 @@ </Reference> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> + <Reference Include="TvLibrary.Interfaces"> + <HintPath>..\..\Binaries\TvLibrary.Interfaces.dll</HintPath> + </Reference> </ItemGroup> </Project> \ No newline at end of file Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerSettings.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerSettings.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/Common-MP-TVE3/PowerScheduler.Interfaces/PowerSettings.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -27,19 +27,6 @@ namespace TvEngine.PowerScheduler.Interfaces { - - #region Enums - - public enum ShutdownMode - { - Sleep = 0, - Hibernate = 1, - ShutDown = 2, - StayOn = 3 - } - - #endregion - /// <summary> /// Holds all PowerScheduler related settings /// </summary> @@ -291,9 +278,8 @@ } /// <summary> - /// How should put the system into standby? suspend/hibernate/stayon - /// suspend uses S3, hibernate uses S4, stayon is for debugging purposes and - /// doesn't put the system into standby at all + /// How should put the system into standby? suspend/hibernate/stayon/shutdown + /// suspend uses S3, hibernate uses S4, stayon doesn't do anyting, shutdown uses S5 (soft power off) /// </summary> public ShutdownMode ShutdownMode { @@ -309,7 +295,7 @@ _shutdownMode = value; break; default: - throw new ArgumentException("unknown ShutdownMode", value.ToString()); + throw new ArgumentException("Unknown ShutdownMode", value.ToString()); } } } Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/MPEI/PowerScheduler++.xmp2 =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/MPEI/PowerScheduler++.xmp2 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/MPEI/PowerScheduler++.xmp2 2011-10-21 18:58:08 UTC (rev 4313) @@ -13,14 +13,14 @@ <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> <Param1 /> <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\TvEngine3\TVLibrary\Plugins\PowerScheduler\bin\Release\PowerScheduler.dll</LocalFileName> + <LocalFileName>..\TvEngine3\TVLibrary\Plugins\PowerScheduler\bin\Debug\PowerScheduler.dll</LocalFileName> <ZipFileName>Installer{CopyFile}\{41ffe535-6bef-44af-8fda-549e2443aabc}-PowerScheduler.dll</ZipFileName> <DestinationFilename>%TvServerPlugins%\PowerScheduler.dll</DestinationFilename> </FileItem> <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> <Param1 /> <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\Common-MP-TVE3\PowerScheduler.Interfaces\bin\Release\PowerScheduler.Interfaces.dll</LocalFileName> + <LocalFileName>..\Common-MP-TVE3\PowerScheduler.Interfaces\bin\Debug\PowerScheduler.Interfaces.dll</LocalFileName> <ZipFileName>Installer{CopyFile}\{fcb1df38-d861-4125-b4a0-8f062cb08d24}-PowerScheduler.Interfaces.dll</ZipFileName> <DestinationFilename>%TvServerBase%\PowerScheduler.Interfaces.dll</DestinationFilename> </FileItem> @@ -37,14 +37,14 @@ <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> <Param1 /> <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\mediaportal\PowerSchedulerClientPlugin\bin\Release\PowerSchedulerClientPlugin.dll</LocalFileName> + <LocalFileName>..\mediaportal\PowerSchedulerClientPlugin\bin\Debug\PowerSchedulerClientPlugin.dll</LocalFileName> <ZipFileName>Installer{CopyFile}\{ed9d9027-eca3-460f-b94e-d17ff4ab38ba}-PowerSchedulerClientPlugin.dll</ZipFileName> <DestinationFilename>%Plugins%\process\PowerSchedulerClientPlugin.dll</DestinationFilename> </FileItem> <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> <Param1 /> <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\mediaportal\PowerSchedulerClientPlugin\bin\Release\PowerScheduler.Interfaces.dll</LocalFileName> + <LocalFileName>..\Common-MP-TVE3\PowerScheduler.Interfaces\bin\Debug\PowerScheduler.Interfaces.dll</LocalFileName> <ZipFileName>Installer{CopyFile}\{ac7155e9-4a57-4108-8731-81f3fd669737}-PowerScheduler.Interfaces.dll</ZipFileName> <DestinationFilename>%Base%\PowerScheduler.Interfaces.dll</DestinationFilename> </FileItem> @@ -59,12 +59,12 @@ <Params> <Items> <SectionParam Name="Header text"> - <Value>[Name] [Version] ([DevelopmentStatus])</Value> + <Value>[Name] [Version] ([DevelopmentStatus] / experimental)</Value> <ValueType>String</ValueType> <Description /> </SectionParam> <SectionParam Name="Description"> - <Value>This will install the [Name] [Version] plugin on your computer. This plugin is designed for MediaPortal 1.2.0 Beta and will not work with other MediaPortal releases. + <Value>This will install the [Name] [Version] plugin on your computer. This plugin is designed for MediaPortal 1.2.1 FINAL and will not work with other MediaPortal releases. It is recommended that you close all other applications before continuing. @@ -424,34 +424,78 @@ </MinVersion> <MaxVersion> <Major>1</Major> - <Minor>1</Minor> - <Build>7</Build> + <Minor>2</Minor> + <Build>1</Build> <Revision>0</Revision> </MaxVersion> <WarnOnly>true</WarnOnly> - <Message>For MediaPortal release 1.2.0 beta (not compatible with 1.1.x stable releases and 1.2.0 alpha)</Message> + <Message>For MediaPortal release 1.2.1 FINAL (not compatible with 1.1.x releases)</Message> <Name>MediaPortal</Name> </DependencyItem> + <DependencyItem> + <Type>MediaPortal</Type> + <Id /> + <MinVersion> + <Major>1</Major> + <Minor>1</Minor> + <Build>6</Build> + <Revision>27644</Revision> + </MinVersion> + <MaxVersion> + <Major>1</Major> + <Minor>1</Minor> + <Build>6</Build> + <Revision>27644</Revision> + </MaxVersion> + <WarnOnly>false</WarnOnly> + <Message>For MediaPortal release 1.2.1 FINAL (not compatible with 1.1.x releases)</Message> + <Name>MediaPortal</Name> + </DependencyItem> </Items> </Dependencies> + <PluginDependencies> + <Items> + <PluginDependencyItem AssemblyName="PowerSchedulerClientPlugin.dll"> + <CompatibleVersion> + <Items> + <CompatibleVersionItem> + <MinRequiredVersion>1.1.6.27644</MinRequiredVersion> + <DesignedForVersion>1.2.1.0</DesignedForVersion> + </CompatibleVersionItem> + </Items> + </CompatibleVersion> + <SubSystemsUsed> + <Items> + <SubSystemItem Name="MP" /> + </Items> + </SubSystemsUsed> + </PluginDependencyItem> + </Items> + </PluginDependencies> <GeneralInfo> <Name>PowerScheduler++</Name> <Id>9b9bc24e-69ca-4abc-8810-f8f95bd4bbe6</Id> <Author>michael_t (based on PowerScheduler by micheloe)</Author> <HomePage>http://www.team-mediaportal.com/extensions/other/powerscheduler</HomePage> - <ForumPage>http://forum.team-mediaportal.com/tv-server-plugins-294/new-plugin-powerscheduler-new-version-1-1-1-5-a-87446/</ForumPage> - <UpdateUrl /> + <ForumPage>http://forum.team-mediaportal.com/tv-server-plugins-294/powerscheduler-test-version-1-2-5-0-mediaportal-1-2-x-1-3-alpha-87446/</ForumPage> + <UpdateUrl>http://forum.team-mediaportal.com/attachments/tv-server-plugins-294/90673d1318776972-powerscheduler-test-version-1-2-5-x-mediaportal-1-2-x-1-3-alpha-update.xml</UpdateUrl> <Version> <Major>1</Major> - <Minor>1</Minor> - <Build>7</Build> + <Minor>2</Minor> + <Build>5</Build> <Revision>1</Revision> </Version> <ExtensionDescription>The PowerScheduler++ plugin is a replacement for the PowerScheduler plugin that comes as part of MediaPortal. Compared to the original PowerScheduler it provides additional features (easy configuration, shares monitoring, reboot option, ...) and is supporting "away mode" for Vista and Win 7 systems.</ExtensionDescription> - <VersionDescription>Version [Version] - [DevelopmentStatus] version for MP 1.2.0 Beta</VersionDescription> - <DevelopmentStatus>Beta</DevelopmentStatus> - <OnlineLocation>http://forum.team-mediaportal.com/attachments/tv-server-plugins-294/80178d1303458252-powerscheduler-test-versions-1-1-6-0-mediaportal-1-2-0-pre-beta-svn-27810-powerscheduler-1.1.7.1.mpe1</OnlineLocation> - <ReleaseDate>2011-04-24T16:03:54</ReleaseDate> + <VersionDescription>Version 1.2.5.1 - Alpha / experimental version for MP 1.2.1 FINAL + +Version 1.2.5.1: +- Load and save "Set PowerSettings automatically" option +- Do not offer "Standby after" option for Windows XP +Version 1.2.5.0 - Initial version +</VersionDescription> + <DevelopmentStatus>Alpha</DevelopmentStatus> + <OnlineLocation>http://forum.team-mediaportal.com/attachments/tv-server-plugins-294/90672d1318776960-powerscheduler-test-version-1-2-5-x-mediaportal-1-2-x-1-3-alpha-powerscheduler-1.2.5.1.mpe1</OnlineLocation> + <ReleaseDate>2011-10-16T16:03:54</ReleaseDate> <Tags>tv server plugins, automation</Tags> <Location>..\MPEI\[Name] [Version].mpe1</Location> <Params> @@ -467,21 +511,14 @@ <Description>The icon file of the package stored online (jpg,png,bmp)</Description> </SectionParam> <SectionParam Name="Configuration file"> - <Value>%Plugins%\process\PowerSchedulerClientPlugin.dll</Value> + <Value /> <ValueType>Template</ValueType> <Description>The file used to configure the extension. If have .exe extension the will be executed If have .dll extension used like MP plugin configuration</Description> </SectionParam> <SectionParam Name="Online Screenshots"> - <Value>http://www.team-mediaportal.com/components/com_mtree/img/listings/m/480.jpg; -http://www.team-mediaportal.com/components/com_mtree/img/listings/m/481.jpg; -http://www.team-mediaportal.com/components/com_mtree/img/listings/m/482.jpg; -http://www.team-mediaportal.com/components/com_mtree/img/listings/m/483.jpg; -http://www.team-mediaportal.com/components/com_mtree/img/listings/m/484.jpg; -http://www.team-mediaportal.com/components/com_mtree/img/listings/m/485.jpg; -http://www.team-mediaportal.com/components/com_mtree/img/listings/m/486.jpg; -http://www.team-mediaportal.com/components/com_mtree/img/listings/m/487.jpg</Value> + <Value /> <ValueType>String</ValueType> <Description>Online stored screenshot urls separated by ; </Description> </SectionParam> @@ -498,52 +535,46 @@ <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> <Param1 /> <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\TvEngine3\TVLibrary\Plugins\PowerScheduler\bin\Release\PowerScheduler.dll</LocalFileName> + <LocalFileName>..\TvEngine3\TVLibrary\Plugins\PowerScheduler\bin\Debug\PowerScheduler.dll</LocalFileName> <ZipFileName>Installer{CopyFile}\{41ffe535-6bef-44af-8fda-549e2443aabc}-PowerScheduler.dll</ZipFileName> <DestinationFilename>%TvServerPlugins%\PowerScheduler.dll</DestinationFilename> </FileItem> <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> <Param1 /> <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\Common-MP-TVE3\PowerScheduler.Interfaces\bin\Release\PowerScheduler.Interfaces.dll</LocalFileName> + <LocalFileName>..\Common-MP-TVE3\PowerScheduler.Interfaces\bin\Debug\PowerScheduler.Interfaces.dll</LocalFileName> <ZipFileName>Installer{CopyFile}\{fcb1df38-d861-4125-b4a0-8f062cb08d24}-PowerScheduler.Interfaces.dll</ZipFileName> <DestinationFilename>%TvServerBase%\PowerScheduler.Interfaces.dll</DestinationFilename> </FileItem> <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> <Param1 /> <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\mediaportal\PowerSchedulerClientPlugin\bin\Release\PowerSchedulerClientPlugin.dll</LocalFileName> + <LocalFileName>..\mediaportal\PowerSchedulerClientPlugin\bin\Debug\PowerSchedulerClientPlugin.dll</LocalFileName> <ZipFileName>Installer{CopyFile}\{ed9d9027-eca3-460f-b94e-d17ff4ab38ba}-PowerSchedulerClientPlugin.dll</ZipFileName> <DestinationFilename>%Plugins%\process\PowerSchedulerClientPlugin.dll</DestinationFilename> </FileItem> - <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> - <Param1 /> - <UpdateOption>AlwaysOverwrite</UpdateOption> - <LocalFileName>..\mediaportal\PowerSchedulerClientPlugin\bin\Release\PowerScheduler.Interfaces.dll</LocalFileName> - <ZipFileName>Installer{CopyFile}\{ac7155e9-4a57-4108-8731-81f3fd669737}-PowerScheduler.Interfaces.dll</ZipFileName> - <DestinationFilename>%Base%\PowerScheduler.Interfaces.dll</DestinationFilename> - </FileItem> <FileItem InstallType="CopyFile" SystemFile="true" Modified="true"> <Param1 /> <UpdateOption>OverwriteIfOlder</UpdateOption> <LocalFileName>PowerScheduler_high.png</LocalFileName> - <ZipFileName>Installer{CopyFile}\{15edb7d9-2dca-45c1-bf4e-54ae231e18b5}-PowerScheduler_high.png</ZipFileName> + <ZipFileName>Installer{CopyFile}\{db12424d-8f08-4bbb-9305-0c9b6fd92950}-PowerScheduler_high.png</ZipFileName> <DestinationFilename /> </FileItem> <FileItem InstallType="CopyFile" SystemFile="true" Modified="true"> <Param1 /> <UpdateOption>OverwriteIfOlder</UpdateOption> <LocalFileName>..\mediaportal\PowerSchedulerClientPlugin\PowerScheduler.gif</LocalFileName> - <ZipFileName>Installer{CopyFile}\{97988cec-fca7-48b4-852a-f1d164a6089e}-PowerScheduler.gif</ZipFileName> + <ZipFileName>Installer{CopyFile}\{e463d5e3-32ae-49e6-b176-fdf8071ff264}-PowerScheduler.gif</ZipFileName> <DestinationFilename /> </FileItem> </Items> </UniqueFileList> <ProjectSettings> <FolderGroups /> - <ProjectFilename>P:\PowerScheduler++ 1.1.7.0\MPEI\PowerScheduler++.xmp2</ProjectFilename> + <ProjectFilename>PowerScheduler++.xmp2</ProjectFilename> <UpdatePath1>..\MPEI\update.xml</UpdatePath1> <UpdatePath2 /> <UpdatePath3 /> </ProjectSettings> + <IsSkin>false</IsSkin> </PackageClass> \ No newline at end of file Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/RemoteClientStandbyHandler.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/RemoteClientStandbyHandler.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/RemoteClientStandbyHandler.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -29,7 +29,7 @@ namespace TvEngine.PowerScheduler.Handlers { /// <summary> - /// Prevent standby if a remote client is active + /// Prevent standby if a remote (multi-seat) client is active (used by PowerScheduler client plugin) /// </summary> public class RemoteClientStandbyHandler : IStandbyHandler, IStandbyHandlerEx { @@ -43,36 +43,23 @@ /// <summary> /// Indicator if a remote client is active /// </summary> - private bool _disAllowShutdown = false; + private StandbyMode _standbyMode = StandbyMode.StandbyAllowed; /// <summary> /// Last time a remote client signalled activity /// </summary> private DateTime _lastUpdate = DateTime.MinValue; - /// <summary> - /// Manages setting the according thread execution state - /// </summary> - private PowerManager _powerManager; - #endregion #region Constructor public RemoteClientStandbyHandler() { - // Create the PowerManager that helps setting the correct thread executation state - _powerManager = new PowerManager(); } ~RemoteClientStandbyHandler() { - // Dereference the PowerManager instance - if (_powerManager != null) - { - _powerManager.SetAwayModeRequired(false); - _powerManager = null; - } } #endregion @@ -83,19 +70,12 @@ { get { - // Check if last update was longer ago than idle timeout - // If so, do not prevent standby any longer - if (_lastUpdate.AddSeconds(_timeout) < DateTime.Now) - { - _disAllowShutdown = false; - } - _powerManager.SetAwayModeRequired(_disAllowShutdown); - return _disAllowShutdown; + return _standbyMode != StandbyMode.StandbyAllowed; } set { _lastUpdate = DateTime.Now; - _disAllowShutdown = value; + _standbyMode = value ? StandbyMode.AwayModeRequested : StandbyMode.StandbyAllowed; } } @@ -103,22 +83,31 @@ public string HandlerName { - get { return "RemoteClientStandbyHandler"; } + get { return "RemoteClient"; } } #endregion - #region IStandbyHandlerEx Members + #region IStandbyHandlerEx implementation - /// <summary> - /// Is away mode required? - /// </summary> - public bool RequireAwayMode + public StandbyMode StandbyMode { - get { return (_disAllowShutdown); } + get + { + // Check if last update was longer ago than idle timeout + // If so, do not prevent standby any longer + if (_lastUpdate.AddSeconds(_timeout) < DateTime.Now) + { + _standbyMode = StandbyMode.StandbyAllowed; + } + return _standbyMode; + } + set + { + _lastUpdate = DateTime.Now; + _standbyMode = value; + } } - #endregion - } } \ No newline at end of file Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/XmlTvImportWakeupHandler.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/XmlTvImportWakeupHandler.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/Handlers/XmlTvImportWakeupHandler.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -39,7 +39,7 @@ { #region Variables - private string _handlerName = "XmlTvImportWakeupHandler"; + private string _handlerName = "XmlTvImport"; #endregion Modified: trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerScheduler.cs =================================================================== --- trunk/plugins/PowerScheduler++/Test/1.1.7.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerScheduler.cs 2011-10-21 18:36:21 UTC (rev 4312) +++ trunk/plugins/PowerScheduler++/Test/1.2.5.1/TvEngine3/TVLibrary/Plugins/PowerScheduler/PowerScheduler.cs 2011-10-21 18:58:08 UTC (rev 4313) @@ -20,7 +20,6 @@ #region Usings -using Gentle.Common; using System; using System.Collections; using System.Collections.Generic; @@ -31,6 +30,7 @@ using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Http; using System.Threading; +using Gentle.Common; using TvControl; using TvDatabase; using TvEngine.Interfaces; @@ -39,24 +39,18 @@ using TvLibrary.Interfaces; using TvLibrary.Log; - #endregion namespace TvEngine.PowerScheduler { /// <summary> - /// PowerScheduler: tvservice plugin which controls power management + /// PowerScheduler++ Server Plugin: tvservice plugin which controls power management /// </summary> public class PowerScheduler : MarshalByRefObject, IPowerScheduler, IPowerController { #region Variables /// <summary> - /// Register to this event to receive status changes from the PowerScheduler - /// </summary> - public event PowerSchedulerEventHandler OnPowerSchedulerEvent; - - /// <summary> /// PowerScheduler single instance /// </summary> private static PowerScheduler _powerScheduler; @@ -78,9 +72,9 @@ private PowerSchedulerFactory _factory; /// <summary> - /// Manages setting the according thread execution state + /// Thread starting and stopping PowerScheduler /// </summary> - private PowerManager _powerManager; + private Thread _tvServiceThread; /// <summary> /// List of registered standby handlers ("disable standby" plugins) @@ -93,14 +87,14 @@ private List<IWakeupHandler> _wakeupHandlers; /// <summary> - /// IStandbyHandler for the client in singleseat setups + /// StandbyHandler for the IPowerController interface /// </summary> - private GenericStandbyHandler _clientStandbyHandler; + private PowerControllerStandbyHandler _powerControllerStandbyHandler; /// <summary> - /// IWakeupHandler for the client in single-seat setups + /// WakeupHandler for the IPowerController interface /// </summary> - private GenericWakeupHandler _clientWakeupHandler; + private PowerControllerWakeupHandler _powerControllerWakeupHandler; /// <summary> /// IStandbyHandler for remote clients in client/server setups @@ -108,11 +102,21 @@ private RemoteClientStandbyHandler _remoteClientStandbyHandler; /// <summary> - /// Timer for executing periodic checks (should we enter standby..) + /// EventWaitHandle to trigger the StandbyWakeupThread /// </summary> - private System.Timers.Timer _timer; + private EventWaitHandle _standbyWakeupTriggered; /// <summary> + /// EventWaitHandle to signal finished + /// </summary> + private EventWaitHandle _standbyWakeupFinished; + + /// <summary> + /// Thread to check for standby and set wakeup timer + /// </summary> + private Thread _standbyWakeupThread; + + /// <summary> /// Timer with support for waking up the system /// </summary> private WaitableTimer _wakeupTimer; @@ -125,7 +129,7 @@ /// <summary> /// Global indicator if the PowerScheduler thinks the system is idle /// </summary> - private bool _idle = false; + private bool _idle; /// <summary> /// Indicating whether the PowerScheduler is in standby-mode. @@ -133,11 +137,31 @@ private bool _standby = false; /// <summary> + /// Used to avoid concurrent suspend requests which could result in a suspend - user resumes - immediately suspends. + /// </summary> + private DateTime _ignoreSuspendUntil = DateTime.MinValue; + + /// <summary> /// All PowerScheduler related settings are stored here /// </summary> private PowerSettings _settings; /// <summary> + /// Prevent standby, if the next event is due within _preNoShutdownTime seconds + /// </summary> + private const int _preNoShutdownTime = 300; + + /// <summary> + /// Check the system status every _checkInterval seconds + /// </summary> + private const int _checkInterval = 15; + + /// <summary> + /// Wakeup system _preWakeuptime seconds earlier than scheduled + /// </summary> + private const int _preWakeupTime = 60; + + /// <summary> /// Indicator if remoting has been setup /// </summary> private bool _remotingStarted = false; @@ -160,208 +184,60 @@ /// <summary> /// Creates a new PowerScheduler plugin and performs the one-time initialization /// </summary> - private PowerScheduler() + public PowerScheduler() { _standbyHandlers = new List<IStandbyHandler>(); _wakeupHandlers = new List<IWakeupHandler>(); _lastUserTime = DateTime.Now; _idle = false; - // Add ourselves to the GlobalServiceProvider - if (GlobalServiceProvider.Instance.IsRegistered<IPowerScheduler>()) + // Register as global service provider instance + if (!GlobalServiceProvider.Instance.IsRegistered<IPowerScheduler>()) { - GlobalServiceProvider.Instance.Remove<IPowerScheduler>(); + GlobalServiceProvider.Instance.Add<IPowerScheduler>(this); } - GlobalServiceProvider.Instance.Add<IPowerScheduler>(this); - Log.Debug("PowerScheduler: Registered PowerScheduler service to GlobalServiceProvider"); + Log.Debug("PS++: Registered PowerScheduler as IPowerScheduler service to GlobalServiceProvider"); } ~PowerScheduler() { + // Unregister as global service provider instance if (GlobalServiceProvider.Instance.IsRegistered<IPowerScheduler>()) { GlobalServiceProvider.Instance.Remove<IPowerScheduler>(); + Log.Debug("PS++: Unregistered IPowerScheduler service from GlobalServiceProvider"); } } - #endregion - - #region Public methods - - #region Start/Stop methods - - /// <summary> - /// Called by the PowerSchedulerPlugin to start the PowerScheduler - /// </summary> - /// <param name="controller">TVController from the tvservice</param> - [MethodImpl(MethodImplOptions.Synchronized)] - public void Start(IController controller) + public static PowerScheduler Instance { - try + get { - // Give PowerScheduler thread a name - string threadname = Thread.CurrentThread.Name; - if (string.IsNullOrEmpty(threadname)) - Thread.CurrentThread.Name = "Powerscheduler"; - - // Save controller - _controller = controller; - - // Create the PowerManager that helps setting the correct thread executation state - _powerManager = new PowerManager(); - - // Create the timer that will wakeup the system after a specific amount of time after the - // system has been put into standby - _wakeupTimer = new WaitableTimer(); - - // Create the timer responsible for standby checking and refreshing settings - _timer = new System.Timers.Timer(); - _timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimerElapsed); - - // Configure remoting if not already done - StartRemoting(); - - // Load settings - LoadSettings(); - - // Register standby/wakeup handlers - _clientStandbyHandler = new GenericStandbyHandler(); - Register(_clientStandbyHandler); - _clientWakeupHandler = new GenericWakeupHandler(); - Register(_clientWakeupHandler); - _remoteClientStandbyHandler = new RemoteClientStandbyHandler(); - Register(_remoteClientStandbyHandler); - _factory = new PowerSchedulerFactory(controller); - _factory.CreateDefaultSet(); - Log.Debug("PowerScheduler: Registered standby/wakeup handlers to PowerScheduler"); - - // Register power event handler to TVServer - RegisterPowerEventHandler(); - - // Start the timer for periodic setting... [truncated message content] |