Changeset 12156


Ignore:
Timestamp:
May 29, 2009, 2:27:08 PM (10 years ago)
Author:
mikel
Message:

more work on slime/ccl protocol. The Emacs can now ask CCL to find and load its swank-loader and start up the swank server on a port specified by the Emacs process. Still need to complete the handshake so that the Emacs side actually connects to the started server, and need to review the whole set of stuff for places that need more error-checking. Also need to adjust the associated UI elements to say and do the right things, and generally smooth out the experience of using the facility.

Location:
trunk/source/cocoa-ide
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/swank-ccl-ide.el

    r12150 r12156  
    1919;;; 3. tell SLIME to connect to swank on the specified port
    2020
    21 (defun swank-loader-path () (concat slime-path "swank-laoder.lisp"))
     21(defun swank-loader-path () (concat slime-path "swank-loader.lisp"))
    2222
    2323(defvar *ccl-swank-listener-host* "127.0.0.1")
     
    3535(defvar $emacs-ccl-swank-request-marker "[emacs-ccl-swank-request]")
    3636
    37 (defun request-ccl-load-swank (&optional
    38                                (host *ccl-swank-listener-host*)
    39                                (listener-port *ccl-swank-listener-port*)
    40                                (connection-port slime-port))
    41   (let ((ping (concat $emacs-ccl-swank-request-marker (format "%d" connection-port) ":" (swank-loader-path) "\n"))
    42         (ccl-proc (open-network-stream "SLIME CCL Swank" nil host listener-port)))
     37(defun request-ccl-load-swank (&optional host listener-port connection-port )
     38  (let* ((host (or host *ccl-swank-listener-host*))
     39         (listener-port (or listener-port *ccl-swank-listener-port*))
     40         (connection-port (or connection-port slime-port))
     41         (ping (concat $emacs-ccl-swank-request-marker (format "%d" connection-port) ":" (swank-loader-path) "\n"))
     42         (ccl-proc (open-network-stream "SLIME CCL Swank" nil host listener-port)))
    4343    (setq *ccl-swank-listener-proc* ccl-proc)
    4444    (set-process-filter ccl-proc 'slime-ccl-swank-filter)
  • trunk/source/cocoa-ide/swank.lisp

    r12155 r12156  
    5151    (let* ((defaults (handler-case (#/values (#/sharedUserDefaultsController ns:ns-user-defaults-controller))
    5252                       (serious-condition (c)
    53                          (progn (log-debug "~%ERROR: Unable to get preferences from the Shared User Defaults Controller")
     53                         (progn (log-debug "~%ERROR: Unable to get preferences from the Shared User Defaults Controller: ~A"
     54                                           c)
    5455                                nil))))
    5556           (swank-port-pref (and defaults (#/valueForKey: defaults #@"swankPort"))))
     
    6566           ;; parsing the port number failed
    6667           (ccl::parse-integer-not-integer-string (c)
     68             (declare (ignore c))
    6769             (setf *ccl-swank-active-p* nil)
    68              (NSLog #@"\nError starting swank server; the swank-port user preference is not a valid port number: %@\n"
    69                     swank-port-pref)
     70             (#_NSLog #@"\nError starting swank server; the swank-port user preference is not a valid port number: %@\n"
     71                    :id swank-port-pref)
    7072             nil)))
    7173        ;; the user default value is incomprehensible
    7274        (t (progn
    73              (NSLog #@"\nERROR: Unrecognized value type in user preference 'swankPort': %@"
    74                     swank-port-pref)
     75             (#_NSLog #@"\nERROR: Unrecognized value type in user preference 'swankPort': %@"
     76                    :id swank-port-pref)
    7577             nil))))))
    7678
     
    115117(defvar $emacs-ccl-swank-request-marker "[emacs-ccl-swank-request]")
    116118
     119(defstruct (swank-status (:conc-name swank-))
     120  (active? nil :read-only t)
     121  (requested-loader nil :read-only t)
     122  (requested-port nil :read-only t))
     123
    117124(defun not-ready-yet (nm)
    118125  (error "Not yet implemented: ~A" nm))
     
    138145        nil)))
    139146
    140 (defun make-swank-loader-pathname (string)
    141   (not-ready-yet 'make-swank-loader-pathname))
    142 
    143 (defun load-swank (pathname)
    144   (not-ready-yet 'load-swank))
     147(defun load-and-start-swank (path requested-port)
     148  (handler-case (progn
     149                  (load path)
     150                  (swank:create-server :port requested-port :dont-close t)
     151                  (make-swank-status :active? t :requested-loader path :requested-port requested-port))
     152    (ccl::socket-creation-error (e) (log-debug "Unable to start a swank server on port: ~A; ~A"
     153                                               requested-port e)
     154                                (make-swank-status :active? nil :requested-loader path :requested-port requested-port))
     155    (serious-condition (e) (log-debug "There was a problem creating the swank server on port ~A: ~A"
     156                                      requested-port e)
     157                       (make-swank-status :active? nil :requested-loader path :requested-port requested-port))))
     158
     159(defun swank-ready? (status)
     160  (swank-active? status))
    145161
    146162(defun send-swank-ready (tcp-stream swank-status)
    147   (not-ready-yet 'send-swank-ready))
     163  (let ((response (format nil "(:active t :loader ~S :port ~D)"
     164                          (swank-requested-loader swank-status)
     165                          (swank-requested-port swank-status))))
     166    (format tcp-stream response)
     167    (force-output)))
    148168
    149169(defun send-swank-load-failed (tcp-stream swank-status)
    150   (not-ready-yet 'send-swank-load-failed))
    151 
     170  (let ((response (format nil "(:active nil :loader ~S :port ~D)"
     171                          (swank-requested-loader swank-status)
     172                          (swank-requested-port swank-status))))
     173    (format tcp-stream response)
     174    (force-output)))
    152175
    153176(defun handle-swank-client (c)
    154   (let* ((msg (read-swank-ping c))
    155          (swank-path (parse-swank-ping msg))
    156          (swank-loader (make-swank-loader-pathname swank-path))
    157          (swank-status (load-swank swank-loader)))
    158     (if (swank-ready? swank-status)
    159         (send-swank-ready c swank-status)
    160         (send-swank-load-failed c swank-status))))
     177  (let* ((msg (read-swank-ping c)))
     178    (multiple-value-bind (swank-path requested-port)
     179        (parse-swank-ping msg)
     180      (let* ((swank-status (load-and-start-swank swank-path requested-port)))
     181        (if (swank-ready? swank-status)
     182            (send-swank-ready c swank-status)
     183            (send-swank-load-failed c swank-status))))))
    161184
    162185;;; the real deal
     
    166189  (handler-case (with-open-socket (sock :type :stream :connect :passive :local-port port :reuse-address t)
    167190                  (loop
     191                     (format t "~%swank listener loop...")
     192                     (force-output)
    168193                     (let ((client-sock (accept-connection sock)))
    169194                       (process-run-function "CCL Swank Listener"
    170                                              #'%handle-swank-client client-sock))))
     195                                             #'handle-swank-client client-sock))))
    171196    (ccl::socket-creation-error (c) (nslog-condition c "Unable to create a socket for the swank-listener: ") c)
    172197    (ccl::socket-error (c) (nslog-condition c "Swank-listener failed trying to accept a client conection: ") c)
     
    184209    (let* ((start-swank-listener? (or (preference-start-swank?) force))
    185210           (swank-listener-port (or (preference-swank-port) *default-gui-swank-port*)))
    186       (if (and start-swank-listener? swank-port)
     211      (if (and start-swank-listener? swank-listener-port)
    187212          ;; try to start the swank listener
    188213          (handler-case (let ((swank-listener (start-swank-listener swank-listener-port)))
Note: See TracChangeset for help on using the changeset viewer.