From: <che...@us...> - 2010-11-11 12:43:09
|
Revision: 3924 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3924&view=rev Author: chef_koch Date: 2010-11-11 12:43:03 +0000 (Thu, 11 Nov 2010) Log Message: ----------- finally making usage of hardwareMonitor: server plugins can optionally be restarted now, when a device has been connected Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server/IR Server.cs trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.Designer.cs trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.cs trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Config.cs trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IRServer.Shared/Settings.cs Modified: trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server/IR Server.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server/IR Server.cs 2010-11-11 12:21:08 UTC (rev 3923) +++ trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server/IR Server.cs 2010-11-11 12:43:03 UTC (rev 3924) @@ -63,6 +63,10 @@ private List<ClientManager> _registeredRepeaters; private Server _server; + private HardwareMonitor hardwareMonitor; + private DateTime lastDeviceEvent = DateTime.MinValue; + private const int timeToWaitForRestart = 10000; + #endregion Variables #region Constructor @@ -201,6 +205,17 @@ #endregion Setup Abstract Remote Model processing + #region Setup Hardware Monitoring + + if (Settings.RestartOnUSBChanges) + { + hardwareMonitor = new HardwareMonitor(); + hardwareMonitor.DeviceConnected += new HardwareMonitor.HardwareMonitorEvent(OnDeviceConnected); + hardwareMonitor.Start(); + } + + #endregion + IrssLog.Info("IR Server started"); } @@ -211,6 +226,10 @@ { IrssLog.Info("Stopping IR Server ..."); + if (hardwareMonitor != null) + hardwareMonitor.Stop(); + hardwareMonitor = null; + if (Settings.Mode == IRServerMode.ServerMode) { try @@ -1688,6 +1707,34 @@ return true; } + #region Hardware Monitoring + + private void OnDeviceConnected() + { + Thread lazyRestartThread = new Thread(LazyRestart); + lazyRestartThread.Start(); + } + + private void LazyRestart() + { + DateTime tempLastDeviceEvent = DateTime.Now; + lastDeviceEvent = tempLastDeviceEvent; + + // wait, if new decice events occur + Thread.Sleep(timeToWaitForRestart); + + // if new device event occured, stop here + if (!tempLastDeviceEvent.Equals(lastDeviceEvent)) return; + + // restart service + IrssLog.Info("New device event. Restarting Input Service."); + StopPlugins(); + LoadPlugins(); + StartPlugins(); + } + + #endregion + #endregion Implementation #region Wrapper-Functions for Executing as Application Modified: trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.Designer.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.Designer.cs 2010-11-11 12:21:08 UTC (rev 3923) +++ trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.Designer.cs 2010-11-11 12:43:03 UTC (rev 3924) @@ -44,9 +44,12 @@ this.groupBoxPriority = new System.Windows.Forms.GroupBox(); this.labelPriority = new System.Windows.Forms.Label(); this.comboBoxPriority = new System.Windows.Forms.ComboBox(); + this.groupBoxHardwareMonitoring = new System.Windows.Forms.GroupBox(); + this.checkBoxRestartOnUSBChanges = new System.Windows.Forms.CheckBox(); this.groupBoxMode.SuspendLayout(); this.groupBoxAbstractRemoteModel.SuspendLayout(); this.groupBoxPriority.SuspendLayout(); + this.groupBoxHardwareMonitoring.SuspendLayout(); this.SuspendLayout(); // // groupBoxMode @@ -132,7 +135,7 @@ // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.buttonCancel.Location = new System.Drawing.Point(328, 272); + this.buttonCancel.Location = new System.Drawing.Point(328, 318); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(64, 24); this.buttonCancel.TabIndex = 4; @@ -143,7 +146,7 @@ // buttonOK // this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonOK.Location = new System.Drawing.Point(256, 272); + this.buttonOK.Location = new System.Drawing.Point(256, 318); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(64, 24); this.buttonOK.TabIndex = 3; @@ -223,13 +226,38 @@ this.comboBoxPriority.Size = new System.Drawing.Size(272, 21); this.comboBoxPriority.TabIndex = 1; // + // groupBoxHardwareMonitoring + // + this.groupBoxHardwareMonitoring.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxHardwareMonitoring.Controls.Add(this.checkBoxRestartOnUSBChanges); + this.groupBoxHardwareMonitoring.Location = new System.Drawing.Point(8, 262); + this.groupBoxHardwareMonitoring.Name = "groupBoxHardwareMonitoring"; + this.groupBoxHardwareMonitoring.Size = new System.Drawing.Size(384, 50); + this.groupBoxHardwareMonitoring.TabIndex = 5; + this.groupBoxHardwareMonitoring.TabStop = false; + this.groupBoxHardwareMonitoring.Text = "Hardware Monitoring"; + // + // checkBoxRestartOnUSBChanges + // + this.checkBoxRestartOnUSBChanges.AutoSize = true; + this.checkBoxRestartOnUSBChanges.Location = new System.Drawing.Point(16, 24); + this.checkBoxRestartOnUSBChanges.Name = "checkBoxRestartOnUSBChanges"; + this.checkBoxRestartOnUSBChanges.Size = new System.Drawing.Size(214, 17); + this.checkBoxRestartOnUSBChanges.TabIndex = 0; + this.checkBoxRestartOnUSBChanges.Text = "Restart IR Server on hardware changes"; + this.toolTips.SetToolTip(this.checkBoxRestartOnUSBChanges, "If enabled, IR Server will be automatically restarted if an USB device hase been " + + "connected or removed."); + this.checkBoxRestartOnUSBChanges.UseVisualStyleBackColor = true; + // // Advanced // this.AcceptButton = this.buttonOK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(400, 308); + this.ClientSize = new System.Drawing.Size(400, 354); + this.Controls.Add(this.groupBoxHardwareMonitoring); this.Controls.Add(this.groupBoxPriority); this.Controls.Add(this.groupBoxAbstractRemoteModel); this.Controls.Add(this.buttonCancel); @@ -246,6 +274,8 @@ this.groupBoxMode.PerformLayout(); this.groupBoxAbstractRemoteModel.ResumeLayout(false); this.groupBoxPriority.ResumeLayout(false); + this.groupBoxHardwareMonitoring.ResumeLayout(false); + this.groupBoxHardwareMonitoring.PerformLayout(); this.ResumeLayout(false); } @@ -267,5 +297,7 @@ private System.Windows.Forms.GroupBox groupBoxPriority; private System.Windows.Forms.ComboBox comboBoxPriority; private System.Windows.Forms.Label labelPriority; + private System.Windows.Forms.GroupBox groupBoxHardwareMonitoring; + private System.Windows.Forms.CheckBox checkBoxRestartOnUSBChanges; } } \ No newline at end of file Modified: trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.cs 2010-11-11 12:21:08 UTC (rev 3923) +++ trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Advanced.cs 2010-11-11 12:43:03 UTC (rev 3924) @@ -83,6 +83,12 @@ set { comboBoxPriority.SelectedItem = value; } } + public bool RestartOnUSBChanges + { + get { return checkBoxRestartOnUSBChanges.Checked; } + set { checkBoxRestartOnUSBChanges.Checked = value; } + } + #endregion Properties #region Constructor Modified: trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Config.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Config.cs 2010-11-11 12:21:08 UTC (rev 3923) +++ trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IR Server Configuration/Config.cs 2010-11-11 12:43:03 UTC (rev 3924) @@ -58,6 +58,7 @@ private string _hostComputer = String.Empty; private IRServerMode _mode = IRServerMode.ServerMode; private string _processPriority = String.Empty; + private bool _restartOnUSBChanges = true; private BackgroundWorker monitorThread; #endregion Variables @@ -311,6 +312,7 @@ advanced.Mode = _mode; advanced.HostComputer = _hostComputer; advanced.ProcessPriority = _processPriority; + advanced.RestartOnUSBChanges = _restartOnUSBChanges; if (advanced.ShowDialog(this) == DialogResult.OK) { @@ -318,6 +320,7 @@ _mode = advanced.Mode; _hostComputer = advanced.HostComputer; _processPriority = advanced.ProcessPriority; + _restartOnUSBChanges = advanced.RestartOnUSBChanges; } } @@ -567,6 +570,7 @@ _mode = Settings.Mode; _hostComputer = Settings.HostComputer; _processPriority = Settings.ProcessPriority; + _restartOnUSBChanges = Settings.RestartOnUSBChanges; PluginReceive = Settings.PluginNameReceive; PluginTransmit = Settings.PluginNameTransmit; } @@ -577,6 +581,7 @@ (Settings.Mode != _mode) || (Settings.HostComputer != _hostComputer) || (Settings.ProcessPriority != _processPriority) || + (Settings.RestartOnUSBChanges != _restartOnUSBChanges) || (Settings.PluginNameReceive != PluginReceive) || (Settings.PluginNameTransmit != PluginTransmit)) { @@ -590,6 +595,7 @@ Settings.Mode = _mode; Settings.HostComputer = _hostComputer; Settings.ProcessPriority = _processPriority; + Settings.RestartOnUSBChanges = _restartOnUSBChanges; Settings.PluginNameReceive = PluginReceive; Settings.PluginNameTransmit = PluginTransmit; Modified: trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IRServer.Shared/Settings.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IRServer.Shared/Settings.cs 2010-11-11 12:21:08 UTC (rev 3923) +++ trunk/plugins/IR Server Suite/IR Server Suite/IR Server/IRServer.Shared/Settings.cs 2010-11-11 12:43:03 UTC (rev 3924) @@ -20,6 +20,7 @@ public static IRServerMode Mode { get; set; } public static string HostComputer { get; set; } public static string ProcessPriority { get; set; } + public static bool RestartOnUSBChanges { get; set; } public static string[] PluginNameReceive { get; set; } public static string PluginNameTransmit { get; set; } @@ -34,6 +35,7 @@ Mode = IRServerMode.ServerMode; HostComputer = String.Empty; ProcessPriority = "No Change"; + RestartOnUSBChanges = true; PluginNameReceive = null; PluginNameTransmit = String.Empty; @@ -105,6 +107,15 @@ try { + RestartOnUSBChanges = bool.Parse(doc.DocumentElement.Attributes["RestartOnUSBChanges"].Value); + } + catch (Exception ex) + { + IrssLog.Warn(ex.ToString()); + } + + try + { PluginNameTransmit = doc.DocumentElement.Attributes["PluginTransmit"].Value; } catch (Exception ex) @@ -145,6 +156,7 @@ writer.WriteAttributeString("Mode", Enum.GetName(typeof(IRServerMode), Mode)); writer.WriteAttributeString("HostComputer", HostComputer); writer.WriteAttributeString("ProcessPriority", ProcessPriority); + writer.WriteAttributeString("RestartOnUSBChanges", RestartOnUSBChanges.ToString()); writer.WriteAttributeString("PluginTransmit", PluginNameTransmit); if (PluginNameReceive != null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |