cl-scopes/core/core.lisp

52 lines
1.1 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 #:send
#: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 msg)))))
(defvar *context* nil)
;;;; simple printer service
(defun do-print (msg)
(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))