Changeset 37 for branches/home/psmith
- Timestamp:
- 01/15/07 06:49:25 (18 years ago)
- 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 37 37 38 38 (defconstant CALL-METHOD-PACKET-ID #x0) 39 (defconstant METHOD-RESPONSE-PACKET-ID 1)39 (defconstant METHOD-RESPONSE-PACKET-ID #x1) 40 40 41 41 (defmethod get-packet ((pf yarpc-packet-factory) buf) 42 42 (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)) 48 51 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)) 51 57 52 58 (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))) 54 60 55 61 (defmethod write-bytes((packet call-method-packet) buf) … … 57 63 ; (nio-buffer:flip buf) 58 64 (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)) 60 66 (format t "yarpc-packet-factory:write-bytes - written ~A~%" buf) ) 61 67 62 68 63 (defclass method-response-packet (packet)()) 69 (defclass method-response-packet (packet) 70 ((response :initarg :response 71 :accessor response))) 64 72 73 (defun method-response-packet (response) 74 (make-instance 'method-response-packet :response response)) 65 75 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 99 99 packet)) 100 100 101 ;TODO queue and thread stuf 102 (defmethod queue-outgoing-packet((sm yarpc-state-machine) packet) 103 (setf (outgoing-packet sm) packet)) 101 104 102 105 ;Process a call method packet, returns 103 106 (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)) 106 108 (format t "yarpc-state-machine:process-incoming-packet called :sm ~A :packet ~A~%" sm call) 107 109 (handler-case 108 (let ((result (execute-call ( get-call-string call))))110 (let ((result (execute-call (call-string call)))) 109 111 (when result 110 112 (let ((response-packet (progn 111 113 (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))))) 116 118 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 117 123 118 124 (defun execute-call (call-string) … … 126 132 127 133 (defmethod remote-execute ((sm yarpc-state-machine) call-string) 128 ( setf (outgoing-packet sm) (make-instance 'call-method-packet :callcall-string)))134 (queue-outgoing-packet sm (make-instance 'call-method-packet :call-string call-string))) 129 135
Note: See TracChangeset
for help on using the changeset viewer.