aboutsummaryrefslogtreecommitdiff
path: root/scripts/rh-client.scm.in
blob: d81acc4aa121262f6df02cae6852b93fd3951428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/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))