64 lines
1.3 KiB
Common Lisp
64 lines
1.3 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
|
|
#:message
|
|
#:context #:name #:send
|
|
#:printer))
|
|
|
|
(in-package :scopes/core)
|
|
|
|
;;;; config
|
|
|
|
(defclass config (config:root)
|
|
(services))
|
|
|
|
(defclass service-config (config:base)
|
|
(start))
|
|
|
|
;;;; message
|
|
|
|
(defclass message ()
|
|
((domain)
|
|
(action)
|
|
(class)
|
|
(item)
|
|
(sender)
|
|
(timestamp)
|
|
(data)))
|
|
|
|
;;;; 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))
|
|
(hdlr (car (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))
|