mirror of https://codeberg.org/cage/tinmop/
- [RPC] added function to close server;
- [JSON-RPC] allowed API to signal a custom 'jsonrpc-error'.
This commit is contained in:
parent
5ce7e5c082
commit
cf0376e666
|
@ -103,7 +103,7 @@
|
||||||
(finish-output *server-stream*))
|
(finish-output *server-stream*))
|
||||||
|
|
||||||
(defun close-server ()
|
(defun close-server ()
|
||||||
(send-to-server +command-delimiter+))
|
(send-to-server (rpc:encode-to-string (rpc:make-request "quit-program" 1))))
|
||||||
|
|
||||||
(defun start-client ()
|
(defun start-client ()
|
||||||
(with-output-to-string (stream)
|
(with-output-to-string (stream)
|
||||||
|
|
|
@ -360,6 +360,12 @@
|
||||||
(defun clear-tour ()
|
(defun clear-tour ()
|
||||||
(clear-tour-link *gemini-window*))
|
(clear-tour-link *gemini-window*))
|
||||||
|
|
||||||
|
(defun quit-program ()
|
||||||
|
(fs:clean-temporary-directories)
|
||||||
|
(fs:clean-temporary-files)
|
||||||
|
(db-utils:close-db)
|
||||||
|
(os-utils:exit-program))
|
||||||
|
|
||||||
(defmacro prepare-rpc (&body body)
|
(defmacro prepare-rpc (&body body)
|
||||||
`(let ((rpc:*function-db* '()))
|
`(let ((rpc:*function-db* '()))
|
||||||
(gen-rpc "add"
|
(gen-rpc "add"
|
||||||
|
@ -402,4 +408,5 @@
|
||||||
'tour-delete-link
|
'tour-delete-link
|
||||||
"url" 0)
|
"url" 0)
|
||||||
(gen-rpc "clear-tour" 'clear-tour)
|
(gen-rpc "clear-tour" 'clear-tour)
|
||||||
|
(gen-rpc "quit-program" 'quit-program)
|
||||||
,@body))
|
,@body))
|
||||||
|
|
|
@ -122,6 +122,11 @@
|
||||||
(format stream "~a" (text condition))))
|
(format stream "~a" (text condition))))
|
||||||
(:documentation "Error for all jsonrpc related problems"))
|
(:documentation "Error for all jsonrpc related problems"))
|
||||||
|
|
||||||
|
(defmacro make-json-rpc-error (code message)
|
||||||
|
`(progn
|
||||||
|
(assert (< -32000 code -32099))
|
||||||
|
(error 'json-rpc-error :text ,message :code ,code)))
|
||||||
|
|
||||||
(defparameter *function-db* '())
|
(defparameter *function-db* '())
|
||||||
|
|
||||||
(defun make-fun-params (name position)
|
(defun make-fun-params (name position)
|
||||||
|
@ -409,10 +414,11 @@
|
||||||
(misc:dbg m))
|
(misc:dbg m))
|
||||||
|
|
||||||
(defun elaborate-single-request (request)
|
(defun elaborate-single-request (request)
|
||||||
(flet ((make-rpc-error (e)
|
(flet ((make-rpc-error (e id)
|
||||||
(maybe-log-message (format nil "jsonrpc request failed: ~a" e))
|
(maybe-log-message (format nil "jsonrpc request failed: ~a" e))
|
||||||
(make-response nil
|
(make-response nil
|
||||||
(transaction-id e)
|
(or (transaction-id e)
|
||||||
|
id)
|
||||||
:error-object (make-response-error (or (code e)
|
:error-object (make-response-error (or (code e)
|
||||||
(response-error-code +error-invalid-request+))
|
(response-error-code +error-invalid-request+))
|
||||||
(text e))))
|
(text e))))
|
||||||
|
@ -433,18 +439,21 @@
|
||||||
(handler-case
|
(handler-case
|
||||||
(let* ((request (apply #'make-request method id params))
|
(let* ((request (apply #'make-request method id params))
|
||||||
(elaborated (call-function request)))
|
(elaborated (call-function request)))
|
||||||
(maybe-log-message (format nil "jsonrpc request ~s results ~s" request elaborated))
|
(maybe-log-message (format nil
|
||||||
|
"jsonrpc request ~s results ~s"
|
||||||
|
request
|
||||||
|
elaborated))
|
||||||
(when id
|
(when id
|
||||||
;; if id is null is a notification (i.e. the client
|
;; if id is null is a notification (i.e. the client
|
||||||
;; does not care about an answer)
|
;; does not care about an answer)
|
||||||
(make-response elaborated id :error-object nil)))
|
(make-response elaborated id :error-object nil)))
|
||||||
(json-rpc-error (e)
|
(json-rpc-error (e)
|
||||||
(make-rpc-error e))
|
(make-rpc-error e id))
|
||||||
(error (e)
|
(error (e)
|
||||||
(maybe-log-message (format nil "jsonrpc request failed: ~a" e))
|
(maybe-log-message (format nil "jsonrpc request failed: ~a" e))
|
||||||
(make-failed-function-error e id nil))))
|
(make-failed-function-error e id nil))))
|
||||||
(json-rpc-error (e)
|
(json-rpc-error (e)
|
||||||
(make-rpc-error e))
|
(make-rpc-error e nil))
|
||||||
(error (e)
|
(error (e)
|
||||||
(maybe-log-message (format nil "jsonrpc request failed with internal error!: ~a" e))
|
(maybe-log-message (format nil "jsonrpc request failed with internal error!: ~a" e))
|
||||||
(make-internal-error e)))))
|
(make-internal-error e)))))
|
||||||
|
|
|
@ -3158,6 +3158,7 @@
|
||||||
:make-response
|
:make-response
|
||||||
:encode-to-string
|
:encode-to-string
|
||||||
:json-rpc-error
|
:json-rpc-error
|
||||||
|
:make-rpc-error
|
||||||
:elaborate-request
|
:elaborate-request
|
||||||
:transaction-id
|
:transaction-id
|
||||||
:code
|
:code
|
||||||
|
|
Loading…
Reference in New Issue