Ignore:
Timestamp:
01/12/07 06:44:39 (18 years ago)
Author:
psmith
Message:

yarpc progress...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/home/psmith/restructure/src/protocol/yarpc/yarpc-state-machine.lisp

    r31 r33  
    4141;; response - who 2 'S
    4242;;
    43 (defclass yarpc-state-machine (async-fd)())
     43(defclass yarpc-state-machine (state-machine)())
    4444
     45(defun yarpc-state-machine ()
     46    (make-instance 'yarpc-state-machine))
     47
     48(defparameter yarpc-pf (yarpc-packet-factory))
     49
     50(defmethod get-packet-factory((sm yarpc-state-machine))
     51  yarpc-pf)
    4552
    4653;;TODO move somewhere suitable
     
    7582  (format stream "#<YARPC-STATE-MACHINE ~A >" (call-next-method sm nil)))
    7683
    77 (defmethod process-read((sm yarpc-state-machine))
    78   (with-slots (foreign-read-buffer foreign-write-buffer) sm
    79     (let ((fn-result (execute-call (sb-ext:octets-to-string (get-string foreign-read-buffer) :external-format :ascii))))
    80       (format t "process-read - function result: ~A~%" fn-result)
    81       (nio-buffer:bytebuffer-write-string foreign-write-buffer (write-to-string fn-result) 0 :utf-8)
    82       (close-sm sm))))
     84(defconstant STATE-INITIALISED 0)
     85(defconstant STATE-SEND-RESPONSE 1)
    8386
     87(defparameter state STATE-INITIALISED)
    8488
    8589(define-condition authorization-error (error) ())
    8690
     91;Process a call method packet, returns
     92(defmethod process-packet ((sm yarpc-state-machine) (call call-method-packet))
     93  ;todo change state, create method-response packet and return it
     94  ;(assert (eql state 0))
     95  (handler-case
     96    (let ((result (execute-call (get-call-string call))))
     97      (when result
     98        (let ((response-packet (progn
     99                                  (setf state STATE-SEND-RESPONSE)
     100                                  (method-response-packet result))))
     101          (values response-packet t))))
     102    (reader-error (re) (format t "No such function ~A~%" (get-call-string call)))
     103    (authorization-error (ae) (format t "Function not declared with defremote ~A~%" (get-call-string call)))))
     104
     105
    87106(defun execute-call (call-string)
    88   (handler-case
    89107      (let* ((rpc-call-list (read-from-string call-string ))
    90108             (fn (member (symbol-function (first rpc-call-list)) *remote-fns* )))
     
    92110        (if fn
    93111            (apply (first rpc-call-list) (rest rpc-call-list))
    94             (error 'authorization-error)))
    95     (reader-error (re) (format t "No such function ~A~%" call-string))))
     112            (error 'authorization-error))))
    96113
Note: See TracChangeset for help on using the changeset viewer.