Example #1
0
 public void Send(MPDCommandList commands)
 {
     if (m_SessionThread != null || m_State == SessionState.Connected)
     {
         m_SessionThread.Send(commands);
     }
 }
Example #2
0
        private void ExecuteCommands()
        {
            bool terminating = Terminating;

            while (!terminating)
            {
                MPDSendable sendable = null;

                lock (m_Lock)
                {
                    // Avoid using the property as it might break
                    // threading. TODO: this could be neatly wrapped into
                    // a method that returns a command or null if
                    // terminating, but it's just cosmetics.
                    terminating = m_Terminating;

                    if (m_CommandQueue.Count > 0)
                    {
                        sendable = m_CommandQueue.Dequeue();
                        m_ThreadEvent.Reset();
                    }
                }

                if (!terminating)
                {
                    if (sendable == null)
                    {
                        m_ThreadEvent.WaitOne();
                    }
                    else
                    {
                        if (sendable is MPDCommand)
                        {
                            MPDCommand command = sendable as MPDCommand;
                            UpdateThreadMessage(command);
                            bool optimizeOut = false;
                            optimizeOut = optimizeOut || (command.Op == "status" && m_StatusUpdateEnqueued);
                            optimizeOut = optimizeOut || (command.Op == "stats" && m_StatsUpdateEnqueued);

                            if (!optimizeOut)
                            {
                                SendCommand(command.FullSyntax);
                                ReceiveResponse(command);
                            }
                        }
                        else if (sendable is MPDCommandList)
                        {
                            MPDCommandList commands = sendable as MPDCommandList;

                            if (commands.Nonempty)
                            {
                                SendCommand(sendable.FullSyntax);
                                ReceiveResponse(sendable);
                            }
                        }
                    }
                }
            }
        }