From: <an...@us...> - 2007-09-18 06:39:01
|
Revision: 935 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=935&view=rev Author: and-81 Date: 2007-09-17 23:38:59 -0700 (Mon, 17 Sep 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs trunk/plugins/IR Server Suite/Applications/IR Server/Program.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/GetKeyCodeForm.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/LearnIR.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/MainForm.cs trunk/plugins/IR Server Suite/Applications/Translator/Program.cs trunk/plugins/IR Server Suite/Applications/Translator/Translator.csproj trunk/plugins/IR Server Suite/Applications/Tray Launcher/GetKeyCodeForm.cs trunk/plugins/IR Server Suite/Applications/Tray Launcher/Setup.cs trunk/plugins/IR Server Suite/Applications/Tray Launcher/Tray Launcher.csproj trunk/plugins/IR Server Suite/Applications/Tray Launcher/Tray.cs trunk/plugins/IR Server Suite/Applications/Virtual Remote/MainForm.Designer.cs trunk/plugins/IR Server Suite/Applications/Virtual Remote/MainForm.cs trunk/plugins/IR Server Suite/Applications/Virtual Remote/Program.cs trunk/plugins/IR Server Suite/Applications/Virtual Remote/Virtual Remote.csproj trunk/plugins/IR Server Suite/Applications/Virtual Remote Skin Editor/MainForm.cs trunk/plugins/IR Server Suite/Applications/Virtual Remote Skin Editor/Virtual Remote Skin Editor.csproj trunk/plugins/IR Server Suite/Common/IrssComms/Client.cs trunk/plugins/IR Server Suite/Common/IrssComms/ClientManager.cs trunk/plugins/IR Server Suite/Common/IrssComms/IrssComms.csproj trunk/plugins/IR Server Suite/Common/IrssComms/Properties/AssemblyInfo.cs trunk/plugins/IR Server Suite/Common/IrssComms/Server.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Win32.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Pronto.cs trunk/plugins/IR Server Suite/IR Server Suite.sln trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/Forms/LearnIR.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/Forms/SetupForm.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MP Blast Zone Plugin.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MPBlastZonePlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/Forms/LearnIR.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/Forms/SetupForm.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MP Control Plugin.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/Forms/LearnIR.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/Forms/SetupForm.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/TV2 Blaster Plugin.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/TV2BlasterPlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/Forms/LearnIR.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/Forms/PluginSetup.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/TV3 Blaster Plugin.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/TV3BlasterPlugin.cs Added Paths: ----------- trunk/plugins/IR Server Suite/Common/IrssComms/GenericMessageQueue.cs trunk/plugins/IR Server Suite/Common/IrssComms/IrssMessage.cs trunk/plugins/IR Server Suite/Common/IrssComms/MessageManagerCombo.cs Removed Paths: ------------- trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs trunk/plugins/IR Server Suite/IPC/ Modified: trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj 2007-09-18 06:38:59 UTC (rev 935) @@ -77,22 +77,14 @@ <Content Include="Icon.ico" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\Common\IrssComms\IrssComms.csproj"> + <Project>{BCAFDF45-70DD-46FD-8B98-880DDA585AD2}</Project> + <Name>IrssComms</Name> + </ProjectReference> <ProjectReference Include="..\..\Common\irssUtils\IrssUtils.csproj"> <Project>{CA15769C-232E-4CA7-94FD-206A06CA3ABB}</Project> <Name>IrssUtils</Name> </ProjectReference> - <ProjectReference Include="..\..\IPC\AppModule.InterProcessComm\AppModule.InterProcessComm.csproj"> - <Project>{E98F1F7E-40B6-44C8-AC66-EC867B141FA1}</Project> - <Name>AppModule.InterProcessComm</Name> - </ProjectReference> - <ProjectReference Include="..\..\IPC\AppModule.NamedPipes\AppModule.NamedPipes.csproj"> - <Project>{077B53BB-404A-4B2F-BA17-AAE98C5E9C66}</Project> - <Name>AppModule.NamedPipes</Name> - </ProjectReference> - <ProjectReference Include="..\..\IPC\Named Pipes\Named Pipes.csproj"> - <Project>{F4EA6055-7133-4F18-8971-E19ADEB482C1}</Project> - <Name>Named Pipes</Name> - </ProjectReference> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Modified: trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs 2007-09-18 06:38:59 UTC (rev 935) @@ -6,13 +6,15 @@ using System.Diagnostics; using System.Drawing; using System.IO; +using System.Net; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Security; using System.Text; using System.Threading; using System.Windows.Forms; -using NamedPipes; +using IrssComms; using IrssUtils; namespace DebugClient @@ -91,8 +93,6 @@ public MainForm() { InitializeComponent(); - - _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); } #endregion @@ -105,23 +105,20 @@ #region Variables - MessageQueue _messageQueue; + Client _client = null; string _serverHost = Environment.MachineName; - string _localPipeName = null; string _learnIRFilename = null; bool _registered = false; - bool _keepAlive = true; int _echoID = -1; - Thread _keepAliveThread; IRServerInfo _irServerInfo = new IRServerInfo(); #endregion Variables delegate void DelegateAddStatusLine(string status); - DelegateAddStatusLine _AddStatusLine = null; + DelegateAddStatusLine _addStatusLine = null; void AddStatusLine(string status) { @@ -137,7 +134,7 @@ IrssLog.LogLevel = IrssLog.Level.Debug; IrssLog.Open(Common.FolderIrssLogs + "Debug Client.log"); - _AddStatusLine = new DelegateAddStatusLine(AddStatusLine); + _addStatusLine = new DelegateAddStatusLine(AddStatusLine); comboBoxRemoteButtons.Items.AddRange(Enum.GetNames(typeof(MceButton))); comboBoxRemoteButtons.SelectedIndex = 0; @@ -157,23 +154,22 @@ { buttonDisconnect_Click(null, null); - _AddStatusLine = null; + _addStatusLine = null; IrssLog.Close(); } - void ReceivedMessage(string message) + void ReceivedMessage(IrssMessage received) { - PipeMessage received = PipeMessage.FromString(message); - this.Invoke(_AddStatusLine, new Object[] { String.Format("Received Message: \"{0}, {1}\"", received.Type, received.Flags) }); + this.Invoke(_addStatusLine, new Object[] { String.Format("Received Message: \"{0}, {1}\"", received.Type, received.Flags) }); try { switch (received.Type) { - case PipeMessageType.RegisterClient: - if ((received.Flags & PipeMessageFlags.Success) == PipeMessageFlags.Success) + case MessageType.RegisterClient: + if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { _registered = true; _irServerInfo = IRServerInfo.FromBytes(received.DataAsBytes); @@ -181,18 +177,18 @@ comboBoxPort.Items.AddRange(_irServerInfo.Ports); comboBoxPort.SelectedIndex = 0; } - else if ((received.Flags & PipeMessageFlags.Failure) == PipeMessageFlags.Failure) + else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { _registered = false; } return; - case PipeMessageType.RemoteEvent: + case MessageType.RemoteEvent: RemoteHandlerCallback(received.DataAsString); return; - case PipeMessageType.LearnIR: - if ((received.Flags & PipeMessageFlags.Success) == PipeMessageFlags.Success) + case MessageType.LearnIR: + if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { byte[] dataBytes = received.DataAsBytes; @@ -204,23 +200,23 @@ _learnIRFilename = null; break; - case PipeMessageType.ServerShutdown: + case MessageType.ServerShutdown: _registered = false; return; - case PipeMessageType.Echo: + case MessageType.Echo: _echoID = BitConverter.ToInt32(received.DataAsBytes, 0); return; - case PipeMessageType.Error: + case MessageType.Error: _learnIRFilename = null; - this.Invoke(_AddStatusLine, new Object[] { received.DataAsString }); + this.Invoke(_addStatusLine, new Object[] { received.DataAsString }); return; } } catch (Exception ex) { - this.Invoke(_AddStatusLine, new Object[] { ex.Message }); + this.Invoke(_addStatusLine, new Object[] { ex.Message }); } } @@ -232,14 +228,15 @@ return false; _learnIRFilename = fileName; - - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.LearnIR, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); + IrssMessage message = new IrssMessage(MessageType.LearnIR, MessageFlags.Request); + _client.Send(message); + AddStatusLine("Learning"); } catch (Exception ex) { + _learnIRFilename = null; AddStatusLine(ex.Message); return false; } @@ -253,7 +250,7 @@ if (!File.Exists(fileName)) return false; - FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + FileStream file = new FileStream(fileName, FileMode.Open); byte[] outData = new byte[4 + port.Length + file.Length]; @@ -263,8 +260,8 @@ file.Read(outData, 4 + port.Length, (int)file.Length); file.Close(); - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.BlastIR, PipeMessageFlags.Request, outData); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); + IrssMessage message = new IrssMessage(MessageType.BlastIR, MessageFlags.Request, outData); + _client.Send(message); } catch (Exception ex) { @@ -278,238 +275,67 @@ { string text = String.Format("Remote Event \"{0}\"", keyCode); - this.Invoke(_AddStatusLine, new Object[] { text }); + this.Invoke(_addStatusLine, new Object[] { text }); } - bool StartComms() + void CommsFailure(object obj) { - try - { - if (OpenLocalPipe()) - { - _messageQueue.Start(); + Exception ex = obj as Exception; + + if (ex != null) + this.Invoke(_addStatusLine, new Object[] { String.Format("Communications failure: {0}", ex.Message) }); + else + this.Invoke(_addStatusLine, new Object[] { "Communications failure" }); - _keepAliveThread = new Thread(new ThreadStart(KeepAliveThread)); - _keepAliveThread.Start(); - return true; - } - } - catch (Exception ex) - { - IrssLog.Error(ex.ToString()); - } + StopClient(); + } + void Connected(object obj) + { + IrssLog.Info("Connected to server"); - return false; + IrssMessage message = new IrssMessage(MessageType.RegisterClient, MessageFlags.Request); + _client.Send(message); } - void StopComms() + void Disconnected(object obj) { - _keepAlive = false; + IrssLog.Warn("Communications with server has been lost"); - try - { - if (_keepAliveThread != null && _keepAliveThread.IsAlive) - _keepAliveThread.Abort(); - } - catch { } - - try - { - if (_registered) - { - _registered = false; - - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.UnregisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); - } - } - catch { } - - _messageQueue.Stop(); - - try - { - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); - } - catch { } + Thread.Sleep(1000); } - bool OpenLocalPipe() + bool StartClient() { - try - { - int pipeNumber = 1; - bool retry = false; + if (_client != null) + return false; - do - { - string localPipeTest = String.Format("irserver\\debug{0:00}", pipeNumber); + ClientMessageSink sink = new ClientMessageSink(ReceivedMessage); - if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) - { - if (++pipeNumber <= Common.MaximumLocalClientCount) - retry = true; - else - throw new Exception(String.Format("Maximum local client limit ({0}) reached", Common.MaximumLocalClientCount)); - } - else - { - if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(_messageQueue.Enqueue))) - throw new Exception(String.Format("Failed to start local pipe server \"{0}\"", localPipeTest)); + IPAddress serverAddress = Client.GetIPFromName(_serverHost); - _localPipeName = localPipeTest; - retry = false; - } - } - while (retry); - - return true; - } - catch (Exception ex) + _client = new Client(serverAddress, 24000, sink); + _client.CommsFailureCallback = new WaitCallback(CommsFailure); + _client.ConnectCallback = new WaitCallback(Connected); + _client.DisconnectCallback = new WaitCallback(Disconnected); + + if (_client.Start()) { - IrssLog.Error(ex.ToString()); - return false; - } - } - - bool ConnectToServer() - { - try - { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.RegisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); return true; } - catch (AppModule.NamedPipes.NamedPipeIOException) + else { + _client = null; return false; } - catch (Exception ex) - { - IrssLog.Error(ex.ToString()); - return false; - } } - - void KeepAliveThread() + void StopClient() { - Random random = new Random((int)DateTime.Now.Ticks); - bool reconnect; - int attempt; + if (_client == null) + return; - _registered = false; - _keepAlive = true; - while (_keepAlive) - { - reconnect = true; - - #region Connect to server - - IrssLog.Info("Connecting ({0}) ...", _serverHost); - attempt = 0; - while (_keepAlive && reconnect) - { - if (ConnectToServer()) - { - reconnect = false; - } - else - { - int wait; - - if (attempt <= 50) - attempt++; - - if (attempt > 50) - wait = 30; // 30 seconds - else if (attempt > 20) - wait = 10; // 10 seconds - else if (attempt > 10) - wait = 5; // 5 seconds - else - wait = 1; // 1 second - - for (int sleeps = 0; sleeps < wait && _keepAlive; sleeps++) - Thread.Sleep(1000); - } - } - - #endregion Connect to server - - #region Wait for registered - - // Give up after 10 seconds ... - attempt = 0; - while (_keepAlive && !_registered && !reconnect) - { - if (++attempt >= 10) - reconnect = true; - else - Thread.Sleep(1000); - } - - #endregion Wait for registered - - #region Ping the server repeatedly - - while (_keepAlive && _registered && !reconnect) - { - int pingID = random.Next(); - long pingTime = DateTime.Now.Ticks; - - try - { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.Ping, PipeMessageFlags.Request, BitConverter.GetBytes(pingID)); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); - } - catch - { - // Failed to ping ... reconnect ... - IrssLog.Warn("Failed to ping, attempting to reconnect ..."); - _registered = false; - reconnect = true; - break; - } - - // Wait 10 seconds for a ping echo ... - bool receivedEcho = false; - while (_keepAlive && _registered && !reconnect && - !receivedEcho && DateTime.Now.Ticks - pingTime < 10 * 1000 * 10000) - { - if (_echoID == pingID) - { - receivedEcho = true; - } - else - { - Thread.Sleep(1000); - } - } - - if (receivedEcho) // Received ping echo ... - { - // Wait 60 seconds before re-pinging ... - for (int sleeps = 0; sleeps < 60 && _keepAlive && _registered; sleeps++) - Thread.Sleep(1000); - } - else // Didn't receive ping echo ... - { - IrssLog.Warn("No echo to ping, attempting to reconnect ..."); - - // Break out of pinging cycle ... - _registered = false; - reconnect = true; - } - } - - #endregion Ping the server repeatedly - - } - + _client.Stop(); + _client = null; } - - #region Controls private void buttonConnect_Click(object sender, EventArgs e) @@ -519,15 +345,15 @@ AddStatusLine("Connect"); listBoxStatus.Update(); - if (PipeAccess.ServerRunning) + if (_client != null) { - AddStatusLine("Already connected"); + AddStatusLine("Already connected/connecting"); return; } _serverHost = comboBoxComputer.Text; - StartComms(); + StartClient(); } catch (Exception ex) { @@ -540,13 +366,19 @@ try { - if (!PipeAccess.ServerRunning) + if (_client == null) { AddStatusLine(" - Not connected"); return; } - StopComms(); + if (_registered) + { + IrssMessage message = new IrssMessage(MessageType.UnregisterClient, MessageFlags.Request); + _client.Send(message); + } + + StopClient(); } catch (Exception ex) { @@ -555,56 +387,78 @@ } private void buttonBlast_Click(object sender, EventArgs e) { - if (!PipeAccess.ServerRunning) + AddStatusLine("Blast IR"); + + if (_client == null) { - AddStatusLine("Not connected"); + AddStatusLine(" - Not connected"); return; } + if (!_client.Connected) + { + AddStatusLine(" - Connecting..."); + return; + } + if (!_irServerInfo.CanTransmit) { - AddStatusLine("IR Server is not setup to blast"); + AddStatusLine(" - IR Server is not setup to blast"); return; } if (BlastIR(DebugIRFile, comboBoxPort.SelectedItem as string)) - AddStatusLine("Blasting"); + AddStatusLine(" - Blasting ..."); else - AddStatusLine("Can't Blast"); + AddStatusLine(" - Can't Blast"); } private void buttonLearnIR_Click(object sender, EventArgs e) { - if (!PipeAccess.ServerRunning) + AddStatusLine("Learn IR"); + + if (_client == null) { - AddStatusLine("Not connected"); + AddStatusLine(" - Not connected"); return; } + if (!_client.Connected) + { + AddStatusLine(" - Connecting..."); + return; + } + if (!_irServerInfo.CanLearn) { - AddStatusLine("IR Server is not setup to support learning"); + AddStatusLine(" - IR Server is not setup to support learning"); return; } if (LearnIR(DebugIRFile)) - AddStatusLine("Learning IR"); + AddStatusLine(" - Learning IR ..."); else - AddStatusLine("Learn IR Busy"); + AddStatusLine(" - Learn IR Busy"); } private void buttonShutdownServer_Click(object sender, EventArgs e) { AddStatusLine("Shutdown"); - if (!PipeAccess.ServerRunning) + if (_client == null) { AddStatusLine(" - Not connected"); return; } + if (!_client.Connected) + { + AddStatusLine(" - Connecting..."); + return; + } + try { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.ServerShutdown, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); + IrssMessage message = new IrssMessage(MessageType.ServerShutdown, MessageFlags.Request); + _client.Send(message); } catch (Exception ex) { @@ -615,16 +469,22 @@ { AddStatusLine("Ping Server"); - if (!PipeAccess.ServerRunning) + if (_client == null) { AddStatusLine(" - Not connected"); return; } + if (!_client.Connected) + { + AddStatusLine(" - Connecting..."); + return; + } + try { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.Ping, PipeMessageFlags.Request, BitConverter.GetBytes(24)); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); + IrssMessage message = new IrssMessage(MessageType.Ping, MessageFlags.Request, BitConverter.GetBytes(24)); + _client.Send(message); } catch (Exception ex) { @@ -635,13 +495,9 @@ private void comboBoxRemoteButtons_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxRemoteButtons.SelectedItem.ToString() == "Custom") - { numericUpDownButton.Enabled = true; - } else - { numericUpDownButton.Enabled = false; - } } private void buttonSendRemoteButton_Click(object sender, EventArgs e) @@ -650,23 +506,24 @@ try { - if (!PipeAccess.ServerRunning) + if (_client == null) { AddStatusLine(" - Not connected"); return; } + if (!_client.Connected) + { + AddStatusLine(" - Connecting..."); + return; + } + int keyCode = (int)Enum.Parse(typeof(MceButton), comboBoxRemoteButtons.SelectedItem.ToString(), true); if (keyCode == -1) keyCode = Decimal.ToInt32(numericUpDownButton.Value); - byte[] data = new byte[8]; - - BitConverter.GetBytes(keyCode).CopyTo(data, 0); - BitConverter.GetBytes(0).CopyTo(data, 4); - - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.ForwardRemoteEvent, PipeMessageFlags.Notify, data); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); + IrssMessage message = new IrssMessage(MessageType.ForwardRemoteEvent, MessageFlags.Notify, keyCode.ToString()); + _client.Send(message); } catch (Exception ex) { @@ -688,8 +545,6 @@ #endregion Controls - - Thread AutoTest; private void buttonAutoTest_Click(object sender, EventArgs e) @@ -713,7 +568,7 @@ { randomNumber = rand.Next(100000); - this.Invoke(_AddStatusLine, new Object[] { String.Format("AutoTest: {0}", randomNumber) }); + this.Invoke(_addStatusLine, new Object[] { String.Format("AutoTest: {0}", randomNumber) }); process.StartInfo.Arguments = "-host localhost -pad 4 -channel " + randomNumber.ToString(); Modified: trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj 2007-09-18 06:38:59 UTC (rev 935) @@ -63,22 +63,14 @@ <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\Common\IrssComms\IrssComms.csproj"> + <Project>{BCAFDF45-70DD-46FD-8B98-880DDA585AD2}</Project> + <Name>IrssComms</Name> + </ProjectReference> <ProjectReference Include="..\..\Common\irssUtils\IrssUtils.csproj"> <Project>{CA15769C-232E-4CA7-94FD-206A06CA3ABB}</Project> <Name>IrssUtils</Name> </ProjectReference> - <ProjectReference Include="..\..\IPC\AppModule.InterProcessComm\AppModule.InterProcessComm.csproj"> - <Project>{E98F1F7E-40B6-44C8-AC66-EC867B141FA1}</Project> - <Name>AppModule.InterProcessComm</Name> - </ProjectReference> - <ProjectReference Include="..\..\IPC\AppModule.NamedPipes\AppModule.NamedPipes.csproj"> - <Project>{077B53BB-404A-4B2F-BA17-AAE98C5E9C66}</Project> - <Name>AppModule.NamedPipes</Name> - </ProjectReference> - <ProjectReference Include="..\..\IPC\Named Pipes\Named Pipes.csproj"> - <Project>{F4EA6055-7133-4F18-8971-E19ADEB482C1}</Project> - <Name>Named Pipes</Name> - </ProjectReference> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Modified: trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs 2007-09-18 06:38:59 UTC (rev 935) @@ -4,11 +4,13 @@ using System.ComponentModel; using System.Data; using System.IO; +using System.Net; +using System.Net.Sockets; using System.Text; using System.Threading; using System.Xml; -using NamedPipes; +using IrssComms; using IrssUtils; namespace IRBlast @@ -19,17 +21,14 @@ #region Variables - static MessageQueue _messageQueue; + static Client _client = null; static bool _registered = false; - static bool _keepAlive = true; static int _echoID = -1; - static Thread _keepAliveThread; static string _serverHost = null; - static string _localPipeName; - static string _blastPort = "None"; + static string _blastPort = "Default"; static bool _treatAsChannelNumber = false; static int _padChannelNumber = 0; @@ -81,8 +80,6 @@ } } - _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); - if (String.IsNullOrEmpty(_serverHost) || irCommands.Count == 0) { Console.WriteLine("Malformed command line parameters ..."); @@ -90,7 +87,7 @@ ShowHelp(); } - else if (StartComms()) + else if (StartClient()) { Thread.Sleep(250); @@ -166,7 +163,7 @@ Error(ex); } - StopComms(); + StopClient(); IrssLog.Close(); } @@ -218,274 +215,103 @@ Console.WriteLine(""); } - static bool StartComms() + static void CommsFailure(object obj) { - try - { - if (OpenLocalPipe()) - { - _messageQueue.Start(); + Exception ex = obj as Exception; + + if (ex != null) + IrssLog.Error("Communications failure: {0}", ex.Message); + else + IrssLog.Error("Communications failure"); - _keepAliveThread = new Thread(new ThreadStart(KeepAliveThread)); - _keepAliveThread.Start(); - return true; - } - } - catch (Exception ex) - { - Error(ex); - } + StopClient(); + } + static void Connected(object obj) + { + IrssLog.Info("Connected to server"); - return false; + IrssMessage message = new IrssMessage(MessageType.RegisterClient, MessageFlags.Request); + _client.Send(message); } - static void StopComms() + static void Disconnected(object obj) { - _keepAlive = false; + IrssLog.Warn("Communications with server has been lost"); - try - { - if (_keepAliveThread != null && _keepAliveThread.IsAlive) - _keepAliveThread.Abort(); - } - catch { } - - try - { - if (_registered) - { - _registered = false; - - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.UnregisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); - } - } - catch { } - - _messageQueue.Stop(); - - try - { - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); - } - catch { } + Thread.Sleep(1000); } - static bool OpenLocalPipe() + static bool StartClient() { - try - { - int pipeNumber = 1; - bool retry = false; + if (_client != null) + return false; - do - { - string localPipeTest = String.Format("irserver\\blast{0:00}", pipeNumber); + ClientMessageSink sink = new ClientMessageSink(ReceivedMessage); - if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) - { - if (++pipeNumber <= Common.MaximumLocalClientCount) - retry = true; - else - throw new Exception(String.Format("Maximum local client limit ({0}) reached", Common.MaximumLocalClientCount)); - } - else - { - if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(_messageQueue.Enqueue))) - throw new Exception(String.Format("Failed to start local pipe server \"{0}\"", localPipeTest)); + IPAddress serverAddress = Client.GetIPFromName(_serverHost); - _localPipeName = localPipeTest; - retry = false; - } - } - while (retry); - - return true; - } - catch (Exception ex) + _client = new Client(serverAddress, 24000, sink); + _client.CommsFailureCallback = new WaitCallback(CommsFailure); + _client.ConnectCallback = new WaitCallback(Connected); + _client.DisconnectCallback = new WaitCallback(Disconnected); + + if (_client.Start()) { - Error(ex); - return false; - } - } - - static bool ConnectToServer() - { - try - { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.RegisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); return true; } - catch (AppModule.NamedPipes.NamedPipeIOException) + else { + _client = null; return false; } - catch (Exception ex) - { - Error(ex); - return false; - } } - - static void KeepAliveThread() + static void StopClient() { - Random random = new Random((int)DateTime.Now.Ticks); - bool reconnect; - int attempt; + if (_client == null) + return; - _registered = false; - _keepAlive = true; - while (_keepAlive) - { - reconnect = true; - - #region Connect to server - - Info("Connecting ({0}) ...", _serverHost); - attempt = 0; - while (_keepAlive && reconnect) - { - if (ConnectToServer()) - { - reconnect = false; - } - else - { - int wait; - - if (attempt <= 50) - attempt++; - - if (attempt > 50) - wait = 30; // 30 seconds - else if (attempt > 20) - wait = 10; // 10 seconds - else if (attempt > 10) - wait = 5; // 5 seconds - else - wait = 1; // 1 second - - for (int sleeps = 0; sleeps < wait && _keepAlive; sleeps++) - Thread.Sleep(1000); - } - } - - #endregion Connect to server - - #region Wait for registered - - // Give up after 10 seconds ... - attempt = 0; - while (_keepAlive && !_registered && !reconnect) - { - if (++attempt >= 10) - reconnect = true; - else - Thread.Sleep(1000); - } - - #endregion Wait for registered - - #region Ping the server repeatedly - - while (_keepAlive && _registered && !reconnect) - { - int pingID = random.Next(); - long pingTime = DateTime.Now.Ticks; - - try - { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.Ping, PipeMessageFlags.Request, BitConverter.GetBytes(pingID)); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); - } - catch - { - // Failed to ping ... reconnect ... - Warn("Failed to ping, attempting to reconnect ..."); - _registered = false; - reconnect = true; - break; - } - - // Wait 10 seconds for a ping echo ... - bool receivedEcho = false; - while (_keepAlive && _registered && !reconnect && - !receivedEcho && DateTime.Now.Ticks - pingTime < 10 * 1000 * 10000) - { - if (_echoID == pingID) - { - receivedEcho = true; - } - else - { - Thread.Sleep(1000); - } - } - - if (receivedEcho) // Received ping echo ... - { - // Wait 60 seconds before re-pinging ... - for (int sleeps = 0; sleeps < 60 && _keepAlive && _registered; sleeps++) - Thread.Sleep(1000); - } - else // Didn't receive ping echo ... - { - Warn("No echo to ping, attempting to reconnect ..."); - - // Break out of pinging cycle ... - _registered = false; - reconnect = true; - } - } - - #endregion Ping the server repeatedly - - } - + _client.Stop(); + _client = null; } - static void ReceivedMessage(string message) + static void ReceivedMessage(IrssMessage received) { - PipeMessage received = PipeMessage.FromString(message); - IrssLog.Debug("Received Message \"{0}\"", received.Type); try { switch (received.Type) { - case PipeMessageType.BlastIR: - if ((received.Flags & PipeMessageFlags.Success) == PipeMessageFlags.Success) + case MessageType.BlastIR: + if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) Info("Blast Success"); - else if ((received.Flags & PipeMessageFlags.Failure) == PipeMessageFlags.Failure) + else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) Warn("Blast Failed!"); break; - case PipeMessageType.RegisterClient: - if ((received.Flags & PipeMessageFlags.Success) == PipeMessageFlags.Success) + case MessageType.RegisterClient: + if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { Info("Registered to IR Server"); _registered = true; //_irServerInfo = TransceiverInfo.FromString(received.Data); } - else if ((received.Flags & PipeMessageFlags.Failure) == PipeMessageFlags.Failure) + else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { _registered = false; Warn("IR Server refused to register"); } break; - case PipeMessageType.ServerShutdown: + case MessageType.ServerShutdown: _registered = false; Warn("IR Server Shutdown - Blasting disabled until IR Server returns"); break; - case PipeMessageType.Echo: + case MessageType.Echo: _echoID = BitConverter.ToInt32(received.DataAsBytes, 0); break; - case PipeMessageType.Error: + case MessageType.Error: Warn(received.DataAsString); break; } @@ -498,7 +324,7 @@ static void BlastIR(string fileName, string port) { - FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + FileStream file = new FileStream(fileName, FileMode.Open); byte[] outData = new byte[4 + port.Length + file.Length]; @@ -508,8 +334,8 @@ file.Read(outData, 4 + port.Length, (int)file.Length); file.Close(); - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.BlastIR, PipeMessageFlags.Request | PipeMessageFlags.ForceNotRespond, outData); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); + IrssMessage message = new IrssMessage(MessageType.BlastIR, MessageFlags.Request | MessageFlags.ForceNotRespond, outData); + _client.Send(message); } #region Log Commands Modified: trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj 2007-09-18 06:38:59 UTC (rev 935) @@ -64,22 +64,14 @@ <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\Common\IrssComms\IrssComms.csproj"> + <Project>{BCAFDF45-70DD-46FD-8B98-880DDA585AD2}</Project> + <Name>IrssComms</Name> + </ProjectReference> <ProjectReference Include="..\..\Common\irssUtils\IrssUtils.csproj"> <Project>{CA15769C-232E-4CA7-94FD-206A06CA3ABB}</Project> <Name>IrssUtils</Name> </ProjectReference> - <ProjectReference Include="..\..\IPC\AppModule.InterProcessComm\AppModule.InterProcessComm.csproj"> - <Project>{E98F1F7E-40B6-44C8-AC66-EC867B141FA1}</Project> - <Name>AppModule.InterProcessComm</Name> - </ProjectReference> - <ProjectReference Include="..\..\IPC\AppModule.NamedPipes\AppModule.NamedPipes.csproj"> - <Project>{077B53BB-404A-4B2F-BA17-AAE98C5E9C66}</Project> - <Name>AppModule.NamedPipes</Name> - </ProjectReference> - <ProjectReference Include="..\..\IPC\Named Pipes\Named Pipes.csproj"> - <Project>{F4EA6055-7133-4F18-8971-E19ADEB482C1}</Project> - <Name>Named Pipes</Name> - </ProjectReference> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Modified: trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs 2007-09-18 06:38:59 UTC (rev 935) @@ -4,12 +4,14 @@ using System.ComponentModel; using System.Data; using System.IO; +using System.Net; +using System.Net.Sockets; using System.Text; using System.Threading; using System.Windows.Forms; using System.Xml; -using NamedPipes; +using IrssComms; using IrssUtils; namespace IRBlast @@ -20,17 +22,14 @@ #region Variables - static MessageQueue _messageQueue; + static Client _client = null; static bool _registered = false; - static bool _keepAlive = true; static int _echoID = -1; - static Thread _keepAliveThread; static string _serverHost = null; - static string _localPipeName; - static string _blastPort = "None"; + static string _blastPort = "Default"; static bool _treatAsChannelNumber = false; static int _padChannelNumber = 0; @@ -80,8 +79,6 @@ } } - _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); - if (String.IsNullOrEmpty(_serverHost) || irCommands.Count == 0) { Console.WriteLine("Malformed command line parameters ..."); @@ -89,7 +86,7 @@ ShowHelp(); } - else if (StartComms()) + else if (StartClient()) { Thread.Sleep(250); @@ -165,7 +162,7 @@ IrssLog.Error(ex.ToString()); } - StopComms(); + StopClient(); IrssLog.Close(); } @@ -180,274 +177,103 @@ "IR Blast (No Window)", MessageBoxButtons.OK, MessageBoxIcon.Error); } - static bool StartComms() + static void CommsFailure(object obj) { - try - { - if (OpenLocalPipe()) - { - _messageQueue.Start(); + Exception ex = obj as Exception; + + if (ex != null) + IrssLog.Error("Communications failure: {0}", ex.Message); + else + IrssLog.Error("Communications failure"); - _keepAliveThread = new Thread(new ThreadStart(KeepAliveThread)); - _keepAliveThread.Start(); - return true; - } - } - catch (Exception ex) - { - IrssLog.Error(ex.ToString()); - } + StopClient(); + } + static void Connected(object obj) + { + IrssLog.Info("Connected to server"); - return false; + IrssMessage message = new IrssMessage(MessageType.RegisterClient, MessageFlags.Request); + _client.Send(message); } - static void StopComms() + static void Disconnected(object obj) { - _keepAlive = false; + IrssLog.Warn("Communications with server has been lost"); - try - { - if (_keepAliveThread != null && _keepAliveThread.IsAlive) - _keepAliveThread.Abort(); - } - catch { } - - try - { - if (_registered) - { - _registered = false; - - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.UnregisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); - } - } - catch { } - - _messageQueue.Stop(); - - try - { - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); - } - catch { } + Thread.Sleep(1000); } - static bool OpenLocalPipe() + static bool StartClient() { - try - { - int pipeNumber = 1; - bool retry = false; + if (_client != null) + return false; - do - { - string localPipeTest = String.Format("irserver\\blast{0:00}", pipeNumber); + ClientMessageSink sink = new ClientMessageSink(ReceivedMessage); - if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) - { - if (++pipeNumber <= Common.MaximumLocalClientCount) - retry = true; - else - throw new Exception(String.Format("Maximum local client limit ({0}) reached", Common.MaximumLocalClientCount)); - } - else - { - if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(_messageQueue.Enqueue))) - throw new Exception(String.Format("Failed to start local pipe server \"{0}\"", localPipeTest)); + IPAddress serverAddress = Client.GetIPFromName(_serverHost); - _localPipeName = localPipeTest; - retry = false; - } - } - while (retry); - - return true; - } - catch (Exception ex) + _client = new Client(serverAddress, 24000, sink); + _client.CommsFailureCallback = new WaitCallback(CommsFailure); + _client.ConnectCallback = new WaitCallback(Connected); + _client.DisconnectCallback = new WaitCallback(Disconnected); + + if (_client.Start()) { - IrssLog.Error(ex.ToString()); - return false; - } - } - - static bool ConnectToServer() - { - try - { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.RegisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); return true; } - catch (AppModule.NamedPipes.NamedPipeIOException) + else { + _client = null; return false; } - catch (Exception ex) - { - IrssLog.Error(ex.ToString()); - return false; - } } - - static void KeepAliveThread() + static void StopClient() { - Random random = new Random((int)DateTime.Now.Ticks); - bool reconnect; - int attempt; + if (_client == null) + return; - _registered = false; - _keepAlive = true; - while (_keepAlive) - { - reconnect = true; - - #region Connect to server - - IrssLog.Info("Connecting ({0}) ...", _serverHost); - attempt = 0; - while (_keepAlive && reconnect) - { - if (ConnectToServer()) - { - reconnect = false; - } - else - { - int wait; - - if (attempt <= 50) - attempt++; - - if (attempt > 50) - wait = 30; // 30 seconds - else if (attempt > 20) - wait = 10; // 10 seconds - else if (attempt > 10) - wait = 5; // 5 seconds - else - wait = 1; // 1 second - - for (int sleeps = 0; sleeps < wait && _keepAlive; sleeps++) - Thread.Sleep(1000); - } - } - - #endregion Connect to server - - #region Wait for registered - - // Give up after 10 seconds ... - attempt = 0; - while (_keepAlive && !_registered && !reconnect) - { - if (++attempt >= 10) - reconnect = true; - else - Thread.Sleep(1000); - } - - #endregion Wait for registered - - #region Ping the server repeatedly - - while (_keepAlive && _registered && !reconnect) - { - int pingID = random.Next(); - long pingTime = DateTime.Now.Ticks; - - try - { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.Ping, PipeMessageFlags.Request, BitConverter.GetBytes(pingID)); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); - } - catch - { - // Failed to ping ... reconnect ... - IrssLog.Warn("Failed to ping, attempting to reconnect ..."); - _registered = false; - reconnect = true; - break; - } - - // Wait 10 seconds for a ping echo ... - bool receivedEcho = false; - while (_keepAlive && _registered && !reconnect && - !receivedEcho && DateTime.Now.Ticks - pingTime < 10 * 1000 * 10000) - { - if (_echoID == pingID) - { - receivedEcho = true; - } - else - { - Thread.Sleep(1000); - } - } - - if (receivedEcho) // Received ping echo ... - { - // Wait 60 seconds before re-pinging ... - for (int sleeps = 0; sleeps < 60 && _keepAlive && _registered; sleeps++) - Thread.Sleep(1000); - } - else // Didn't receive ping echo ... - { - IrssLog.Warn("No echo to ping, attempting to reconnect ..."); - - // Break out of pinging cycle ... - _registered = false; - reconnect = true; - } - } - - #endregion Ping the server repeatedly - - } - + _client.Stop(); + _client = null; } - static void ReceivedMessage(string message) + static void ReceivedMessage(IrssMessage received) { - PipeMessage received = PipeMessage.FromString(message); - IrssLog.Debug("Received Message \"{0}\"", received.Type); try { switch (received.Type) { - case PipeMessageType.BlastIR: - if ((received.Flags & PipeMessageFlags.Success) == PipeMessageFlags.Success) + case MessageType.BlastIR: + if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) IrssLog.Info("Blast Success"); - else if ((received.Flags & PipeMessageFlags.Failure) == PipeMessageFlags.Failure) + else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) IrssLog.Warn("Blast Failed!"); break; - case PipeMessageType.RegisterClient: - if ((received.Flags & PipeMessageFlags.Success) == PipeMessageFlags.Success) + case MessageType.RegisterClient: + if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { IrssLog.Info("Registered to IR Server"); _registered = true; //_irServerInfo = TransceiverInfo.FromString(received.Data); } - else if ((received.Flags & PipeMessageFlags.Failure) == PipeMessageFlags.Failure) + else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { _registered = false; IrssLog.Warn("IR Server refused to register"); } break; - case PipeMessageType.ServerShutdown: + case MessageType.ServerShutdown: _registered = false; IrssLog.Warn("IR Server Shutdown - Blasting disabled until IR Server returns"); break; - case PipeMessageType.Echo: + case MessageType.Echo: _echoID = BitConverter.ToInt32(received.DataAsBytes, 0); break; - case PipeMessageType.Error: + case MessageType.Error: IrssLog.Warn(received.DataAsString); break; } @@ -460,7 +286,7 @@ static void BlastIR(string fileName, string port) { - FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + FileStream file = new FileStream(fileName, FileMode.Open); byte[] outData = new byte[4 + port.Length + file.Length]; @@ -470,8 +296,8 @@ file.Read(outData, 4 + port.Length, (int)file.Length); file.Close(); - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.BlastIR, PipeMessageFlags.Request | PipeMessageFlags.ForceNotRespond, outData); - PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); + IrssMessage message = new IrssMessage(MessageType.BlastIR, MessageFlags.Request | MessageFlags.ForceNotRespond, outData); + _client.Send(message); } } Deleted: trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs 2007-09-18 06:38:59 UTC (rev 935) @@ -1,25 +0,0 @@ -using System; - -namespace IRServer -{ - - struct Client - { - - public string Pipe; - public string Server; - - public Client(string pipe, string server) - { - Pipe = pipe; - Server = server; - } - - public override string ToString() - { - return String.Format("({0}, {1})", Server, Pipe); - } - - } - -} Modified: trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj 2007-09-18 06:38:59 UTC (rev 935) @@ -101,7 +101,6 @@ <Compile Include="Advanced.Designer.cs"> <DependentUpon>Advanced.cs</DependentUpon> </Compile> - <Compile Include="Client.cs" /> <Compile Include="Properties\Resources.Designer.cs"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> @@ -145,14 +144,14 @@ </BootstrapperPackage> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\Common\IrssComms\IrssComms.csproj"> + <Project>{BCAFDF45-70DD-46FD-8B98-880DDA585AD2}</Project> + <Name>IrssComms</Name> + </ProjectReference> <ProjectReference Include="..\..\Common\irssUtils\IrssUtils.csproj"> <Project>{CA15769C-232E-4CA7-94FD-206A06CA3ABB}</Project> <Name>IrssUtils</Name> </ProjectReference> - <ProjectReference Include="..\..\IPC\Named Pipes\Named Pipes.csproj"> - <Project>{F4EA6055-7133-4F18-8971-E19ADEB482C1}</Project> - <Name>Named Pipes</Name> - </ProjectReference> <ProjectReference Include="..\..\IR Server Plugins\IR Server Plugin Interface\IR Server Plugin Interface.csproj"> <Project>{D8B3D28F-62CE-4CA7-86CE-B7EAD614A94C}</Project> <Name>IR Server Plugin Interface</Name> Modified: trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2007-09-16 18:08:48 UTC (rev 934) +++ trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2007-09-18 06:38:59 UTC (rev 935) @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Net; +using System.Net.Sockets; using System.Reflection; using System.Text; using System.Threading; @@ -11,8 +13,8 @@ using Microsoft.Win32; using Microsoft.Win32.SafeHandles; -using NamedPipes; using IRServerPluginInterface; +using IrssComms; using IrssUtils; namespace IRServer @@ -54,15 +56,17 @@ NotifyIcon _notifyIcon; - List<Client> _registeredClients; - List<Client> _registeredRepeaters; + List<ClientManager> _registeredClients; + List<ClientManager> _registeredRepeaters; - MessageQueue _messageQueue; + Server _server = null; + Client _client = null; + int _serverPort = 24000; + IRServerMode _mode; string _hostComputer; - string _localPipeName = String.Empty; bool _registered = false; // Used for relay and repeater modes. string _pluginNameReceive = String.Empty; @@ -79,8 +83,6 @@ public IRServer() { - _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); - // Setup taskbar icon _notifyIcon = new NotifyIcon(); _notifyIcon.ContextMenuStrip = new ContextMenuStrip(); @@ -140,24 +142,16 @@ else { _pluginTransmit = Program.GetPlugin(_pluginNameTransmit); - } - + } } - _messageQueue.Start(); - switch (_mode) { case IRServerMode.ServerMode: { - // Initialize registered client lists ... - _registeredClients = new List<Client>(); - _registeredRepeaters = new List<Client>(); + StartServer(); - // Start server pipe - PipeAccess.StartServer(Common.ServerPipeName, new PipeMessageHandler(_messageQueue.Enqueue)); - - IrssLog.Info("Server Mode: \\\\" + Environment.MachineName + "\\pipe\\" + Common.ServerPipeName); + IrssLog.Info("Started in Server Mode"); break; } @@ -256,7 +250,7 @@ if (_mode == IRServerMode.ServerMode) { - PipeMessage message = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.ServerShutdown, PipeMessageFlags.Notify); + IrssMessage message = new IrssMessage(MessageType.ServerShutdown, MessageFlags.Notify); SendToAll(message); } @@ -292,16 +286,13 @@ IrssLog.Error(ex.ToString()); } - _messageQueue.Stop(); - // Stop Server try { switch (_mode) { case IRServerMode.ServerMode: - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); + StopServer(); break; case IRServerMode.RelayMode: @@ -360,117 +351,137 @@ _inConfiguration = false; } - bool StartRelay() + void StartServer() { - bool retry = false; - int pipeNumber = 1; - string localPipeTest; + if (_server != null) + return; - try + // Initialize registered client lists ... + _registeredClients = new List<ClientManager>(); + _registeredRepeaters = new List<ClientManager>(); + + ServerMessageSink sink = new ServerMessageSink(ServerReceivedMessage); + _server = new Server(_serverPort, sink); + + _server.Start(); + } + void StopServer() + { + if (_server == null) + return; + + _server.Stop(); + _server = null; + + _registeredClients.Clear(); + ... [truncated message content] |