public void Send(MPDCommand command) { if (m_SessionThread != null || m_State == SessionState.Connected) { m_SessionThread.Send(command); } }
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); } } } } } }
public void Send(MPDCommand command) { lock (m_Lock) { m_CommandQueue.Enqueue(command); m_ThreadEvent.Set(); } }
private void UpdateThreadMessage(MPDCommand command) { string message = ""; if (command.Op == "listallinfo") { message = "Querying music database."; } else if (command.Op == "listplaylistinfo") { message = "Querying playlist " + command.Argument1 + "..."; } else if (command.Op == "search") { message = "Searching for " + command.Argument2 + "..."; } m_Parent.OnActivityChanged(message); }
private void Send(MPDCommand command) { if (m_SessionThread != null || m_State == SessionState.Connected) { m_SessionThread.Send(command); } }
private void ReceiveResponse(MPDSendable sendable) { // TODO: if the server is really slow (Mopidy on an RPI for // example), we can get stuck here during shutdown. MPDResponseLine statusLine = GetResponseLine(); while (statusLine != null && !statusLine.IsStatus) { m_DataModel.NetworkLog?.LogResponseVerbose(statusLine); if (statusLine.Key != MPDResponseLine.Keyword.Unknown) { m_CurrentResponse.Add(statusLine); } statusLine = GetResponseLine(); } if (statusLine != null) { m_DataModel.NetworkLog?.LogResponseCompact(statusLine); if (statusLine.Key == MPDResponseLine.Keyword.ACK) { m_Parent.OnErrorMessageChanged(statusLine.Value); } else if (sendable is MPDCommand) { MPDCommand command = sendable as MPDCommand; if (command.Op == "currentsong") { ParseSongList(); Callback(m_DataModel.CurrentSong.OnCurrentSongResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "listallinfo") { ParseSongList(); Callback(m_DataModel.Database.OnListAllInfoResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "listplaylistinfo") { ParseSongList(); Callback(m_DataModel.SavedPlaylists.OnListPlaylistInfoResponseReceived, command.Argument1); m_CurrentSongList.Clear(); } else if (command.Op == "lsinfo") { Callback(m_DataModel.SavedPlaylists.OnLsInfoResponseReceived); } else if (command.Op == "outputs") { Callback(m_DataModel.OutputCollection.OnOutputsResponseReceived); } else if (command.Op == "playlistinfo") { ParseSongList(); Callback(m_DataModel.Playlist.OnPlaylistInfoResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "search") { ParseSongList(); Callback(m_DataModel.AdvancedSearch.OnSearchResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "stats") { Callback(m_DataModel.ServerStatus.OnStatsResponseReceived); } else if (command.Op == "status") { Callback(m_DataModel.ServerStatus.OnStatusResponseReceived); } } } m_CurrentResponse.Clear(); }
private void ReceiveResponse(MPDCommand command) { MPDResponseLine statusLine = GetResponseLine(); while (statusLine != null && !statusLine.IsStatus) { if (statusLine.Key != MPDResponseLine.Keyword.Unknown) { m_CurrentResponse.Add(statusLine); } statusLine = GetResponseLine(); } if (statusLine != null) { if (statusLine.Key == MPDResponseLine.Keyword.ACK) { if (command.Op == "listallinfo" && statusLine.Value.Contains("Not implemented")) { // TODO: this is a workaround for Mopidy not implementing listallinfo. // It can hopefully removed later. Send(new MPDCommand()); } else { m_Parent.OnErrorMessageChanged(statusLine.Value); } } else { if (command.Op == "currentsong") { ParseSongList(); Callback(m_DataModel.CurrentSong.OnCurrentSongResponseReceived); m_CurrentSongList.Clear(); } // TODO: remove the latter when Mopidy starts properly supporting the former. else if (command.Op == "listallinfo" || command.Op == "mopidylistallinfokludge") { ParseSongList(); Callback(m_DataModel.Database.OnListAllInfoResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "listplaylistinfo") { ParseSongList(); Callback(m_DataModel.SavedPlaylists.OnListPlaylistInfoResponseReceived, command.Argument1); m_CurrentSongList.Clear(); } else if (command.Op == "lsinfo") { Callback(m_DataModel.SavedPlaylists.OnLsInfoResponseReceived); } else if (command.Op == "outputs") { Callback(m_DataModel.OutputCollection.OnOutputsResponseReceived); } else if (command.Op == "playlistinfo") { ParseSongList(); Callback(m_DataModel.Playlist.OnPlaylistInfoResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "search") { ParseSongList(); Callback(m_DataModel.AdvancedSearch.OnSearchResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "stats") { Callback(m_DataModel.ServerStatus.OnStatsResponseReceived); } else if (command.Op == "status") { Callback(m_DataModel.ServerStatus.OnStatusResponseReceived); } } } m_CurrentResponse.Clear(); }
private void ReceiveResponse(MPDCommand command) { // TODO: if the server is really slow (Mopidy on an RPI for // example), we can get stuck here during shutdown. MPDResponseLine statusLine = GetResponseLine(); while (statusLine != null && !statusLine.IsStatus) { if (statusLine.Key != MPDResponseLine.Keyword.Unknown) { m_CurrentResponse.Add(statusLine); } statusLine = GetResponseLine(); } if (statusLine != null) { if (statusLine.Key == MPDResponseLine.Keyword.ACK) { m_Parent.OnErrorMessageChanged(statusLine.Value); } else { if (command.Op == "currentsong") { ParseSongList(); Callback(m_DataModel.CurrentSong.OnCurrentSongResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "listallinfo") { ParseSongList(); Callback(m_DataModel.Database.OnListAllInfoResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "listplaylistinfo") { ParseSongList(); Callback(m_DataModel.SavedPlaylists.OnListPlaylistInfoResponseReceived, command.Argument1); m_CurrentSongList.Clear(); } else if (command.Op == "lsinfo") { Callback(m_DataModel.SavedPlaylists.OnLsInfoResponseReceived); } else if (command.Op == "outputs") { Callback(m_DataModel.OutputCollection.OnOutputsResponseReceived); } else if (command.Op == "playlistinfo") { ParseSongList(); Callback(m_DataModel.Playlist.OnPlaylistInfoResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "search") { ParseSongList(); Callback(m_DataModel.AdvancedSearch.OnSearchResponseReceived); m_CurrentSongList.Clear(); } else if (command.Op == "stats") { Callback(m_DataModel.ServerStatus.OnStatsResponseReceived); } else if (command.Op == "status") { Callback(m_DataModel.ServerStatus.OnStatusResponseReceived); } } } m_CurrentResponse.Clear(); }
public void Add(MPDCommand command) { m_Queue.Enqueue(command); }