Commit 8f3d227f authored by Alastair Bridgewater's avatar Alastair Bridgewater
Browse files

port/port-discovery: How to find (and possibly make) a suitable port.

  * There is some clever magic here, along with an nq-clim private
extension interface (not part of the specification) for creating
new port instances.  For the most part, however, this is...

  * Actually, it's two different things, which is not right.  This
file both manages the *ALL-PORTS* list for MAP-OVER-PORTS, it also
covers FIND-PORT and *DEFAULT-SERVER-PATH*.  In order for this to
work, CREATE-PORT would need an :AROUND method to update
*ALL-PORTS*, removing that responsibility from FIND-PORT.

  * FIND-PORT requires MAP-OVER-PORTS.  MAP-OVER-PORTS uses
*ALL-PORTS*, and maintaining *ALL-PORTS* would require methods on
both DESTROY-PORT and CREATE-PORT, necessitating three files in
place of one.  We might go there at some point, but not now.
parent eea73802
......@@ -44,6 +44,7 @@
"sheet/mirrored-sheet-mixin"
"port/port-protocol"
"port/basic-port"
"port/port-discovery"
"backend/clx/medium"))
(load (compile-file file)))
......
;;;
;;; nq-clim/port/port-discovery
;;;
;;; Part of CLIM II 9.2.
;;;
(cl:defpackage :nq-clim/port/port-discovery
(:use :cl
:nq-clim/port/port
:nq-clim/port/port-protocol)
(:export
"*DEFAULT-SERVER-PATH*"
"FIND-PORT"
"MAP-OVER-PORTS"
;; The following are nq-clim specific implementation hooks.
"RESOLVE-SERVER-PATH"
"CREATE-PORT"))
(cl:in-package :nq-clim/port/port-discovery)
(defvar *all-ports* nil "All currently-open ports.")
(defun map-over-ports (function)
(dolist (port *all-ports*)
(funcall function port)))
(defmethod destroy-port :after (port)
(setf *all-ports* (remove port *all-ports*)))
(defparameter *default-server-path* '(:clx))
(defgeneric resolve-server-path (port-type &key)
(:documentation "To be implemented by each port type, convert the
spread server path passed as arguments to what would be returned from
PORT-SERVER-PATH called on the port should a port be opened with this
path designator."))
(defgeneric create-port (port-type &key)
(:documentation "To be implemented by each port type, create a port
object corresponding to the server path passed as parameters."))
(defun find-port (&rest initargs
&key (server-path *default-server-path*)
&allow-other-keys)
(let ((server-path (apply #'resolve-server-path server-path)))
(map-over-ports
(lambda (port)
(when (equal server-path (port-server-path port))
(return-from find-port port))))
(push (apply #'create-port (car server-path) initargs)
*all-ports*)))
;;; EOF
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment