Add the possibility to talk to the server synchronously.
This commit is contained in:
parent
9d0d66b9e3
commit
aecf561c6a
1 changed files with 18 additions and 0 deletions
18
empc.el
18
empc.el
|
|
@ -106,6 +106,7 @@ playlist is a vector of song ids, keeping the order of the songs
|
||||||
Leave the idle state beforehand if necessary."
|
Leave the idle state beforehand if necessary."
|
||||||
(if (empc-queue object)
|
(if (empc-queue object)
|
||||||
(when (string= (empc-queue-head-command object) "idle\n")
|
(when (string= (empc-queue-head-command object) "idle\n")
|
||||||
|
(setcar (caaar object) "noidle\n")
|
||||||
(process-send-string (empc-process object) "noidle\n"))
|
(process-send-string (empc-process object) "noidle\n"))
|
||||||
(when command
|
(when command
|
||||||
(process-send-string (empc-process object) command)))
|
(process-send-string (empc-process object) command)))
|
||||||
|
|
@ -113,6 +114,11 @@ Leave the idle state beforehand if necessary."
|
||||||
(nconc (empc-queue object)
|
(nconc (empc-queue object)
|
||||||
(list (cons command (cons closure fn))))))
|
(list (cons command (cons closure fn))))))
|
||||||
|
|
||||||
|
(defun empc-queue-sync (object)
|
||||||
|
"Empty object's queue synchronously."
|
||||||
|
(while (and (not (string= (empc-queue-head-command object) "idle\n"))
|
||||||
|
(accept-process-output (empc-process object) 10))))
|
||||||
|
|
||||||
(defun empc-queue-pop (object)
|
(defun empc-queue-pop (object)
|
||||||
"Pop the head of the queue then send the next command.
|
"Pop the head of the queue then send the next command.
|
||||||
If there is no command left to send, put the client in idle state."
|
If there is no command left to send, put the client in idle state."
|
||||||
|
|
@ -612,6 +618,18 @@ CLOSURE will be called on the parsed response."
|
||||||
(empc-queue-push empc-object command closure
|
(empc-queue-push empc-object command closure
|
||||||
(if handler handler 'empc-handle-response)))
|
(if handler handler 'empc-handle-response)))
|
||||||
|
|
||||||
|
(defun empc-send-sync (command &optional closure handler)
|
||||||
|
"Send COMMAND synchronously. That means empc will push the
|
||||||
|
command to the queue before synchronously emptying it."
|
||||||
|
(empc-send command closure handler)
|
||||||
|
(empc-queue-sync empc-object))
|
||||||
|
|
||||||
|
(defun empc-send-output (command)
|
||||||
|
"Send COMMAND synchronously and return the server response as string."
|
||||||
|
(let ((output))
|
||||||
|
(empc-send-sync command nil (lambda (closures msg) (setq output msg)))
|
||||||
|
output))
|
||||||
|
|
||||||
(defun empc-send-list (&rest commands)
|
(defun empc-send-list (&rest commands)
|
||||||
"Send COMMANDS to the mpd server using command_list.
|
"Send COMMANDS to the mpd server using command_list.
|
||||||
COMMANDS is a list of cons of the form: '(COMMAND . CLOSURE),
|
COMMANDS is a list of cons of the form: '(COMMAND . CLOSURE),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue