core: rename 'start' to 'setup' - used only for creation and initial set-up (with name)

This commit is contained in:
Helmut Merz 2024-06-19 10:51:33 +02:00
parent 0eeabb4321
commit 978c3ee8bc
4 changed files with 15 additions and 15 deletions

View file

@ -5,8 +5,8 @@
(:local-nicknames (:config :scopes/config) (:local-nicknames (:config :scopes/config)
(:message :scopes/core/message)) (:message :scopes/core/message))
(:export #:root-config #:add-config #:add-action (:export #:root-config #:add-config #:add-action
#:default-start #:default-setup #:setup-services
#:context #:*root* #:setup #:find-service #:config #:name #:send #:context #:*root* #:find-service #:config #:name #:send
#:printer)) #:printer))
(in-package :scopes/core) (in-package :scopes/core)
@ -20,11 +20,11 @@
(defclass service-config (config:base) (defclass service-config (config:base)
((name :reader name :initarg :name) ((name :reader name :initarg :name)
(start :reader start :initarg :start :initform #'default-start) (setup :reader setup :initarg :setup :initform #'default-setup)
(actions :accessor actions :initarg :actions :initform nil))) (actions :accessor actions :initarg :actions :initform nil)))
(defun add-config (parent name start &rest actions) (defun add-config (parent name setup &rest actions)
(make-instance 'service-config :parent parent :name name :start start (make-instance 'service-config :parent parent :name name :setup setup
:actions actions)) :actions actions))
(defgeneric add-action (container pattern handler) (defgeneric add-action (container pattern handler)
@ -64,18 +64,19 @@
(defclass context () (defclass context ()
((config :reader config :initarg :config) ((config :reader config :initarg :config)
(name :reader name :initarg :name)
(actions :accessor actions :initform nil) (actions :accessor actions :initform nil)
(services :initform (make-hash-table)))) (services :initform (make-hash-table))))
(defun default-start (cfg &optional (cls 'context)) (defun default-setup (cfg &optional (cls 'context))
(make-instance cls :config cfg)) (make-instance cls :config cfg :name (name cfg)))
(defun find-service (name) (defun find-service (name)
(with-slots (services) *root* (with-slots (services) *root*
(when services (when services
(gethash name services)))) (gethash name services))))
(defun setup (cfg) (defun setup-services (cfg)
(setf *root* (make-instance 'context :config cfg)) (setf *root* (make-instance 'context :config cfg))
(dolist (c (config:children cfg)) (dolist (c (config:children cfg))
(add-service *root* c))) (add-service *root* c)))
@ -90,7 +91,7 @@
(defun add-service (ctx cfg) (defun add-service (ctx cfg)
(with-slots (services) ctx (with-slots (services) ctx
(let ((child (funcall (start cfg) cfg))) (let ((child (funcall (setup cfg) cfg)))
(dolist (a (actions cfg)) (dolist (a (actions cfg))
(add-action child (car a) (cadr a))) (add-action child (car a) (cadr a)))
(setf (gethash (name cfg) services) child)))) (setf (gethash (name cfg) services) child))))

View file

@ -4,5 +4,5 @@
(setf *config* (core:root-config)) (setf *config* (core:root-config))
(let ((cfg (core:add-config *config* :test-receiver #'start))) (let ((cfg (core:add-config *config* :test-receiver #'setup)))
(core:add-action cfg '(:test) #'check-message)) (core:add-action cfg '(:test) #'check-message))

View file

@ -4,7 +4,6 @@
(in-package :scopes/test-config) (in-package :scopes/test-config)
(setf *config* (setf *config* (make-instance 'test-config))
(make-instance 'test-config))
(make-instance 'child-config :parent *config*) (make-instance 'child-config :parent *config*)

View file

@ -21,8 +21,8 @@
((expected :accessor expected ((expected :accessor expected
:initform (make-hash-table :test #'equalp)))) :initform (make-hash-table :test #'equalp))))
(defun start (cfg) (defun setup (cfg)
(core:default-start cfg 'test-receiver)) (core:default-setup cfg 'test-receiver))
(defun check-message (ctx msg) (defun check-message (ctx msg)
(let ((key (message:head-as-list msg))) (let ((key (message:head-as-list msg)))
@ -53,7 +53,7 @@
(t:*test-suite* (make-instance 'test-suite :name "core"))) (t:*test-suite* (make-instance 'test-suite :name "core")))
(log4cl:log-config :sane :daily (t:test-path "scopes-test.log" "log")) (log4cl:log-config :sane :daily (t:test-path "scopes-test.log" "log"))
(load (t:test-path "config-core" "etc")) (load (t:test-path "config-core" "etc"))
(core:setup *config*) (core:setup-services *config*)
(setf (receiver t:*test-suite*) (core:find-service :test-receiver)) (setf (receiver t:*test-suite*) (core:find-service :test-receiver))
(test-send) (test-send)
(check-expected) (check-expected)