Initial import
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#lang racket/base
|
||||
|
||||
;; Typed interface for the UPnP RenderingControl service.
|
||||
|
||||
(require "../service.rkt")
|
||||
|
||||
(provide rendering-control?
|
||||
device-rendering-control
|
||||
rendering-control-volume
|
||||
rendering-control-set-volume!
|
||||
rendering-control-muted?
|
||||
rendering-control-set-muted!)
|
||||
|
||||
(define (rendering-control? value)
|
||||
(and (upnp-service? value)
|
||||
(eq? (upnp-service-kind value) 'rendering-control)))
|
||||
|
||||
(define (check-rendering-control who value)
|
||||
(unless (rendering-control? value)
|
||||
(raise-argument-error who "rendering-control?" value)))
|
||||
|
||||
(define (device-rendering-control device)
|
||||
(upnp-device-service device 'rendering-control))
|
||||
|
||||
(define (result-ref result name [default #f])
|
||||
(hash-ref result name default))
|
||||
|
||||
(define (upnp-boolean value)
|
||||
(and value
|
||||
(or (string=? value "1")
|
||||
(string-ci=? value "true")
|
||||
(string-ci=? value "yes"))))
|
||||
|
||||
(define (rendering-control-volume control
|
||||
#:channel [channel "Master"]
|
||||
#:instance-id [instance-id 0])
|
||||
(check-rendering-control 'rendering-control-volume control)
|
||||
(let* ([result
|
||||
(upnp-service-call
|
||||
control
|
||||
"GetVolume"
|
||||
(list (cons "InstanceID" instance-id)
|
||||
(cons "Channel" channel)))]
|
||||
[volume (result-ref result "CurrentVolume" #f)])
|
||||
(and volume (string->number volume))))
|
||||
|
||||
(define (rendering-control-set-volume! control volume
|
||||
#:channel [channel "Master"]
|
||||
#:instance-id [instance-id 0])
|
||||
(check-rendering-control 'rendering-control-set-volume! control)
|
||||
(unless (and (exact-integer? volume) (<= 0 volume 65535))
|
||||
(raise-argument-error 'rendering-control-set-volume!
|
||||
"(integer-in 0 65535)"
|
||||
volume))
|
||||
(upnp-service-call
|
||||
control
|
||||
"SetVolume"
|
||||
(list (cons "InstanceID" instance-id)
|
||||
(cons "Channel" channel)
|
||||
(cons "DesiredVolume" volume)))
|
||||
(void))
|
||||
|
||||
(define (rendering-control-muted? control
|
||||
#:channel [channel "Master"]
|
||||
#:instance-id [instance-id 0])
|
||||
(check-rendering-control 'rendering-control-muted? control)
|
||||
(let ([result
|
||||
(upnp-service-call
|
||||
control
|
||||
"GetMute"
|
||||
(list (cons "InstanceID" instance-id)
|
||||
(cons "Channel" channel)))])
|
||||
(upnp-boolean (result-ref result "CurrentMute" #f))))
|
||||
|
||||
(define (rendering-control-set-muted! control muted?
|
||||
#:channel [channel "Master"]
|
||||
#:instance-id [instance-id 0])
|
||||
(check-rendering-control 'rendering-control-set-muted! control)
|
||||
(unless (boolean? muted?)
|
||||
(raise-argument-error 'rendering-control-set-muted! "boolean?" muted?))
|
||||
(upnp-service-call
|
||||
control
|
||||
"SetMute"
|
||||
(list (cons "InstanceID" instance-id)
|
||||
(cons "Channel" channel)
|
||||
(cons "DesiredMute" muted?)))
|
||||
(void))
|
||||
Reference in New Issue
Block a user