Changeset 37 for branches/home/psmith


Ignore:
Timestamp:
01/15/07 06:49:25 (18 years ago)
Author:
psmith
Message:

yarpc roundtrip complete

Location:
branches/home/psmith/restructure/src/protocol/yarpc
Files:
2 edited

Legend:

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

    r36 r37  
    3737
    3838(defconstant CALL-METHOD-PACKET-ID #x0)
    39 (defconstant METHOD-RESPONSE-PACKET-ID 1)
     39(defconstant METHOD-RESPONSE-PACKET-ID #x1)
    4040
    4141(defmethod get-packet ((pf yarpc-packet-factory) buf)
    4242  (flip buf)
    43 ;  (format t "get-packet::read string - ~A~%" (bytebuffer-read-string buf (remaining buf)))
    44   (if (>= (remaining buf) 1) ;; First byte denotes packet ID
    45     (ecase (elt (bytebuffer-read-vector buf 1) 0)
    46       (0 (progn (format t "got CALL-METHOD-PACKET-ID~%") (make-instance 'call-method-packet :call (bytebuffer-read-string buf (remaining buf)))))
    47       (1 (format t "got METHOD-RESPONSE-PACKET-ID~%")))))
     43  (let ((ret (if (> (remaining buf) 0) ;; First byte denotes packet ID
     44                 (ecase (elt (bytebuffer-read-vector buf 1) 0)
     45                   (0 (progn (format t "got CALL-METHOD-PACKET-ID~%") (call-method-packet (bytebuffer-read-string buf (remaining buf)))))
     46                   (1 (progn (format t "got METHOD-RESPONSE-PACKET-ID~%") (method-response-packet (bytebuffer-read-string buf (remaining buf)))))))))
     47    (if (> (remaining buf) 0)
     48        (error 'not-implemented-yet)
     49        (clear buf))
     50    ret))
    4851
    49 (defclass call-method-packet (packet)((call-string :initarg :call
    50                                             :accessor get-call-string)))
     52(defclass call-method-packet (packet)((call-string :initarg :call-string
     53                                            :accessor call-string)))
     54
     55(defun call-method-packet (call-string)
     56  (make-instance 'call-method-packet :call-string call-string))
    5157
    5258(defmethod print-object ((packet call-method-packet) stream)
    53   (format stream "#<CALL-METHOD-PACKET ~A >" (get-call-string packet)))
     59  (format stream "#<CALL-METHOD-PACKET ~A >" (call-string packet)))
    5460
    5561(defmethod write-bytes((packet call-method-packet) buf)
     
    5763;  (nio-buffer:flip buf)
    5864  (nio-buffer:bytebuffer-write-vector buf #(#x0))
    59   (nio-buffer:bytebuffer-write-string buf (get-call-string packet))
     65  (nio-buffer:bytebuffer-write-string buf (call-string packet))
    6066  (format t "yarpc-packet-factory:write-bytes - written ~A~%" buf)  )
    6167 
    6268
    63 (defclass method-response-packet (packet)())
     69(defclass method-response-packet (packet)
     70  ((response :initarg :response
     71             :accessor response)))
    6472
     73(defun method-response-packet (response)
     74  (make-instance 'method-response-packet :response response))
    6575
     76(defmethod print-object ((packet method-response-packet) stream)
     77  (format stream "#<METHID-RESPONSE-PACKET ~A >" (response packet)))
     78
     79(defmethod write-bytes((packet method-response-packet) buf)
     80  (format t "yarpc-packet-factory:write-bytes - writing ~A to ~A~%" packet buf)
     81  (nio-buffer:bytebuffer-write-vector buf #(#x1))
     82  (nio-buffer:bytebuffer-write-string buf (write-to-string (response packet)))
     83  (format t "yarpc-packet-factory:write-bytes - written ~A~%" buf)  )
  • TabularUnified branches/home/psmith/restructure/src/protocol/yarpc/yarpc-state-machine.lisp

    r36 r37  
    9999    packet))
    100100
     101;TODO queue and thread stuf
     102(defmethod queue-outgoing-packet((sm yarpc-state-machine) packet)
     103  (setf (outgoing-packet sm) packet))
    101104
    102105;Process a call method packet, returns
    103106(defmethod process-incoming-packet ((sm yarpc-state-machine) (call call-method-packet))
    104   ;todo change state, create method-response packet and return it
    105   ;(assert (eql state 0))
     107  (assert (eql state STATE-INITIALISED))
    106108  (format t "yarpc-state-machine:process-incoming-packet called :sm ~A :packet ~A~%" sm call)
    107109  (handler-case
    108     (let ((result (execute-call (get-call-string call))))
     110    (let ((result (execute-call (call-string call))))
    109111      (when result
    110112        (let ((response-packet (progn
    111113                                  (setf state STATE-SEND-RESPONSE)
    112                                   (method-response-packet result))))
    113           (values response-packet t))))
    114     (reader-error (re) (format t "No such function ~A~%" (get-call-string call)))
    115     (authorization-error (ae) (format t "Function not declared with defremote ~A~%" (get-call-string call)))))
     114                                  (queue-outgoing-packet sm (method-response-packet result)))))
     115          t)))
     116    (reader-error (re) (format t "No such function ~A~%" (call-string call)))
     117    (authorization-error (ae) (format t "Function not declared with defremote ~A~%" (call-string call)))))
    116118
     119(defmethod process-incoming-packet ((sm yarpc-state-machine) (response method-response-packet))
     120  (assert (eql state STATE-INITIALISED))
     121  (format t "yarpc-state-machine:process-incoming-packet called :sm ~A :packet ~A~%" sm response))
     122 
    117123
    118124(defun execute-call (call-string)
     
    126132
    127133(defmethod remote-execute ((sm yarpc-state-machine) call-string)
    128   (setf (outgoing-packet sm) (make-instance 'call-method-packet :call call-string)))
     134  (queue-outgoing-packet sm (make-instance 'call-method-packet :call-string call-string)))
    129135   
Note: See TracChangeset for help on using the changeset viewer.