about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/dtas/mpd_emu_client.rb31
-rw-r--r--test/test_mpd_emu.rb2
2 files changed, 31 insertions, 2 deletions
diff --git a/lib/dtas/mpd_emu_client.rb b/lib/dtas/mpd_emu_client.rb
index 01258d1..25c96a0 100644
--- a/lib/dtas/mpd_emu_client.rb
+++ b/lib/dtas/mpd_emu_client.rb
@@ -46,17 +46,44 @@ class DTAS::MpdEmuClient # :nodoc:
   def dispatch(argv)
     cmd = argv.shift or return err(:ERROR_UNKNOWN)
     cmd = "mpdcmd_#{cmd}"
-    respond_to?(cmd) ? __send__(cmd, argv) : err(:ERROR_UNKNOWN)
+    if respond_to?(cmd)
+      m = method(cmd)
+      params = m.parameters
+      rest = params.any? { |x| x[0] == :rest }
+      req = params.count { |x| x[0] == :req }
+      opt = params.count { |x| x[0] == :opt }
+      argc = argv.size
+      return err(:ERROR_ARG) if argc < req
+      return err(:ERROR_ARG) if !rest && (argc > (req + opt))
+      m.call(*argv)
+    else
+      err(:ERROR_UNKNOWN)
+    end
   end
 
   def err(sym)
     "[#{ACK[sym]}@#@cmd_listnum {}"
   end
 
-  def mpdcmd_ping(argv)
+  def mpdcmd_ping; out("OK\n"); end
+  def mpdcmd_close(*); nil; end
+
+  def mpdcmd_clearerror
+    # player_clear_error
     out("OK\n")
   end
 
+  def mpdcmd_stats
+    out("artists: \n" \
+        "albums: \n" \
+        "songs: \n" \
+        "uptime: \n" \
+        "playtime: \n" \
+        "db_playtime: \n" \
+        "db_update: \n" \
+        "OK\n")
+  end
+
   # returns true on complete, :wait_writable when blocked, or nil on error
   def out(buf)
     buf = buf.b
diff --git a/test/test_mpd_emu.rb b/test/test_mpd_emu.rb
index 9c73ae9..487e743 100644
--- a/test/test_mpd_emu.rb
+++ b/test/test_mpd_emu.rb
@@ -46,6 +46,8 @@ class TestMlib < Testcase
     @c.write "ping\n"
     assert_equal "OK\n", @c.gets
     assert_nil IO.select([@c], nil, nil, 0)
+    @c.write "close\n"
+    assert_nil @c.read(1)
   end
 
   # to ensure output buffering works: