summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xreading-heap.scm18
-rw-r--r--reading-heap/zmq.scm11
-rwxr-xr-x[-rw-r--r--]scripts/rh-client.scm.in62
3 files changed, 77 insertions, 14 deletions
diff --git a/reading-heap.scm b/reading-heap.scm
index 6d821b2..846cc51 100755
--- a/reading-heap.scm
+++ b/reading-heap.scm
@@ -24,6 +24,12 @@
(string-append (getenv "HOME")
"/.local/share"))
"/media-library")))
+ (setting
+ (name 'service-socket)
+ (synopsis "socket for communication with the service")
+ (default (string-append "ipc://" (or (getenv "XDG_RUNTIME_DIR")
+ "/tmp")
+ "/reading-heap.sock")))
(switch
(name 'write)
(synopsis "write the default config")
@@ -46,17 +52,15 @@
(eager? #t))))
(parser sexp-parser)))
-(define-public media (filetree->media-list "/home/christopher/src/reading-heap/tests"))
-(define-public priorities (map media-priority media))
-(define-public heap (fold heap-insert 'E priorities media))
-
-;; (rh-receive heap)
-
(define (main cmd-line)
(let ((options (getopt-config-auto cmd-line config)))
(when (option-ref options 'write)
(options-write options))
(when (option-ref options 'serve)
- (rh-receive heap))))
+ (let* ((media (filetree->media-list (option-ref options 'media-library)))
+ (priorities (map media-priority media))
+ (heap (fold heap-insert 'E priorities media)))
+ (server-setup (option-ref options 'service-socket))
+ (rh-receive heap)))))
(main (command-line))
diff --git a/reading-heap/zmq.scm b/reading-heap/zmq.scm
index 51b530c..208ed75 100644
--- a/reading-heap/zmq.scm
+++ b/reading-heap/zmq.scm
@@ -8,15 +8,14 @@
(define context (zmq-create-context))
(define server-socket (zmq-create-socket context ZMQ_REP))
-(zmq-bind-socket server-socket (string-append "ipc://"
- (or (getenv "XDG_RUNTIME_DIR")
- "/tmp")
- "/reading-zmq"))
+(define (server-setup sock)
+ (zmq-bind-socket server-socket sock))
(define (rh-receive heap)
- (let ((command (zmq-receive server-socket 100)))
+ (let ((command (zmq-receive server-socket 65335)))
(display command)
(zmq-send server-socket (media->json (heap-get-min heap))))
(rh-receive heap))
-(export rh-receive)
+(export rh-receive
+ server-setup)
diff --git a/scripts/rh-client.scm.in b/scripts/rh-client.scm.in
index 0fddb63..d81acc4 100644..100755
--- a/scripts/rh-client.scm.in
+++ b/scripts/rh-client.scm.in
@@ -1,5 +1,65 @@
-(use-modules (reading-heap client)
+#!/usr/bin/env guile
+!#
+(define-module (reading-heap client))
+
+(use-modules (simple-zmq)
(config)
(config api)
+ (config parser sexp)
(config licenses))
+(define config
+ (configuration
+ (name 'rh-client)
+ (synopsis "client for reading-heap")
+ (keywords
+ (list
+ (setting
+ (name 'service-socket)
+ (synopsis "socket for communication with the service")
+ (default (string-append "ipc://" (or (getenv "XDG_RUNTIME_DIR")
+ "/tmp")
+ "/reading-heap.sock")))
+ (switch
+ (name 'write)
+ (synopsis "write the default config")
+ (default #f)
+ (test boolean?)
+ (character #f))
+ (switch
+ (name 'next)
+ (synopsis "get the next media to consume")
+ (default #f)
+ (test boolean?)
+ (character #t))
+ ))
+ (directory (list (in-home ".reading-heap/")
+ (path (given
+ (string-append (or (getenv "XDG_CONFIG_HOME")
+ (string-append (getenv "HOME")
+ "/.config"))
+ "/reading-heap/"))
+ (eager? #t))))
+ (parser sexp-parser)))
+
+
+(define context (zmq-create-context))
+(define client-socket (zmq-create-socket context ZMQ_REQ))
+
+(define (client-setup sock)
+ (zmq-connect client-socket sock))
+
+(define (rh-client-next)
+ (zmq-send client-socket "next")
+ (let ((msg (zmq-receive-bytevector client-socket 65335)))
+ (display (bv->string msg))))
+
+(define (main cmd-line)
+ (let ((options (getopt-config-auto cmd-line config)))
+ (when (option-ref options 'write)
+ (options-write options))
+ (when (option-ref options 'next)
+ (client-setup (option-ref options 'service-socket))
+ (rh-client-next))))
+
+(main (command-line))