about summary refs log tree commit homepage
path: root/lib/dtas/mpd_emu_client.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dtas/mpd_emu_client.rb')
-rw-r--r--lib/dtas/mpd_emu_client.rb31
1 files changed, 29 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