Don't use callbacks -- use several submit buttons or special return addresses.

This commit is contained in:
interp 2002-10-02 19:13:14 +00:00
parent d690a7a24e
commit 9203e245bf
4 changed files with 71 additions and 47 deletions

View File

@ -25,7 +25,7 @@
(td ,number-field) (td ,number-field)
(td ,(make-submit-button "Change"))))) (td ,(make-submit-button "Change")))))
(hr) (hr)
(URL ,(make-callback return-to-main-page) "Return to main page"))) (URL ,(string-append new-url "?return=") "Return to main page")))
))) )))
(define (handler-options req . maybe-update-text) (define (handler-options req . maybe-update-text)
@ -33,18 +33,26 @@
,(:optional maybe-update-text ""))) ,(:optional maybe-update-text "")))
(number-field (number-field
(make-number-input-field `(@ ((value ,(options-instance-lifetime)))))) (make-number-input-field `(@ ((value ,(options-instance-lifetime))))))
(req (get-option-change number-field update-text))) (req (get-option-change number-field update-text))
(with-fatal-error-handler (bindings (get-bindings req)))
(lambda (condition more) (format #t "bindings ~s~%" bindings)
(handler-options req "Please enter a valid, positive integer number")) (cond
(set-options-instance-lifetime ((assoc "return" bindings)
(let ((result (input-field-value number-field (get-bindings req)))) (return-to-main-page req))
(if (and (integer? result) (else
(> result 0))
(handler-options req (with-fatal-error-handler
(format #f "Instance lifetime changed to ~a." (lambda (condition more)
(options-instance-lifetime))) (handler-options req "Please enter a valid, positive integer number"))
(error "not a positive integer"))))))) (let ((result (input-field-value number-field bindings)))
(if (and (integer? result)
(> result 0))
(begin
(set-options-instance-lifetime result)
(handler-options req
(format #f "Instance lifetime changed to ~a."
(options-instance-lifetime))))
(error "not a positive integer"))))))))
(define (return-to-main-page req) (define (return-to-main-page req)
(send/finish (make-http-error-response http-status/moved-perm req (send/finish (make-http-error-response http-status/moved-perm req

View File

@ -17,16 +17,10 @@
(define counter 0) (define counter 0)
(define gnuplot "/usr/bin/gnuplot") (define gnuplot "/usr/bin/gnuplot")
(define (reset-profiling-state!)
(set! counter 0)
(for-each delete-file file-names-to-delete)
(delete-file file-name)
(set! file-name (create-temp-file "servlet-profiling"))
(set! file-names-to-delete '()))
(define (profile req . maybe-update-text) (define (profile req . maybe-update-text)
(let* ((update-text (:optional maybe-update-text "")) (let* ((update-text (:optional maybe-update-text ""))
(input-field (make-text-input-field gnuplot '(@ (size 20)))) (input-field (make-text-input-field gnuplot '(@ (size 20))))
(change-button (make-submit-button "Change"))
(req (req
(send-html/suspend (send-html/suspend
(lambda (new-url) (lambda (new-url)
@ -37,31 +31,46 @@
(font (@ (color "red")) ,update-text) (font (@ (color "red")) ,update-text)
(p "Currently, there are " ,counter " profiles saved.") (p "Currently, there are " ,counter " profiles saved.")
(ul (ul
(li (URL ,(make-callback new-profile) "Create new profile")) (li (URL ,(string-append new-url "?newprofile=")
(li (URL ,(make-callback result) "Show profile results") "Create new profile")
(li (URL ,(string-append new-url "?result=")
"Show profile results")
(br) (br)
(servlet-form (servlet-form
,new-url ,new-url
(p "This uses " (var "gnuplot") " that is searched at " (p "This uses " (var "gnuplot") " that is searched at "
,input-field ,(make-submit-button "Change")))) ,input-field ,change-button)))
(li (URL ,(make-callback reset) "Delete files and reset profile state."))) (li (URL ,(string-append new-url "?delete_reset=")
(hr) "Delete files and reset profile state."))))
(URL ,(make-callback return-to-main-page) (hr)
"Return to main page leaving profile state untouched.") (URL ,(string-append new-url "?return=")
(br) "Return to main page leaving profile state untouched.")
(URL ,(make-callback reset-and-return-to-main-page) (br)
"Return to main page reseting profile-state")))))) (URL ,(string-append new-url "?reset_return=")
"Return to main page reseting profile-state"))))))
(bindings (get-bindings req))) (bindings (get-bindings req)))
(let ((new-gnuplot-location (with-fatal-error-handler (cond
(lambda (condition more) ((assoc "newprofile" bindings)
#f) (new-profile req))
(input-field-value input-field bindings)))) ((assoc "result" bindings)
(if (and new-gnuplot-location (result req))
(file-executable? new-gnuplot-location)) ((assoc "delete_reset" bindings)
(begin (reset req))
(set! gnuplot new-gnuplot-location) ((assoc "return" bindings)
(profile req (format #f "Gnuplot is now searched at ~a." gnuplot))) (reset req))
(profile req "Please enter a file name of an existing executable."))))) ((assoc "reset_return" bindings)
(reset-and-return-to-main-page req))
(else
(let ((new-gnuplot-location (with-fatal-error-handler
(lambda (condition more)
#f)
(input-field-value input-field bindings))))
(if (and new-gnuplot-location
(file-executable? new-gnuplot-location))
(begin
(set! gnuplot new-gnuplot-location)
(profile req (format #f "Gnuplot is now searched at ~a." gnuplot)))
(profile req "Please enter a file name of an existing executable.")))))))
(define (new-profile req) (define (new-profile req)
(profile-space file-name) (profile-space file-name)
@ -105,15 +114,22 @@ plot '~a' title 'Servlet Profiling ~a' with lines"
(define (reset req) (define (reset req)
(reset-profiling-state!) (reset-profiling-state!)
(profile req)) (profile req "Profiling state reseted."))
(define (return-to-main-page req) (define (reset-profiling-state!)
(send/finish (make-http-error-response http-status/moved-perm req (set! counter 0)
"admin.scm" "admin.scm"))) (for-each delete-filesys-object file-names-to-delete)
(delete-filesys-object file-name)
(set! file-name (create-temp-file "servlet-profiling"))
(set! file-names-to-delete '()))
(define (reset-and-return-to-main-page req) (define (reset-and-return-to-main-page req)
(reset-profiling-state!) (reset-profiling-state!)
(return-to-main-page req)) (return-to-main-page req))
(define (return-to-main-page req)
(send/finish (make-http-error-response http-status/moved-perm req
"admin.scm" "admin.scm")))
(define (main req) (define (main req)
(profile req)) (profile req))

View File

@ -7,7 +7,7 @@
scheme) scheme)
(begin (begin
;; This uses callbacks. ;; This doesn't use c-a-l-l-b-a-c-k-s anymore.
(define (make-byte-input-fields bits) (define (make-byte-input-fields bits)
(let ((checkboxes (let ((checkboxes

View File

@ -7,7 +7,7 @@
scheme) scheme)
(begin (begin
;; This doesn't use callbacks anymore. ;; This doesn't use c-a-l-l-b-a-c-k-s anymore.
(define *operator-alist* (define *operator-alist*
`(("+" . ,+) `(("+" . ,+)