From: <an...@us...> - 2007-09-15 16:36:51
|
Revision: 928 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=928&view=rev Author: and-81 Date: 2007-09-15 09:36:50 -0700 (Sat, 15 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.Designer.cs trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs trunk/plugins/IR Server Suite/Applications/IR Server/Config.cs trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs trunk/plugins/IR Server Suite/Applications/Translator/Program.cs trunk/plugins/IR Server Suite/Applications/Tray Launcher/Tray.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 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/IrssUtils/Common.cs trunk/plugins/IR Server Suite/Common/IrssUtils/IrssUtils.csproj trunk/plugins/IR Server Suite/IR Server Suite.sln trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MPBlastZonePlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MappedKeyCode.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/TV2BlasterPlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/TV3BlasterPlugin.cs Added Paths: ----------- trunk/plugins/IR Server Suite/Common/IrssComms/ 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/Message.cs trunk/plugins/IR Server Suite/Common/IrssComms/Properties/ trunk/plugins/IR Server Suite/Common/IrssComms/Properties/AssemblyInfo.cs trunk/plugins/IR Server Suite/Common/IrssComms/Server.cs 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-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj 2007-09-15 16:36:50 UTC (rev 928) @@ -81,6 +81,14 @@ <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> Modified: trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.Designer.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.Designer.cs 2007-09-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.Designer.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -37,11 +37,7 @@ this.buttonDisconnect = new System.Windows.Forms.Button(); this.buttonShutdownServer = new System.Windows.Forms.Button(); this.listBoxStatus = new System.Windows.Forms.ListBox(); - this.buttonCrash = new System.Windows.Forms.Button(); this.buttonPing = new System.Windows.Forms.Button(); - this.groupBoxGenerateMessage = new System.Windows.Forms.GroupBox(); - this.textBoxCustom = new System.Windows.Forms.TextBox(); - this.buttonSendCustom = new System.Windows.Forms.Button(); this.groupBoxStatus = new System.Windows.Forms.GroupBox(); this.groupBoxRemoteButton = new System.Windows.Forms.GroupBox(); this.labelCustomButton = new System.Windows.Forms.Label(); @@ -55,7 +51,6 @@ this.toolTips = new System.Windows.Forms.ToolTip(this.components); this.buttonIRBlastAutoTest = new System.Windows.Forms.Button(); this.buttonHelp = new System.Windows.Forms.Button(); - this.groupBoxGenerateMessage.SuspendLayout(); this.groupBoxStatus.SuspendLayout(); this.groupBoxRemoteButton.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownButton)).BeginInit(); @@ -65,7 +60,7 @@ // // buttonBlast // - this.buttonBlast.Location = new System.Drawing.Point(8, 48); + this.buttonBlast.Location = new System.Drawing.Point(80, 16); this.buttonBlast.Name = "buttonBlast"; this.buttonBlast.Size = new System.Drawing.Size(64, 24); this.buttonBlast.TabIndex = 1; @@ -122,12 +117,12 @@ // buttonShutdownServer // this.buttonShutdownServer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonShutdownServer.Location = new System.Drawing.Point(296, 48); + this.buttonShutdownServer.Location = new System.Drawing.Point(368, 16); this.buttonShutdownServer.Name = "buttonShutdownServer"; this.buttonShutdownServer.Size = new System.Drawing.Size(64, 24); this.buttonShutdownServer.TabIndex = 4; this.buttonShutdownServer.Text = "Shutdown"; - this.toolTips.SetToolTip(this.buttonShutdownServer, "Shutdown server"); + this.toolTips.SetToolTip(this.buttonShutdownServer, "Shutdown the server"); this.buttonShutdownServer.UseVisualStyleBackColor = true; this.buttonShutdownServer.Click += new System.EventHandler(this.buttonShutdownServer_Click); // @@ -142,26 +137,14 @@ this.listBoxStatus.Location = new System.Drawing.Point(8, 16); this.listBoxStatus.Name = "listBoxStatus"; this.listBoxStatus.ScrollAlwaysVisible = true; - this.listBoxStatus.Size = new System.Drawing.Size(424, 192); + this.listBoxStatus.Size = new System.Drawing.Size(424, 185); this.listBoxStatus.TabIndex = 0; this.toolTips.SetToolTip(this.listBoxStatus, "Status messages"); // - // buttonCrash - // - this.buttonCrash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCrash.Location = new System.Drawing.Point(368, 48); - this.buttonCrash.Name = "buttonCrash"; - this.buttonCrash.Size = new System.Drawing.Size(64, 24); - this.buttonCrash.TabIndex = 5; - this.buttonCrash.Text = "Crash"; - this.toolTips.SetToolTip(this.buttonCrash, "Crash this program"); - this.buttonCrash.UseVisualStyleBackColor = true; - this.buttonCrash.Click += new System.EventHandler(this.buttonCrash_Click); - // // buttonPing // this.buttonPing.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonPing.Location = new System.Drawing.Point(368, 16); + this.buttonPing.Location = new System.Drawing.Point(296, 16); this.buttonPing.Name = "buttonPing"; this.buttonPing.Size = new System.Drawing.Size(64, 24); this.buttonPing.TabIndex = 3; @@ -170,53 +153,16 @@ this.buttonPing.UseVisualStyleBackColor = true; this.buttonPing.Click += new System.EventHandler(this.buttonPing_Click); // - // groupBoxGenerateMessage - // - this.groupBoxGenerateMessage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.groupBoxGenerateMessage.Controls.Add(this.textBoxCustom); - this.groupBoxGenerateMessage.Controls.Add(this.buttonSendCustom); - this.groupBoxGenerateMessage.Location = new System.Drawing.Point(8, 224); - this.groupBoxGenerateMessage.Name = "groupBoxGenerateMessage"; - this.groupBoxGenerateMessage.Size = new System.Drawing.Size(440, 80); - this.groupBoxGenerateMessage.TabIndex = 3; - this.groupBoxGenerateMessage.TabStop = false; - this.groupBoxGenerateMessage.Text = "Generate message"; - // - // textBoxCustom - // - this.textBoxCustom.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBoxCustom.Location = new System.Drawing.Point(8, 16); - this.textBoxCustom.Multiline = true; - this.textBoxCustom.Name = "textBoxCustom"; - this.textBoxCustom.Size = new System.Drawing.Size(352, 56); - this.textBoxCustom.TabIndex = 0; - this.toolTips.SetToolTip(this.textBoxCustom, "Create a custom message to send to the server"); - // - // buttonSendCustom - // - this.buttonSendCustom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonSendCustom.Location = new System.Drawing.Point(376, 48); - this.buttonSendCustom.Name = "buttonSendCustom"; - this.buttonSendCustom.Size = new System.Drawing.Size(56, 24); - this.buttonSendCustom.TabIndex = 1; - this.buttonSendCustom.Text = "Send"; - this.toolTips.SetToolTip(this.buttonSendCustom, "Send custom message to server"); - this.buttonSendCustom.UseVisualStyleBackColor = true; - this.buttonSendCustom.Click += new System.EventHandler(this.buttonSendCustom_Click); - // // groupBoxStatus // this.groupBoxStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBoxStatus.Controls.Add(this.listBoxStatus); - this.groupBoxStatus.Location = new System.Drawing.Point(8, 312); + this.groupBoxStatus.Location = new System.Drawing.Point(8, 192); this.groupBoxStatus.Name = "groupBoxStatus"; this.groupBoxStatus.Size = new System.Drawing.Size(440, 216); - this.groupBoxStatus.TabIndex = 4; + this.groupBoxStatus.TabIndex = 3; this.groupBoxStatus.TabStop = false; this.groupBoxStatus.Text = "Status"; // @@ -228,7 +174,7 @@ this.groupBoxRemoteButton.Controls.Add(this.numericUpDownButton); this.groupBoxRemoteButton.Controls.Add(this.comboBoxRemoteButtons); this.groupBoxRemoteButton.Controls.Add(this.buttonSendRemoteButton); - this.groupBoxRemoteButton.Location = new System.Drawing.Point(8, 168); + this.groupBoxRemoteButton.Location = new System.Drawing.Point(8, 136); this.groupBoxRemoteButton.Name = "groupBoxRemoteButton"; this.groupBoxRemoteButton.Size = new System.Drawing.Size(440, 48); this.groupBoxRemoteButton.TabIndex = 2; @@ -310,21 +256,20 @@ this.comboBoxComputer.Location = new System.Drawing.Point(8, 32); this.comboBoxComputer.Name = "comboBoxComputer"; this.comboBoxComputer.Size = new System.Drawing.Size(240, 21); - this.comboBoxComputer.TabIndex = 5; + this.comboBoxComputer.TabIndex = 1; // // groupBoxCommands // this.groupBoxCommands.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBoxCommands.Controls.Add(this.comboBoxPort); - this.groupBoxCommands.Controls.Add(this.buttonCrash); this.groupBoxCommands.Controls.Add(this.buttonBlast); this.groupBoxCommands.Controls.Add(this.buttonLearnIR); this.groupBoxCommands.Controls.Add(this.buttonShutdownServer); this.groupBoxCommands.Controls.Add(this.buttonPing); this.groupBoxCommands.Location = new System.Drawing.Point(8, 80); this.groupBoxCommands.Name = "groupBoxCommands"; - this.groupBoxCommands.Size = new System.Drawing.Size(440, 80); + this.groupBoxCommands.Size = new System.Drawing.Size(440, 48); this.groupBoxCommands.TabIndex = 1; this.groupBoxCommands.TabStop = false; this.groupBoxCommands.Text = "Commands"; @@ -333,7 +278,7 @@ // this.comboBoxPort.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxPort.FormattingEnabled = true; - this.comboBoxPort.Location = new System.Drawing.Point(80, 50); + this.comboBoxPort.Location = new System.Drawing.Point(152, 18); this.comboBoxPort.Name = "comboBoxPort"; this.comboBoxPort.Size = new System.Drawing.Size(80, 21); this.comboBoxPort.TabIndex = 2; @@ -342,10 +287,10 @@ // buttonIRBlastAutoTest // this.buttonIRBlastAutoTest.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonIRBlastAutoTest.Location = new System.Drawing.Point(336, 536); + this.buttonIRBlastAutoTest.Location = new System.Drawing.Point(336, 416); this.buttonIRBlastAutoTest.Name = "buttonIRBlastAutoTest"; this.buttonIRBlastAutoTest.Size = new System.Drawing.Size(112, 24); - this.buttonIRBlastAutoTest.TabIndex = 8; + this.buttonIRBlastAutoTest.TabIndex = 5; this.buttonIRBlastAutoTest.Text = "IRBlast Auto-Test"; this.toolTips.SetToolTip(this.buttonIRBlastAutoTest, "Runs a random number blasting test"); this.buttonIRBlastAutoTest.UseVisualStyleBackColor = true; @@ -354,10 +299,10 @@ // buttonHelp // this.buttonHelp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonHelp.Location = new System.Drawing.Point(8, 536); + this.buttonHelp.Location = new System.Drawing.Point(8, 416); this.buttonHelp.Name = "buttonHelp"; this.buttonHelp.Size = new System.Drawing.Size(56, 24); - this.buttonHelp.TabIndex = 5; + this.buttonHelp.TabIndex = 4; this.buttonHelp.Text = "Help"; this.buttonHelp.UseVisualStyleBackColor = true; this.buttonHelp.Click += new System.EventHandler(this.buttonHelp_Click); @@ -366,23 +311,20 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(456, 566); + this.ClientSize = new System.Drawing.Size(456, 446); this.Controls.Add(this.buttonIRBlastAutoTest); this.Controls.Add(this.buttonHelp); this.Controls.Add(this.groupBoxCommands); this.Controls.Add(this.groupBoxSetup); this.Controls.Add(this.groupBoxRemoteButton); this.Controls.Add(this.groupBoxStatus); - this.Controls.Add(this.groupBoxGenerateMessage); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MinimumSize = new System.Drawing.Size(464, 600); + this.MinimumSize = new System.Drawing.Size(472, 482); this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Debug Client"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); this.Load += new System.EventHandler(this.MainForm_Load); - this.groupBoxGenerateMessage.ResumeLayout(false); - this.groupBoxGenerateMessage.PerformLayout(); this.groupBoxStatus.ResumeLayout(false); this.groupBoxRemoteButton.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownButton)).EndInit(); @@ -401,11 +343,7 @@ private System.Windows.Forms.Button buttonDisconnect; private System.Windows.Forms.Button buttonShutdownServer; private System.Windows.Forms.ListBox listBoxStatus; - private System.Windows.Forms.Button buttonCrash; private System.Windows.Forms.Button buttonPing; - private System.Windows.Forms.GroupBox groupBoxGenerateMessage; - private System.Windows.Forms.TextBox textBoxCustom; - private System.Windows.Forms.Button buttonSendCustom; private System.Windows.Forms.GroupBox groupBoxStatus; private System.Windows.Forms.GroupBox groupBoxRemoteButton; private System.Windows.Forms.NumericUpDown numericUpDownButton; Modified: trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs 2007-09-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -91,6 +91,8 @@ public MainForm() { InitializeComponent(); + + _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); } #endregion @@ -103,12 +105,16 @@ #region Variables - string _serverAddress = Environment.MachineName; + MessageQueue _messageQueue; + + string _serverHost = Environment.MachineName; string _localPipeName = null; string _learnIRFilename = null; - //static bool _keepAlive = true; - static int _echoID = -1; + bool _registered = false; + bool _keepAlive = true; + int _echoID = -1; + Thread _keepAliveThread; IRServerInfo _irServerInfo = new IRServerInfo(); @@ -131,9 +137,6 @@ IrssLog.LogLevel = IrssLog.Level.Debug; IrssLog.Open(Common.FolderIrssLogs + "Debug Client.log"); - string customTemp = String.Format(Common.LocalPipeFormat, 1); - textBoxCustom.Text = String.Format("{0},{1},Register,null", customTemp, Environment.MachineName); - _AddStatusLine = new DelegateAddStatusLine(AddStatusLine); comboBoxRemoteButtons.Items.AddRange(Enum.GetNames(typeof(MceButton))); @@ -147,7 +150,7 @@ if (networkPCs != null) { comboBoxComputer.Items.AddRange(networkPCs.ToArray()); - comboBoxComputer.Text = _serverAddress; + comboBoxComputer.Text = _serverHost; } } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) @@ -172,6 +175,7 @@ case PipeMessageType.RegisterClient: if ((received.Flags & PipeMessageFlags.Success) == PipeMessageFlags.Success) { + _registered = true; _irServerInfo = IRServerInfo.FromBytes(received.DataAsBytes); comboBoxPort.Items.Clear(); comboBoxPort.Items.AddRange(_irServerInfo.Ports); @@ -179,8 +183,7 @@ } else if ((received.Flags & PipeMessageFlags.Failure) == PipeMessageFlags.Failure) { - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); + _registered = false; } return; @@ -202,8 +205,7 @@ break; case PipeMessageType.ServerShutdown: - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); + _registered = false; return; case PipeMessageType.Echo: @@ -222,48 +224,6 @@ } } - bool ConnectToServer(string server) - { - _serverAddress = server; - - bool retry = false; - int pipeNumber = 1; - string localPipeTest; - - do - { - localPipeTest = String.Format(Common.LocalPipeFormat, pipeNumber); - AddStatusLine("Trying pipe: " + localPipeTest); - listBoxStatus.Update(); - - if (PipeAccess.PipeExists(String.Format("\\\\.\\pipe\\{0}", localPipeTest))) - { - pipeNumber++; - if (pipeNumber <= Common.MaximumLocalClientCount) - { - retry = true; - } - else - { - AddStatusLine("Maximum local client limit reached"); - return false; - } - } - else - { - PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(ReceivedMessage)); - _localPipeName = localPipeTest; - retry = false; - } - } - while (retry); - - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.RegisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, message); - - return true; - } - bool LearnIR(string fileName) { try @@ -274,7 +234,7 @@ _learnIRFilename = fileName; PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.LearnIR, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, message); + PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); AddStatusLine("Learning"); } @@ -304,7 +264,7 @@ file.Close(); PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.BlastIR, PipeMessageFlags.Request, outData); - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, message); + PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); } catch (Exception ex) { @@ -321,55 +281,272 @@ this.Invoke(_AddStatusLine, new Object[] { text }); } - #region Controls + bool StartComms() + { + try + { + if (OpenLocalPipe()) + { + _messageQueue.Start(); - private void buttonConnect_Click(object sender, EventArgs e) + _keepAliveThread = new Thread(new ThreadStart(KeepAliveThread)); + _keepAliveThread.Start(); + return true; + } + } + catch (Exception ex) + { + IrssLog.Error(ex.ToString()); + } + + return false; + } + void StopComms() { + _keepAlive = false; + try { - AddStatusLine("Connect"); - listBoxStatus.Update(); + 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 { } + } + + bool OpenLocalPipe() + { + try + { + int pipeNumber = 1; + bool retry = false; + + do { - AddStatusLine("Already connected"); - return; + string localPipeTest = String.Format("irserver\\debug{0:00}", pipeNumber); + + 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)); + + _localPipeName = localPipeTest; + retry = false; + } } + while (retry); - ConnectToServer(comboBoxComputer.Text); + return true; } catch (Exception ex) { - AddStatusLine(ex.Message); + IrssLog.Error(ex.ToString()); + return false; + } + } - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); + 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) + { + return false; + } + catch (Exception ex) + { + IrssLog.Error(ex.ToString()); + return false; + } } - private void buttonDisconnect_Click(object sender, EventArgs e) + + void KeepAliveThread() { - AddStatusLine("Disconnect"); + Random random = new Random((int)DateTime.Now.Ticks); + bool reconnect; + int attempt; - if (!PipeAccess.ServerRunning) + _registered = false; + _keepAlive = true; + while (_keepAlive) { - AddStatusLine(" - Not connected"); - return; + 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 + } + } + + + + #region Controls + + private void buttonConnect_Click(object sender, EventArgs e) + { try { - PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.UnregisterClient, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, message); + AddStatusLine("Connect"); + listBoxStatus.Update(); + + if (PipeAccess.ServerRunning) + { + AddStatusLine("Already connected"); + return; + } + + _serverHost = comboBoxComputer.Text; + + StartComms(); } catch (Exception ex) { AddStatusLine(ex.Message); } + } + private void buttonDisconnect_Click(object sender, EventArgs e) + { + AddStatusLine("Disconnect"); try { - if (PipeAccess.ServerRunning) - PipeAccess.StopServer(); + if (!PipeAccess.ServerRunning) + { + AddStatusLine(" - Not connected"); + return; + } + + StopComms(); } catch (Exception ex) { @@ -427,17 +604,13 @@ try { PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.ServerShutdown, PipeMessageFlags.Request); - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, message); + PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); } catch (Exception ex) { AddStatusLine(ex.Message); } } - private void buttonCrash_Click(object sender, EventArgs e) - { - throw new System.InvalidOperationException("User initiated exception thrown"); - } private void buttonPing_Click(object sender, EventArgs e) { AddStatusLine("Ping Server"); @@ -451,7 +624,7 @@ try { PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.Ping, PipeMessageFlags.Request, BitConverter.GetBytes(24)); - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, message); + PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); } catch (Exception ex) { @@ -459,27 +632,6 @@ } } - private void buttonSendCustom_Click(object sender, EventArgs e) - { - try - { - AddStatusLine("Sending custom message to server ..."); - - if (PipeMessage.FromString(textBoxCustom.Text) == null) - AddStatusLine("Warning: The specified custom message is not a valid message structure"); - - PipeMessage customMessage = PipeMessage.FromString(textBoxCustom.Text); - - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, customMessage); - - AddStatusLine("Custom message sent"); - } - catch (Exception ex) - { - AddStatusLine(ex.Message); - } - } - private void comboBoxRemoteButtons_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxRemoteButtons.SelectedItem.ToString() == "Custom") @@ -514,7 +666,7 @@ BitConverter.GetBytes(0).CopyTo(data, 4); PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.ForwardRemoteEvent, PipeMessageFlags.Notify, data); - PipeAccess.SendMessage(Common.ServerPipeName, _serverAddress, message); + PipeAccess.SendMessage(Common.ServerPipeName, _serverHost, message); } catch (Exception ex) { @@ -536,6 +688,8 @@ #endregion Controls + + Thread AutoTest; private void buttonAutoTest_Click(object sender, EventArgs e) Modified: trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs 2007-09-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -19,6 +19,8 @@ #region Variables + static MessageQueue _messageQueue; + static bool _registered = false; static bool _keepAlive = true; static int _echoID = -1; @@ -79,6 +81,8 @@ } } + _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); + if (String.IsNullOrEmpty(_serverHost) || irCommands.Count == 0) { Console.WriteLine("Malformed command line parameters ..."); @@ -220,6 +224,8 @@ { if (OpenLocalPipe()) { + _messageQueue.Start(); + _keepAliveThread = new Thread(new ThreadStart(KeepAliveThread)); _keepAliveThread.Start(); return true; @@ -255,6 +261,8 @@ } catch { } + _messageQueue.Stop(); + try { if (PipeAccess.ServerRunning) @@ -272,9 +280,9 @@ do { - string localPipeTest = String.Format(Common.LocalPipeFormat, pipeNumber); + string localPipeTest = String.Format("irserver\\blast{0:00}", pipeNumber); - if (PipeAccess.PipeExists(String.Format("\\\\.\\pipe\\{0}", localPipeTest))) + if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) { if (++pipeNumber <= Common.MaximumLocalClientCount) retry = true; @@ -283,7 +291,7 @@ } else { - if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(ReceivedMessage))) + if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(_messageQueue.Enqueue))) throw new Exception(String.Format("Failed to start local pipe server \"{0}\"", localPipeTest)); _localPipeName = localPipeTest; 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-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -20,6 +20,8 @@ #region Variables + static MessageQueue _messageQueue; + static bool _registered = false; static bool _keepAlive = true; static int _echoID = -1; @@ -78,6 +80,8 @@ } } + _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); + if (String.IsNullOrEmpty(_serverHost) || irCommands.Count == 0) { Console.WriteLine("Malformed command line parameters ..."); @@ -182,6 +186,8 @@ { if (OpenLocalPipe()) { + _messageQueue.Start(); + _keepAliveThread = new Thread(new ThreadStart(KeepAliveThread)); _keepAliveThread.Start(); return true; @@ -217,6 +223,8 @@ } catch { } + _messageQueue.Stop(); + try { if (PipeAccess.ServerRunning) @@ -234,9 +242,9 @@ do { - string localPipeTest = String.Format(Common.LocalPipeFormat, pipeNumber); + string localPipeTest = String.Format("irserver\\blast{0:00}", pipeNumber); - if (PipeAccess.PipeExists(String.Format("\\\\.\\pipe\\{0}", localPipeTest))) + if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) { if (++pipeNumber <= Common.MaximumLocalClientCount) retry = true; @@ -245,7 +253,7 @@ } else { - if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(ReceivedMessage))) + if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(_messageQueue.Enqueue))) throw new Exception(String.Format("Failed to start local pipe server \"{0}\"", localPipeTest)); _localPipeName = localPipeTest; Modified: trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs 2007-09-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/IR Server/Client.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -15,6 +15,11 @@ Server = server; } + public override string ToString() + { + return String.Format("({0}, {1})", Server, Pipe); + } + } } Modified: trunk/plugins/IR Server Suite/Applications/IR Server/Config.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/Config.cs 2007-09-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/IR Server/Config.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -336,7 +336,6 @@ #endregion Controls - } } Modified: trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2007-09-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -79,7 +79,7 @@ public IRServer() { - _messageQueue = new MessageQueue(new MessageQueueSink(HandlePipeMessage)); + _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); // Setup taskbar icon _notifyIcon = new NotifyIcon(); @@ -256,7 +256,7 @@ if (_mode == IRServerMode.ServerMode) { - PipeMessage message = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.ServerShutdown, PipeMessageFlags.Notify); + PipeMessage message = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.ServerShutdown, PipeMessageFlags.Notify); SendToAll(message); } @@ -370,9 +370,9 @@ { do { - localPipeTest = String.Format(Common.LocalPipeFormat, pipeNumber); + localPipeTest = String.Format("irserver\\relay{0:00}", pipeNumber); - if (PipeAccess.PipeExists(String.Format("\\\\.\\pipe\\{0}", localPipeTest))) + if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) { pipeNumber++; if (pipeNumber <= Common.MaximumLocalClientCount) @@ -437,9 +437,9 @@ { do { - localPipeTest = String.Format(Common.LocalPipeFormat, pipeNumber); + localPipeTest = String.Format("irserver\\repeat{0:00}", pipeNumber); - if (PipeAccess.PipeExists(String.Format("\\\\.\\pipe\\{0}", localPipeTest))) + if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) { pipeNumber++; if (pipeNumber <= Common.MaximumLocalClientCount) @@ -504,7 +504,7 @@ { case IRServerMode.ServerMode: { - PipeMessage message = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.RemoteEvent, PipeMessageFlags.Notify, bytes); + PipeMessage message = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.RemoteEvent, PipeMessageFlags.Notify, bytes); SendToAll(message); break; } @@ -512,7 +512,7 @@ case IRServerMode.RelayMode: { PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.ForwardRemoteEvent, PipeMessageFlags.Request, bytes); - SendTo(Common.ServerPipeName, _hostComputer, message); + SendTo(new Client(Common.ServerPipeName, _hostComputer), message); break; } @@ -536,7 +536,7 @@ { case IRServerMode.ServerMode: { - PipeMessage message = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.KeyboardEvent, PipeMessageFlags.Notify, bytes); + PipeMessage message = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.KeyboardEvent, PipeMessageFlags.Notify, bytes); SendToAll(message); break; } @@ -544,7 +544,7 @@ case IRServerMode.RelayMode: { PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.ForwardKeyboardEvent, PipeMessageFlags.Request, bytes); - SendTo(Common.ServerPipeName, _hostComputer, message); + SendTo(new Client(Common.ServerPipeName, _hostComputer), message); break; } @@ -569,7 +569,7 @@ { case IRServerMode.ServerMode: { - PipeMessage message = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.MouseEvent, PipeMessageFlags.Notify, bytes); + PipeMessage message = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.MouseEvent, PipeMessageFlags.Notify, bytes); SendToAll(message); break; } @@ -577,7 +577,7 @@ case IRServerMode.RelayMode: { PipeMessage message = new PipeMessage(Environment.MachineName, _localPipeName, PipeMessageType.ForwardMouseEvent, PipeMessageFlags.Request, bytes); - SendTo(Common.ServerPipeName, _hostComputer, message); + SendTo(new Client(Common.ServerPipeName, _hostComputer), message); break; } @@ -620,7 +620,7 @@ // Inform clients ... if (_mode == IRServerMode.ServerMode) { - PipeMessage message = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.ServerShutdown, PipeMessageFlags.Notify); + PipeMessage message = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.ServerShutdown, PipeMessageFlags.Notify); SendToAll(message); } break; @@ -656,13 +656,13 @@ // while enumerating it. foreach (Client client in unregister) { - UnregisterClient(client.Pipe, client.Server); + UnregisterClient(client); } } } - void SendToAllExcept(string exceptPipe, string exceptServer, PipeMessage message) + void SendToAllExcept(Client exceptClient, PipeMessage message) { - IrssLog.Debug("SendToAllExcept({0}, {1}, {2})", exceptPipe, exceptServer, message); + IrssLog.Debug("SendToAllExcept({0}, {1})", exceptClient.ToString(), message); List<Client> unregister = new List<Client>(); @@ -670,11 +670,11 @@ { foreach (Client client in _registeredClients) { + if (client.Server.Equals(exceptClient.Server, StringComparison.InvariantCultureIgnoreCase) && client.Pipe.Equals(exceptClient.Pipe, StringComparison.InvariantCultureIgnoreCase)) + continue; + try { - if (client.Pipe == exceptPipe && client.Server == exceptServer) - continue; - PipeAccess.SendMessage(client.Pipe, client.Server, message); } catch (Exception ex) @@ -691,24 +691,24 @@ // while enumerating it. foreach (Client client in unregister) { - UnregisterClient(client.Pipe, client.Server); + UnregisterClient(client); } } } - void SendTo(string pipe, string server, PipeMessage message) + void SendTo(Client receiver, PipeMessage message) { - IrssLog.Debug("SendTo({0}, {1}, {2})", pipe, server, message); + IrssLog.Debug("SendTo({0}, {1})", receiver.ToString(), message); try { - PipeAccess.SendMessage(pipe, server, message); + PipeAccess.SendMessage(receiver.Pipe, receiver.Server, message); } catch (Exception ex) { - IrssLog.Warn("Failed to send message to client ({0}\\{1}): {2}", server, pipe, ex.Message); + IrssLog.Warn("Failed to send message to client ({0}): {1}", receiver.ToString(), ex.Message); // If a message doesn't get through then unregister that client - UnregisterClient(pipe, server); + UnregisterClient(receiver); } } void SendToRepeaters(PipeMessage message) @@ -739,54 +739,34 @@ // while enumerating it. foreach (Client client in unregister) { - UnregisterRepeater(client.Pipe, client.Server); + UnregisterRepeater(client); } } } - bool RegisterClient(string pipe, string server) + bool RegisterClient(Client addClient) { - if (String.IsNullOrEmpty(pipe) || String.IsNullOrEmpty(server)) - return false; - if (_mode != IRServerMode.ServerMode) return false; - bool alreadyRegistered = false; - lock (_registeredClients) { - foreach (Client client in _registeredClients) - { - if (client.Pipe == pipe && client.Server == server) - { - alreadyRegistered = true; - break; - } - } + if (_registeredClients.Contains(addClient)) + return true; + else if (_registeredClients.Count >= Common.MaximumLocalClientCount) + return false; - if (!alreadyRegistered) - { - if (_registeredClients.Count >= Common.MaximumLocalClientCount) - return false; - else - _registeredClients.Add(new Client(pipe, server)); - } + _registeredClients.Add(addClient); } - IrssLog.Info("Registered: \\\\{0}\\pipe\\{1}", server, pipe); + IrssLog.Info("Registered: {0}", addClient.ToString()); return true; } - bool UnregisterClient(string pipe, string server) + bool UnregisterClient(Client removeClient) { - if (String.IsNullOrEmpty(pipe) || String.IsNullOrEmpty(server)) - return false; - if (_mode != IRServerMode.ServerMode) return false; - Client removeClient = new Client(pipe, server); - lock (_registeredClients) { if (!_registeredClients.Contains(removeClient)) @@ -795,62 +775,42 @@ _registeredClients.Remove(removeClient); } - IrssLog.Info("Unregistered: \\\\{0}\\pipe\\{1}", server, pipe); + IrssLog.Info("Unregistered: {0}", removeClient.ToString()); return true; } - bool RegisterRepeater(string pipe, string server) + bool RegisterRepeater(Client addRepeater) { - if (String.IsNullOrEmpty(pipe) || String.IsNullOrEmpty(server)) - return false; - if (_mode != IRServerMode.ServerMode) return false; - bool alreadyRegistered = false; - lock (_registeredRepeaters) { - foreach (Client client in _registeredRepeaters) - { - if (client.Pipe == pipe && client.Server == server) - { - alreadyRegistered = true; - break; - } - } + if (_registeredRepeaters.Contains(addRepeater)) + return true; + else if (_registeredRepeaters.Count >= Common.MaximumLocalClientCount) + return false; - if (!alreadyRegistered) - { - if (_registeredRepeaters.Count >= Common.MaximumLocalClientCount) - return false; - else - _registeredRepeaters.Add(new Client(pipe, server)); - } + _registeredRepeaters.Add(addRepeater); } - IrssLog.Info("Registered Repeater: \\\\{0}\\pipe\\{1}", server, pipe); + IrssLog.Info("Registered Repeater: {0}", addRepeater.ToString()); return true; } - bool UnregisterRepeater(string pipe, string server) + bool UnregisterRepeater(Client removeRepeater) { - if (String.IsNullOrEmpty(pipe) || String.IsNullOrEmpty(server)) - return false; - if (_mode != IRServerMode.RepeaterMode) return false; - Client removeClient = new Client(pipe, server); - lock (_registeredRepeaters) { - if (!_registeredRepeaters.Contains(removeClient)) + if (!_registeredRepeaters.Contains(removeRepeater)) return false; - _registeredRepeaters.Remove(removeClient); + _registeredRepeaters.Remove(removeRepeater); } - IrssLog.Info("Unregistered Repeater: \\\\{0}\\pipe\\{1}", server, pipe); + IrssLog.Info("Unregistered Repeater: {0}", removeRepeater.ToString()); return true; } @@ -927,17 +887,20 @@ return status; } - void HandlePipeMessage(string message) + void ReceivedMessage(string message) { PipeMessage received = PipeMessage.FromString(message); + if (received == null) { IrssLog.Warn("Invalid message received: {0}", message); return; } - IrssLog.Debug("Message received from client \\\\{0}\\pipe\\{1} = {2}", received.FromServer, received.FromPipe, message); + Client receivedFromClient = new Client(received.FromPipe, received.FromServer); + IrssLog.Debug("Message received from client {0} = {1}", receivedFromClient.ToString(), message); + try { switch (received.Type) @@ -945,45 +908,45 @@ case PipeMessageType.ForwardRemoteEvent: if (_mode == IRServerMode.RelayMode) { - PipeMessage forward = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.ForwardRemoteEvent, PipeMessageFlags.Request, received.DataAsBytes); - SendTo(Common.ServerPipeName, _hostComputer, forward); + PipeMessage forward = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.ForwardRemoteEvent, PipeMessageFlags.Request, received.DataAsBytes); + SendTo(new Client(Common.ServerPipeName, _hostComputer), forward); } else { - PipeMessage forward = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.RemoteEvent, PipeMessageFlags.Notify, received.DataAsBytes); - SendToAllExcept(received.FromPipe, received.FromServer, forward); + PipeMessage forward = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.RemoteEvent, PipeMessageFlags.Notify, received.DataAsBytes); + SendToAllExcept(receivedFromClient, forward); } break; case PipeMessageType.ForwardKeyboardEvent: if (_mode == IRServerMode.RelayMode) { - PipeMessage forward = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.ForwardKeyboardEvent, PipeMessageFlags.Request, received.DataAsBytes); - SendTo(Common.ServerPipeName, _hostComputer, forward); + PipeMessage forward = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.ForwardKeyboardEvent, PipeMessageFlags.Request, received.DataAsBytes); + SendTo(new Client(Common.ServerPipeName, _hostComputer), forward); } else { - PipeMessage forward = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.KeyboardEvent, PipeMessageFlags.Notify, received.DataAsBytes); - SendToAllExcept(received.FromPipe, received.FromServer, forward); + PipeMessage forward = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.KeyboardEvent, PipeMessageFlags.Notify, received.DataAsBytes); + SendToAllExcept(receivedFromClient, forward); } break; case PipeMessageType.ForwardMouseEvent: if (_mode == IRServerMode.RelayMode) { - PipeMessage forward = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.ForwardMouseEvent, PipeMessageFlags.Request, received.DataAsBytes); - SendTo(Common.ServerPipeName, _hostComputer, forward); + PipeMessage forward = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.ForwardMouseEvent, PipeMessageFlags.Request, received.DataAsBytes); + SendTo(new Client(Common.ServerPipeName, _hostComputer), forward); } else { - PipeMessage forward = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.MouseEvent, PipeMessageFlags.Notify, received.DataAsBytes); - SendToAllExcept(received.FromPipe, received.FromServer, forward); + PipeMessage forward = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.MouseEvent, PipeMessageFlags.Notify, received.DataAsBytes); + SendToAllExcept(receivedFromClient, forward); } break; case PipeMessageType.BlastIR: { - PipeMessage response = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.BlastIR, PipeMessageFlags.Response); + PipeMessage response = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.BlastIR, PipeMessageFlags.Response); if (_mode == IRServerMode.RelayMode) { @@ -1001,14 +964,14 @@ } if ((received.Flags & PipeMessageFlags.ForceNotRespond) != PipeMessageFlags.ForceNotRespond) - SendTo(received.FromPipe, received.FromServer, response); + SendTo(receivedFromClient, response); break; } case PipeMessageType.LearnIR: { - PipeMessage response = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.LearnIR, PipeMessageFlags.Response); + PipeMessage response = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.LearnIR, PipeMessageFlags.Response); if (_mode == IRServerMode.RelayMode) { @@ -1037,7 +1000,7 @@ } } - SendTo(received.FromPipe, received.FromServer, response); + SendTo(receivedFromClient, response); break; } @@ -1064,8 +1027,8 @@ case PipeMessageType.Ping: { - PipeMessage response = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.Echo, PipeMessageFlags.Response, received.DataAsBytes); - SendTo(received.FromPipe, received.FromServer, response); + PipeMessage response = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.Echo, PipeMessageFlags.Response, received.DataAsBytes); + SendTo(receivedFromClient, response); break; } @@ -1074,9 +1037,9 @@ { if ((received.Flags & PipeMessageFlags.Request) == PipeMessageFlags.Request) { - PipeMessage response = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.RegisterClient, PipeMessageFlags.Response); + PipeMessage response = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.RegisterClient, PipeMessageFlags.Response); - if (RegisterClient(received.FromPipe, received.FromServer)) + if (RegisterClient(receivedFromClient)) { IRServerInfo irServerInfo = new IRServerInfo(); @@ -1098,7 +1061,7 @@ response.Flags |= PipeMessageFlags.Failure; } - SendTo(received.FromPipe, received.FromServer, response); + SendTo(receivedFromClient, response); } } else if ((received.Flags & PipeMessageFlags.Response) == PipeMessageFlags.Response) @@ -1117,32 +1080,32 @@ break; case PipeMessageType.UnregisterClient: - UnregisterClient(received.FromPipe, received.FromServer); + UnregisterClient(receivedFromClient); break; case PipeMessageType.RegisterRepeater: { - PipeMessage response = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.RegisterRepeater, PipeMessageFlags.Response); - - if (RegisterRepeater(received.FromPipe, received.FromServer)) + PipeMessage response = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.RegisterRepeater, PipeMessageFlags.Response); + + if (RegisterRepeater(receivedFromClient)) response.Flags |= PipeMessageFlags.Success; else response.Flags |= PipeMessageFlags.Failure; - SendTo(received.FromPipe, received.FromServer, response); + SendTo(receivedFromClient, response); break; } case PipeMessageType.UnregisterRepeater: - UnregisterRepeater(received.FromPipe, received.FromServer); + UnregisterRepeater(receivedFromClient); break; } } catch (Exception ex) { IrssLog.Error(ex.ToString()); - PipeMessage response = new PipeMessage(Common.ServerPipeName, Environment.MachineName, PipeMessageType.Error, PipeMessageFlags.Notify, ex.Message); - SendTo(received.FromPipe, received.FromServer, response); + PipeMessage response = new PipeMessage(Environment.MachineName, Common.ServerPipeName, PipeMessageType.Error, PipeMessageFlags.Notify, ex.Message); + SendTo(receivedFromClient, response); } } Modified: trunk/plugins/IR Server Suite/Applications/Translator/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Program.cs 2007-09-15 16:30:02 UTC (rev 927) +++ trunk/plugins/IR Server Suite/Applications/Translator/Program.cs 2007-09-15 16:36:50 UTC (rev 928) @@ -31,6 +31,8 @@ #region Variables + static MessageQueue _messageQueue; + static Configuration _config; static string _localPipeName = String.Empty; @@ -141,6 +143,8 @@ _focusWatcher.Start(); */ + _messageQueue = new MessageQueue(new MessageQueueSink(ReceivedMessage)); + // Start server communications ... if (StartComms()) { @@ -660,6 +664,8 @@ { _notifyIcon.Visible = true; + _messageQueue.Start(); + _keepAliveThread = new Thread(new ThreadStart(KeepAliveThread)); _keepAliveThread.Start(); @@ -698,6 +704,8 @@ } catch { } + _messageQueue.Stop(); + try { if (PipeAccess.ServerRunning) @@ -715,9 +723,9 @@ do { - string localPipeTest = String.Format(Common.LocalPipeFormat, pipeNumber); + string localPipeTest = String.Format("irserver\\trans{0:00}", pipeNumber); - if (PipeAccess.PipeExists(String.Format("\\\\.\\pipe\\{0}", localPipeTest))) + if (PipeAccess.PipeExists(Common.LocalPipePrefix + localPipeTest)) { if (++pipeNumber <= Common.MaximumLocalClientCount) retry = true; @@ -726,7 +734,7 @@ } else { - if (!PipeAccess.StartServer(localPipeTest, new PipeMessageHandler(ReceivedMe... [truncated message content] |