54 lines
1.2 KiB
Common Lisp
54 lines
1.2 KiB
Common Lisp
;;;; cl-scopes/core - here comes the real action
|
|
|
|
(defpackage :scopes/core
|
|
(:use :common-lisp)
|
|
(:local-nicknames (:config :scopes/config))
|
|
(:export #:config #:service-config
|
|
#:context #:name #:actions #:send
|
|
#:action-spec
|
|
#:printer))
|
|
|
|
(in-package :scopes/core)
|
|
|
|
;;;; config
|
|
|
|
(defclass config (config:root)
|
|
(services))
|
|
|
|
(defclass service-config (config:base)
|
|
(start))
|
|
|
|
;;;; actions
|
|
|
|
(defclass action-spec ()
|
|
((pattern :initarg :pattern :initform nil)
|
|
(handlers :reader handlers :initarg :handlers)))
|
|
|
|
;;;; context
|
|
|
|
(defclass context ()
|
|
((name :reader name :initarg :name)
|
|
(actions :accessor actions :initform nil)))
|
|
|
|
(defgeneric send (rcvr msg)
|
|
(:method ((rcvr context) msg)
|
|
(let* ((acts (actions rcvr))
|
|
(selected (car acts)))
|
|
(dolist (hdlr (handlers selected))
|
|
(funcall hdlr rcvr msg)))))
|
|
|
|
(defvar *context* nil)
|
|
|
|
;;;; simple printer service
|
|
|
|
(defun do-print (ctx msg)
|
|
(declare (ignore ctx))
|
|
(format t "~&~s~%" msg))
|
|
|
|
(defclass printer (context)
|
|
((actions :initform
|
|
(list (make-instance 'action-spec
|
|
:handlers (list #'do-print))))))
|
|
|
|
(defun printer (name)
|
|
(make-instance 'printer :name name))
|