From: <an...@us...> - 2008-03-03 23:19:21
|
Revision: 1419 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1419&view=rev Author: and-81 Date: 2008-03-03 15:19:19 -0800 (Mon, 03 Mar 2008) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputListener.cs trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputReceiver.cs Modified: trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2008-03-03 22:47:28 UTC (rev 1418) +++ trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2008-03-03 23:19:19 UTC (rev 1419) @@ -176,20 +176,27 @@ for (int index = 0; index < _pluginNameReceive.Length; index++) { - string pluginName = _pluginNameReceive[index]; + try + { + string pluginName = _pluginNameReceive[index]; - PluginBase plugin = Program.GetPlugin(pluginName); + PluginBase plugin = Program.GetPlugin(pluginName); - if (plugin == null) - { - IrssLog.Warn("Receiver plugin not found: {0}", pluginName); + if (plugin == null) + { + IrssLog.Warn("Receiver plugin not found: {0}", pluginName); + } + else + { + _pluginReceive.Add(plugin); + + if (!String.IsNullOrEmpty(_pluginNameTransmit) && plugin.Name.Equals(_pluginNameTransmit, StringComparison.OrdinalIgnoreCase)) + _pluginTransmit = plugin; + } } - else + catch (Exception ex) { - _pluginReceive.Add(plugin); - - if (!String.IsNullOrEmpty(_pluginNameTransmit) && plugin.Name.Equals(_pluginNameTransmit, StringComparison.OrdinalIgnoreCase)) - _pluginTransmit = plugin; + IrssLog.Error(ex); } } Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputListener.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputListener.cs 2008-03-03 22:47:28 UTC (rev 1418) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputListener.cs 2008-03-03 23:19:19 UTC (rev 1419) @@ -29,22 +29,29 @@ namespace InputService.Plugin { + /// <summary> /// Summary description for DirectInputListener. /// </summary> /// class DirectInputListener { + + #region Variables + Device device = null; Thread inputListener = null; - bool isRunning = false; + volatile bool isListening = false; int delay = 150; // sleep time in milliseconds // event: send info on joystick state change public delegate void diStateChange(object sender, JoystickState state); public event diStateChange OnStateChange = null; + #endregion Variables + #region Constructor / Deconstructor + public DirectInputListener() { // @@ -52,29 +59,29 @@ // } - ~DirectInputListener() { StopListener(); DeInitDevice(); } + #endregion Constructor / Deconstructor + + #region Properties + public Device SelectedDevice { get { return device; } } - public bool IsRunning - { - get { return isRunning; } - } - public int Delay { get { return delay; } set { delay = value; } } + #endregion Properties + public bool InitDevice(Guid guid) { device = new Device(guid); @@ -87,16 +94,16 @@ if ((doi.ObjectId & (int) DeviceObjectTypeFlags.Axis) != 0) { // We found an axis, set the range to a max of 10,000 - device.Properties.SetRange(ParameterHow.ById, - doi.ObjectId, new InputRange(-5000, 5000)); + device.Properties.SetRange(ParameterHow.ById, doi.ObjectId, new InputRange(-5000, 5000)); } } + StopListener(); StartListener(); device.Acquire(); + return true; } - public void DeInitDevice() { if (null != device) @@ -113,11 +120,11 @@ } } - public string GetCurrentButtonCombo() { string res = ""; JoystickState state; + if (CheckDevice()) { // Get the state of the device. @@ -133,6 +140,7 @@ return res; } } + return res; } @@ -158,7 +166,7 @@ void ThreadFunction() { - while (true) + while (isListening) { UpdateInputState(); Thread.Sleep(delay); @@ -172,6 +180,7 @@ { return false; } + try { // Poll the device for info. @@ -198,7 +207,6 @@ return false; } } - } //catch(InputException inputex) return (device != null); @@ -207,6 +215,7 @@ void UpdateInputState() { JoystickState state; + if (CheckDevice()) { // Get the state of the device. @@ -214,12 +223,11 @@ { state = device.CurrentJoystickState; } - // Catch any exceptions. None will be handled here, - // any device re-aquisition will be handled above. - catch (InputException) + catch (InputException) // Catch any exceptions. None will be handled here, any device re-aquisition will be handled above. { return; } + // send events here if (null != this.OnStateChange) { @@ -231,31 +239,28 @@ public void StopListener() { - if (null != inputListener) - { - isRunning = false; + if (inputListener != null) + return; + + isListening = false; + + Thread.Sleep(500); + + if (inputListener != null && inputListener.IsAlive) inputListener.Abort(); - inputListener = null; - } + + inputListener = null; } void StartListener() { + isListening = true; + inputListener = new Thread(new ThreadStart(this.ThreadFunction)); + inputListener.IsBackground = true; inputListener.Start(); - isRunning = true; } - public void Pause() - { - isRunning = false; - } + } - public void Resume() - { - isRunning = true; - } - - - } -} \ No newline at end of file +} Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputReceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputReceiver.cs 2008-03-03 22:47:28 UTC (rev 1418) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Direct Input Receiver/DirectInputReceiver.cs 2008-03-03 23:19:19 UTC (rev 1419) @@ -198,8 +198,9 @@ { if (_diListener != null) { - UnacquireDevice(); - + _diListener.DeInitDevice(); + _diListener.StopListener(); + _diListener.OnStateChange -= new DirectInputListener.diStateChange(diListener_OnStateChange); _diListener = null; } @@ -297,11 +298,6 @@ SendActions(state); } - void UnacquireDevice() - { - _diListener.DeInitDevice(); - } - bool AcquireDevice() { if (_deviceList == null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |